/// <summary> /// Generates the code for a Statement node. /// </summary> /// <param name="s">The Statement node.</param> /// <returns>String containing C# code for Statement s.</returns> private string GenerateStatement(Statement s) { string retstr = String.Empty; bool printSemicolon = true; retstr += Indent(); if (0 < s.kids.Count) { // Jump label prints its own colon, we don't need a semicolon. printSemicolon = !(s.kids.Top is JumpLabel); foreach (SYMBOL kid in s.kids) retstr += GenerateNode(kid); } if (printSemicolon) retstr += GenerateLine(";"); return retstr; }
/// <summary> /// Generates the code for a Statement node. /// </summary> /// <param name="s">The Statement node.</param> /// <returns>String containing C# code for Statement s.</returns> private string GenerateStatement(SYMBOL previousSymbol, Statement s) { string retstr = String.Empty; bool printSemicolon = true; bool transformToBlock = false; if (m_insertCoopTerminationChecks) { // A non-braced single line do while structure cannot contain multiple statements. // So to insert the termination check we change this to a braced control structure instead. if (previousSymbol is WhileStatement || previousSymbol is DoWhileStatement || previousSymbol is ForLoop) { transformToBlock = true; // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented. retstr += GenerateIndentedLine("{"); retstr += GenerateIndentedLine(m_coopTerminationCheck); } } retstr += Indent(); if (0 < s.kids.Count) { // Jump label prints its own colon, we don't need a semicolon. printSemicolon = !(s.kids.Top is JumpLabel); // If we encounter a lone Ident, we skip it, since that's a C# // (MONO) error. if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count)) foreach (SYMBOL kid in s.kids) retstr += GenerateNode(s, kid); } if (printSemicolon) retstr += GenerateLine(";"); if (transformToBlock) { // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent retstr += GenerateIndentedLine("}"); } return retstr; }
public ForLoop (Parser yyp, ForLoopStatement flsa , Expression e , ForLoopStatement flsb , Statement s ):base(((LSLSyntax )yyp)){ kids . Add ( flsa ); kids . Add ( e ); kids . Add ( flsb ); if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); else kids . Add ( s ); }
/// <summary> /// Generates the code for a Statement node. /// </summary> /// <param name="s">The Statement node.</param> /// <returns>String containing C# code for Statement s.</returns> private string GenerateStatement(Statement s) { string retstr = String.Empty; bool printSemicolon = true; retstr += Indent(); if (0 < s.kids.Count) { // Jump label prints its own colon, we don't need a semicolon. printSemicolon = !(s.kids.Top is JumpLabel); // If we encounter a lone Ident, we skip it, since that's a C# // (MONO) error. if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count)) foreach (SYMBOL kid in s.kids) retstr += GenerateNode(kid); } if (printSemicolon) retstr += GenerateLine(";"); return retstr; }
public IfStatement (Parser yyp, SYMBOL s , Statement ifs , Statement es ):base(((LSLSyntax )yyp)){ kids . Add ( s ); AddStatement ( ifs ); if (0< es . kids . Count && es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ()); else AddStatement ( es ); }
public DoWhileStatement (Parser yyp, SYMBOL s , Statement st ):base(((LSLSyntax )yyp)){ if (0< st . kids . Count && st . kids . Top is CompoundStatement ) kids . Add ( st . kids . Pop ()); else kids . Add ( st ); kids . Add ( s ); }
public IfStatement (Parser yyp, SYMBOL s , Statement ifs ):base(((LSLSyntax )yyp)){ kids . Add ( s ); AddStatement ( ifs ); }
private void AddStatement ( Statement s ){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); else kids . Add ( s ); }
public StatementList (Parser yyp, StatementList sl , Statement s ):base(((LSLSyntax )yyp)){ while (0< sl . kids . Count ) kids . Add ( sl . kids . Pop ()); AddStatement ( s ); }
public StatementList (Parser yyp, Statement s ):base(((LSLSyntax )yyp)){ AddStatement ( s ); }
private void AddStatement ( Statement s ){ if ( s . kids . Top is IfStatement || s . kids . Top is WhileStatement || s . kids . Top is DoWhileStatement || s . kids . Top is ForLoop ) kids . Add ( s . kids . Pop ()); else kids . Add ( s ); }