public override Template Visit(StmtForEach stmt_for_each) { if (stmt_for_each.Var is ExprConst) { ExprConst expr = (ExprConst) stmt_for_each.Var; Template template = new Template("for (auto <var> : <expr>) {\n <body>\n}"); template.Add("var", expr.Text); template.Add("expr", stmt_for_each.Target.Accept(this)); template.Add("body", stmt_for_each.Body.Accept(this)); return template; } else if (stmt_for_each.Var is ExprCall) { ExprCall expr = (ExprCall)stmt_for_each.Var; List<Stmt> stmt_list = new List<Stmt>(); List<Expr> condition_list = new List<Expr>(); int i = 0; foreach (var argument in expr.Args) { ExprCall get = new ExprCall(new ExprConst("std::get", ConstType.Ident), new List<string> {i.ToString()}, new List<Expr> {new ExprConst("_t_match", ConstType.Ident)}); i++; if (argument is ExprConst && ((ExprConst)argument).Type == ConstType.Ident && !((ExprConst)argument).Text.StartsWith("@")) { ExprConst const_expr = (ExprConst)argument; if (const_expr.Text == "_") { continue; } stmt_list.Add(new StmtExpr(new ExprAlloc("auto", new List<string> { const_expr.Text }, new List<Expr>{ get }, true))); } else { if (((ExprConst)argument).Text.StartsWith("@")) { ((ExprConst)argument).Text = ((ExprConst)argument).Text.Substring(1); } condition_list.Add(new ExprBin("==", get, argument)); } } StmtBlock block = new StmtBlock(); foreach (var item in stmt_list) { block.StmtList.Add(item); } foreach (var item in stmt_for_each.Body.StmtList) { block.StmtList.Add(item); } if (condition_list.Count() > 0) { StmtBlock if_body = new StmtBlock(); if_body.StmtList.Add(new StmtExpr(new ExprAlloc("auto&&", new List<string> { "_t_match" }, new List<Expr> { new ExprCall(new ExprAccess(new ExprConst("_t_iterator", ConstType.Ident), ".", "Unapply"), null, null) }, true))); Expr condition = null; foreach (var item in condition_list) { if (condition == null) { condition = item; if (condition_list.Count() > 1) { condition = new ExprBracket(condition); } } else { condition = new ExprBin("&&", condition, new ExprBracket(item)); } } StmtIf stmt_if = new StmtIf(condition, block, null); if_body.StmtList.Add(stmt_if); block = if_body; } else { block.StmtList.Insert(0, new StmtExpr(new ExprAlloc("auto&&", new List<string> { "_t_match" }, new List<Expr> { new ExprCall(new ExprAccess(new ExprConst("_t_iterator", ConstType.Ident), ".", "Unapply"), null, null) }, true))); } StmtForEach for_each = new StmtForEach(new ExprConst("_t_iterator", ConstType.Ident), stmt_for_each.Target, block); return for_each.Accept(this); } else if (stmt_for_each.Var is ExprTuple) { ExprTuple expr = (ExprTuple)stmt_for_each.Var; List<Stmt> stmt_list = new List<Stmt>(); List<Expr> condition_list = new List<Expr>(); int i = 0; foreach (var argument in expr.ExprList) { ExprCall get = new ExprCall(new ExprConst("get", ConstType.Ident), new List<string> { i.ToString() }, new List<Expr> { new ExprConst("_t_match", ConstType.Ident) }); i++; if (argument is ExprConst && ((ExprConst)argument).Type == ConstType.Ident) { ExprConst const_expr = (ExprConst)argument; if (const_expr.Text == "_") { continue; } stmt_list.Add(new StmtExpr(new ExprAlloc("auto", new List<string> { const_expr.Text }, new List<Expr> { get }, true))); } else { condition_list.Add(new ExprBin("==", get, argument)); } } StmtBlock block = new StmtBlock(); foreach (var item in stmt_list) { block.StmtList.Add(item); } foreach (var item in stmt_for_each.Body.StmtList) { block.StmtList.Add(item); } if (condition_list.Count() > 0) { StmtBlock if_body = new StmtBlock(); Expr condition = null; foreach (var item in condition_list) { if (condition == null) { condition = item; if (condition_list.Count() > 1) { condition = new ExprBracket(condition); } } else { condition = new ExprBin("&&", condition, new ExprBracket(item)); } } StmtIf stmt_if = new StmtIf(condition, block, null); if_body.StmtList.Add(stmt_if); block = if_body; } StmtForEach for_each = new StmtForEach(new ExprConst("_t_match", ConstType.Ident), stmt_for_each.Target, block); return for_each.Accept(this); } else { throw new Exception(string.Format("Iterators in foreach must be either variable or pattern matching")); } }
private ExprCall call_with_expr() { EnterRule_call_with_expr(); EnterRule("call_with_expr", 43); TraceIn("call_with_expr", 43); ExprCall value = default(ExprCall); Expr a = default(Expr); string b = default(string); List<Expr> c = default(List<Expr>); try { DebugEnterRule(GrammarFileName, "call_with_expr"); DebugLocation(514, 1); try { // SugarWalker.g:515:2: ( ^( Expr_Call_With a= expr b= ident (c= expr_list )? ) ) DebugEnterAlt(1); // SugarWalker.g:515:4: ^( Expr_Call_With a= expr b= ident (c= expr_list )? ) { DebugLocation(515, 4); DebugLocation(515, 6); Match(input,Expr_Call_With,Follow._Expr_Call_With_in_call_with_expr2074); Match(input, TokenTypes.Down, null); DebugLocation(515, 22); PushFollow(Follow._expr_in_call_with_expr2078); a=expr(); PopFollow(); DebugLocation(515, 29); PushFollow(Follow._ident_in_call_with_expr2082); b=ident(); PopFollow(); DebugLocation(515, 37); // SugarWalker.g:515:37: (c= expr_list )? int alt70=2; try { DebugEnterSubRule(70); try { DebugEnterDecision(70, false); int LA70_0 = input.LA(1); if (((LA70_0>=Expr_Access && LA70_0<=Expr_Tuple)||LA70_0==IDENT||LA70_0==Match_Tuple||LA70_0==NUMBER||LA70_0==STRING||LA70_0==75||LA70_0==78||LA70_0==82||LA70_0==85||LA70_0==89||LA70_0==95||LA70_0==98||LA70_0==102||LA70_0==104||LA70_0==110||LA70_0==113||LA70_0==117||LA70_0==150||LA70_0==DOUBLE)) { alt70 = 1; } } finally { DebugExitDecision(70); } switch (alt70) { case 1: DebugEnterAlt(1); // SugarWalker.g:515:37: c= expr_list { DebugLocation(515, 37); PushFollow(Follow._expr_list_in_call_with_expr2086); c=expr_list(); PopFollow(); } break; } } finally { DebugExitSubRule(70); } Match(input, TokenTypes.Up, null); DebugLocation(516, 2); List<Expr> Args = new List<Expr>(); Args.Add(a); if (c != null) { foreach (var item in c) { Args.Add(item); } } value = new ExprCall(new ExprConst(b, ConstType.Ident), null, Args); } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("call_with_expr", 43); LeaveRule("call_with_expr", 43); LeaveRule_call_with_expr(); } DebugLocation(528, 1); } finally { DebugExitRule(GrammarFileName, "call_with_expr"); } return value; }
public override Template Visit(ExprCall expr) { if (expr.GenericParameter.Count() == 0) { Template template = new Template("<expr>(<args; separator=\", \">)"); template.Add("expr", expr.Expr.Accept(this)); template.Add("args", expr.Args.Select(x => x.Accept(this))); return template; } else { Template template = new Template("<expr>\\<<generics; separator=\", \">>(<args; separator=\", \">)"); template.Add("expr", expr.Expr.Accept(this)); template.Add("generics", expr.GenericParameter); template.Add("args", expr.Args.Select(x => x.Accept(this))); return template; } }
private ExprCall call_expr() { EnterRule_call_expr(); EnterRule("call_expr", 39); TraceIn("call_expr", 39); ExprCall value = default(ExprCall); Expr a = default(Expr); List<string> b = default(List<string>); List<Expr> c = default(List<Expr>); try { DebugEnterRule(GrammarFileName, "call_expr"); DebugLocation(478, 1); try { // SugarWalker.g:479:2: ( ^( Expr_Call a= expr (b= generic_parameter )? (c= expr_list )? ) ) DebugEnterAlt(1); // SugarWalker.g:479:4: ^( Expr_Call a= expr (b= generic_parameter )? (c= expr_list )? ) { DebugLocation(479, 4); DebugLocation(479, 6); Match(input,Expr_Call,Follow._Expr_Call_in_call_expr1902); Match(input, TokenTypes.Down, null); DebugLocation(479, 17); PushFollow(Follow._expr_in_call_expr1906); a=expr(); PopFollow(); DebugLocation(479, 23); // SugarWalker.g:479:23: (b= generic_parameter )? int alt62=2; try { DebugEnterSubRule(62); try { DebugEnterDecision(62, false); int LA62_0 = input.LA(1); if ((LA62_0==Generic_Patameters)) { alt62 = 1; } } finally { DebugExitDecision(62); } switch (alt62) { case 1: DebugEnterAlt(1); // SugarWalker.g:479:24: b= generic_parameter { DebugLocation(479, 25); PushFollow(Follow._generic_parameter_in_call_expr1911); b=generic_parameter(); PopFollow(); } break; } } finally { DebugExitSubRule(62); } DebugLocation(479, 46); // SugarWalker.g:479:46: (c= expr_list )? int alt63=2; try { DebugEnterSubRule(63); try { DebugEnterDecision(63, false); int LA63_0 = input.LA(1); if (((LA63_0>=Expr_Access && LA63_0<=Expr_Tuple)||LA63_0==IDENT||LA63_0==Match_Tuple||LA63_0==NUMBER||LA63_0==STRING||LA63_0==75||LA63_0==78||LA63_0==82||LA63_0==85||LA63_0==89||LA63_0==95||LA63_0==98||LA63_0==102||LA63_0==104||LA63_0==110||LA63_0==113||LA63_0==117||LA63_0==150||LA63_0==DOUBLE)) { alt63 = 1; } } finally { DebugExitDecision(63); } switch (alt63) { case 1: DebugEnterAlt(1); // SugarWalker.g:479:47: c= expr_list { DebugLocation(479, 48); PushFollow(Follow._expr_list_in_call_expr1918); c=expr_list(); PopFollow(); } break; } } finally { DebugExitSubRule(63); } Match(input, TokenTypes.Up, null); DebugLocation(480, 2); value = new ExprCall(a, b, c); } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("call_expr", 39); LeaveRule("call_expr", 39); LeaveRule_call_expr(); } DebugLocation(483, 1); } finally { DebugExitRule(GrammarFileName, "call_expr"); } return value; }
public abstract Template Visit(ExprCall expr);
private ExprCall call_with_expr() { EnterRule_call_with_expr(); EnterRule("call_with_expr", 52); TraceIn("call_with_expr", 52); ExprCall value = default(ExprCall); Expr a = default(Expr); string b = default(string); List<Expr> c = default(List<Expr>); try { DebugEnterRule(GrammarFileName, "call_with_expr"); DebugLocation(670, 1); try { // SugarWalker.g:671:2: ( ^( Expr_Call_With a= expr b= ident c= expr_list ) ) DebugEnterAlt(1); // SugarWalker.g:671:4: ^( Expr_Call_With a= expr b= ident c= expr_list ) { DebugLocation(671, 4); DebugLocation(671, 6); Match(input,Expr_Call_With,Follow._Expr_Call_With_in_call_with_expr2620); Match(input, TokenTypes.Down, null); DebugLocation(671, 22); PushFollow(Follow._expr_in_call_with_expr2624); a=expr(); PopFollow(); DebugLocation(671, 29); PushFollow(Follow._ident_in_call_with_expr2628); b=ident(); PopFollow(); DebugLocation(671, 37); PushFollow(Follow._expr_list_in_call_with_expr2632); c=expr_list(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(672, 2); List<Expr> Args = new List<Expr>(); Args.Add(a); if (c != null) { foreach (var item in c) { Args.Add(item); } } value = new ExprCall(new ExprConst(b, ConstType.Ident), null, Args); } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("call_with_expr", 52); LeaveRule("call_with_expr", 52); LeaveRule_call_with_expr(); } DebugLocation(684, 1); } finally { DebugExitRule(GrammarFileName, "call_with_expr"); } return value; }
private ExprCall call_expr() { EnterRule_call_expr(); EnterRule("call_expr", 48); TraceIn("call_expr", 48); ExprCall value = default(ExprCall); Expr a = default(Expr); List<SugarType> b = default(List<SugarType>); List<Expr> c = default(List<Expr>); try { DebugEnterRule(GrammarFileName, "call_expr"); DebugLocation(626, 1); try { // SugarWalker.g:627:2: ( ^( Expr_Call a= expr (b= generic_parameter )? c= expr_list ) ) DebugEnterAlt(1); // SugarWalker.g:627:4: ^( Expr_Call a= expr (b= generic_parameter )? c= expr_list ) { DebugLocation(627, 4); DebugLocation(627, 6); Match(input,Expr_Call,Follow._Expr_Call_in_call_expr2381); Match(input, TokenTypes.Down, null); DebugLocation(627, 17); PushFollow(Follow._expr_in_call_expr2385); a=expr(); PopFollow(); DebugLocation(627, 23); // SugarWalker.g:627:23: (b= generic_parameter )? int alt73=2; try { DebugEnterSubRule(73); try { DebugEnterDecision(73, false); int LA73_0 = input.LA(1); if ((LA73_0==Generic_Patameters)) { alt73 = 1; } } finally { DebugExitDecision(73); } switch (alt73) { case 1: DebugEnterAlt(1); // SugarWalker.g:627:24: b= generic_parameter { DebugLocation(627, 25); PushFollow(Follow._generic_parameter_in_call_expr2390); b=generic_parameter(); PopFollow(); } break; } } finally { DebugExitSubRule(73); } DebugLocation(627, 47); PushFollow(Follow._expr_list_in_call_expr2396); c=expr_list(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(628, 2); value = new ExprCall(a, b, c); } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("call_expr", 48); LeaveRule("call_expr", 48); LeaveRule_call_expr(); } DebugLocation(631, 1); } finally { DebugExitRule(GrammarFileName, "call_expr"); } return value; }