KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ast > Node


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

16 public interface Node extends JL, Copy
17 {
18     /**
19      * Set the delegate of the node.
20      */

21     Node del(JL del);
22
23     /**
24      * Get the node's delegate.
25      */

26     JL del();
27
28     /**
29      * Set the extension of the node.
30      */

31     Node ext(Ext ext);
32
33     /**
34      * Get the node's extension.
35      */

36     Ext ext();
37
38     /**
39      * Set the node's nth extension, n &gt;= 1.
40      */

41     Node ext(int n, Ext ext);
42
43     /**
44      * Get the node's nth extension, n &gt;= 1.
45      */

46     Ext ext(int n);
47
48     /**
49      * Get the position of the node in the source file. Returns null if
50      * the position is not set.
51      */

52     Position position();
53
54     /** Create a copy of the node with a new position. */
55     Node position(Position position);
56
57     /**
58      * Visit the node. This method is equivalent to
59      * <code>visitEdge(null, v)</code>.
60      *
61      * @param v The visitor which will traverse/rewrite the AST.
62      * @return A new AST if a change was made, or <code>this</code>.
63      */

64     Node visit(NodeVisitor v);
65
66     /**
67      * Visit the node, passing in the node's parent. This method is called by
68      * a <code>NodeVisitor</code> to traverse the AST starting at this node.
69      * This method should call the <code>override</code>, <code>enter</code>,
70      * and <code>leave<code> methods of the visitor. The method may return a
71      * new version of the node.
72      *
73      * @param parent The parent of <code>this</code> in the AST.
74      * @param v The visitor which will traverse/rewrite the AST.
75      * @return A new AST if a change was made, or <code>this</code>.
76      */

77     Node visitEdge(Node parent, NodeVisitor v);
78
79     /**
80      * Visit a single child of the node.
81      *
82      * @param v The visitor which will traverse/rewrite the AST.
83      * @param child The child to visit.
84      * @return The result of <code>child.visit(v)</code>, or <code>null</code>
85      * if <code>child</code> was <code>null</code>.
86      */

87     Node visitChild(Node child, NodeVisitor v);
88
89     /**
90      * Visit all the elements of a list.
91      * @param l The list to visit.
92      * @param v The visitor to use.
93      * @return A new list with each element from the old list
94      * replaced by the result of visiting that element.
95      * If <code>l</code> is a <code>TypedList</code>, the
96      * new list will also be typed with the same type as
97      * <code>l</code>. If <code>l</code> is <code>null</code>,
98      * <code>null</code> is returned.
99      */

100     public List JavaDoc visitList(List JavaDoc l, NodeVisitor v);
101
102     /**
103      * Get the expected type of a child expression of <code>this</code>.
104      * The expected type is determined by the context in that the child occurs
105      * (e.g., for <code>x = e</code>, the expected type of <code>e</code> is
106      * the declared type of <code>x</code>.
107      *
108      * The expected type should impose the least constraints on the child's
109      * type that are allowed by the parent node.
110      *
111      * @param child A child expression of this node.
112      * @param av An ascription visitor.
113      * @return The expected type of <code>child</code>.
114      */

115     Type childExpectedType(Expr child, AscriptionVisitor av);
116
117     /**
118      * Dump the AST node for debugging purposes.
119      */

120     void dump(CodeWriter w);
121 }
122
Popular Tags