KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > ast > KeyNode_c


1 package polyglot.ext.coffer.ast;
2
3 import polyglot.ext.jl.ast.*;
4 import polyglot.ext.coffer.types.*;
5 import polyglot.ast.*;
6 import polyglot.types.*;
7 import polyglot.visit.*;
8 import polyglot.util.*;
9
10 /**
11  * An AST node for a <code>Key</code>. The key may be ambiguous.
12  */

13 public class KeyNode_c extends Node_c implements KeyNode
14 {
15     protected Key key;
16
17     public KeyNode_c(Position pos, Key key) {
18         super(pos);
19         this.key = key;
20     }
21
22     public String JavaDoc name() {
23         return key.name();
24     }
25
26     public Key key() {
27         return key;
28     }
29
30     public KeyNode key(Key key) {
31         KeyNode_c n = (KeyNode_c) copy();
32         n.key = key;
33         return n;
34     }
35
36     public Node disambiguate(AmbiguityRemover sc) throws SemanticException {
37         CofferTypeSystem ts = (CofferTypeSystem) sc.typeSystem();
38
39         Key key = this.key;
40
41         if (! key.isCanonical()) {
42             CofferContext c = (CofferContext) sc.context();
43
44             try {
45                 key = c.findKey(key.name());
46             }
47             catch (SemanticException e) {
48                 if (c.inCode()) {
49                     key = ts.instKey(key.position(), key.name());
50                 }
51                 else {
52                     throw e;
53                 }
54             }
55         }
56
57         if (! key.isCanonical()) {
58             throw new SemanticException("Could not disambiguate key \"" +
59                                         key + "\".", position());
60         }
61
62         return this.key(key);
63     }
64
65     public void addDecls(Context c) {
66         CofferContext vc = (CofferContext) c;
67         if (key.isCanonical()) {
68             vc.addKey(key);
69         }
70     }
71
72     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
73         w.write(key.toString());
74     }
75
76     public void translate(CodeWriter w, Translator tr) {
77     throw new InternalCompilerError(position(),
78         "Cannot translate key \"" + key + "\".");
79     }
80
81     public String JavaDoc toString() {
82         return key.toString();
83     }
84 }
85
Popular Tags