public VList <LNode> EliminateSequenceExpressions(VList <LNode> stmts, bool isDeclContext) { return(stmts.SmartSelectMany(stmt => { /* * // Optimization: scan find out whether this construct has any block * // expressions. If not, skip it. * hasBlockExprs = false; * stmt.ReplaceRecursive(new Func<LNode, Maybe<LNode>>(n => { * if (!hasBlockExprs) * hasBlockExprs = n.IsCall && ( * (n.Calls(S.ColonColon, 2) && n.Args[1].IsId) || * (n.Calls(S.Var, 2) && n.AttrNamed(S.Out) != null) || * (n.Calls(S.In, 2) && n.Args[1].Calls(S.Braces))); * return hasBlockExprs ? n : null; * })); * if (!hasBlockExprs) * return stmt; */ LNode result = EliminateSequenceExpressions(stmt, isDeclContext); if (result != stmt) { VList <LNode> results; if (result.Calls(__numrunSequence)) { results = MaybeRemoveNoOpFromRunSeq(result.Args); return results; } } _arrayOf1[0] = result; return _arrayOf1; })); }
LNode ESEInForLoop(LNode stmt, VList <LNode> attrs, VList <LNode> init, LNode cond, VList <LNode> inc, LNode block) { // TODO: handle multi-int and multi-inc var preInit = VList <LNode> .Empty; var init_apos = init.SmartSelect(init1 => { init1 = EliminateSequenceExpressionsInExecStmt(init1); if (init1.CallsMin(__numrunSequence, 1)) { preInit.AddRange(init1.Args.WithoutLast(1)); return(init1.Args.Last); } return(init1); }); var cond_apos = BubbleUpBlocks(cond); var inc_apos = inc.SmartSelectMany(inc1 => { inc1 = BubbleUpBlocks(inc1); return(inc1.AsList(__numrunSequence)); }); block = EliminateSequenceExpressionsInChildStmt(block); if (init_apos != init || cond_apos != cond || inc_apos != inc) { init = init_apos; if (inc_apos != inc) { var blockStmts = block.AsList(S.Braces).AddRange(inc_apos); block = blockStmts.AsLNode(S.Braces); inc = LNode.List(); } if (cond_apos.CallsMin(__numrunSequence, 1)) { var preCond = cond_apos.Args.WithoutLast(1); cond = cond_apos.Args.Last; stmt = LNode.Call(CodeSymbols.For, LNode.List(LNode.Call(CodeSymbols.AltList, LNode.List(init)), LNode.Missing, LNode.Call(CodeSymbols.AltList, LNode.List(inc)), LNode.Call(CodeSymbols.Braces, LNode.List().AddRange(preCond).Add(LNode.Call(CodeSymbols.If, LNode.List(cond, block, LNode.Call(CodeSymbols.Break))))).SetStyle(NodeStyle.Statement))); } else { stmt = LNode.Call(LNode.List(attrs), CodeSymbols.For, LNode.List(LNode.Call(CodeSymbols.AltList, LNode.List(init)), cond, LNode.Call(CodeSymbols.AltList, LNode.List(inc)), block)); } if (preInit.Count != 0) { stmt = LNode.Call(CodeSymbols.Braces, LNode.List().AddRange(preInit).Add(stmt)).SetStyle(NodeStyle.Statement); } return(stmt); } else { return(stmt.WithArgChanged(3, block)); } }
public VList <LNode> EliminateSequenceExpressions(VList <LNode> stmts, bool isDeclContext) { return(stmts.SmartSelectMany(stmt => { LNode result = EliminateSequenceExpressions(stmt, isDeclContext); if (result != stmt) { VList <LNode> results; if (result.Calls(__numrunSequence)) { results = MaybeRemoveNoOpFromRunSeq(result.Args); return results; } } _arrayOf1[0] = result; return _arrayOf1; })); }
public VList<LNode> EliminateSequenceExpressions(VList<LNode> stmts, bool isDeclContext) { return stmts.SmartSelectMany(stmt => { /* // Optimization: scan find out whether this construct has any block // expressions. If not, skip it. hasBlockExprs = false; stmt.ReplaceRecursive(new Func<LNode, Maybe<LNode>>(n => { if (!hasBlockExprs) hasBlockExprs = n.IsCall && ( (n.Calls(S.ColonColon, 2) && n.Args[1].IsId) || (n.Calls(S.Var, 2) && n.AttrNamed(S.Out) != null) || (n.Calls(S.In, 2) && n.Args[1].Calls(S.Braces))); return hasBlockExprs ? n : null; })); if (!hasBlockExprs) return stmt; */ LNode result = EliminateSequenceExpressions(stmt, isDeclContext); if (result != stmt) { VList<LNode> results; if (result.Calls(__numrunSequence)) { results = MaybeRemoveNoOpFromRunSeq(result.Args); return results; } } _arrayOf1[0] = result; return _arrayOf1; }); }
LNode ESEInForLoop(LNode stmt, VList<LNode> attrs, VList<LNode> init, LNode cond, VList<LNode> inc, LNode block) { // TODO: handle multi-int and multi-inc var preInit = VList<LNode>.Empty; var init_apos = init.SmartSelect(init1 => { init1 = EliminateSequenceExpressionsInExecStmt(init1); if (init1.CallsMin(__numrunSequence, 1)) { preInit.AddRange(init1.Args.WithoutLast(1)); return init1.Args.Last; } return init1; }); var cond_apos = BubbleUpBlocks(cond); var inc_apos = inc.SmartSelectMany(inc1 => { inc1 = BubbleUpBlocks(inc1); return inc1.AsList(__numrunSequence); }); block = EliminateSequenceExpressionsInChildStmt(block); if (init_apos != init || cond_apos != cond || inc_apos != inc) { init = init_apos; if (inc_apos != inc) { var blockStmts = block.AsList(S.Braces).AddRange(inc_apos); block = blockStmts.AsLNode(S.Braces); inc = LNode.List(); } if (cond_apos.CallsMin(__numrunSequence, 1)) { var preCond = cond_apos.Args.WithoutLast(1); cond = cond_apos.Args.Last; stmt = LNode.Call(CodeSymbols.For, LNode.List(LNode.Call(CodeSymbols.AltList, LNode.List(init)), LNode.Missing, LNode.Call(CodeSymbols.AltList, LNode.List(inc)), LNode.Call(CodeSymbols.Braces, LNode.List().AddRange(preCond).Add(LNode.Call(CodeSymbols.If, LNode.List(cond, block, LNode.Call(CodeSymbols.Break))))).SetStyle(NodeStyle.Statement))); } else { stmt = LNode.Call(LNode.List(attrs), CodeSymbols.For, LNode.List(LNode.Call(CodeSymbols.AltList, LNode.List(init)), cond, LNode.Call(CodeSymbols.AltList, LNode.List(inc)), block)); } if (preInit.Count != 0) { stmt = LNode.Call(CodeSymbols.Braces, LNode.List().AddRange(preInit).Add(stmt)).SetStyle(NodeStyle.Statement); } return stmt; } else { return stmt.WithArgChanged(3, block); } }