Пример #1
0
        public virtual void Visit(IfStatement ifStatement)
        {
            WriteLinkLine(ifStatement);
            Visit((Statement)ifStatement);

            Write("if").WriteSpace().Write("(");
            VisitDynamic(ifStatement.Condition);
            Write(")");
            WriteStatementContent(ifStatement.Then);
            if (ifStatement.Else != null)
            {
                WriteLinkLine(ifStatement.Else);
                Write("else");
                var nestedIfStatement = ifStatement.Else as IfStatement;
                if (nestedIfStatement != null && nestedIfStatement.Attributes.Count == 0)
                {
                    Write(" ");
                    Visit(nestedIfStatement);
                }
                else WriteStatementContent(ifStatement.Else);
            }
        }
Пример #2
0
        public override Node Visit(IfStatement ifStatement)
        {
            // First, dispatch to resolve type of node at deeper level
            base.Visit(ifStatement);

            var conditionType = ifStatement.Condition.TypeInference.TargetType;
            if (!(ifStatement.Condition is BinaryExpression || ifStatement.Condition is UnaryExpression))
            {
                ifStatement.Condition = ConvertExpressionToBool(ifStatement.Condition, conditionType);
            }

            return ifStatement;
        }
Пример #3
0
        protected virtual void Visit(IfStatement ifStatement)
        {
            // First, dispatch to resolve type of node at deeper level
            Visit((Node)ifStatement);

            var conditionType = ifStatement.Condition.TypeInference.TargetType;
            if (!(ifStatement.Condition is BinaryExpression || ifStatement.Condition is UnaryExpression))
            {
                ifStatement.Condition = ConvertExpressionToBool(ifStatement.Condition, conditionType);
            }
        }
Пример #4
0
        protected virtual void Visit(IfStatement ifStatement)
        {
            // First, dispatch to resolve type of node at deeper level
            Visit((Node)ifStatement);

            ifStatement.Condition.TypeInference.ExpectedType = ScalarType.Bool;
        }
Пример #5
0
 protected void Visit(IfStatement ifStatement)
 {
     containerStack.Push(ifStatement);
     Visit((Node)ifStatement);
     containerStack.Pop();
 }
Пример #6
0
        /// <summary>
        /// Inserts the break variable in the flow of the loop
        /// </summary>
        /// <param name="breakFlag">the break variable</param>
        protected void TransformBreaks(Variable breakFlag)
        {
            var breakTest = new UnaryExpression(UnaryOperator.LogicalNot, new VariableReferenceExpression(breakFlag));
            scopeList.Reverse();
            foreach (var breakScope in scopeList)
            {
                for (int i = 0; i < breakScope.Count - 1; ++i)
                {
                    var currentScope = breakScope[i];
                    var nextScope = breakScope[i+1];

                    if (currentScope is StatementList)
                    {
                        var typedScope = currentScope as StatementList;
                        var index = typedScope.Statements.IndexOf(nextScope);
                        if (index == -1)
                        {
                            parserResult.Error("unable to find the next scope when replacing break/continue", nextScope.Span);
                            break;
                        }

                        var testBlock = new IfStatement();
                        testBlock.Condition = breakTest;
                        var thenBlock = new StatementList();
                        for (int j = index + 1; j < typedScope.Statements.Count; ++j)
                            thenBlock.Add(typedScope.Statements[j]);
                        testBlock.Then = thenBlock;

                        typedScope.Statements.RemoveRange(index + 1, typedScope.Statements.Count - index - 1);
                        if (typedScope.Statements.Count > 0 && i != breakScope.Count - 2) // do not add the statements behind the break/continue
                            typedScope.Statements.Add(testBlock);
                    }
                }

                var last = breakScope.LastOrDefault() as ExpressionStatement;
                if (last != null)
                    last.Expression = new AssignmentExpression(AssignmentOperator.Default, new VariableReferenceExpression(breakFlag), new LiteralExpression(true));
            }
        }
Пример #7
0
        public override Node Visit(IfStatement ifStatement)
        {
            // First, dispatch to resolve type of node at deeper level
            base.Visit(ifStatement);

            ifStatement.Condition.TypeInference.ExpectedType = ScalarType.Bool;

            return ifStatement;
        }
 public override void Visit(IfStatement ifStatement)
 {
     containerStack.Push(ifStatement);
     base.Visit(ifStatement);
     containerStack.Pop();
 }