KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > extension > LocalDeclExt_c


1 package polyglot.ext.coffer.extension;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.util.*;
6 import polyglot.visit.*;
7 import polyglot.ext.jl.ast.*;
8 import polyglot.ext.coffer.ast.*;
9 import polyglot.ext.coffer.types.*;
10
11 import java.util.*;
12
13 public class LocalDeclExt_c extends CofferExt_c {
14     public KeySet keyFlow(KeySet held_keys, Type throwType) {
15         LocalDecl n = (LocalDecl) node();
16         return super.keyFlow(held_keys, throwType);
17     }
18
19     public KeySet keyAlias(KeySet stored_keys, Type throwType) {
20         LocalDecl n = (LocalDecl) node();
21
22         if (n.init() != null && n.init().type() instanceof CofferClassType) {
23             CofferClassType t = (CofferClassType) n.init().type();
24
25             if (t.key() != null) {
26                 return stored_keys.add(t.key());
27             }
28         }
29
30         return stored_keys;
31     }
32
33     public void checkHeldKeys(KeySet held, KeySet stored) throws SemanticException {
34         LocalDecl n = (LocalDecl) node();
35
36         if (n.init() != null && n.init().type() instanceof CofferClassType) {
37             CofferClassType t = (CofferClassType) n.init().type();
38
39             if (t.key() != null && ! held.contains(t.key())) {
40                 throw new SemanticException("Cannot assign tracked value unless key \"" + t.key() + "\" held.", n.position());
41             }
42
43             if (t.key() != null && stored.contains(t.key())) {
44                 throw new SemanticException("Cannot assign tracked value with key \"" + t.key() + "\" more than once.", n.position());
45             }
46         }
47     }
48 }
49
Popular Tags