public Statement (Parser yyp, ForLoop fl ):base(((LSLSyntax )yyp)){ kids . Add ( fl ); }
/// <summary> /// Generates the code for a ForLoop node. /// </summary> /// <param name="fl">The ForLoop node.</param> /// <returns>String containing C# code for ForLoop fl.</returns> private string GenerateForLoop(ForLoop fl) { string retstr = ""; string tmpstr = ""; tmpstr += GenerateIndented("for (", fl); // It's possible that we don't have an assignment, in which case // the child will be null and we only print the semicolon. // for (x = 0; x < 10; x++) // ^^^^^ ForLoopStatement s = (ForLoopStatement)fl.kids.Pop(); if (null != s) { tmpstr += GenerateForLoopStatement(s); } tmpstr += Generate("; "); // for (x = 0; x < 10; x++) // ^^^^^^ tmpstr += GenerateNode((SYMBOL)fl.kids.Pop()); tmpstr += Generate("; "); // for (x = 0; x < 10; x++) // ^^^ tmpstr += GenerateForLoopStatement((ForLoopStatement)fl.kids.Pop()); tmpstr += GenerateLine(")"); retstr += tmpstr.ToString(); // CompoundStatement handles indentation itself but we need to do it // otherwise. bool indentHere = fl.kids.Top is Statement; if (indentHere) m_braceCount++; retstr += GenerateNode((SYMBOL)fl.kids.Pop()); if (indentHere) m_braceCount--; return retstr.ToString(); }
/// <summary> /// Generates the code for a ForLoop node. /// </summary> /// <param name="fl">The ForLoop node.</param> /// <returns>String containing C# code for ForLoop fl.</returns> private string GenerateForLoop(ForLoop fl) { string retstr = ""; string tmpstr = ""; bool marc = FuncCallsMarc(); tmpstr += GenerateIndented("for (", fl); // It's possible that we don't have an assignment, in which case // the child will be null and we only print the semicolon. // for (x = 0; x < 10; x++) // ^^^^^ ForLoopStatement s = (ForLoopStatement)fl.kids.Pop(); if (null != s) { tmpstr += GenerateForLoopStatement(s); } tmpstr += Generate("; "); // for (x = 0; x < 10; x++) // ^^^^^^ tmpstr += GenerateNode((SYMBOL)fl.kids.Pop()); tmpstr += Generate("; "); // for (x = 0; x < 10; x++) // ^^^ tmpstr += GenerateForLoopStatement((ForLoopStatement)fl.kids.Pop()); tmpstr += GenerateLine(")"); retstr += DumpFunc(marc) + tmpstr.ToString(); if (IsParentEnumerable) { retstr += GenerateLine("{"); // SLAM! No 'for(i = 0; i < 1; i = 0) doSomething();' statements for you retstr += GenerateLine("if (CheckSlice()) yield return null;"); } // CompoundStatement handles indentation itself but we need to do it // otherwise. bool indentHere = fl.kids.Top is Statement; if (indentHere) m_braceCount++; retstr += GenerateNode((SYMBOL)fl.kids.Pop()); if (indentHere) m_braceCount--; if (IsParentEnumerable) retstr += GenerateLine("}"); return retstr.ToString(); }
/// <summary> /// Generates the code for a ForLoop node. /// </summary> /// <param name="fl">The ForLoop node.</param> /// <returns>String containing C# code for ForLoop fl.</returns> private string GenerateForLoop(ForLoop fl) { StringBuilder retstr = new StringBuilder(); if (IsParentEnumerable) { retstr.Append(GenerateLine("yield return null;")); } retstr.Append(GenerateIndented("for (", fl)); // It's possible that we don't have an assignment, in which case // the child will be null and we only print the semicolon. // for (x = 0; x < 10; x++) // ^^^^^ ForLoopStatement s = (ForLoopStatement) fl.kids.Pop(); if (null != s) { retstr.Append(GenerateForLoopStatement(s)); } retstr.Append(Generate("; ")); // for (x = 0; x < 10; x++) // ^^^^^^ retstr.Append(GenerateNode((SYMBOL) fl.kids.Pop())); retstr.Append(Generate("; ")); // for (x = 0; x < 10; x++) // ^^^ retstr.Append(GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop())); retstr.Append(GenerateLine(")")); if (IsParentEnumerable) { retstr.Append(GenerateLine("{")); // SLAM! No 'for(i = 0; i < 1; i = 0) doSomething();' statements for you retstr.Append(GenerateLine("yield return null;")); } // CompoundStatement handles indentation itself but we need to do it // otherwise. bool indentHere = fl.kids.Top is Statement; if (indentHere) m_braceCount++; retstr.Append(GenerateNode((SYMBOL) fl.kids.Pop())); if (indentHere) m_braceCount--; if (IsParentEnumerable) retstr.Append(GenerateLine("}")); return retstr.ToString(); }