KickJava   Java API By Example, From Geeks To Geeks.

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


1 package polyglot.ext.jl.ast;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.util.*;
6 import polyglot.visit.*;
7 import polyglot.frontend.*;
8 import java.util.*;
9
10 /**
11  * A local class declaration statement. The node is just a wrapper around
12  * a class declaration.
13  */

14 public class LocalClassDecl_c extends Stmt_c implements LocalClassDecl
15 {
16     protected ClassDecl decl;
17
18     public LocalClassDecl_c(Position pos, ClassDecl decl) {
19     super(pos);
20     this.decl = decl;
21     }
22
23     /** Get the class declaration. */
24     public ClassDecl decl() {
25     return this.decl;
26     }
27
28     /** Set the class declaration. */
29     public LocalClassDecl decl(ClassDecl decl) {
30     LocalClassDecl_c n = (LocalClassDecl_c) copy();
31     n.decl = decl;
32     return n;
33     }
34
35     /** Reconstruct the statement. */
36     protected LocalClassDecl_c reconstruct(ClassDecl decl) {
37         if (decl != this.decl) {
38         LocalClassDecl_c n = (LocalClassDecl_c) copy();
39         n.decl = decl;
40         return n;
41     }
42
43     return this;
44     }
45
46     /**
47      * Return the first (sub)term performed when evaluating this
48      * term.
49      */

50     public Term entry() {
51         return this.decl().entry();
52     }
53
54     /**
55      * Visit this term in evaluation order.
56      */

57     public List acceptCFG(CFGBuilder v, List succs) {
58         v.visitCFG(this.decl(), this);
59         return succs;
60     }
61
62     /** Visit the children of the statement. */
63     public Node visitChildren(NodeVisitor v) {
64         ClassDecl decl = (ClassDecl) visitChild(this.decl, v);
65         return reconstruct(decl);
66     }
67
68     public void addDecls(Context c) {
69         // We should now be back in the scope of the enclosing block.
70
// Add the type.
71
if (! decl.type().toClass().isLocal())
72             throw new InternalCompilerError("Non-local " + decl.type() +
73                                             " found in method body.");
74         c.addNamed(decl.type().toClass());
75     }
76
77     public NodeVisitor disambiguateEnter(AmbiguityRemover ar) throws SemanticException {
78         return ar.bypassChildren(this);
79     }
80
81     public Node disambiguate(AmbiguityRemover ar) throws SemanticException {
82         if (ar.kind() == AmbiguityRemover.ALL) {
83             Job sj = ar.job().spawn(ar.context(), decl,
84                                     Pass.CLEAN_SUPER, Pass.ADD_MEMBERS_ALL);
85
86             if (! sj.status()) {
87                 if (! sj.reportedErrors()) {
88                     throw new SemanticException("Could not disambiguate local " +
89                                                 "class \"" + decl.name() + "\".",
90                                                 position());
91                 }
92                 throw new SemanticException();
93             }
94
95             ClassDecl d = (ClassDecl) sj.ast();
96             LocalClassDecl n = decl(d);
97             return n.visitChildren(ar);
98         }
99
100         return this;
101     }
102
103     public String JavaDoc toString() {
104     return decl.toString();
105     }
106
107     /** Write the statement to an output file. */
108     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
109         printBlock(decl, w, tr);
110     w.write(";");
111     }
112 }
113
Popular Tags