Example #1
0
        /// <summary>
        /// 根据配置执行循环逻辑
        /// </summary>
        /// <exception cref="System.Configuration.ConfigurationErrorsException">模块类型配置错误,至少需要有while满足的条件!</exception>
        public override void InvokeInScope(ModuleRunScope scope)
        {
            if (While == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("模块类型(" + typeof(ModuleDoWhile).FullName + ")配置错误,至少需要有while满足的条件!");
            }

            if (RunMode == DoWhileMode.While)
            {
                while (While.Match.CanRunInScope(scope))
                {
                    While.InvokeInScope(scope);
                }
            }
            else if (RunMode == DoWhileMode.DoWhile)
            {
                do
                {
                    Do.InvokeInScope(scope);
                }while (While.Match.CanRunInScope(scope));
            }
            else if (RunMode == DoWhileMode.WhileDo)
            {
                while (While.Match.CanRunInScope(scope))
                {
                    Do.InvokeInScope(scope);
                }
            }
        }
        public object VisitWhileStatement(While statement)
        {
            statement.Condition.Accept(this);
            statement.Body.Accept(this);

            return(null);
        }
Example #3
0
 public void VisitWhile(While whileStatement)
 {
     while (Calc <bool>(whileStatement.Condition))
     {
         RunBlock(whileStatement.Body);
     }
 }
        public override void VisitWhile(While p)
        {
            var continueLabel = IL.DefineLabel();

            EmitLoopSkeleton(continueLabel, (breakLabel) =>
            {
                var dowhile = IL.DefineLabel();

                IL.MarkLabel(continueLabel);
                VisitExpression(p.Expression);
                IL.Emit(OpCodes.Stloc, E);
                IL.Emit(OpCodes.Ldloca, E);
                IL.Emit(OpCodes.Call, isReal);
                IL.Emit(OpCodes.Brtrue, dowhile);
                IL.Emit(OpCodes.Ldsfld, typeof(Error).GetField("ExpectedBooleanExpression"));
                IL.Emit(OpCodes.Newobj, typeof(ProgramError).GetConstructor(new[] { typeof(Error) }));
                IL.Emit(OpCodes.Throw);

                IL.MarkLabel(dowhile);
                IL.Emit(OpCodes.Ldloc, E);
                EmitImplicitConversion(typeof(bool));
                IL.Emit(OpCodes.Brfalse, breakLabel);

                VisitStatement(p.Body);

                IL.Emit(OpCodes.Br, continueLabel);
            });
        }
        public override void Visit(While @while)
        {
            var expr = new ExpressionSimplifierVisitor().Visit(@while.Expr);

            if (expr is Bool b && b.Value == false)
            {
                return;
            }

            _state.GoToNextLabel(out var startWhileLabel);
            _llvmGenerator.Emit($"br label %{startWhileLabel}");
            _llvmGenerator.Emit($"{startWhileLabel}:");

            var exprResult = new ExpressionGeneratorVisitor(_state).Visit(expr);

            _state.GoToNextLabel(out var whileLabel);
            var endWhileLabel = _state.NewLabel;

            _llvmGenerator.Emit($"br i1 {exprResult.Register}, label %{whileLabel}, label %{endWhileLabel}");

            _llvmGenerator.Emit($"{whileLabel}:");
            Visit(@while.Block);
            _llvmGenerator.Emit($"br label %{startWhileLabel}");

            _state.CurrentLabel = endWhileLabel;
            _llvmGenerator.Emit($"{endWhileLabel}:");
            _llvmGenerator.Emit($"br label %{endWhileLabel}");
        }
 public OverUnderProgram(
     PushValue<RandomValueProvider> dummyData,
     While<NotEquals<StaticRandomNumberValueProvider>, GameLoop> loop,
     PrintValueNewLine<YouWin> winnerIsYou
     )
 {
 }
        protected override object VisitWhile(While W)
        {
            string name = target.LabelName();

            LinqExprs.LabelTarget begin = LinqExpr.Label("while_" + name + "_begin");
            LinqExprs.LabelTarget end   = LinqExpr.Label("while_" + name + "_end");
            loops.Push(new Loop(LinqExpr.Goto(end), LinqExpr.Goto(begin)));

            target.PushScope();

            // Check the condition, exit if necessary.
            target.Add(LinqExpr.Label(begin));
            target.Add(LinqExpr.IfThen(LinqExpr.Not(target.Compile(W.Condition)), LinqExpr.Goto(end)));

            // Generate the body target.
            Visit(W.Body);

            // Loop.
            target.Add(LinqExpr.Goto(begin));

            // Exit label.
            target.Add(LinqExpr.Label(end));

            loops.Pop();
            target.PopScope();
            return(null);
        }
 public void Visit(While node)
 {
     level++;
     Visit((dynamic)node[0]);
     Visit((dynamic)node[1]);
     level--;
 }
        public string Visit(While node)
        {
            var sb = new StringBuilder();

            var previousLabel = currentBlock;

            var labelBlock = GenerateLabel();

            currentBlock = labelBlock;
            var labelLoop = GenerateLabel();

            sb.Append($"    block {labelBlock}\n");
            sb.Append($"    loop {labelLoop}\n");
            level++;
            sb.Append(Visit((dynamic)node[0]));
            level--;
            sb.Append($"    i32.eqz\n");
            sb.Append($"    br_if {labelBlock}\n");
            sb.Append(Visit((dynamic)node[1]));
            sb.Append($"    br {labelLoop}\n");
            sb.Append($"    end\n");
            sb.Append($"    end\n");

            currentBlock = previousLabel;

            return(sb.ToString());
        }
Example #10
0
        private Stmt ForStatement()
        {
            Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'.");

            Stmt initializer;

            if (Match(TokenType.SEMICOLON))
            {
                initializer = null;
            }
            else if (Match(TokenType.VAR))
            {
                initializer = VarDeclaration();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr condition = null;

            if (!Check(TokenType.SEMICOLON))
            {
                condition = Expression();
            }

            Consume(TokenType.SEMICOLON, "Expect ';' after loop condition");

            Expr increment = null;

            if (!Check(TokenType.RIGHT_PAREN))
            {
                increment = Expression();
            }
            Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses");

            var body = Statement();

            if (condition == null)
            {
                condition = new Literal(true);
            }
            if (increment != null)
            {
                body = new Block(new List <Stmt> {
                    body, new Expression(increment)
                });
            }

            body = new While(condition, body);

            if (initializer != null)
            {
                body = new Block(new List <Stmt> {
                    initializer, body
                });
            }

            return(body);
        }
Example #11
0
        public override void VisitWhile(While node)
        {
            // Declare loop labels, preserving parent ones
            var previousContinueTargetLabel = continueTargetLabel;
            var previousBreakTargetLabel    = breakTargetLabel;

            continueTargetLabel = cil.CreateLabel("while_continue");
            breakTargetLabel    = cil.CreateLabel("while_break");

            // Condition
            cil.MarkLabel(continueTargetLabel);
            EmitLoad(node.Condition);
            EmitIsTrue(node.Condition.StaticRepr);
            cil.Branch(false, breakTargetLabel);

            // Body
            EmitStatements(node.Body);
            cil.Branch(continueTargetLabel);

            // End
            cil.MarkLabel(breakTargetLabel);

            // Restore parent loop labels
            continueTargetLabel = previousContinueTargetLabel;
            breakTargetLabel    = previousBreakTargetLabel;
        }
Example #12
0
        public void WriteWhile(While s)
        {
            Skip();

            if (s.DoWhile)
            {
                WriteLine("do");
            }
            else
            {
                BeginLine("while" + Space + "(");
                WriteExpression(s.Condition);
                EndLine(")");
            }

            WriteShortScope(s.OptionalBody);

            if (s.DoWhile)
            {
                DisableSkip();
                BeginLine("while" + Space + "(");
                WriteExpression(s.Condition);
                EndLine(");");
                Skip();
            }
        }
Example #13
0
        /// <summary>
        ///     Ends a while statement
        /// </summary>
        /// <param name="whileCommand">While statement to end</param>
        public virtual void EndWhile(While whileCommand)
        {
            SetCurrentMethod();
            var tempCommand = new EndWhile(whileCommand);

            tempCommand.Setup();
            Commands.Add(tempCommand);
        }
Example #14
0
 object Statements.IVisitor <object> .VisitWhileStmt(While stmt)
 {
     while (IsTruthy(Evaluate(stmt.Condition)))
     {
         Execute(stmt.Body);
     }
     return(null);
 }
Example #15
0
 public object VisitWhileStatement(While statement)
 {
     _callingBodyStack.Push(CallingBody.WHILE);
     Resolve(statement.Condition);
     Resolve(statement.Body);
     _callingBodyStack.Pop();
     return(null);
 }
Example #16
0
        /// <summary>
        /// Ends a while statement
        /// </summary>
        /// <param name="WhileCommand">While statement to end</param>
        public virtual void EndWhile(While WhileCommand)
        {
            SetCurrentMethod();
            EndWhile TempCommand = new EndWhile(WhileCommand);

            TempCommand.Setup();
            Commands.Add(TempCommand);
        }
Example #17
0
        public WhileAction(ParseInfo parseInfo, Scope scope, While whileContext)
        {
            RawContinue = true;
            Condition   = parseInfo.GetExpression(scope, whileContext.Condition);

            Block = parseInfo.SetLoop(this).GetStatement(scope, whileContext.Statement);
            Path  = new PathInfo(Block, whileContext.Range, false);
        }
Example #18
0
        public void Visit(While whiles)
        {
            var oldRet = _foundReturn;

            _foundReturn = false;
            whiles.Body.Accept(this);
            _foundReturn = oldRet;
        }
Example #19
0
        public object VisitWhileStmt(While stmt)
        {
            while (IsTruthy(Evaluate(stmt.Condition)))
            {
                Execute(stmt.Body);
            }

            return(null);
        }
Example #20
0
        /// <summary>
        /// Creates a while statement
        /// </summary>
        /// <param name="LeftHandSide">Left hand side variable</param>
        /// <param name="ComparisonType">Comparison type</param>
        /// <param name="RightHandSide">Right hand side variable</param>
        /// <returns>The while object</returns>
        public virtual While While(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide)
        {
            SetCurrentMethod();
            While TempCommand = new While(ComparisonType, LeftHandSide, RightHandSide);

            TempCommand.Setup();
            Commands.Add(TempCommand);
            return(TempCommand);
        }
Example #21
0
        /// <summary>
        ///     Creates a while statement
        /// </summary>
        /// <param name="leftHandSide">Left hand side variable</param>
        /// <param name="comparisonType">Comparison type</param>
        /// <param name="rightHandSide">Right hand side variable</param>
        /// <returns>The while object</returns>
        public virtual While While(VariableBase leftHandSide, Comparison comparisonType, VariableBase rightHandSide)
        {
            SetCurrentMethod();
            var tempCommand = new While(comparisonType, leftHandSide, rightHandSide);

            tempCommand.Setup();
            Commands.Add(tempCommand);
            return(tempCommand);
        }
Example #22
0
 public void Execute(While cmd)
 {
     Execute(cmd.Expression);
     while (cmd.Result.Value)
     {
         Execute(cmd.WhileBlock);
         Execute(cmd.Expression);
     }
 }
Example #23
0
 object Stmt.Visitor <object> .visitWhileStmt(While stmt)
 {
     //Console.WriteLine("visitWhileStmt");
     while (isTruthy(evaluate(stmt.condition)))
     {
         execute(stmt.body);
     }
     return(null);
 }
Example #24
0
 public void Visit(While whiles)
 {
     Indent();
     _sb.Append("while (");
     whiles.Guard.Accept(this);
     _sb.Append(")\r\n");
     ++_level;
     whiles.Body.Accept(this);
     --_level;
 }
Example #25
0
        public object visit_While_Stmt(While stmt)
        {
            bool currentLoop = inLoop;

            inLoop = true;
            resolve(stmt.condition);
            resolve(stmt.body);
            inLoop = currentLoop;
            return(null);
        }
Example #26
0
        public void TestWhile()
        {
            var while_ = new While();

            while_.Init(new Rel(new Token('>'), new Constant(42), new Constant(99)), new Stmt());
            while_.Gen(10, 88);
            //output:
            //      iffalse 42 > 99 goto L88
            //L1:	goto L 10
        }
Example #27
0
 public void Visit(While node)
 {
     Visit(node.Condition);
     if (node.Condition.computedType.Name != "Bool")
     {
         errorLog.LogError(ConditionIsBool);
     }
     Visit(node.Body);
     node.computedType = Context.GetType("Object");
 }
Example #28
0
 public void Visit(While n)
 {
     Helpers.WriteColor($"{_tab}while ", ConsoleColor.DarkCyan, ConsoleColor.Black);
     Helpers.Write("(");
     n.Test.Accept(this);
     Helpers.WriteLine(") ");
     Tab();
     n.Action.Accept(this);
     Untab();
 }
Example #29
0
        public void CloneTest()
        {
            var body = new Define(Variable.X, new Add(Variable.X, new Number(2)));
            var cond = new LessThan(Variable.X, new Number(10));

            var exp   = new While(body, cond);
            var clone = exp.Clone();

            Assert.Equal(exp, clone);
        }
Example #30
0
        public void WhileCtorTest()
        {
            var variable  = new Id(new Word("x", Tag.ID), VarType.INT, 0);
            var constant  = new Constant(new Num(12), VarType.INT);
            var expresion = new Rel(Word.EQ, variable, constant);

            var whilenode = new While();

            whilenode.Init(expresion, new Stmt());
        }
Example #31
0
        private static ActivityInfo[] GetWhileChildren(While activity)
        {
            var children = new List <ActivityInfo>();

            if (activity.Body != null)
            {
                children.Add(new ActivityInfo(activity.Body, activity, "Body"));
            }

            return(children.ToArray());
        }
        public override string ToString()
        {
            w = (While)base.Tag;

            Binding myBinding = new Binding("condition");
            myBinding.Mode = BindingMode.TwoWay;
            myBinding.Source = w;
            txtcond.SetBinding(TextBox.TextProperty, myBinding);



            Binding descbinding = new Binding("Description");
            descbinding.Mode = BindingMode.TwoWay;
            descbinding.Source = w;
            txtdesc.SetBinding(TextBox.TextProperty, descbinding);


            return base.ToString();
        }
Example #33
0
 public override Statement VisitWhile(While While) {
   if (While == null) return null;
   this.loopCount++;
   While.Condition = this.VisitBooleanExpression(While.Condition);
   While.Invariants = this.VisitLoopInvariantList(While.Invariants);
   While.Body = this.VisitBlock(While.Body);
   this.loopCount--;
   return While;
 }
Example #34
0
 public void Visit(While whiles)
 {
     whiles.Guard.Accept(this);
     MustBeBool("The while guard");
     whiles.Body.Accept(this);
 }
Example #35
0
 public virtual Statement VisitWhile(While While, While changes, While deletions, While insertions){
   this.UpdateSourceContext(While, changes);
   if (While == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return While;
 }
Example #36
0
 public override Statement VisitWhile(While While)
 {
     if (While == null) return null;
     return base.VisitWhile((While)While.Clone());
 }
 void OP_WHILE(out pBaseLangObject outObj, pBaseLangObject parent)
 {
     var obj = new While(parent); outObj = obj; pBaseLangObject blo;
     Expect(62);
     Expect(10);
     EXPRESSION(out blo, obj);
     obj.expression = blo;
     Expect(11);
     if (la.kind == 14) {
         Get();
         while (StartOf(21)) {
             if (StartOf(14)) {
                 CODEINSTRUCTION(out blo, obj);
                 obj.addChild(blo);
             } else {
                 OP_BREAK(out blo, obj);
                 obj.addChild(blo);
                 TERMINATOR();
             }
         }
         Expect(15);
     } else if (StartOf(14)) {
         CODEINSTRUCTION(out blo, obj);
         obj.addChild(blo);
     } else SynErr(108);
 }
 public override Statement VisitWhile(While While)
 {
   throw new ApplicationException("unimplemented");
 }
Example #39
0
 public void Visit(While @while)
 {
     var guard = Instruction.Create(OpCodes.Nop);
     _instructions.Add(guard);
     @while.Guard.Accept(this);
     var end = Instruction.Create(OpCodes.Nop);
     _instructions.Add(Instruction.Create(OpCodes.Brfalse, end));
     @while.Body.Accept(this);
     _instructions.Add(Instruction.Create(OpCodes.Br, guard));
     _instructions.Add(end);
 }
Example #40
0
        private NodeCollection parseStatement()
        {
            NodeCollection nc;
            // statement = ("if" | "while"), expression, "{", statement-list, "}"
            if (Grammar.isControl(currentScannerToken))
            {
                StatementList sl;
                GingerToken controlToken = currentScannerToken;

                nextScannerToken();

                Node conditionExpression = parseExpression();

                nextScannerToken();
                if (currentScannerToken == GingerToken.OpenStatementList)
                {
                    nextScannerToken();
                    sl = parseStatementList(GingerToken.CloseStatementList);
                }
                else
                {
                    throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.OpenStatementList.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
                }

                if (controlToken == GingerToken.While)
                {
                    nc = new While(conditionExpression, sl);
                }
                else
                {
                    nc = new If(conditionExpression, sl);
                }
            }
            // statement = type, identifier
            else if (Grammar.isType(currentScannerToken))
            {
                Node type;
                if (currentScannerToken == GingerToken.Int)
                {
                    type = new Integer(scanner.row, scanner.col);
                }
                else
                {
                    type = new Boolean(scanner.row, scanner.col);
                }

                nextScannerToken();
                if (currentScannerToken != GingerToken.Identifier)
                {
                    throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.Identifier.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
                }
                else
                {
                    nc = new Declaration(type, new Identifier(scanner.row, scanner.col, new string(scanner.tokenValue)));
                }
            }
            // statement = identifier, "=", expression
            else if (currentScannerToken == GingerToken.Identifier)
            {
                Identifier identifier = new Identifier(scanner.row, scanner.col, new string(scanner.tokenValue));
                nextScannerToken();
                if (currentScannerToken == GingerToken.Assignment)
                {
                    nextScannerToken();
                    nc = new Assign(identifier, parseExpression());
                }
                else
                {
                    throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.Assignment.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
                }
            }
            else
            {
                throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.If.ToString()}', '{GingerToken.While.ToString()}', '{GingerToken.Int.ToString()}', '{GingerToken.Bool.ToString()}', or '{GingerToken.Identifier.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
            }

            return nc;
        }
 public void Visit(While whiles)
 {
     var oldRet = _foundReturn;
     _foundReturn = false;
     whiles.Body.Accept(this);
     _foundReturn = oldRet;
 }
Example #42
0
    public void visit(While n) {

        Type t1 = n.e.accept(this);
        Type t2 = boolType.accept(this);

        if (compatible(t1,  t2)) {
            n.s.accept(this);
            return;
        }

        throw new TypeException("types not compatible");
    }
Example #43
0
		public virtual object Visit (While whileStatement)
		{
			return null;
		}
Example #44
0
void case_931()
#line 6200 "cs-parser.jay"
{
		if (yyVals[0+yyTop] is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
			Warning_EmptyStatement (GetLocation (yyVals[0+yyTop]));
	  
		yyVal = new While ((BooleanExpression) yyVals[-2+yyTop], (Statement) yyVals[0+yyTop], GetLocation (yyVals[-4+yyTop]));
		lbag.AddStatement (yyVal, GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[-1+yyTop]));
	  }
Example #45
0
void case_932()
#line 6208 "cs-parser.jay"
{
		Error_SyntaxError (yyToken);
		
		yyVal = new While ((BooleanExpression) yyVals[-1+yyTop], null, GetLocation (yyVals[-3+yyTop]));
		lbag.AddStatement (yyVal, GetLocation (yyVals[-2+yyTop]));
	  }
Example #46
0
 public virtual void VisitWhile(While While)
 {
   if (While == null) return;
   this.VisitExpression(While.Condition);
   this.VisitLoopInvariantList(While.Invariants);
   this.VisitBlock(While.Body);
 }
Example #47
0
 public virtual Statement VisitWhile(While While){
   if (While == null) return null;
   While.Condition = this.VisitExpression(While.Condition);
   While.Invariants = this.VisitLoopInvariantList(While.Invariants);
   While.Body = this.VisitBlock(While.Body);
   return While;
 }
Example #48
0
        public override AstNode VisitWhile(While ast)
        {
            var beforeWhile = m_ilgen.DefineLabel();
            var afterWhile = m_ilgen.DefineLabel();

            m_ilgen.MarkLabel(beforeWhile);

            Visit(ast.Condition);
            //the e-stack should have a bool value
            m_ilgen.Emit(OpCodes.Brfalse, afterWhile);

            Visit(ast.LoopBody);

            m_ilgen.Emit(OpCodes.Br, beforeWhile);
            m_ilgen.MarkLabel(afterWhile);

            return ast;
        }
    public virtual Differences VisitWhile(While while1, While while2){
      Differences differences = new Differences(while1, while2);
      if (while1 == null || while2 == null){
        if (while1 != while2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      While changes = (While)while2.Clone();
      While deletions = (While)while2.Clone();
      While insertions = (While)while2.Clone();

      Differences diff = this.VisitBlock(while1.Body, while2.Body);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Body = diff.Changes as Block;
      deletions.Body = diff.Deletions as Block;
      insertions.Body = diff.Insertions as Block;
      Debug.Assert(diff.Changes == changes.Body && diff.Deletions == deletions.Body && diff.Insertions == insertions.Body);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpressionList(while1.Invariants, while2.Invariants, out changes.Invariants, out deletions.Invariants, out insertions.Invariants);
      if (diff == null){Debug.Assert(false); return differences;}
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(while1.Condition, while2.Condition);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Condition = diff.Changes as Expression;
      deletions.Condition = diff.Deletions as Expression;
      insertions.Condition = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Condition && diff.Deletions == deletions.Condition && diff.Insertions == insertions.Condition);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Example #50
0
            internal static stmt Convert(Statement stmt) {
                stmt ast;

                if (stmt is FunctionDefinition)
                    ast = new FunctionDef((FunctionDefinition)stmt);
                else if (stmt is ReturnStatement)
                    ast = new Return((ReturnStatement)stmt);
                else if (stmt is AssignmentStatement)
                    ast = new Assign((AssignmentStatement)stmt);
                else if (stmt is AugmentedAssignStatement)
                    ast = new AugAssign((AugmentedAssignStatement)stmt);
                else if (stmt is DelStatement)
                    ast = new Delete((DelStatement)stmt);
                else if (stmt is PrintStatement)
                    ast = new Print((PrintStatement)stmt);
                else if (stmt is ExpressionStatement)
                    ast = new Expr((ExpressionStatement)stmt);
                else if (stmt is ForStatement)
                    ast = new For((ForStatement)stmt);
                else if (stmt is WhileStatement)
                    ast = new While((WhileStatement)stmt);
                else if (stmt is IfStatement)
                    ast = new If((IfStatement)stmt);
                else if (stmt is WithStatement)
                    ast = new With((WithStatement)stmt);
                else if (stmt is RaiseStatement)
                    ast = new Raise((RaiseStatement)stmt);
                else if (stmt is TryStatement)
                    ast = Convert((TryStatement)stmt);
                else if (stmt is AssertStatement)
                    ast = new Assert((AssertStatement)stmt);
                else if (stmt is ImportStatement)
                    ast = new Import((ImportStatement)stmt);
                else if (stmt is FromImportStatement)
                    ast = new ImportFrom((FromImportStatement)stmt);
                else if (stmt is ExecStatement)
                    ast = new Exec((ExecStatement)stmt);
                else if (stmt is GlobalStatement)
                    ast = new Global((GlobalStatement)stmt);
                else if (stmt is ClassDefinition)
                    ast = new ClassDef((ClassDefinition)stmt);
                else if (stmt is BreakStatement)
                    ast = new Break();
                else if (stmt is ContinueStatement)
                    ast = new Continue();
                else if (stmt is EmptyStatement)
                    ast = new Pass();
                else
                    throw new ArgumentTypeException("Unexpected statement type: " + stmt.GetType());

                ast.GetSourceLocation(stmt);
                return ast;
            }
Example #51
0
 public void Visit(While whiles)
 {
     Indent();
     _sb.Append("while (");
     whiles.Guard.Accept(this);
     _sb.Append(")\r\n");
     ++_level;
     whiles.Body.Accept(this);
     --_level;
 }
Example #52
0
 public override Statement VisitWhile(While While){
   if (While == null) return null;
   StatementList statements = new StatementList(5);
   ExpressionList invariants = While.Invariants;
   if (invariants != null && invariants.Count > 0)
     statements.Add(VisitLoopInvariants(invariants));
   Block whileBlock = new Block(statements);
   whileBlock.SourceContext = While.SourceContext;
   Block endOfLoop = new Block(null);
   this.continueTargets.Add(whileBlock);
   this.exitTargets.Add(endOfLoop);
   if (While.Condition == null) return null;
   SourceContext ctx = While.SourceContext; ctx.EndPos = While.Condition.SourceContext.EndPos;
   Statement whileCondition = this.VisitAndInvertBranchCondition(While.Condition, endOfLoop, ctx);
   this.VisitBlock(While.Body);
   statements.Add(whileCondition);
   statements.Add(While.Body);
   ctx = While.SourceContext;
   if (While.Body != null)
     ctx.StartPos = While.Body.SourceContext.EndPos;
   statements.Add(new Branch(null, whileBlock, ctx));
   statements.Add(endOfLoop);
   this.continueTargets.Count--;
   this.exitTargets.Count--;
   return whileBlock;
 }
			public override object Visit (While whileStatement)
			{
				var result = new WhileStatement ();
				var location = LocationsBag.GetLocations (whileStatement);
				result.AddChild (new CSharpTokenNode (Convert (whileStatement.loc), WhileStatement.WhileKeywordRole), WhileStatement.WhileKeywordRole);
				
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LPar), Roles.LPar);
				if (whileStatement.expr != null)
					result.AddChild ((Expression)whileStatement.expr.Accept (this), Roles.Condition);
				if (location != null && location.Count > 1)
					result.AddChild (new CSharpTokenNode (Convert (location [1]), Roles.RPar), Roles.RPar);
				if (whileStatement.Statement != null)
					result.AddChild ((Statement)whileStatement.Statement.Accept (this), Roles.EmbeddedStatement);
				return result;
			}
        public override void VisitWhile(While p)
        {
            var continueLabel = IL.DefineLabel();

            EmitLoopSkeleton(continueLabel, (breakLabel) =>
            {
                var dowhile = IL.DefineLabel();

                IL.MarkLabel(continueLabel);
                VisitExpression(p.Expression);
                IL.Emit(OpCodes.Stloc, E);
                IL.Emit(OpCodes.Ldloca, E);
                IL.Emit(OpCodes.Call, isReal);
                IL.Emit(OpCodes.Brtrue, dowhile);
                IL.Emit(OpCodes.Ldsfld, typeof(Error).GetField("ExpectedBooleanExpression"));
                IL.Emit(OpCodes.Newobj, typeof(ProgramError).GetConstructor(new[] { typeof(Error) }));
                IL.Emit(OpCodes.Throw);

                IL.MarkLabel(dowhile);
                IL.Emit(OpCodes.Ldloc, E);
                EmitImplicitConversion(typeof(bool));
                IL.Emit(OpCodes.Brfalse, breakLabel);

                VisitStatement(p.Body);

                IL.Emit(OpCodes.Br, continueLabel);
            });
        }
Example #55
0
 public virtual Statement VisitWhile(While While1, While While2)
 {
     if (While1 == null) return null;
     if (While2 == null)
     {
         While1.Invariants = this.VisitExpressionList(While1.Invariants, null);
         While1.Condition = this.VisitExpression(While1.Condition, null);
         While1.Body = this.VisitBlock(While1.Body, null);
     }
     else
     {
         While1.Invariants = this.VisitExpressionList(While1.Invariants, While2.Invariants);
         While1.Condition = this.VisitExpression(While1.Condition, While2.Condition);
         While1.Body = this.VisitBlock(While1.Body, While2.Body);
     }
     return While1;
 }
Example #56
0
        public override AstNode VisitWhile(While ast)
        {
            Visit(ast.Condition);

            if (ast.Condition.ExpressionType != PrimaryType.Boolean)
            {
                m_errorManager.AddError(c_SE_WhileStmtTypeInvalid, ast.WhileSpan);
            }

            Visit(ast.LoopBody);

            return ast;
        }