Пример #1
0
        private void EmitRangeExpNode(Func node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.isRange);

            RangeExprNode rangeNode = new RangeExprNode();

            // Set FromNode, ToNode, stepOperator and StepNode for rangeNode
            Dictionary <int, Node> nodes = node.GetChildrenWithIndices();
            //int numParams = node.numParameters;

            AssociativeNode startNode = null;
            AssociativeNode endNode   = null;
            AssociativeNode stepNode  = null;

            if (nodes.Count >= 1)
            {
                DFSTraverse(nodes[0], out startNode);
            }
            if (nodes.Count >= 2)
            {
                DFSTraverse(nodes[1], out endNode);
            }
            if (nodes.Count >= 3)
            {
                DFSTraverse(nodes[2], out stepNode);
            }
            rangeNode.FromNode = startNode;
            rangeNode.ToNode   = endNode;
            rangeNode.StepNode = stepNode;

            if (node.Name == "Range.ByIncrementValue")
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.stepsize;
            }
            else if (node.Name == "Range.ByIntervals")
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.num;
            }
            else
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.approxsize;
            }

            outnode = rangeNode;
            //outnode = CreateBinaryExpNode(node, rangeNode);
        }
Пример #2
0
        private void EmitFunctionCallNode(Func node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            FunctionCallNode fNode = new FunctionCallNode();
            List <ProtoCore.AST.AssociativeAST.AssociativeNode> args = new List <ProtoCore.AST.AssociativeAST.AssociativeNode>();

            if (node.Name.Contains("."))
            {
                string funcName = (node.Name.Split('.'))[1];
                fNode.Function = new IdentifierNode(funcName);
            }
            //else if (node.GetChildrenWithIndices().Count != 0)
            //{

            //}
            else
            {
                fNode.Function = new IdentifierNode(node.Name);
            }


            for (int i = 0; i < node.numParameters; i++)
            {
                args.Add(new NullNode());
            }

            if (args.Count > 0)
            {
                Dictionary <int, Node> nodes = node.GetChildrenWithIndices();
                for (int i = 0; i < nodes.Count; ++i)
                {
                    AssociativeNode argNode = null;
                    DFSTraverse(nodes[i], out argNode);
                    args.RemoveAt(i);
                    args.Insert(i, argNode);
                }
            }

            fNode.FormalArguments = args;

            outnode = fNode;
        }
Пример #3
0
        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;
        }
        private void EmitRangeExpNode(Func node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.isRange);

            RangeExprNode rangeNode = new RangeExprNode();
            
            // Set FromNode, ToNode, stepOperator and StepNode for rangeNode
            Dictionary<int, Node> nodes = node.GetChildrenWithIndices();
            //int numParams = node.numParameters;

            AssociativeNode startNode = null;
            AssociativeNode endNode = null;
            AssociativeNode stepNode = null;

            if (nodes.Count >= 1)
            {                
                DFSTraverse(nodes[0], out startNode);
            }
            if (nodes.Count >= 2)
            {
                DFSTraverse(nodes[1], out endNode);
            }
            if (nodes.Count >= 3)
            {
                DFSTraverse(nodes[2], out stepNode);
            }
            rangeNode.FromNode = startNode;
            rangeNode.ToNode = endNode;
            rangeNode.StepNode = stepNode;
            
            if (node.Name == "Range.ByIncrementValue")
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.stepsize;
            }
            else if (node.Name == "Range.ByIntervals")
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.num;
            }
            else
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.approxsize;
            }

            outnode = rangeNode;
            //outnode = CreateBinaryExpNode(node, rangeNode);
        }
        private void EmitFunctionCallNode(Func node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            FunctionCallNode fNode = new FunctionCallNode();
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> args = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            
            if (node.Name.Contains("."))
            {
                string funcName = (node.Name.Split('.'))[1];
                fNode.Function = new IdentifierNode(funcName);
            }
            //else if (node.GetChildrenWithIndices().Count != 0)
            //{

            //}
            else
                fNode.Function = new IdentifierNode(node.Name);

            
            for (int i = 0; i < node.numParameters; i++)
                args.Add(new NullNode());

            if (args.Count > 0)
            {
                Dictionary<int, Node> nodes = node.GetChildrenWithIndices();
                for (int i = 0; i < nodes.Count; ++i)
                {
                    AssociativeNode argNode = null;
                    DFSTraverse(nodes[i], out argNode);
                    args.RemoveAt(i);
                    args.Insert(i, argNode);
                }
            }

            fNode.FormalArguments = args;

            outnode = fNode;
        }
        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;
        }