Ejemplo n.º 1
0
        private void EmitRangeExprNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AssociativeGraph.GraphNode graphNode = null, ProtoCore.DSASM.AssociativeSubCompilePass subPass = ProtoCore.DSASM.AssociativeSubCompilePass.kNone)
        {
            RangeExprNode range = node as RangeExprNode;

            // Do some static checking...
            if ((range.FromNode is IntNode || range.FromNode is DoubleNode) &&
                (range.ToNode is IntNode || range.ToNode is DoubleNode) &&
                (range.StepNode == null || (range.StepNode != null && (range.StepNode is IntNode || range.StepNode is DoubleNode))))
            {
                decimal current = (range.FromNode is IntNode) ? Int64.Parse((range.FromNode as IntNode).value) : Decimal.Parse((range.FromNode as DoubleNode).value);
                decimal end = (range.ToNode is IntNode) ? Int64.Parse((range.ToNode as IntNode).value) : Decimal.Parse((range.ToNode as DoubleNode).value);
                ProtoCore.DSASM.RangeStepOperator stepoperator = range.stepoperator;

                decimal step = 1;
                if (range.StepNode != null)
                {
                    step = (range.StepNode is IntNode) ? Int64.Parse((range.StepNode as IntNode).value) : Decimal.Parse((range.StepNode as DoubleNode).value);
                }

                if (stepoperator == ProtoCore.DSASM.RangeStepOperator.stepsize)
                {
                    if (range.StepNode == null && end < current)
                    {
                        step = -1;
                    }

                    if (step == 0)
                    {
                        buildStatus.LogWarning(ProtoCore.BuildData.WarningID.kInvalidRangeExpression, ProtoCore.BuildData.WarningMessage.kRangeExpressionWithStepSizeZero, compileStateTracker.CurrentDSFileName, range.StepNode.line, range.StepNode.col);
                        EmitNullNode(new NullNode(), ref inferedType);
                        return;
                    }
                    if ((end > current && step < 0) || (end < current && step > 0))
                    {
                        buildStatus.LogWarning(ProtoCore.BuildData.WarningID.kInvalidRangeExpression, ProtoCore.BuildData.WarningMessage.kRangeExpressionWithInvalidStepSize, compileStateTracker.CurrentDSFileName, range.StepNode.line, range.StepNode.col);
                        EmitNullNode(new NullNode(), ref inferedType);
                        return;
                    }
                }
                else if (stepoperator == ProtoCore.DSASM.RangeStepOperator.num)
                {
                    if (range.StepNode != null && !(range.StepNode is IntNode))
                    {
                        buildStatus.LogWarning(ProtoCore.BuildData.WarningID.kInvalidRangeExpression, ProtoCore.BuildData.WarningMessage.kRangeExpressionWithNonIntegerStepNumber, compileStateTracker.CurrentDSFileName, range.StepNode.line, range.StepNode.col);
                        EmitNullNode(new NullNode(), ref inferedType);
                        return;
                    }

                    if (step <= 0)
                    {
                        buildStatus.LogWarning(ProtoCore.BuildData.WarningID.kInvalidRangeExpression, ProtoCore.BuildData.WarningMessage.kRangeExpressionWithNegativeStepNumber, compileStateTracker.CurrentDSFileName, range.StepNode.line, range.StepNode.col);
                        EmitNullNode(new NullNode(), ref inferedType);
                        return;
                    }
                }
                else if (stepoperator == ProtoCore.DSASM.RangeStepOperator.approxsize)
                {
                    if (step == 0)
                    {
                        buildStatus.LogWarning(ProtoCore.BuildData.WarningID.kInvalidRangeExpression, ProtoCore.BuildData.WarningMessage.kRangeExpressionWithStepSizeZero, compileStateTracker.CurrentDSFileName, range.StepNode.line, range.StepNode.col);
                        EmitNullNode(new NullNode(), ref inferedType);
                        return;
                    }
                }
            }

            // Replace with build-in RangeExpression() function. - Yu Ke
            bool emitReplicationgGuideState = emitReplicationGuide;
            emitReplicationGuide = false;

            BooleanNode hasStep = new BooleanNode { value = range.StepNode == null ? "false" : "true" };

            IntNode op = new IntNode();
            switch (range.stepoperator)
            {
                case ProtoCore.DSASM.RangeStepOperator.stepsize:
                    op.value = "0";
                    break;
                case ProtoCore.DSASM.RangeStepOperator.num:
                    op.value = "1";
                    break;
                case ProtoCore.DSASM.RangeStepOperator.approxsize:
                    op.value = "2";
                    break;
                default:
                    op.value = "-1";
                    break;
            }

            var rangeExprFunc = nodeBuilder.BuildFunctionCall(Constants.kFunctionRangeExpression,
                new List<AssociativeNode> { range.FromNode, range.ToNode, range.StepNode == null ? new NullNode() : range.StepNode, op, hasStep });

            EmitFunctionCallNode(rangeExprFunc, ref inferedType, false, graphNode, subPass);

            emitReplicationGuide = emitReplicationgGuideState;

            if (subPass != ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier)
            {
                if (range.ArrayDimensions != null)
                {
                    int dimensions = DfsEmitArrayIndexHeap(range.ArrayDimensions, graphNode);
                    EmitInstrConsole(ProtoCore.DSASM.kw.pushindex, dimensions.ToString() + "[dim]");
                    EmitPushArrayIndex(dimensions);
                }

                if (compileStateTracker.Options.TempReplicationGuideEmptyFlag && emitReplicationGuide)
                {
                    int replicationGuideNumber = EmitReplicationGuides(range.ReplicationGuides);
                    EmitInstrConsole(ProtoCore.DSASM.kw.pushindex, replicationGuideNumber + "[guide]");
                    EmitPushReplicationGuide(replicationGuideNumber);
                }
            }
        }
Ejemplo n.º 2
0
	void Associative_Factor(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
		node = null; 
		if (IsNumber()) {
			Associative_Number(out node);
		} else if (la.kind == 41) {
			Get();
			node = new ProtoCore.AST.AssociativeAST.BooleanNode(true);
			NodeUtils.SetNodeLocation(node, t);
			
		} else if (la.kind == 42) {
			Get();
			node = new ProtoCore.AST.AssociativeAST.BooleanNode(false);
			NodeUtils.SetNodeLocation(node, t);
			
		} else if (la.kind == 43) {
			Get();
			node = new ProtoCore.AST.AssociativeAST.NullNode();
			NodeUtils.SetNodeLocation(node, t);
			
		} else if (la.kind == 5) {
			Associative_Char(out node);
		} else if (la.kind == 4) {
			Associative_String(out node);
		} else if (la.kind == 1 || la.kind == 12 || la.kind == 45) {
			Associative_IdentifierList(out node);
		} else if (StartOf(20)) {
			Associative_UnaryExpression(out node);
		} else SynErr(95);
	}
Ejemplo n.º 3
0
        void Associative_Factor(out ProtoCore.AST.AssociativeAST.AssociativeNode node)
        {
            node = null;
            if (IsNumber()) {
            Associative_Number(out node);
            } else if (la.kind == 40) {
            Get();
            node = new ProtoCore.AST.AssociativeAST.BooleanNode() { value = ProtoCore.DSASM.Literal.True };
            NodeUtils.SetNodeLocation(node, t);

            } else if (la.kind == 41) {
            Get();
            node = new ProtoCore.AST.AssociativeAST.BooleanNode() { value = ProtoCore.DSASM.Literal.False };
            NodeUtils.SetNodeLocation(node, t);

            } else if (la.kind == 42) {
            Get();
            node = new ProtoCore.AST.AssociativeAST.NullNode();
            NodeUtils.SetNodeLocation(node, t);

            } else if (la.kind == 5) {
            Associative_Char(out node);
            } else if (la.kind == 4) {
            Associative_String(out node);
            } else if (la.kind == 1 || la.kind == 9 || la.kind == 44) {
            Associative_IdentifierList(out node);
            } else if (StartOf(21)) {
            Associative_UnaryExpression(out node);
            } else SynErr(97);
        }
        /// <summary>
        /// TODO: Deprecate
        /// Emit IntNode or DoubleNode
        /// </summary>
        /// <param name="node"></param>
        /// <param name="outnode"></param>
        private void EmitLiteralNode(LiteralNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.children.Count == 0);

            // Create temp identifier and assign it to the literal (IntNode or DoubleNode) to create a BinaryExpressionNode
            // Return the temp IdentifierNode
            //BinaryExpressionNode expressionNode = new BinaryExpressionNode();
            AssociativeNode rightNode = null;
            
            Int64 number;
            double real;
            bool flag;
            string val = node.ToScript();
            // If LiternalNode is double
            if(Double.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out real))
            {
                rightNode = new DoubleNode(real); 
            }
            // If LiteralNode type is Int
            else if (Int64.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out number))
            {
            
                rightNode = new IntNode(number);
            }            
            // If LiteralNode is bool
            else if (Boolean.TryParse(val, out flag))
            {
                rightNode = new BooleanNode(flag); 
            }

            /*IdentifierNode ident = CreateTempIdentifierNode(node);
            expressionNode.RightNode = rightNode;
            expressionNode.LeftNode = ident;
            expressionNode.Optr = ProtoCore.DSASM.Operator.assign;*/

            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);

            //outnode = expressionNode;
            outnode = CreateBinaryExpNode(node, rightNode);
        }
Ejemplo n.º 5
0
 public BooleanNode(BooleanNode rhs)
     : base(rhs)
 {
     value = rhs.value;
 }