protected override List <AssemblyElement> VisitNull(NullNode node)
 {
     return(new List <AssemblyElement>
     {
         new PushNullInstance(),
     });
 }
Beispiel #2
0
        public void WritesCommentsForNullNodes()
        {
            var uxNode = new NullNode(new UxComment("Please skip me"));
            var ux     = uxNode.SerializeUx(new UxSerializerContext());

            Assert.That(ux, Is.EqualTo("<!-- Please skip me -->"));
        }
        public NullNode Null(string value)
        {
            NullNode nullNode = new NullNode();

            Match(TokenType.NULL);
            return(nullNode);
        }
Beispiel #4
0
 public void Visit(NullNode n)
 {
     foreach (var node in n.GetChildren())
     {
         node.SymTable = n.SymTable;
         node.Accept(this);
     }
 }
Beispiel #5
0
 public void Visit(NullNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Beispiel #6
0
 private IntList()
 {
     mRoot = new NullNode()
     {
         Previous = new NullNode()
     };
     mRoot.Previous.Previous = mRoot.Previous;
     mEnd = mRoot;
 }
        public void Visit(NullNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }
        }
Beispiel #8
0
 void factor(out Node node)
 {
     node = null;
     if (la.kind == 2 || la.kind == 3 || la.kind == 38)
     {
         num(out node);
     }
     else if (isFunctionCall())
     {
         functioncall(out node);
     }
     else if (isArrayAccess())
     {
         arrayident(out node);
     }
     else if (la.kind == 27)
     {
         Get();
         node = new BooleanNode()
         {
             value = ProtoCore.DSASM.Literal.True
         };
     }
     else if (la.kind == 28)
     {
         Get();
         node = new BooleanNode()
         {
             value = ProtoCore.DSASM.Literal.False
         };
     }
     else if (la.kind == 29)
     {
         Get();
         node = new NullNode();
     }
     else if (la.kind == 32)
     {
         Get();
         ExprListNode exprlist = new ExprListNode();
         if (StartOf(3))
         {
             expr(out node);
             exprlist.list.Add(node);
             while (la.kind == 30)
             {
                 Get();
                 expr(out node);
                 exprlist.list.Add(node);
             }
         }
         Expect(33);
         node = exprlist;
     }
     else if (la.kind == 8)
     {
         Get();
         expr(out node);
         Expect(9);
     }
     else if (la.kind == 1)
     {
         identifierList(out node);
     }
     else
     {
         SynErr(65);
     }
 }
 public void Visit(NullNode node)
 {
     node.Accept(_visitor);
 }
Beispiel #10
0
        protected void MethodCallNodeExecuteCall <T>(T objectValue, AbstractSyntaxTreeNode item)
        {
            var array = objectValue.GetType().IsArray;

            if (array)
            {
                IEnumerable arrayItems = objectValue as IEnumerable;
                foreach (var arrayItem in arrayItems)
                {
                    var arrayMethod = arrayItem.GetType().GetMethod(((MethodCallNode)item).Name);
                    if (arrayMethod != null)
                    {
                        var objectList = new List <object>();
                        for (int parameterCount = 0; parameterCount < ((MethodCallNode)item).parameterList.Count; parameterCount++)
                        {
                            var parameter = ((MethodCallNode)item).parameterList[parameterCount];
                            if (parameter is StringNode)
                            {
                                var      value    = ((StringNode)parameter).Value;
                                DateTime dateTime = new DateTime();
                                if (DateTime.TryParse(value, out dateTime))
                                {
                                    objectList.Add(dateTime);
                                }
                                else
                                {
                                    objectList.Add(value);
                                }
                            }
                            else if (parameter is DateTimeNode)
                            {
                                var value = ((DateTimeNode)parameter).Value;
                                objectList.Add(value);
                            }
                            else if (parameter is BooleanNode)
                            {
                                var value = ((BooleanNode)parameter).Value;
                                objectList.Add(value);
                            }
                            else if (parameter is DoubleNode)
                            {
                                var value = ((DoubleNode)parameter).Value;
                                objectList.Add(value);
                            }
                            else if (parameter is IntegerNode)
                            {
                                var value = ((IntegerNode)parameter).Value;
                                objectList.Add(value);
                            }
                            else if (parameter is ObjectNode)
                            {
                                var value     = (ObjectNode)parameter;
                                var name      = value.PropertyName;
                                var valueItem = value.ObjectValue.GetType().GetProperty(name).GetValue(value.ObjectValue, null);
                                if (valueItem is int)
                                {
                                    objectList.Add((int)valueItem);
                                }
                                else if (valueItem is double)
                                {
                                    objectList.Add((double)valueItem);
                                }
                                else if (valueItem is bool)
                                {
                                    objectList.Add((bool)valueItem);
                                }
                                else if (valueItem is DateTime)
                                {
                                    objectList.Add((DateTime)valueItem);
                                }
                                else if (valueItem is String)
                                {
                                    objectList.Add((String)valueItem);
                                }
                            }
                        }
                        var      result = arrayMethod.Invoke(arrayItem, objectList.ToArray());
                        int      intOutValue;
                        double   doubleOutValue;
                        bool     boolOutValue;
                        DateTime dateTimeOutValue;
                        if (result == null)
                        {
                            NullNode nullNode = new NullNode();
                            valueStack.Push(nullNode);
                        }
                        else if (int.TryParse(result.ToString(), out intOutValue))
                        {
                            IntegerNode integerNode = new IntegerNode();
                            integerNode.Value = intOutValue;
                            valueStack.Push(integerNode);
                        }
                        else if (double.TryParse(result.ToString(), out doubleOutValue))
                        {
                            DoubleNode doubleNode = new DoubleNode();
                            doubleNode.Value = doubleOutValue;
                            valueStack.Push(doubleNode);
                        }
                        else if (bool.TryParse(result.ToString(), out boolOutValue))
                        {
                            BooleanNode booleanNode = new BooleanNode();
                            booleanNode.Value = boolOutValue;
                            valueStack.Push(booleanNode);
                        }
                        else if (DateTime.TryParse(result.ToString(), out dateTimeOutValue))
                        {
                            DateTimeNode dateTimeNode = new DateTimeNode();
                            dateTimeNode.Value = dateTimeOutValue;
                            valueStack.Push(dateTimeNode);
                        }
                        else
                        {
                            StringNode stringNode = new StringNode();
                            stringNode.Value = result.ToString();
                            valueStack.Push(stringNode);
                        }
                    }
                }
            }
            var method = objectValue.GetType().GetMethod(((MethodCallNode)item).Name);

            if (method != null)
            {
                var objectList = new List <object>();
                for (int parameterCount = 0; parameterCount < ((MethodCallNode)item).parameterList.Count; parameterCount++)
                {
                    var parameter = ((MethodCallNode)item).parameterList[parameterCount];
                    if (parameter is StringNode)
                    {
                        var      value    = ((StringNode)parameter).Value;
                        DateTime dateTime = new DateTime();
                        if (DateTime.TryParse(value, out dateTime))
                        {
                            objectList.Add(dateTime);
                        }
                        else
                        {
                            objectList.Add(value);
                        }
                    }
                    else if (parameter is DateTimeNode)
                    {
                        var value = ((DateTimeNode)parameter).Value;
                        objectList.Add(value);
                    }
                    else if (parameter is BooleanNode)
                    {
                        var value = ((BooleanNode)parameter).Value;
                        objectList.Add(value);
                    }
                    else if (parameter is DoubleNode)
                    {
                        var value = ((DoubleNode)parameter).Value;
                        objectList.Add(value);
                    }
                    else if (parameter is IntegerNode)
                    {
                        var value = ((IntegerNode)parameter).Value;
                        objectList.Add(value);
                    }
                }
                var      result = method.Invoke(objectValue, objectList.ToArray());
                int      intOutValue;
                double   doubleOutValue;
                bool     boolOutValue;
                DateTime dateTimeOutValue;
                if (result == null)
                {
                    NullNode nullNode = new NullNode();
                    valueStack.Push(nullNode);
                }
                else if (int.TryParse(result.ToString(), out intOutValue))
                {
                    IntegerNode integerNode = new IntegerNode();
                    integerNode.Value = intOutValue;
                    valueStack.Push(integerNode);
                }
                else if (double.TryParse(result.ToString(), out doubleOutValue))
                {
                    DoubleNode doubleNode = new DoubleNode();
                    doubleNode.Value = doubleOutValue;
                    valueStack.Push(doubleNode);
                }
                else if (bool.TryParse(result.ToString(), out boolOutValue))
                {
                    BooleanNode booleanNode = new BooleanNode();
                    booleanNode.Value = boolOutValue;
                    valueStack.Push(booleanNode);
                }
                else if (DateTime.TryParse(result.ToString(), out dateTimeOutValue))
                {
                    DateTimeNode dateTimeNode = new DateTimeNode();
                    dateTimeNode.Value = dateTimeOutValue;
                    valueStack.Push(dateTimeNode);
                }
                else
                {
                    StringNode stringNode = new StringNode();
                    stringNode.Value = result.ToString();
                    valueStack.Push(stringNode);
                }
            }
        }
Beispiel #11
0
        public void ShouldThrowErrorOnForcedNullMatch()
        {
            var node = new NullNode();

            Assert.Throws <InvalidOperationException>(() => node.Match(this.RecentChangeBuilder().Object));
        }
Beispiel #12
0
 public static ENullNode Editor(this NullNode node) =>
 Editor <ENullNode>(node);
Beispiel #13
0
 public virtual TAssociative VisitNullNode(NullNode node)
 {
     return(VisitAssociativeNode(node));
 }
        private void EmitFunctionNode(Func node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            AssociativeNode fNode         = new NullNode();
            string          funcQualifier = node.Name;

            if (node.isRange)
            {
                EmitRangeExpNode(node, out fNode);
            }
            else if (!funcQualifier.Contains("."))
            {
                if (node.isProperty)
                {
                    Dictionary <int, Node> nodes = node.GetChildrenWithIndices();
                    Validity.Assert(nodes.Count == 1);
                    for (int i = 0; i < nodes.Count; ++i)
                    {
                        AssociativeNode instanceNode = null;
                        DFSTraverse(nodes[i], out instanceNode);

                        EmitFunctionCallNode(node, out fNode);
                        ((fNode as FunctionCallNode).Function as IdentifierNode).Value = ProtoCore.DSASM.Constants.kGetterPrefix + ((fNode as FunctionCallNode).Function as IdentifierNode).Value;
                        //string className = (node.Name.Split('.'))[0];
                        //IdentifierNode inode = new IdentifierNode(className);

                        fNode = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(instanceNode, fNode as FunctionCallNode);
                    }
                }
                else if (node.isMemberFunction)
                {
                    Dictionary <int, Node> nodes = node.GetChildrenWithIndices();

                    AssociativeNode instanceNode = null;
                    DFSTraverse(nodes[0], out instanceNode);

                    EmitFunctionCallNode(node, out fNode);
                    //string className = (node.Name.Split('.'))[0];
                    //IdentifierNode inode = new IdentifierNode(className);

                    fNode = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(instanceNode, fNode as FunctionCallNode);
                }
                else
                {
                    // Create AssociativeAST.FunctionCallNode for global and built-in functions
                    EmitFunctionCallNode(node, out fNode);
                }
            }
            else
            {
                // Create FunctionDotCallNode for ctors, static and instance methods
                EmitFunctionDotCallNode(node, out fNode);
            }

            BinaryExpressionNode assignmentNode = new BinaryExpressionNode();

            assignmentNode.LeftNode  = new IdentifierNode(node.tempName);
            assignmentNode.Optr      = ProtoCore.DSASM.Operator.assign;
            assignmentNode.RightNode = fNode;
            assignmentNode.Guid      = node.Guid;

            Validity.Assert(gc != null);
            gc.HandleNewNode(assignmentNode);

            outnode = assignmentNode;
        }
Beispiel #15
0
 public void Visit(NullNode node)
 {
 }
Beispiel #16
0
 public void Visit(NullNode node)
 {
     Nodes.Push(new NullNode());
 }
Beispiel #17
0
        internal override IEnumerable <AssociativeNode> BuildAst(List <AssociativeNode> inputAstNodes)
        {
            var resultAst = new List <AssociativeNode>();

            string          function = Definition.Name;
            AssociativeNode rhs;

            var paramCount = Definition.Parameters.Count();
            var packId     = "__var_arg_pack_" + GUID;

            resultAst.Add(
                AstFactory.BuildAssignment(
                    AstFactory.BuildIdentifier(packId),
                    AstFactory.BuildExprList(inputAstNodes.Skip(paramCount - 1).ToList())));

            inputAstNodes =
                inputAstNodes.Take(paramCount - 1)
                .Concat(new[] { AstFactory.BuildIdentifier(packId) })
                .ToList();

            switch (Definition.Type)
            {
            case FunctionType.Constructor:
            case FunctionType.StaticMethod:
                if (HasUnconnectedInput())
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.Name)
                    };
                    rhs = CreateFunctionObject(functionNode, inputAstNodes);
                }
                else
                {
                    rhs = AstFactory.BuildFunctionCall(Definition.ClassName,
                                                       Definition.Name,
                                                       inputAstNodes);
                }
                break;

            case FunctionType.StaticProperty:

                var staticProp = new IdentifierListNode
                {
                    LeftNode  = new IdentifierNode(Definition.ClassName),
                    RightNode = new IdentifierNode(Definition.Name)
                };
                rhs = staticProp;
                break;

            case FunctionType.InstanceProperty:

                // Only handle getter here. Setter could be handled in CBN.
                rhs = new NullNode();
                if (inputAstNodes != null && inputAstNodes.Count >= 1)
                {
                    var thisNode = inputAstNodes[0];
                    if (thisNode != null && !(thisNode is NullNode))
                    {
                        var insProp = new IdentifierListNode
                        {
                            LeftNode  = inputAstNodes[0],
                            RightNode = new IdentifierNode(Definition.Name)
                        };
                        rhs = insProp;
                    }
                }

                break;

            case FunctionType.InstanceMethod:

                rhs = new NullNode();
                if (inputAstNodes != null && inputAstNodes.Count >= 1)
                {
                    var thisNode = inputAstNodes[0];
                    inputAstNodes.RemoveAt(0);     // remove this pointer

                    if (thisNode != null && !(thisNode is NullNode))
                    {
                        var memberFunc = new IdentifierListNode
                        {
                            LeftNode  = thisNode,
                            RightNode = AstFactory.BuildFunctionCall(function, inputAstNodes)
                        };
                        rhs = memberFunc;
                    }
                }

                break;

            default:
                if (HasUnconnectedInput())
                {
                    var functionNode = new IdentifierNode(function);
                    rhs = CreateFunctionObject(functionNode, inputAstNodes);
                }
                else
                {
                    rhs = AstFactory.BuildFunctionCall(function, inputAstNodes);
                }
                break;
            }

            resultAst.Add(AstFactory.BuildAssignment(AstIdentifierForPreview, rhs));

            if (OutPortData.Count == 1)
            {
                var    outputIdentiferNode = GetAstIdentifierForOutputIndex(0);
                string outputIdentifier    = outputIdentiferNode.ToString();
                string thisIdentifier      = AstIdentifierForPreview.ToString();
                if (!string.Equals(outputIdentifier, thisIdentifier))
                {
                    resultAst.Add(
                        AstFactory.BuildAssignment(outputIdentiferNode, AstIdentifierForPreview));
                }
            }
            else
            {
                var undefinedOutputs = Definition.ReturnKeys == null || !Definition.ReturnKeys.Any();

                resultAst.AddRange(
                    Enumerable.Range(0, OutPortData.Count)
                    .Select(
                        outputIdx =>
                        undefinedOutputs
                                          ? AstIdentifierForPreview
                                          : new IdentifierNode(AstIdentifierForPreview)
                {
                    ArrayDimensions =
                        new ArrayNode
                    {
                        Expr =
                            new StringNode
                        {
                            value =
                                Definition.ReturnKeys.ElementAt(
                                    outputIdx)
                        }
                    }
                }));
            }

            return(resultAst);
        }
        public bool Evaluate <T>(List <AbstractSyntaxTreeNode> postfixList,
                                 Dictionary <string, AbstractSyntaxTreeNode> symbolTable, T objectValue)
        {
            int  setNameValue = 0;
            bool thenNode     = false;
            bool elseNode     = false;

            foreach (var item in postfixList)
            {
                if (item is IntegerNode || item is DoubleNode || item is DateTimeNode ||
                    item is BooleanNode || item is StringNode || item is NullNode)
                {
                    valueStack.Push(item);
                }
                else if (item is SetNode)
                {
                    var equalNode = postfixList[setNameValue - 1];
                    var valueNode = postfixList[setNameValue - 2];
                    var nameNode  = postfixList[setNameValue - 3];
                    if (equalNode is EqualNode)
                    {
                        var pop = valueStack.Pop();
                        setList.Add(((VariableNode)nameNode).Name, valueNode);
                    }
                    else
                    {
                        var pop             = valueStack.Pop();
                        var methodValueNode = postfixList[setNameValue - 1];
                        var methodNode      = postfixList[setNameValue - 2];
                        if (methodNode is VariableNode)
                        {
                            setList.Add(((VariableNode)methodNode).Name, methodValueNode);
                        }
                    }
                }
                else if (item is ThenNode)
                {
                    thenNode = true;
                }
                else if (item is ElseNode)
                {
                    thenNode = false;
                    elseNode = true;
                }
                else if (item is VariableNode)
                {
                    if (symbolTable.ContainsKey(((VariableNode)item).Name))
                    {
                        var property = objectValue.GetType().GetProperty(((VariableNode)item).Name);
                        if (property != null)
                        {
                            object   value = property.GetValue(objectValue, null);
                            int      intOutValue;
                            double   doubleOutValue;
                            bool     boolOutValue;
                            DateTime dateTimeOutValue;
                            if (value == null)
                            {
                                NullNode nullNode = new NullNode();
                                valueStack.Push(nullNode);
                            }
                            else if (int.TryParse(value.ToString(), out intOutValue))
                            {
                                IntegerNode integerNode = new IntegerNode();
                                integerNode.Value = intOutValue;
                                valueStack.Push(integerNode);
                            }
                            else if (double.TryParse(value.ToString(), out doubleOutValue))
                            {
                                DoubleNode doubleNode = new DoubleNode();
                                doubleNode.Value = doubleOutValue;
                                valueStack.Push(doubleNode);
                            }
                            else if (bool.TryParse(value.ToString(), out boolOutValue))
                            {
                                BooleanNode booleanNode = new BooleanNode();
                                booleanNode.Value = boolOutValue;
                                valueStack.Push(booleanNode);
                            }
                            else if (DateTime.TryParse(value.ToString(), out dateTimeOutValue))
                            {
                                DateTimeNode dateTimeNode = new DateTimeNode();
                                dateTimeNode.Value = dateTimeOutValue;
                                valueStack.Push(dateTimeNode);
                            }
                            else
                            {
                                StringNode stringNode = new StringNode();
                                stringNode.Value = value.ToString();
                                valueStack.Push(stringNode);
                            }
                        }
                    }
                }
                else if (item is MethodCallNode)
                {
                    if (!thenNode && !elseNode)
                    {
                        MethodCallNodeExecuteCall(objectValue, item);
                    }
                    else if (thenNode)
                    {
                        var methodNodeName = ((MethodCallNode)item).Name;
                        var list           = new List <Tuple <AbstractSyntaxTreeNode, AbstractSyntaxTreeNode> >();
                        list.Add(new Tuple <AbstractSyntaxTreeNode, AbstractSyntaxTreeNode>(item, item));
                        thenList.Add(new Tuple <string, string>(methodNodeName, null), list);
                        thenNode = false;
                    }
                    else if (elseNode)
                    {
                        var methodNodeName = ((MethodCallNode)item).Name;
                        var list           = new List <Tuple <AbstractSyntaxTreeNode, AbstractSyntaxTreeNode> >();
                        list.Add(new Tuple <AbstractSyntaxTreeNode, AbstractSyntaxTreeNode>(item, item));
                        elseList.Add(new Tuple <string, string>(methodNodeName, null), list);
                        elseNode = false;
                    }
                }
                else if (item is AddNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        IntegerNode integerNode = new IntegerNode();
                        integerNode.Value = ((IntegerNode)firstoperand).Value +
                                            ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((DoubleNode)firstoperand).Value + ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        DoubleNode integerNode = new DoubleNode();
                        integerNode.Value = ((DoubleNode)firstoperand).Value + ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((IntegerNode)firstoperand).Value + ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                }
                else if (item is SubNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        IntegerNode integerNode = new IntegerNode();
                        integerNode.Value = ((IntegerNode)firstoperand).Value - ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((DoubleNode)firstoperand).Value - ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        DoubleNode integerNode = new DoubleNode();
                        integerNode.Value = ((DoubleNode)firstoperand).Value - ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((IntegerNode)firstoperand).Value - ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                }
                else if (item is MulNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        IntegerNode integerNode = new IntegerNode();
                        integerNode.Value = ((IntegerNode)firstoperand).Value * ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((DoubleNode)firstoperand).Value * ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        DoubleNode integerNode = new DoubleNode();
                        integerNode.Value = ((DoubleNode)firstoperand).Value * ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((IntegerNode)firstoperand).Value * ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                }
                else if (item is DivNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        IntegerNode integerNode = new IntegerNode();
                        integerNode.Value = ((IntegerNode)firstoperand).Value / ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((DoubleNode)firstoperand).Value / ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        DoubleNode integerNode = new DoubleNode();
                        integerNode.Value = ((DoubleNode)firstoperand).Value / ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((IntegerNode)firstoperand).Value / ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                }
                else if (item is ModuloNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        IntegerNode integerNode = new IntegerNode();
                        integerNode.Value = ((IntegerNode)firstoperand).Value % ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((DoubleNode)firstoperand).Value % ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        DoubleNode integerNode = new DoubleNode();
                        integerNode.Value = ((DoubleNode)firstoperand).Value % ((IntegerNode)secondoperand).Value;
                        valueStack.Push(integerNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        DoubleNode doubleNode = new DoubleNode();
                        doubleNode.Value = ((IntegerNode)firstoperand).Value % ((DoubleNode)secondoperand).Value;
                        valueStack.Push(doubleNode);
                    }
                }
                else if (item is LikeNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is StringNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode         = new BooleanNode();
                        var         firstoperatorString = ((StringNode)firstoperand).Value;
                        var         secondperatorString = ((StringNode)secondoperand).Value;
                        var         result = Like(firstoperatorString, secondperatorString);
                        booleanNode.Value = result;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode         = new BooleanNode();
                        var         firstoperatorString = ((IntegerNode)firstoperand).Value.ToString();
                        var         secondperatorString = ((StringNode)secondoperand).Value;
                        var         result = Like(firstoperatorString, secondperatorString);
                        booleanNode.Value = result;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode         = new BooleanNode();
                        var         firstoperatorString = ((DoubleNode)firstoperand).Value.ToString();
                        var         secondperatorString = ((StringNode)secondoperand).Value;
                        var         result = Like(firstoperatorString, secondperatorString);
                        booleanNode.Value = result;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode         = new BooleanNode();
                        var         firstoperatorString = ((DateTimeNode)firstoperand).Value.ToString();
                        var         secondperatorString = ((StringNode)secondoperand).Value;
                        var         result = Like(firstoperatorString, secondperatorString);
                        booleanNode.Value = result;
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is EqualNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value == ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value == ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is BooleanNode && firstoperand is BooleanNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((BooleanNode)firstoperand).Value == ((BooleanNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((StringNode)firstoperand).Value == ((StringNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value == ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value == ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value == ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value == ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((StringNode)firstoperand).Value == ((DateTimeNode)secondoperand).Value.ToString();
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value.ToString() == ((StringNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is UnEqualNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value != ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value != ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is BooleanNode && firstoperand is BooleanNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((BooleanNode)firstoperand).Value != ((BooleanNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((StringNode)firstoperand).Value != ((StringNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value != ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value != ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value != ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value != ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((StringNode)firstoperand).Value != ((DateTimeNode)secondoperand).Value.ToString();
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value.ToString() != ((StringNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is SmallerThenNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value < ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value < ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value < ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value < ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value < ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)firstoperand).Value;
                        booleanNode.Value = DateTime.Parse(str) < ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)secondoperand).Value;
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value < DateTime.Parse(str);
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is SmallerThenOrEqualNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value <= ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value <= ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value <= ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value <= ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value <= ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)firstoperand).Value;
                        booleanNode.Value = DateTime.Parse(str) <= ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)secondoperand).Value;
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value <= DateTime.Parse(str);
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is GreaterThenNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value > ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value > ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value > ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value > ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value > ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)firstoperand).Value;
                        booleanNode.Value = DateTime.Parse(str) > ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)secondoperand).Value;
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value > DateTime.Parse(str);
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is GreaterThenOrEqualNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is IntegerNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value >= ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value >= ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is IntegerNode && firstoperand is DoubleNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DoubleNode)firstoperand).Value >= ((IntegerNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DoubleNode && firstoperand is IntegerNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((IntegerNode)firstoperand).Value >= ((DoubleNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value >= ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is DateTimeNode && firstoperand is StringNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)firstoperand).Value;
                        booleanNode.Value = DateTime.Parse(str) >= ((DateTimeNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                    else if (secondoperand is StringNode && firstoperand is DateTimeNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        var         str         = ((StringNode)secondoperand).Value;
                        booleanNode.Value = ((DateTimeNode)firstoperand).Value >= DateTime.Parse(str);
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is IsNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is NullNode && firstoperand is NullNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = true;
                        valueStack.Push(booleanNode);
                    }
                    else
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = false;
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is OrNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is BooleanNode && firstoperand is BooleanNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((BooleanNode)firstoperand).Value || ((BooleanNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                }
                else if (item is AndNode)
                {
                    var secondoperand = valueStack.Pop();
                    var firstoperand  = valueStack.Pop();
                    if (secondoperand is BooleanNode && firstoperand is BooleanNode)
                    {
                        BooleanNode booleanNode = new BooleanNode();
                        booleanNode.Value = ((BooleanNode)firstoperand).Value && ((BooleanNode)secondoperand).Value;
                        valueStack.Push(booleanNode);
                    }
                }
                setNameValue++;
            }
            if (valueStack.Count > 0)
            {
                var endValue = valueStack.Pop();
                if (endValue is BooleanNode)
                {
                    if (((BooleanNode)endValue).Value)
                    {
                        if (setList.Count > 0)
                        {
                            foreach (var item in setList)
                            {
                                var propertyName    = item.Key;
                                var objectToSet     = item.Value;
                                var objectCastValue = new object();
                                if (objectToSet is IntegerNode)
                                {
                                    objectCastValue = ((IntegerNode)objectToSet).Value;
                                }
                                else if (objectToSet is DoubleNode)
                                {
                                    objectCastValue = ((DoubleNode)objectToSet).Value;
                                }
                                else if (objectToSet is BooleanNode)
                                {
                                    objectCastValue = ((BooleanNode)objectToSet).Value;
                                }
                                else if (objectToSet is StringNode)
                                {
                                    objectCastValue = ((StringNode)objectToSet).Value;
                                }
                                else if (objectToSet is DateTimeNode)
                                {
                                    objectCastValue = ((DateTimeNode)objectToSet).Value;
                                }
                                var property = objectValue.GetType().GetProperty(propertyName);
                                if (property != null)
                                {
                                    property.SetValue(objectValue, objectCastValue, null);
                                }
                                else
                                {
                                    var method = objectValue.GetType().GetMethod(propertyName);
                                    if (method != null)
                                    {
                                        method.Invoke(objectValue, new object[] { objectCastValue });
                                    }
                                }
                            }
                        }
                    }
                    if (((BooleanNode)endValue).Value)
                    {
                        foreach (var item in thenList)
                        {
                            MethodCallNodeExecuteCall(objectValue, item.Value.First().Item2);
                        }
                    }
                    else
                    {
                        foreach (var item in elseList)
                        {
                            MethodCallNodeExecuteCall(objectValue, item.Value.First().Item2);
                        }
                    }
                    return(((BooleanNode)endValue).Value);
                }
            }
            return(false);
        }
Beispiel #19
0
 public static Node NewNull()
 {
     NullNode node = new NullNode();
     return node;
 }
 public LanguageType Visit(NullNode node)
 {
     return(LanguageType.Null);
 }
 public ENullNode(NullNode nullNode) : base(nullNode)
 {
     _nullNode = nullNode;
 }
 public virtual bool VisitNullNode(NullNode node)
 {
     return(DefaultVisit(node));
 }
        protected void MethodCallNodeExecuteCall <T>(T objectValue, AbstractSyntaxTreeNode item)
        {
            var method = objectValue.GetType().GetMethod(((MethodCallNode)item).Name);

            if (method != null)
            {
                var objectList = new List <object>();
                for (int parameterCount = 0; parameterCount < ((MethodCallNode)item).parameterList.Count; parameterCount++)
                {
                    var parameter = ((MethodCallNode)item).parameterList[parameterCount];
                    if (parameter is StringNode)
                    {
                        var      value    = ((StringNode)parameter).Value;
                        DateTime dateTime = new DateTime();
                        if (DateTime.TryParse(value, out dateTime))
                        {
                            objectList.Add(dateTime);
                        }
                        else
                        {
                            objectList.Add(value);
                        }
                    }
                    else if (parameter is DateTimeNode)
                    {
                        var value = ((DateTimeNode)parameter).Value;
                        objectList.Add(value);
                    }
                    else if (parameter is BooleanNode)
                    {
                        var value = ((BooleanNode)parameter).Value;
                        objectList.Add(value);
                    }
                    else if (parameter is DoubleNode)
                    {
                        var value = ((DoubleNode)parameter).Value;
                        objectList.Add(value);
                    }
                    else if (parameter is IntegerNode)
                    {
                        var value = ((IntegerNode)parameter).Value;
                        objectList.Add(value);
                    }
                }
                var      result = method.Invoke(objectValue, objectList.ToArray());
                int      intOutValue;
                double   doubleOutValue;
                bool     boolOutValue;
                DateTime dateTimeOutValue;
                if (result == null)
                {
                    NullNode nullNode = new NullNode();
                    valueStack.Push(nullNode);
                }
                else if (int.TryParse(result.ToString(), out intOutValue))
                {
                    IntegerNode integerNode = new IntegerNode();
                    integerNode.Value = intOutValue;
                    valueStack.Push(integerNode);
                }
                else if (double.TryParse(result.ToString(), out doubleOutValue))
                {
                    DoubleNode doubleNode = new DoubleNode();
                    doubleNode.Value = doubleOutValue;
                    valueStack.Push(doubleNode);
                }
                else if (bool.TryParse(result.ToString(), out boolOutValue))
                {
                    BooleanNode booleanNode = new BooleanNode();
                    booleanNode.Value = boolOutValue;
                    valueStack.Push(booleanNode);
                }
                else if (DateTime.TryParse(result.ToString(), out dateTimeOutValue))
                {
                    DateTimeNode dateTimeNode = new DateTimeNode();
                    dateTimeNode.Value = dateTimeOutValue;
                    valueStack.Push(dateTimeNode);
                }
                else
                {
                    StringNode stringNode = new StringNode();
                    stringNode.Value = result.ToString();
                    valueStack.Push(stringNode);
                }
            }
        }
Beispiel #24
0
 public virtual void VisitNullNode(NullNode node)
 {
     DefaultVisit(node);
 }
 public void Visit(NullNode node)
 {
     return;
 }
        private void EmitBinaryExpNode(Operator node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            Dictionary <int, Node> nodes = node.GetChildrenWithIndices();

            Validity.Assert(nodes.Count <= 2);

            BinaryExpressionNode expressionNode = new BinaryExpressionNode();

            // Create operator from input node
            switch (node.Name)
            {
            case "=":
                expressionNode.Optr = ProtoCore.DSASM.Operator.assign;
                break;

            case "+":
                expressionNode.Optr = ProtoCore.DSASM.Operator.add;
                break;

            case "-":
                expressionNode.Optr = ProtoCore.DSASM.Operator.sub;
                break;

            case "*":
                expressionNode.Optr = ProtoCore.DSASM.Operator.mul;
                break;

            case "/":
                expressionNode.Optr = ProtoCore.DSASM.Operator.div;
                break;

            case "%":
                expressionNode.Optr = ProtoCore.DSASM.Operator.mod;
                break;

            case "==":
                expressionNode.Optr = ProtoCore.DSASM.Operator.eq;
                break;

            case "!=":
                expressionNode.Optr = ProtoCore.DSASM.Operator.nq;
                break;

            case ">=":
                expressionNode.Optr = ProtoCore.DSASM.Operator.ge;
                break;

            case ">":
                expressionNode.Optr = ProtoCore.DSASM.Operator.gt;
                break;

            case "<=":
                expressionNode.Optr = ProtoCore.DSASM.Operator.le;
                break;

            case "<":
                expressionNode.Optr = ProtoCore.DSASM.Operator.lt;
                break;

            case "&&":
                expressionNode.Optr = ProtoCore.DSASM.Operator.and;
                break;

            case "||":
                expressionNode.Optr = ProtoCore.DSASM.Operator.or;
                break;

            case "&":
                expressionNode.Optr = ProtoCore.DSASM.Operator.bitwiseand;
                break;

            case "|":
                expressionNode.Optr = ProtoCore.DSASM.Operator.bitwiseor;
                break;

            case "^":
                expressionNode.Optr = ProtoCore.DSASM.Operator.bitwisexor;
                break;

            default: break;
            }

            AssociativeNode identNode1 = new NullNode();
            AssociativeNode identNode2 = new NullNode();

            if (nodes.Count == 2)
            {
                // Create BinaryExpressionNode from identNode1, identNode2 and operator
                DFSTraverse(nodes[0], out identNode1);
                DFSTraverse(nodes[1], out identNode2);
            }
            else if (nodes.Count == 1)
            {
                // Create BinaryExpressionNode from identNode1, null
                DFSTraverse(nodes[0], out identNode1);
            }
            expressionNode.LeftNode  = identNode1;
            expressionNode.RightNode = identNode2;

            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);
            BinaryExpressionNode assignmentNode = new BinaryExpressionNode();

            assignmentNode.LeftNode  = new IdentifierNode(node.tempName);
            assignmentNode.Optr      = ProtoCore.DSASM.Operator.assign;
            assignmentNode.RightNode = expressionNode;
            assignmentNode.Guid      = node.Guid;

            Validity.Assert(gc != null);
            gc.HandleNewNode(assignmentNode);

            outnode = assignmentNode;
        }
Beispiel #27
0
	void Factor(out Node node) {
		node = null; 
		if (IsReplicationGuideIdent()) {
			ReplicationGuideIdent(out node);
		} else if (la.kind == 2 || la.kind == 3 || la.kind == 14) {
			Number(out node);
		} else if (la.kind == 28) {
			Get();
			node = new BooleanNode() { value = ProtoCore.DSASM.Literal.True }; 
		} else if (la.kind == 29) {
			Get();
			node = new BooleanNode() { value = ProtoCore.DSASM.Literal.False }; 
		} else if (la.kind == 30) {
			Get();
			node = new NullNode(); 
		} else if (la.kind == 32) {
			ArrayExprList(out node);
		} else if (la.kind == 18) {
			Get();
			Expression(out node);
			Expect(19);
		} else if (la.kind == 1) {
			IdentifierList(out node);
		} else SynErr(80);
	}
Beispiel #28
0
 public virtual void AddNullValue(NullNode nullNode)
 {
     AddValue("null");
 }
Beispiel #29
0
 public virtual void VisitNullNode(NullNode val)
 {
 }
Beispiel #30
0
 void factor(out Node node)
 {
     node = null;
     if (la.kind == 2 || la.kind == 3 || la.kind == 38) {
     num(out node);
     } else if (isFunctionCall()) {
     functioncall(out node);
     } else if (isArrayAccess()) {
     arrayident(out node);
     } else if (la.kind == 27) {
     Get();
     node = new BooleanNode() { value = ProtoCore.DSASM.Literal.True };
     } else if (la.kind == 28) {
     Get();
     node = new BooleanNode() { value = ProtoCore.DSASM.Literal.False };
     } else if (la.kind == 29) {
     Get();
     node = new NullNode();
     } else if (la.kind == 32) {
     Get();
     ExprListNode exprlist = new ExprListNode();
     if (StartOf(3)) {
         expr(out node);
         exprlist.list.Add(node);
         while (la.kind == 30) {
             Get();
             expr(out node);
             exprlist.list.Add(node);
         }
     }
     Expect(33);
     node = exprlist;
     } else if (la.kind == 8) {
     Get();
     expr(out node);
     Expect(9);
     } else if (la.kind == 1) {
     identifierList(out node);
     } else SynErr(65);
 }
Beispiel #31
0
 public override void VisitNullNode(NullNode nil)
 {
     Text += IndentStr() + nil.Value.ToString() + ";";
 }
Beispiel #32
0
        protected override AssociativeNode GetFunctionApplication(NodeModel model, List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode rhs;

            string function = Definition.FunctionName;

            switch (Definition.Type)
            {
            case FunctionType.Constructor:
            case FunctionType.StaticMethod:
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.FunctionName)
                    };
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    model.UseLevelAndReplicationGuide(inputAstNodes);
                    rhs = AstFactory.BuildFunctionCall(
                        Definition.ClassName,
                        Definition.FunctionName,
                        inputAstNodes);
                }
                break;

            case FunctionType.StaticProperty:

                var staticProp = new IdentifierListNode
                {
                    LeftNode  = new IdentifierNode(Definition.ClassName),
                    RightNode = new IdentifierNode(Definition.FunctionName)
                };
                rhs = staticProp;
                break;

            case FunctionType.InstanceProperty:

                // Only handle getter here. Setter could be handled in CBN.
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.FunctionName)
                    };
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    rhs = new NullNode();
                    if (inputAstNodes != null && inputAstNodes.Count >= 1)
                    {
                        var thisNode = inputAstNodes[0];
                        if (thisNode != null && !(thisNode is NullNode))
                        {
                            var insProp = new IdentifierListNode
                            {
                                LeftNode  = inputAstNodes[0],
                                RightNode = new IdentifierNode(Definition.FunctionName)
                            };
                            rhs = insProp;
                        }
                    }
                }

                break;

            case FunctionType.InstanceMethod:
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.FunctionName)
                    };
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    rhs = new NullNode();
                    model.UseLevelAndReplicationGuide(inputAstNodes);

                    if (inputAstNodes != null && inputAstNodes.Count >= 1)
                    {
                        var thisNode = inputAstNodes[0];
                        inputAstNodes.RemoveAt(0);     // remove this pointer

                        if (thisNode != null && !(thisNode is NullNode))
                        {
                            var memberFunc = new IdentifierListNode
                            {
                                LeftNode  = thisNode,
                                RightNode =
                                    AstFactory.BuildFunctionCall(function, inputAstNodes)
                            };
                            rhs = memberFunc;
                        }
                    }
                }

                break;

            default:
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierNode(function);
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    model.UseLevelAndReplicationGuide(inputAstNodes);
                    rhs = AstFactory.BuildFunctionCall(function, inputAstNodes);
                }
                break;
            }

            return(rhs);
        }
        public void TestNullNode()
        {
            NullNode node = new NullNode();

            CheckSerializationRoundTrip(node);
        }