KickJava   Java API By Example, From Geeks To Geeks.

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


1 package polyglot.ext.coffer.ast;
2
3 import polyglot.ast.*;
4 import polyglot.ext.jl.ast.*;
5 import polyglot.ext.coffer.types.*;
6 import polyglot.types.*;
7 import polyglot.util.*;
8 import polyglot.visit.*;
9 import java.util.*;
10
11 /**
12  * This statement revokes the key associated with a tracked expression.
13  * The expression cannot be evaluated after this statement executes.
14  */

15 public class Free_c extends Stmt_c implements Free
16 {
17     protected Expr expr;
18
19     public Free_c(Position pos, Expr expr) {
20         super(pos);
21         this.expr = expr;
22     }
23
24     public Expr expr() {
25         return expr;
26     }
27
28     public Free expr(Expr expr) {
29         Free_c n = (Free_c) copy();
30         n.expr = expr;
31         return n;
32     }
33
34     public Free_c reconstruct(Expr expr) {
35         if (this.expr != expr) {
36             Free_c n = (Free_c) copy();
37             n.expr = expr;
38             return n;
39         }
40         return this;
41     }
42
43     public Node visitChildren(NodeVisitor v) {
44         Expr expr = (Expr) visitChild(this.expr, v);
45         return reconstruct(expr);
46     }
47
48     public Node typeCheck(TypeChecker tc) throws SemanticException {
49         CofferContext c = (CofferContext) tc.context();
50
51         Type t = expr.type();
52
53         if (! (t instanceof CofferClassType)) {
54             throw new SemanticException("Cannot free expression of non-tracked type \"" + t + "\".", position());
55         }
56
57         return this;
58     }
59
60     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
61         w.write("free ");
62         print(expr, w, tr);
63         w.write(";");
64     }
65
66     public void translate(CodeWriter w, Translator tr) {
67         w.write(";");
68     }
69
70     public String JavaDoc toString() {
71         return "free " + expr + ";";
72     }
73
74     public Term entry() {
75         return expr.entry();
76     }
77
78     public List acceptCFG(CFGBuilder v, List succs) {
79         v.visitCFG(expr, this);
80         return succs;
81     }
82 }
83
Popular Tags