예제 #1
0
        // Try to fold a negated constant int32.  We have to do this so that parsing int32.MinValue will work
        public override Node ExitNegateExpression(Production node)
        {
            IList childValues = GetChildValues(node);

            // Get last child
            var childElement = (BaseExpressionElement)childValues[childValues.Count - 1];

            // Is it an signed integer constant?
            if (ReferenceEquals(childElement.GetType(), typeof(Int32LiteralElement)) & childValues.Count == 2)
            {
                ((Int32LiteralElement)childElement).Negate();
                // Add it directly instead of the negate element since it will already be negated
                node.AddValue(childElement);
            }
            else if (ReferenceEquals(childElement.GetType(), typeof(Int64LiteralElement)) & childValues.Count == 2)
            {
                ((Int64LiteralElement)childElement).Negate();
                // Add it directly instead of the negate element since it will already be negated
                node.AddValue(childElement);
            }
            else
            {
                // No so just add a regular negate
                AddUnaryOp(node, typeof(NegateElement));
            }

            return(node);
        }
예제 #2
0
        public override Node ExitNegateExpression(Production node)
        {
            IList childValues  = this.GetChildValues(node);
            var   childElement = (ExpressionElement)childValues[childValues.Count - 1];
            var   flag         = (childElement.GetType() == typeof(Int32LiteralElement)) & (childValues.Count == 2);

            if (flag)
            {
                ((Int32LiteralElement)childElement).Negate();
                node.AddValue(childElement);
            }
            else
            {
                var flag2 = (childElement.GetType() == typeof(Int64LiteralElement)) & (childValues.Count == 2);
                if (flag2)
                {
                    ((Int64LiteralElement)childElement).Negate();
                    node.AddValue(childElement);
                }
                else
                {
                    this.AddUnaryOp(node, typeof(NegateElement));
                }
            }
            return(node);
        }
예제 #3
0
        public override Node ExitCastTypeExpression(Production node)
        {
            var childValues = this.GetChildValues(node);
            var parts       = childValues.Map(Conversions.ToString).ToList();
            //try
            //{
            //    IEnumerator enumerator = childValues.GetEnumerator();
            //    while (enumerator.MoveNext())
            //    {
            //        string part = Conversions.ToString(enumerator.Current);
            //        parts.Add(part);
            //    }
            //}
            //finally
            //{
            //    IEnumerator enumerator;
            //    if (enumerator is IDisposable)
            //    {
            //        (enumerator as IDisposable).Dispose();
            //    }
            //}
            var isArray = false;
            var flag    = Operators.CompareString(parts[parts.Count - 1], "[]", false) == 0;

            if (flag)
            {
                isArray = true;
                parts.RemoveAt(parts.Count - 1);
            }
            node.AddValue(parts.ToArray());
            node.AddValue(isArray);
            return(node);
        }
예제 #4
0
 public override Node ExitArith(Production node)
 {
     if (node.Count > 1)
     {
         node.AddValue(new Func((string)node[1].Values[0], (Expression)node[0].Values[0], (Expression)node[2].Values[0]));
     }
     else
     {
         node.AddValue(node[0].Values[0]);
     }
     return(node);
 }
예제 #5
0
 public override Node ExitCons(Production node)
 {
     if (node.Count > 1)
     {
         node.AddValue(new Func(":", (Expression)node[0].Values[0], (Expression)node[node.Count - 1].Values[0]));
     }
     else
     {
         node.AddValue(node[0].Values[0]);
     }
     return(node);
 }
예제 #6
0
        private void AddUnaryOp(Production node, Type elementType)
        {
            IList childValues = GetChildValues(node);

            if (childValues.Count == 2)
            {
                var element = (UnaryElement)Activator.CreateInstance(elementType, childValues[1]);
                node.AddValue(element);
            }
            else
            {
                node.AddValue(childValues[0]);
            }
        }
예제 #7
0
        public override Node ExitEqualOrExpr(Production node)
        {
            var isExpression = (ExpConstants)node[1].Id == ExpConstants.NEWLINE;

            if (isExpression)
            {
                node.AddValue(node[0].Values[0]);
            }
            else
            {
                node.AddValue(new Func("=", (Expression)node[0].Values[0], (Expression)node[2].Values[0]));
            }
            return(node);
        }
예제 #8
0
        private void AddUnaryOp(Production node, Type elementType)
        {
            IList childValues = this.GetChildValues(node);

            if (childValues.Count == 2)
            {
                UnaryElement element = (UnaryElement)Activator.CreateInstance(elementType);
                element.SetChild((ExpressionElement)childValues[1]);
                node.AddValue(element);
            }
            else
            {
                node.AddValue(childValues[0]);
            }
        }
예제 #9
0
        public override Node ExitInExpression(Production node)
        {
            IList childValues = GetChildValues(node);

            if (childValues.Count == 1)
            {
                AddFirstChildValue(node);
                return(node);
            }

            var operand = (BaseExpressionElement)childValues[0];

            childValues.RemoveAt(0);

            var       second = childValues[0];
            InElement op;

            if (second is IList list)
            {
                op = new InElement(operand, list);
            }
            else
            {
                var invocationListElement = new InvocationListElement(childValues, context);
                op = new InElement(operand, invocationListElement);
            }

            node.AddValue(op);
            return(node);
        }
예제 #10
0
        public override Node ExitGridReferenceExpression(Production node)
        {
            var    cr        = new CharacterRange();
            string sheetName = null;

            Node refNode = node.GetChildAt(node.GetChildCount() - 1);
            var  creator = (ReferenceCreator)refNode.GetValue(0);

            cr.First  = refNode.StartColumn - 1;
            cr.Length = refNode.EndColumn - refNode.StartColumn + 1;

            if (node.GetChildCount() == 2)
            {
                var sheetToken = (Token)node.GetChildAt(0);
                sheetName = sheetToken.Image.Substring(0, sheetToken.Image.Length - 1);
                cr.First  = sheetToken.StartColumn - 1;
                cr.Length = refNode.EndColumn - sheetToken.StartColumn + 1;
            }

            Reference @ref = creator.CreateReference();
            var       info = new ReferenceParseInfo
            {
                Target          = @ref,
                Location        = cr,
                Properties      = creator.CreateProperties(node.GetChildCount() == 1),
                ParseProperties = new ReferenceParseProperties {
                    SheetName = sheetName
                }
            };

            _referenceInfos.Add(info);

            node.AddValue(@ref);
            return(node);
        }
예제 #11
0
        public override Node ExitBoolean(Production node)
        {
            var b = (bool)node.GetChildAt(0).Values[0];

            node.AddValue(new BooleanOperand(b));
            return(node);
        }
예제 #12
0
        public override Node ExitInExpression(Production node)
        {
            var  childValues = this.GetChildValues(node);
            var  flag        = childValues.Count == 1;
            Node exitInExpression;

            if (flag)
            {
                this.AddFirstChildValue(node);
                exitInExpression = node;
            }
            else
            {
                var operand = (ExpressionElement)childValues[0];
                childValues.RemoveAt(0);
                var       second = RuntimeHelpers.GetObjectValue(childValues[0]);
                var       flag2  = second is IList;
                InElement op;
                if (flag2)
                {
                    op = new InElement(operand, (IList)second);
                }
                else
                {
                    var il = new InvocationListElement(childValues, this.myServices);
                    op = new InElement(operand, il);
                }
                node.AddValue(op);
                exitInExpression = node;
            }
            return(exitInExpression);
        }
예제 #13
0
        public override Node ExitInListTargetExpression(Production node)
        {
            IList childValues = GetChildValues(node);

            node.AddValue(childValues);
            return(node);
        }
예제 #14
0
        public override Node ExitInExpression(Production node)
        {
            IList childValues = this.GetChildValues(node);

            if (childValues.Count == 1)
            {
                this.AddFirstChildValue(node);
                return(node);
            }

            ExpressionElement operand = (ExpressionElement)childValues[0];

            childValues.RemoveAt(0);

            object    second = childValues[0];
            InElement op     = default(InElement);

            if ((second) is IList)
            {
                op = new InElement(operand, (IList)second);
            }
            else
            {
                InvocationListElement il = new InvocationListElement(childValues, _myServices);
                op = new InElement(operand, il);
            }

            node.AddValue(op);
            return(node);
        }
예제 #15
0
        private void AddUnaryOp(Production node, Type elementType)
        {
            IList childValues = this.GetChildValues(node);
            var   flag        = childValues.Count == 2;

            if (flag)
            {
                var element = (UnaryElement)Activator.CreateInstance(elementType);
                element.SetChild((ExpressionElement)childValues[1]);
                node.AddValue(element);
            }
            else
            {
                node.AddValue(RuntimeHelpers.GetObjectValue(childValues[0]));
            }
        }
예제 #16
0
        public override Node ExitMemberExpression(Production node)
        {
            IList childValues = GetChildValues(node);
            var   first       = childValues[0];

            if (childValues.Count == 1 && !(first is MemberElement))
            {
                node.AddValue(first);
            }
            else
            {
                var invocationListElement = new InvocationListElement(childValues, context);
                node.AddValue(invocationListElement);
            }

            return(node);
        }
예제 #17
0
        public override Node ExitMemberExpression(Production node)
        {
            var childValues = this.GetChildValues(node);
            var first       = RuntimeHelpers.GetObjectValue(childValues[0]);
            var flag        = childValues.Count == 1 && !(first is MemberElement);

            if (flag)
            {
                node.AddValue(RuntimeHelpers.GetObjectValue(first));
            }
            else
            {
                var list = new InvocationListElement(childValues, this.myServices);
                node.AddValue(list);
            }
            return(node);
        }
예제 #18
0
        public override Node ExitPrimitive(Production node)
        {
            IList values = GetChildValues(node);
            var   oe     = new ContainerElement(values[0]);

            node.AddValue(oe);
            return(node);
        }
예제 #19
0
        public override Node ExitPercentExpression(Production node)
        {
            IList values = GetChildValues(node);
            var   first  = (ParseTreeElement)values[0];

            if (values.Count > 1)
            {
                var pe = new PercentOperator(values.Count - 1);
                node.AddValue(new UnaryOperatorElement(pe, first));
            }
            else
            {
                node.AddValue(first);
            }

            return(node);
        }
예제 #20
0
        public override Node ExitIfExpression(Production node)
        {
            IList childValues = GetChildValues(node);
            var   op          = new ConditionalElement((BaseExpressionElement)childValues[0], (BaseExpressionElement)childValues[1], (BaseExpressionElement)childValues[2]);

            node.AddValue(op);
            return(node);
        }
예제 #21
0
        public override Node ExitMemberExpression(Production node)
        {
            IList  childValues = this.GetChildValues(node);
            object first       = childValues[0];

            if (childValues.Count == 1 && !(first is MemberElement))
            {
                node.AddValue(first);
            }
            else
            {
                InvocationListElement list = new InvocationListElement(childValues, _myServices);
                node.AddValue(list);
            }

            return(node);
        }
예제 #22
0
        public override Node ExitFieldPropertyExpression(Production node)
        {
            var name = (string)node.GetChildAt(0).GetValue(0);
            var elem = new IdentifierElement(name);

            node.AddValue(elem);
            return(node);
        }
예제 #23
0
        public override Node ExitFunctionCall(Production node)
        {
            var fe = new FunctionCallElement();

            fe.AcceptValues(GetChildValues(node));
            node.AddValue(fe);
            return(node);
        }
예제 #24
0
        public override Node ExitFieldPropertyExpression(Production node)
        {
            //string name = ((Token)node.GetChildAt(0))?.Image;
            var name = node.GetChildAt(0).GetValue(0).ToString();
            var elem = new IdentifierElement(name);

            node.AddValue(elem);
            return(node);
        }
예제 #25
0
        private void AddBinaryOp(Production node, Type elementType)
        {
            IList childValues = GetChildValues(node);

            if (childValues.Count > 1)
            {
                var expressionElement = BinaryExpressionElement.CreateElement(childValues, elementType);
                node.AddValue(expressionElement);
            }
            else if (childValues.Count == 1)
            {
                node.AddValue(childValues[0]);
            }
            else
            {
                Debug.Assert(false, "wrong number of children");
            }
        }
예제 #26
0
        public override Node ExitIndexExpression(Production node)
        {
            IList childValues = GetChildValues(node);
            var   args        = new ArgumentList(childValues);
            var   e           = new IndexerElement(args);

            node.AddValue(e);
            return(node);
        }
예제 #27
0
        public override Node ExitCastExpression(Production node)
        {
            IList childValues   = GetChildValues(node);
            var   destTypeParts = (string[])childValues[1];
            var   isArray       = (bool)childValues[2];
            var   op            = new CastElement((BaseExpressionElement)childValues[0], destTypeParts, isArray, context);

            node.AddValue(op);
            return(node);
        }
예제 #28
0
        public override Node ExitUnaryExpression(Production node)
        {
            IList values = GetChildValues(node);
            var   last   = (ParseTreeElement)values[values.Count - 1];

            int negCount = values.Cast <object>().Count(op => ReferenceEquals(op.GetType(), typeof(BinarySubOperator)));

            if ((negCount & 1) != 0)
            {
                var ne = new UnaryNegateOperator();
                node.AddValue(new UnaryOperatorElement(ne, last));
            }
            else
            {
                node.AddValue(last);
            }

            return(node);
        }
예제 #29
0
        public override Node ExitCastExpression(Production node)
        {
            IList childValues = this.GetChildValues(node);

            string[]    destTypeParts = (string[])childValues[1];
            bool        isArray       = (bool)childValues[2];
            CastElement op            = new CastElement((ExpressionElement)childValues[0], destTypeParts, isArray, _myServices);

            node.AddValue(op);
            return(node);
        }
예제 #30
0
        public override Node ExitFunctionCallExpression(Production node)
        {
            var childValues = GetChildValues(node);
            var name        = (string)childValues[0];

            childValues.RemoveAt(0);
            var args     = new ArgumentList(childValues);
            var funcCall = new FunctionCallElement(name, args);

            node.AddValue(funcCall);
            return(node);
        }