KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > Eval_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>Eval</code> is a wrapper for an expression in the context of
11  * a statement.
12  */

13 public class Eval_c extends Stmt_c implements Eval
14 {
15     protected Expr expr;
16
17     public Eval_c(Position pos, Expr expr) {
18     super(pos);
19     this.expr = expr;
20     }
21
22     /** Get the expression of the statement. */
23     public Expr expr() {
24     return this.expr;
25     }
26
27     /** Set the expression of the statement. */
28     public Eval expr(Expr expr) {
29     Eval_c n = (Eval_c) copy();
30     n.expr = expr;
31     return n;
32     }
33
34     /** Reconstruct the statement. */
35     protected Eval_c reconstruct(Expr expr) {
36     if (expr != this.expr) {
37         Eval_c n = (Eval_c) copy();
38         n.expr = expr;
39         return n;
40     }
41
42     return this;
43     }
44
45     public Type childExpectedType(Expr child, AscriptionVisitor av) {
46         TypeSystem ts = av.typeSystem();
47
48         if (child == expr) {
49             return ts.Void();
50         }
51
52         return child.type();
53     }
54
55     /** Visit the children of the statement. */
56     public Node visitChildren(NodeVisitor v) {
57     Expr expr = (Expr) visitChild(this.expr, v);
58     return reconstruct(expr);
59     }
60
61     public String JavaDoc toString() {
62     return "eval(" + expr.toString() + ");";
63     }
64
65     /** Write the statement to an output file. */
66     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
67     boolean semi = tr.appendSemicolon(true);
68
69     print(expr, w, tr);
70
71     if (semi) {
72         w.write(";");
73     }
74
75     tr.appendSemicolon(semi);
76     }
77
78     public Term entry() {
79         return expr.entry();
80     }
81
82     public List acceptCFG(CFGBuilder v, List succs) {
83         v.visitCFG(expr, this);
84         return succs;
85     }
86 }
87
Popular Tags