/// <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>
        string GenerateForLoop(ForLoop fl)
        {
            StringBuilder retVal = new StringBuilder();
            StringBuilder tmpVal = new StringBuilder();

            bool marc = FuncCallsMarc();

            tmpVal.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)
            {
                tmpVal.Append(GenerateForLoopStatement(s));
            }
            tmpVal.Append(Generate("; "));
            // for (x = 0; x < 10; x++)
            //             ^^^^^^
            tmpVal.Append(GenerateNode((SYMBOL) fl.kids.Pop()));
            tmpVal.Append(Generate("; "));
            // for (x = 0; x < 10; x++)
            //                     ^^^
            tmpVal.Append(GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop()));
            tmpVal.Append(GenerateLine(")"));

            retVal.Append(DumpFunc(marc));
            retVal.Append(tmpVal.ToString());

            if (IsParentEnumerable)
            {
                retVal.Append(GenerateLine("{")); // SLAM! No 'for(i = 0; i < 1; i = 0) doSomething();' statements for you
                retVal.Append(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++;
            retVal.Append(GenerateNode((SYMBOL) fl.kids.Pop()));
            if (indentHere) m_braceCount--;

            if (IsParentEnumerable)
                retVal.Append(GenerateLine("}"));
            
            retVal.Append(DumpAfterFunc(marc));
            return retVal.ToString();
        }
示例#2
0
 public Statement(Parser yyp, ForLoop fl) : base((yyp))
 {
     kids.Add(fl);
 }