KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ast > NodeOps


1 package polyglot.ast;
2
3 import java.util.List JavaDoc;
4
5 import polyglot.util.CodeWriter;
6 import polyglot.types.SemanticException;
7 import polyglot.types.Context;
8 import polyglot.types.TypeSystem;
9 import polyglot.visit.*;
10
11 /**
12  * A <code>Node</code> represents an AST node. All AST nodes must implement
13  * this interface. Nodes should be immutable: methods which set fields
14  * of the node should copy the node, set the field in the copy, and then
15  * return the copy.
16  */

17 public interface NodeOps
18 {
19     /**
20      * Visit the children of the node.
21      *
22      * @param v The visitor that will traverse/rewrite the AST.
23      * @return A new AST if a change was made, or <code>this</code>.
24      */

25     Node visitChildren(NodeVisitor v);
26
27     /**
28      * Push a new scope upon entering this node, and add any declarations to the
29      * context that should be in scope when visiting children of this node.
30      * This should <i>not</i> update the old context
31      * imperatively. Use <code>addDecls</code> when leaving the node
32      * for that.
33      *
34      * @param c the current <code>Context</code>
35      * @return the <code>Context</code> to be used for visiting this node.
36      */

37     public Context enterScope(Context c);
38
39     /**
40      * Push a new scope for visiting the child node <code>child</code>.
41      * The default behavior is to delegate the call to the child node, and let
42      * it add appropriate declarations that should be in scope. However,
43      * this method gives parent nodes have the ability to modify this behavior.
44      *
45      * @param child the child node about to be entered.
46      * @param c the current <code>Context</code>
47      * @return the <code>Context</code> to be used for visiting node
48      * <code>child</code>
49      */

50     public Context enterScope(Node child, Context c);
51
52     /**
53      * Add any declarations to the context that should be in scope when
54      * visiting later sibling nodes.
55      *
56      * @param c The context to which to add declarations.
57      */

58     void addDecls(Context c);
59
60     /**
61      * Collects classes, methods, and fields from the AST rooted at this node
62      * and constructs type objects for these. These type objects may be
63      * ambiguous. Inserts classes into the <code>TypeSystem</code>.
64      *
65      * This method is called by the <code>enter()</code> method of the
66      * visitor. The * method should perform work that should be done
67      * before visiting the children of the node. The method may return
68      * <code>this</code> or a new copy of the node on which
69      * <code>visitChildren()</code> and <code>leave()</code> will be
70      * invoked.
71      *
72      * @param tb The visitor which adds new type objects to the
73      * <code>TypeSystem</code>.
74      */

75     NodeVisitor buildTypesEnter(TypeBuilder tb) throws SemanticException;
76
77     /**
78      * Collects classes, methods, and fields from the AST rooted at this node
79      * and constructs type objects for these. These type objects may be
80      * ambiguous. Inserts classes into the <code>TypeSystem</code>.
81      *
82      * This method is called by the <code>leave()</code> method of the
83      * visitor. The method should perform work that should be done
84      * after visiting the children of the node. The method may return
85      * <code>this</code> or a new copy of the node which will be
86      * installed as a child of the node's parent.
87      *
88      * @param tb The visitor which adds new type objects to the
89      * <code>TypeSystem</code>.
90      */

91     Node buildTypes(TypeBuilder tb) throws SemanticException;
92
93     /**
94      * Remove any remaining ambiguities from the AST.
95      *
96      * This method is called by the <code>enter()</code> method of the
97      * visitor. The * method should perform work that should be done
98      * before visiting the children of the node. The method may return
99      * <code>this</code> or a new copy of the node on which
100      * <code>visitChildren()</code> and <code>leave()</code> will be
101      * invoked.
102      *
103      * @param ar The visitor which disambiguates.
104      */

105     NodeVisitor disambiguateEnter(AmbiguityRemover ar) throws SemanticException;
106
107     /**
108      * Remove any remaining ambiguities from the AST.
109      *
110      * This method is called by the <code>leave()</code> method of the
111      * visitor. The method should perform work that should be done
112      * after visiting the children of the node. The method may return
113      * <code>this</code> or a new copy of the node which will be
114      * installed as a child of the node's parent.
115      *
116      * @param ar The visitor which disambiguates.
117      */

118     Node disambiguate(AmbiguityRemover ar) throws SemanticException;
119
120     /**
121      * Adds disambiguated methods and fields to the types.
122      *
123      * This method is called by the <code>enter()</code> method of the
124      * visitor. The * method should perform work that should be done
125      * before visiting the children of the node. The method may return
126      * <code>this</code> or a new copy of the node on which
127      * <code>visitChildren()</code> and <code>leave()</code> will be
128      * invoked.
129      *
130      * @param am The visitor which builds types.
131      */

132     NodeVisitor addMembersEnter(AddMemberVisitor am) throws SemanticException;
133
134     /**
135      * Adds disambiguated methods and fields to the types.
136      *
137      * This method is called by the <code>leave()</code> method of the
138      * visitor. The method should perform work that should be done
139      * after visiting the children of the node. The method may return
140      * <code>this</code> or a new copy of the node which will be
141      * installed as a child of the node's parent.
142      *
143      * @param am The visitor which builds types.
144      */

145     Node addMembers(AddMemberVisitor am) throws SemanticException;
146
147     /**
148      * Type check the AST.
149      *
150      * This method is called by the <code>enter()</code> method of the
151      * visitor. The * method should perform work that should be done
152      * before visiting the children of the node. The method may return
153      * <code>this</code> or a new copy of the node on which
154      * <code>visitChildren()</code> and <code>leave()</code> will be
155      * invoked.
156      *
157      * @param tc The type checking visitor.
158      */

159     NodeVisitor typeCheckEnter(TypeChecker tc) throws SemanticException;
160
161     /**
162      * Type check the AST.
163      *
164      * This method is called by the <code>leave()</code> method of the
165      * visitor. The method should perform work that should be done
166      * after visiting the children of the node. The method may return
167      * <code>this</code> or a new copy of the node which will be
168      * installed as a child of the node's parent.
169      *
170      * @param tc The type checking visitor.
171      */

172     Node typeCheck(TypeChecker tc) throws SemanticException;
173
174     /**
175      * Check that exceptions are properly propagated throughout the AST.
176      *
177      * This method is called by the <code>enter()</code> method of the
178      * visitor. The * method should perform work that should be done
179      * before visiting the children of the node. The method may return
180      * <code>this</code> or a new copy of the node on which
181      * <code>visitChildren()</code> and <code>leave()</code> will be
182      * invoked.
183      *
184      * @param ec The visitor.
185      */

186     NodeVisitor exceptionCheckEnter(ExceptionChecker ec) throws SemanticException;
187
188     /**
189      * Check that exceptions are properly propagated throughout the AST.
190      *
191      * This method is called by the <code>leave()</code> method of the
192      * visitor. The method should perform work that should be done
193      * after visiting the children of the node. The method may return
194      * <code>this</code> or a new copy of the node which will be
195      * installed as a child of the node's parent.
196      *
197      * @param ec The visitor.
198      */

199     Node exceptionCheck(ExceptionChecker ec) throws SemanticException;
200
201     /**
202      * List of Types of exceptions that might get thrown. The result is
203      * not necessarily correct until after type checking.
204      */

205     List JavaDoc throwTypes(TypeSystem ts);
206
207     /**
208      * Pretty-print the AST using the given code writer.
209      *
210      * @param w The code writer to which to write.
211      * @param pp The pretty printer. This is <i>not</i> a visitor.
212      */

213     void prettyPrint(CodeWriter w, PrettyPrinter pp);
214
215     /**
216      * Translate the AST using the given code writer.
217      *
218      * @param w The code writer to which to write.
219      * @param tr The translation pass. This is <i>not</i> a visitor.
220      */

221     void translate(CodeWriter w, Translator tr);
222 }
223
Popular Tags