public override bool ReplaceChild(AstNode oldNode, AstNode newNode) { // if the old node isn't our element list, ignore the cal if (oldNode == Elements) { if (newNode == null) { // we want to remove the list altogether Elements = null; return(true); } else { // if the new node isn't an AstNodeList, then ignore the call AstNodeList newList = newNode as AstNodeList; if (newList != null) { // replace it Elements = newList; return(true); } } } return(false); }
public override void Visit(AstNodeList node) { if (node != null && node.Count > 0) { // this is really only ever not-ed when it's the right-hand operand // of a comma operator, which we flattened to decrease stack recursion. // so to logical-not this element, we only need to not the last item // in the list (because all the others are comma-separated) node[node.Count - 1].Accept(this); } }
public void Visit(AstNodeList node) { if (node != null) { // don't bother setting the order of the list itself, just the items for (var ndx = 0; ndx < node.Count; ++ndx) { var item = node[ndx]; if (item != null) { item.Accept(this); } } } }
public void Visit(AstNodeList node) { if (node != null) { for (var ndx = 0; ndx < node.Count; ++ndx) { if (ndx > 0) { m_writer.Write(','); } if (node[ndx] != null) { node[ndx].Accept(this); } } } }
public override bool ReplaceChild(AstNode oldNode, AstNode newNode) { if (Expression == oldNode) { Expression = newNode; return(true); } if (Cases == oldNode) { AstNodeList newList = newNode as AstNodeList; if (newNode == null || newList != null) { // remove it Cases = newList; return(true); } } return(false); }
/// <summary> /// an astlist is equivalent to another astlist if they both have the same number of /// items, and each item is equivalent to the corresponding item in the other /// </summary> /// <param name="otherNode"></param> /// <returns></returns> public override bool IsEquivalentTo(AstNode otherNode) { bool isEquivalent = false; AstNodeList otherList = otherNode as AstNodeList; if (otherList != null && m_list.Count == otherList.Count) { // now assume it's true unless we come across an item that ISN'T // equivalent, at which case we'll bail the test. isEquivalent = true; for (var ndx = 0; ndx < m_list.Count; ++ndx) { if (!m_list[ndx].IsEquivalentTo(otherList[ndx])) { isEquivalent = false; break; } } } return(isEquivalent); }
public static AstNode CombineWithComma(Context context, JSParser parser, AstNode operand1, AstNode operand2) { var comma = new CommaOperator(context, parser) { OperatorToken = JSToken.Comma }; // if the left is a comma-operator already.... var leftBinary = operand1 as BinaryOperator; var rightBinary = operand2 as BinaryOperator; if (leftBinary != null && leftBinary.OperatorToken == JSToken.Comma) { // the left-hand side is already a comma operator. Instead of nesting these, we're // going to combine them // move the old list's left-hand side to our left-hand side comma.Operand1 = leftBinary.Operand1; AstNodeList list; if (rightBinary != null && rightBinary.OperatorToken == JSToken.Comma) { // the right is ALSO a comma operator. Create a new list, append all the rest of the operands // and set our right-hand side to be the list list = new AstNodeList(null, parser); list.Append(leftBinary.Operand2).Append(rightBinary.Operand1).Append(rightBinary.Operand2); } else { // the right is not a comma operator. // see if the left-hand side already has a list we can use list = leftBinary.Operand2 as AstNodeList; if (list == null) { // it's not a list already // create a new list with the left's right and our right and set it to our right list = new AstNodeList(null, parser); list.Append(leftBinary.Operand2); } // and add our right-hand operand to the end of the list list.Append(operand2); } // set the list on the right comma.Operand2 = list; } else if (rightBinary != null && rightBinary.OperatorToken == JSToken.Comma) { // the left hand side is NOT a comma operator. comma.Operand1 = operand1; // the right-hand side is already a comma-operator, but the left is not. // see if it already has a list we can reuse var rightList = rightBinary.Operand2 as AstNodeList; if (rightList != null) { // it does. Prepend its right-hand operand and use the list rightList.Insert(0, rightBinary.Operand1); } else { // it's not -- create a new list containing the operands rightList = new AstNodeList(rightBinary.Context, parser); rightList.Append(rightBinary.Operand1); rightList.Append(rightBinary.Operand2); } comma.Operand2 = rightList; } else { comma.Operand1 = operand1; comma.Operand2 = operand2; } return(comma); }
// // expression elements we shouldn't get to // public void Visit(AstNodeList node) { Debug.Fail("shouldn't get here"); }
public void Visit(AstNodeList node) { // not applicable; terminate }