/* * This file is part of the X10 project (http://x10-lang.org). * * This file is licensed to You under the Eclipse Public License (EPL); * You may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.opensource.org/licenses/eclipse-1.0.php * * This file was originally derived from the Polyglot extensible compiler framework. * * (C) Copyright 2000-2007 Polyglot project group, Cornell University * (C) Copyright IBM Corporation 2007-2012. */ package polyglot.ast; import java.util.List; import polyglot.types.Type; import polyglot.util.*; import polyglot.visit.NodeVisitor; /** * A <code>Node</code> represents an AST node. All AST nodes must implement * this interface. Nodes should be immutable: methods which set fields * of the node should copy the node, set the field in the copy, and then * return the copy. */ public interface Node extends JL, Copy { /** * Set the delegate of the node. */ Node del(JL del); /** * Get the node's delegate. */ JL del(); /** * Set the extension of the node. */ Node ext(Ext ext); /** * Get the node's extension. */ Ext ext(); /** * Set the node's nth extension, n >= 1. */ Node ext(int n, Ext ext); /** * Get the node's nth extension, n >= 1. */ Ext ext(int n); /** * Get the position of the node in the source file. Returns null if * the position is not set. */ Position position(); /** Create a copy of the node with a new position. */ Node position(Position position); /** Return true if there an error in this node or its children. */ boolean error(); Node error(boolean flag); /** * Visit the node. This method is equivalent to * <code>visitEdge(null, v)</code>. * * @param v The visitor which will traverse/rewrite the AST. * @return A new AST if a change was made, or <code>this</code>. */ Node visit(NodeVisitor v); /** * Visit the node, passing in the node's parent. This method is called by * a <code>NodeVisitor</code> to traverse the AST starting at this node. * This method should call the <code>override</code>, <code>enter</code>, * and <code>leave<code> methods of the visitor. The method may return a * new version of the node. * * @param parent The parent of <code>this</code> in the AST. * @param v The visitor which will traverse/rewrite the AST. * @return A new AST if a change was made, or <code>this</code>. * * @deprecated Call {@link Node#visitChild(Node, NodeVisitor)} instead. */ Node visitEdge(Node parent, NodeVisitor v); /** * Visit a single child of the node. * * @param v The visitor which will traverse/rewrite the AST. * @param child The child to visit. * @return The result of <code>child.visit(v)</code>, or <code>null</code> * if <code>child</code> was <code>null</code>. */ Node visitChild(Node child, NodeVisitor v); /** * Visit all the elements of a list. * @param l The list to visit. * @param v The visitor to use. * @return A new list with each element from the old list * replaced by the result of visiting that element. * If <code>l</code> is a <code>TypedList</code>, the * new list will also be typed with the same type as * <code>l</code>. If <code>l</code> is <code>null</code>, * <code>null</code> is returned. */ public <T extends Node> List<T> visitList(List<T> l, NodeVisitor v); /** * Dump the AST node for debugging purposes. */ void dump(CodeWriter w); }