1 package polyglot.visit; 2 3 import polyglot.ast.Node; 4 import polyglot.util.InternalCompilerError; 5 6 22 public abstract class NodeVisitor 23 { 24 44 public Node override(Node parent, Node n) { 45 return override(n); 46 } 47 48 67 public Node override(Node n) { 68 return null; 69 } 70 71 85 public NodeVisitor enter(Node parent, Node n) { 86 return enter(n); 87 } 88 89 103 public NodeVisitor enter(Node n) { 104 return this; 105 } 106 107 133 public Node leave(Node parent, Node old, Node n, NodeVisitor v) { 134 return leave(old, n, v); 135 } 136 137 162 public Node leave(Node old, Node n, NodeVisitor v) { 163 return n; 164 } 165 166 175 public NodeVisitor begin() { 176 return this; 177 } 178 179 184 public void finish() { } 185 public void finish(Node ast) { this.finish(); } 186 187 public String toString() { 188 return getClass().getName(); 189 } 190 191 205 public Node visitEdge(Node parent, Node child) { 206 Node n = override(parent, child); 207 208 if (n == null) { 209 NodeVisitor v_ = this.enter(parent, child); 210 211 if (v_ == null) { 212 throw new InternalCompilerError( 213 "NodeVisitor.enter() returned null."); 214 } 215 216 n = child.visitChildren(v_); 217 218 if (n == null) { 219 throw new InternalCompilerError( 220 "Node_c.visitChildren() returned null."); 221 } 222 223 n = this.leave(parent, child, n, v_); 224 225 if (n == null) { 226 throw new InternalCompilerError( 227 "NodeVisitor.leave() returned null."); 228 } 229 } 230 231 return n; 232 } 233 } 234 | Popular Tags |