public override void VisitForStmt(ForStmt x) { using (new ScopeHelper(this, x)) { base.VisitForStmt(x); } }
/// <summary> /// Visit "for" initialization,condition and action expressions. /// Visit "for" body. /// </summary> /// <param name="x"></param> virtual public void VisitForStmt(ForStmt x) { VisitList(x.InitExList); VisitList(x.CondExList); VisitList(x.ActionExList); VisitElement(x.Body); }
public void visit_for(ForStmt for_stmt) { bool enclosing_loop = in_loop; in_loop = true; resolve(for_stmt.counter_definition); resolve(for_stmt.body); in_loop = enclosing_loop; }
public virtual bool VisitForStmt(ForStmt stmt) { if (!VisitStmt(stmt)) { return(false); } return(true); }
public override void Visit(ForStmt n) { plusScope(); n.stm1.accept(this); n.stm2.accept(this); n.stm3.accept(this); foreach (AST ast in n.stmt_list) { ast.accept(this); } minusScope(); }
public override void Visit(ForStmt n) { emit("for("); n.stm1.accept(this); n.stm2.accept(this); emit(" ; "); n.stm3.accept(this); emit(") {\n"); foreach (AST ast in n.stmt_list) { ast.accept(this); } emit("}\n"); }
override public void VisitForStmt(ForStmt x) { _serializer.StartSerialize(typeof(WhileStmt).Name, SerializeSpan(x.Span)); _serializer.StartSerialize("InitExList"); VisitList(x.InitExList); _serializer.EndSerialize(); _serializer.StartSerialize("CondExList"); VisitList(x.CondExList); _serializer.EndSerialize(); _serializer.StartSerialize("ActionExList"); VisitList(x.ActionExList); _serializer.EndSerialize(); SerializeOptionalProperty("Body", x.Body); _serializer.EndSerialize(); }
public override void Visit(ForStmt n) { emit("for("); n.stm1.accept(this); n.stm2.accept(this); emit(" ; "); n.stm3.accept(this); if (Code[Code.Length - 2] == ';') { Code = Code.Remove(Code.Length - 2); } emit(") {\n"); foreach (AST ast in n.stmt_list) { ast.accept(this); } emit("}\n"); }
public override void VisitForStmt(ForStmt x) { using (new ScopeHelper(this, x)) { ConsumeToken(Tokens.T_FOR, "for", x.Span.Start); ConsumeToken(Tokens.T_LPAREN, "("); VisitElementList(x.InitExList, Tokens.T_COMMA, ","); ConsumeToken(Tokens.T_SEMI, ";"); VisitElementList(x.CondExList, Tokens.T_COMMA, ","); ConsumeToken(Tokens.T_SEMI, ";"); VisitElementList(x.ActionExList, Tokens.T_COMMA, ","); ConsumeToken(Tokens.T_LPAREN, ")"); VisitElement(x.Body); } }
public override void Visit(ForStmt stmt) { if (isNewLine) { isNewLine = false; AddStr(WS()); } ignoreNewLine = true; AddStr("for("); if (stmt.initializer != null) { stmt.initializer.Accept(this); } else { AddStr(";"); } if (stmt.condition != null) { stmt.condition.Accept(this); } AddStr(";"); if (stmt.increment != null) { stmt.increment.Accept(this); } AddStr(") "); ignoreNewLine = false; if (stmt.body.GetType() != typeof(BlockStmt)) { whiteSpaceCount += 4; NewLine(); } stmt.body.Accept(this); if (stmt.body.GetType() != typeof(BlockStmt)) { whiteSpaceCount -= 4; } }
public object Visit(ForStmt stmt) { DataType startValType = stmt.StartVal.Accept(this); DataType maxValType = stmt.MaxVal.Accept(this); DataType incrType = stmt.Increment == null ? startValType : stmt.Increment.Accept(this); if (!startValType.BaseType.IsNumber() || !maxValType.BaseType.IsNumber() || !incrType.BaseType.IsNumber()) { Reporter.Error(new Pos(0, 0), "Expected number."); } _scope.Define(stmt.VarName.Lexeme, startValType, false); stmt.Branch.Accept(this); return(null); }
public object Visit(ForStmt stmt) { LLVMValueRef func = LLVM.GetBasicBlockParent(LLVM.GetInsertBlock(_builder)); new VarDeclarationStmt(stmt.StartVal.DataType, stmt.VarName, new List <IExpression>() { }).Accept(this); // Blocks LLVMBasicBlockRef condBB = LLVM.AppendBasicBlock(func, "cond"); LLVMBasicBlockRef branchBB = LLVM.AppendBasicBlock(func, "branch"); LLVMBasicBlockRef mergeBB = LLVM.AppendBasicBlock(func, "forcont"); // Build condition LLVM.BuildBr(_builder, condBB); LLVM.PositionBuilderAtEnd(_builder, condBB); LLVMValueRef counter = new VariableExpr(stmt.VarName).Accept(this); LLVMValueRef maxVal = stmt.MaxVal.Accept(this); LLVMValueRef incr = stmt.Increment == null ? LLVM.ConstInt(stmt.StartVal.DataType.BaseType.ToLLVMType(), 1, LLVMBoolTrue) : stmt.Increment.Accept(this); LLVMValueRef condition = LLVM.BuildICmp(_builder, LLVMIntPredicate.LLVMIntSLT, counter, maxVal, "tmpcmp"); LLVM.BuildCondBr(_builder, condition, branchBB, mergeBB); // branch LLVM.PositionBuilderAtEnd(_builder, branchBB); // Position builder at block stmt.Branch.Accept(this); // Generate branch code // Increment counter LLVMValueRef newVal = LLVM.BuildAdd(_builder, counter, incr, "tmpadd"); LLVM.BuildStore(_builder, newVal, _namedValues[stmt.VarName.Lexeme].ValueRef); LLVM.BuildBr(_builder, condBB); LLVM.PositionBuilderAtEnd(_builder, mergeBB); return(null); }
/// <summary> /// Visits ForStmt and builds controlflow graf for for cycle. /// </summary> /// <param name="x">ForStmt</param> public override void VisitForStmt(ForStmt x) { BasicBlock forTest = new BasicBlock(); BasicBlock forBody = new BasicBlock(); BasicBlock forEnd = new BasicBlock(); BasicBlock forIncrement = new BasicBlock(); currentBasicBlock.CreateWorklistSegment(forEnd); // Create CFG for initialization of the for cycle VisitExpressionList(x.InitExList); //Adds initial connection from initialization to the test block BasicBlockEdge.ConnectDirectEdge(currentBasicBlock, forTest); // Connects test block with body of the for cycle and end of the for cycle var forCondition = (x.CondExList.Count > 0) ? constructSimpleCondition(x.CondExList) : new BoolLiteral(Position.Invalid, true); var currBl = currentBasicBlock; BasicBlockEdge.ConnectConditionalBranching(forCondition, forTest, forBody, forEnd); // Create CFG for Loop body loopData.Push(new LoopData(forIncrement, forEnd)); currentBasicBlock = forBody; x.Body.VisitMe(this); loopData.Pop(); // Connect end of the loop body to the increment BasicBlockEdge.ConnectDirectEdge(currentBasicBlock, forIncrement); // Generate CFG for the loop increment currentBasicBlock = forIncrement; VisitExpressionList(x.ActionExList); // Connect for increment to the test block BasicBlockEdge.ConnectDirectEdge(forIncrement, forTest); currentBasicBlock = forEnd; }
public void visit_for(ForStmt for_stmt) { execute(for_stmt.counter_definition); while (get_truth(evaluate(for_stmt.condition))) { try { execute(for_stmt.body); evaluate(for_stmt.counter_action); } catch (ReturnException) { break; } catch (ContinueException) { // If we catch a continue, we need to ensure the counter action is evaluated evaluate(for_stmt.counter_action); continue; } } }
private void Resolve(ForStmt @for) { var enclosingLoop = _currentLoop; _currentLoop = true; Resolve(@for.Value); if (@for.Variable != null) { BeginScope(); Define(@for.Variable); } Resolve(@for.Body); if (@for.Variable != null) { EndScope(); } _currentLoop = enclosingLoop; }
private void Execute(ForStmt @for) { throw new NotImplementedException(); }
public bool VisitForStmt(ForStmt stmt) { throw new NotImplementedException(); }
public override void Visit(ForStmt stmt) { }
public virtual void Visit(ForStmt stmt) { }
public override void VisitForStmt(ForStmt x) { BuildForLoop(x.InitExList, x.CondExList, x.ActionExList, x.Body); }
public void visit_for(ForStmt for_stmt) { execute(for_stmt.counter_definition); execute(for_stmt.body); }
public void Visit(ForStmt forStmt) { TreeLevel++; PrintNode("ForStm"); forStmt.LoopVar.Accept(this); forStmt.StartExpr.Accept(this); forStmt.EndExpr.Accept(this); forStmt.Body.Accept(this); TreeLevel--; }
public static Int32 Parse(List<Token> src, Int32 begin, out Stmt stmt) { stmt = null; Int32 current; if (Parser.IsKeyword(src[begin], KeywordVal.WHILE)) { // while current = begin + 1; Expr cond; current = Parser.ParseParenExpr(src, current, out cond); if (current == -1) { return -1; } Stmt body; current = _statement.Parse(src, current, out body); if (current == -1) { return -1; } stmt = new WhileStmt(cond, body); return current; } else if (Parser.IsKeyword(src[begin], KeywordVal.DO)) { // do current = begin + 1; Stmt body; current = _statement.Parse(src, current, out body); if (current == -1) { return -1; } Expr cond; current = Parser.ParseParenExpr(src, current, out cond); if (current == -1) { return -1; } stmt = new DoWhileStmt(body, cond); return current; } else if (Parser.IsKeyword(src[begin], KeywordVal.FOR)) { // for current = begin + 1; // match '(' if (!Parser.EatOperator(src, ref current, OperatorVal.LPAREN)) { return -1; } // match init Option<Expr> init_opt; // Expr init; Int32 saved = current; current = Parser.ParseOption(src, current, out init_opt, _expression.Parse); //current = _expression.Parse(src, current, out init); //if (current == -1) { // init = null; // init_opt = new None<Expr>(); // current = saved; //} else { // init_opt = new Some<Expr>(init); //} // match ';' if (!Parser.EatOperator(src, ref current, OperatorVal.SEMICOLON)) { return -1; } // match cond Option<Expr> cond_opt; current = Parser.ParseOption(src, current, out cond_opt, _expression.Parse); //Expr cond; //saved = current; //current = _expression.Parse(src, current, out cond); //if (current == -1) { // init = null; // current = saved; //} // match ';' if (!Parser.EatOperator(src, ref current, OperatorVal.SEMICOLON)) { return -1; } // match loop Option<Expr> loop_opt; current = Parser.ParseOption(src, current, out loop_opt, _expression.Parse); //Expr loop; //saved = current; //current = _expression.Parse(src, current, out loop); //if (current == -1) { // init = null; // current = saved; //} // match ')' if (!Parser.EatOperator(src, ref current, OperatorVal.RPAREN)) { return -1; } Stmt body; current = _statement.Parse(src, current, out body); if (current == -1) { return -1; } stmt = new ForStmt(init_opt, cond_opt, loop_opt, body); return current; } else { return -1; } }