Beispiel #1
0
 public virtual void PostWalk(CommaOperator node) { }
 public override bool Walk(CommaOperator node)
 {
     AddNode(node); return(true);
 }
Beispiel #3
0
 public virtual bool Walk(CommaOperator node) { return true; }
        private static AstNode CreateSplitNodeFromEnd(AstNodeList nodeList, int ndx)
        {
            AstNode newNode;

            if (ndx == nodeList.Count - 1)
            {
                // the LAST one can be broken. Pull it off the list and we will just
                // insert it after the current node.
                newNode = nodeList[ndx];
                nodeList.RemoveAt(ndx);
            }
            else if (ndx == nodeList.Count - 2)
            {
                // the PENULTIMATE item can be broken. So create a new comma operator
                // with the just the last two item and we'll insert it after the current node
                var left = nodeList[ndx];
                nodeList.RemoveAt(ndx);
                var right = nodeList[ndx];
                nodeList.RemoveAt(ndx);

                newNode = new CommaOperator(left.Context.FlattenToStart())
                {
                    Operand1 = left,
                    Operand2 = right
                };
            }
            else
            {
                // at least three items will be pulled off, which means there will
                // be at least two items on the right, so we'll create a new astlist to
                // insert those items into a new comma operator
                var left = nodeList[ndx];
                nodeList.RemoveAt(ndx);

                // if we were passed zero, then just reuse the node list.
                // otherwise we need to create a new one and move the items
                // from the index position over.
                AstNodeList right;
                if (ndx == 0)
                {
                    right = nodeList;
                }
                else
                {
                    right = new AstNodeList(nodeList[ndx].Context.FlattenToStart());
                    while (ndx < nodeList.Count)
                    {
                        var temp = nodeList[ndx];
                        nodeList.RemoveAt(ndx);
                        right.Append(temp);
                    }
                }

                newNode = new CommaOperator(left.Context.FlattenToStart())
                {
                    Operand1 = left,
                    Operand2 = right
                };
            }

            return(newNode);
        }
        public static AstNode CombineWithComma(Context context, AstNode operand1, AstNode operand2)
        {
            var comma = new CommaOperator(context);

            // 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(leftBinary.Context.FlattenToStart());
                    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(leftBinary.Operand2.Context.FlattenToStart());
                        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);
                    rightList.Append(rightBinary.Operand1);
                    rightList.Append(rightBinary.Operand2);
                }

                comma.Operand2 = rightList;
            }
            else
            {
                comma.Operand1 = operand1;
                comma.Operand2 = operand2;
            }

            return(comma);
        }
Beispiel #6
0
 public virtual bool Walk(CommaOperator node)
 {
     return(true);
 }
Beispiel #7
0
 public virtual void PostWalk(CommaOperator node)
 {
 }