KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > AmbExpr_c


1 package polyglot.ext.jl.ast;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.visit.*;
6 import polyglot.util.*;
7 import java.util.*;
8
9 /**
10  * An <code>AmbExpr</code> is an ambiguous AST node composed of a single
11  * identifier that must resolve to an expression.
12  */

13 public class AmbExpr_c extends Expr_c implements AmbExpr
14 {
15   protected String JavaDoc name;
16
17   public AmbExpr_c(Position pos, String JavaDoc name) {
18     super(pos);
19     this.name = name;
20   }
21
22   /** Get the precedence of the field. */
23   public Precedence precedence() {
24     return Precedence.LITERAL;
25   }
26
27   /** Get the name of the expression. */
28   public String JavaDoc name() {
29     return this.name;
30   }
31
32   /** Set the name of the expression. */
33   public AmbExpr name(String JavaDoc name) {
34     AmbExpr_c n = (AmbExpr_c) copy();
35     n.name = name;
36     return n;
37   }
38
39   /** Disambiguate the expression. */
40   public Node disambiguate(AmbiguityRemover ar) throws SemanticException {
41     Node n = ar.nodeFactory().disamb().disambiguate(this, ar, position(),
42                                                     null, name);
43
44     if (n instanceof Expr) {
45       return n;
46     }
47
48     throw new SemanticException("Could not find field or local " +
49                                 "variable \"" + name + "\".", position());
50   }
51
52   /** Type check the expression. */
53   public Node typeCheck(TypeChecker tc) throws SemanticException {
54     throw new InternalCompilerError(position(),
55                                     "Cannot type check ambiguous node "
56                                     + this + ".");
57   }
58
59   /** Check exceptions thrown by the expression. */
60   public Node exceptionCheck(ExceptionChecker ec) throws SemanticException {
61     throw new InternalCompilerError(position(),
62                                     "Cannot exception check ambiguous node "
63                                     + this + ".");
64   }
65
66   /** Write the expression to an output file. */
67   public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
68     w.write(name);
69   }
70
71   public void translate(CodeWriter w, Translator tr) {
72     throw new InternalCompilerError(position(),
73                                     "Cannot translate ambiguous node "
74                                     + this + ".");
75   }
76
77   public String JavaDoc toString() {
78     return name + "{amb}";
79   }
80
81   /**
82    * Return the first (sub)term performed when evaluating this
83    * term.
84    */

85   public Term entry() {
86       return this;
87   }
88
89   /**
90    * Visit this term in evaluation order.
91    */

92   public List acceptCFG(CFGBuilder v, List succs) {
93       return succs;
94   }
95
96   public void dump(CodeWriter w) {
97     super.dump(w);
98     w.allowBreak(4, " ");
99     w.begin(0);
100     w.write("(name \"" + name + "\")");
101     w.end();
102   }
103 }
104
Popular Tags