public abstract Template Visit(ExprListGeneration expr);
public override Template Visit(ExprListGeneration expr) { Template template = new Template("({\n <declare>;\n <for>\n <var>;\n})"); ExprAlloc delcare = new ExprAlloc(expr.Type, "_t_return_value", null, AllocType.Declare); template.Add("declare", delcare.Accept(this)); template.Add("var", "_t_return_value"); Stmt stmt = null; if (expr.Type is TemplateType && (((TemplateType)expr.Type).Type is IdentType)) { string type = ((IdentType)((TemplateType)expr.Type).Type).Type; if (type == "vector" || type == "list") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "push_back"), null, new List<Expr> { expr.Expr })); } if (type == "forward_list" || type == "deque") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "push_front"), null, new List<Expr> { expr.Expr })); } if (type == "queue" || type == "priority_queue" || type == "stack") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "push"), null, new List<Expr> { expr.Expr })); } if (type == "set" || type == "multiset" || type == "unordered_set" || type == "unordered_multiset" || type == "map" || type == "multimap" || type == "unordered_map" || type == "unordered_multimap") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "insert"), null, new List<Expr> { expr.Expr })); } } if (stmt == null) { string msg = string.Format("Type {0} is not supported in list generation.", expr.Type.Accept(this).Render()); throw new Exception(msg); } expr.For.Body = new StmtBlock(); expr.For.Body.StmtList.Add(stmt); template.Add("for", expr.For.Accept(this)); return template; }
private ExprListGeneration list_generation_expr() { EnterRule_list_generation_expr(); EnterRule("list_generation_expr", 55); TraceIn("list_generation_expr", 55); ExprListGeneration value = default(ExprListGeneration); SugarType a = default(SugarType); StmtFor b = default(StmtFor); Expr c = default(Expr); try { DebugEnterRule(GrammarFileName, "list_generation_expr"); DebugLocation(704, 1); try { // SugarWalker.g:705:2: ( ^( Expr_List_Generation a= type_name b= stmt_for c= expr ) ) DebugEnterAlt(1); // SugarWalker.g:705:4: ^( Expr_List_Generation a= type_name b= stmt_for c= expr ) { DebugLocation(705, 4); DebugLocation(705, 6); Match(input,Expr_List_Generation,Follow._Expr_List_Generation_in_list_generation_expr2714); Match(input, TokenTypes.Down, null); DebugLocation(705, 28); PushFollow(Follow._type_name_in_list_generation_expr2718); a=type_name(); PopFollow(); DebugLocation(705, 40); PushFollow(Follow._stmt_for_in_list_generation_expr2722); b=stmt_for(); PopFollow(); DebugLocation(705, 51); PushFollow(Follow._expr_in_list_generation_expr2726); c=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(706, 2); value = new ExprListGeneration(a, b, c); } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("list_generation_expr", 55); LeaveRule("list_generation_expr", 55); LeaveRule_list_generation_expr(); } DebugLocation(709, 1); } finally { DebugExitRule(GrammarFileName, "list_generation_expr"); } return value; }