/// <summary> /// Returns a copy of the specified AST Node instance. The copy is obtained by /// using the <see cref="ICloneable"/> method Clone(). /// </summary> /// <param name="t">AST Node to copy.</param> /// <returns>An AST Node (or null if <c>t</c> is null).</returns> public virtual AST dup(AST t) { // The Java version is implemented using code like this: if (t == null) { return(null); } AST dup_edNode = createFromNodeTypeObject(t.GetType()); dup_edNode.initialize(t); return(dup_edNode); //return (AST)((t == null) ? null : t.Clone()); }
/// <summary> /// Creates and initializes a new AST node using the specified AST Node instance. /// the new AST node is initialized with the specified Token type ID and string. /// The <see cref="System.Type"/> used for creating this new AST node is /// determined solely by <c>aNode</c>. /// The AST Node type must have a default/parameterless constructor. /// </summary> /// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param> /// <returns>An initialized AST node object.</returns> public virtual AST create(AST aNode) { AST newNode; if (aNode == null) { newNode = null; } else { newNode = createFromNodeTypeObject(aNode.GetType()); newNode.initialize(aNode); } return(newNode); }
protected bool checkNode(AST t, Type typ, int tokenType) { if (t == null) { return(false); } if (t.GetType() != typ) { return(false); } if (t.Type != tokenType) { return(false); } return(true); }
/** Is t an exact structural match of this tree with the same node * types? 'self' is considered the start of a sibling list. */ protected bool equalsNodeTypesList(AST self, AST t) { // Console.Out.WriteLine("self="+self+", t="+t); // Console.Out.WriteLine("self.class="+self.getClass()+", t.class="+t.getClass()); AST sibling; // the empty tree is not a match of any non-null tree. if (t == null) { return(false); } // Otherwise, start walking sibling lists. First mismatch, return false. for (sibling = self; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling()) { // Console.Out.WriteLine("sibling="+sibling+", t="+t); // as a quick optimization, check root types first. if (sibling.GetType() != t.GetType()) { return(false); } // if roots match, do full list match test on children. if (sibling.getFirstChild() != null) { if (!equalsNodeTypesList(sibling.getFirstChild(), t.getFirstChild())) { return(false); } } // sibling has no kids, make sure t doesn't either else if (t.getFirstChild() != null) { return(false); } } if (sibling == null && t == null) { return(true); } // one sibling list has more than the other return(false); }
private AST createFromAST(AST node) { AST newNode = null; Type nodeAsTypeObj = node.GetType(); ASTNodeCreator creator = (ASTNodeCreator)typename2creator_[nodeAsTypeObj.FullName]; if (creator != null) { newNode = creator.Create(); if (newNode == null) { throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'"); } } else { newNode = createFromNodeTypeObject(nodeAsTypeObj); } return(newNode); }
/// <summary> /// Returns a copy of the specified AST Node instance. The copy is obtained by /// using the <see cref="ICloneable"/> method Clone(). /// </summary> /// <param name="t">AST Node to copy.</param> /// <returns>An AST Node (or null if <c>t</c> is null).</returns> public virtual AST dup(AST t) { // The Java version is implemented using code like this: if (t == null) return null; AST dup_edNode = createFromNodeTypeObject(t.GetType()); dup_edNode.initialize(t); return dup_edNode; //return (AST)((t == null) ? null : t.Clone()); }
/// <summary> /// Creates and initializes a new AST node using the specified AST Node instance. /// the new AST node is initialized with the specified Token type ID and string. /// The <see cref="System.Type"/> used for creating this new AST node is /// determined solely by <c>aNode</c>. /// The AST Node type must have a default/parameterless constructor. /// </summary> /// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param> /// <returns>An initialized AST node object.</returns> public virtual AST create(AST aNode) { AST newNode; if (aNode == null) newNode = null; else { newNode = createFromNodeTypeObject(aNode.GetType()); newNode.initialize(aNode); } return newNode; }
/** Is t an exact structural match of this tree with the same node * types? 'self' is considered the start of a sibling list. */ protected bool equalsNodeTypesList(AST self, AST t) { // Console.Out.WriteLine("self="+self+", t="+t); // Console.Out.WriteLine("self.class="+self.getClass()+", t.class="+t.getClass()); AST sibling; // the empty tree is not a match of any non-null tree. if (t == null) { return false; } // Otherwise, start walking sibling lists. First mismatch, return false. for (sibling = self; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling()) { // Console.Out.WriteLine("sibling="+sibling+", t="+t); // as a quick optimization, check root types first. if ( sibling.GetType()!=t.GetType() ) { return false; } // if roots match, do full list match test on children. if (sibling.getFirstChild() != null) { if (!equalsNodeTypesList(sibling.getFirstChild(), t.getFirstChild())) { return false; } } // sibling has no kids, make sure t doesn't either else if (t.getFirstChild() != null) { return false; } } if (sibling == null && t == null) { return true; } // one sibling list has more than the other return false; }
protected bool checkNode(AST t, Type typ, int tokenType) { if ( t==null ) { return false; } if ( t.GetType()!=typ ) { return false; } if ( t.Type!=tokenType ) { return false; } return true; }
private AST createFromAST(AST node) { AST newNode = null; Type nodeAsTypeObj = node.GetType(); ASTNodeCreator creator = (ASTNodeCreator) typename2creator_[nodeAsTypeObj.FullName]; if (creator != null) { newNode = creator.Create(); if (newNode == null) { throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'"); } } else { newNode = createFromNodeTypeObject(nodeAsTypeObj); } return newNode; }