Ejemplo n.º 1
0
        static void RecurseParameters(AstNodeList parameterList, AstNode node)
        {
            if (node != null)
            {
                // if this is a comma operator, then we need to
                var binOp = node as BinaryExpression;
                if (binOp != null && binOp.OperatorToken == JSToken.Comma)
                {
                    // there are two or more parameters - recurse the list so we get them added left to right,
                    // converting each one to a binding object
                    RecurseParameters(parameterList, binOp.Operand1);

                    // comma operators can flatten lots of commas to an element on the left, and subsequent
                    // elements in a list on the right.
                    var rightList = binOp.Operand2 as AstNodeList;
                    if (rightList != null)
                    {
                        foreach (var listItem in rightList.Children)
                        {
                            parameterList.Append(ConvertToParameter(listItem, parameterList.Count));
                        }
                    }
                    else
                    {
                        // nope, just a single item
                        parameterList.Append(ConvertToParameter(binOp.Operand2, parameterList.Count));
                    }
                }
                else
                {
                    // nope; single operand to convert to a parameter
                    parameterList.Append(ConvertToParameter(node, 0));
                }
            }
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        public static AstNodeList ToParameters(AstNode node)
        {
            AstNodeList parameterList = null;

            if (node != null)
            {
                parameterList = new AstNodeList(node.Context);

                // ignore any parentheses around the parameter(s)
                var groupingOperator = node as GroupingOperator;
                RecurseParameters(
                    parameterList,
                    groupingOperator != null ? groupingOperator.Operand : node);
            }

            return(parameterList);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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);
        }