public Statement (Parser yyp, IfStatement ifs ):base(((LSLSyntax )yyp)){ kids . Add ( ifs ); }
/// <summary> /// Generates the code for an IfStatement node. /// </summary> /// <param name="ifs">The IfStatement node.</param> /// <returns>String containing C# code for IfStatement ifs.</returns> private string GenerateIfStatement(IfStatement ifs) { /* * Test script that was used to make sure that if statements do not fail integer a = 0; integer test() { a++; return a; } default { state_entry() { if(test() == 0) //1 gets returned here { llSay(0, "Script running. 0"); } else if(test() == 1) //2 gets returned here { llSay(0, "Script running. 2"); } else { // 3 gets returned here if(test() == 4) { llSay(0, "Script running. 4"); } else if(test() == 4) { // It should hit this path llSay(0, "Script running. 2 4"); } else { // 5 would be returned here llSay(0, "Script running. else " + test()); } } } }*/ string retstr = ""; string tmpstr = ""; bool DoBrace = false; bool marc = FuncCallsMarc(); tmpstr += GenerateIndented("if (", ifs); tmpstr += GenerateNode((SYMBOL)ifs.kids.Pop()); tmpstr += GenerateLine(")"); retstr += DumpFunc(marc) + tmpstr.ToString(); // CompoundStatement handles indentation itself but we need to do it // otherwise. // bool indentHere = ifs.kids.Top is Statement; // if (indentHere) m_braceCount++; DoBrace = !(ifs.kids.Top is CompoundStatement); if (DoBrace) retstr += GenerateLine("{"); retstr += GenerateNode((SYMBOL)ifs.kids.Pop()); // if (indentHere) m_braceCount--; if (DoBrace) retstr += GenerateLine("}"); if (0 < ifs.kids.Count) // do it again for an else { retstr += GenerateIndentedLine("else", ifs); // indentHere = ifs.kids.Top is Statement; // if (indentHere) m_braceCount++; DoBrace = !(ifs.kids.Top is CompoundStatement); if (DoBrace) retstr += GenerateLine("{"); retstr += GenerateNode((SYMBOL)ifs.kids.Pop()); if (DoBrace) retstr += GenerateLine("}"); // if (indentHere) m_braceCount--; } return retstr.ToString(); }
/// <summary> /// Generates the code for an IfStatement node. /// </summary> /// <param name="ifs">The IfStatement node.</param> /// <returns>String containing C# code for IfStatement ifs.</returns> private string GenerateIfStatement(IfStatement ifs) { string retstr = ""; string tmpstr = ""; bool marc = FuncCallsMarc(); tmpstr += GenerateIndented("if (", ifs); tmpstr += GenerateNode((SYMBOL)ifs.kids.Pop()); tmpstr += GenerateLine(")"); retstr += DumpFunc(marc) + tmpstr.ToString(); // CompoundStatement handles indentation itself but we need to do it // otherwise. bool indentHere = ifs.kids.Top is Statement; if (indentHere) m_braceCount++; retstr += GenerateNode((SYMBOL)ifs.kids.Pop()); if (indentHere) m_braceCount--; if (0 < ifs.kids.Count) // do it again for an else { retstr += GenerateIndentedLine("else", ifs); indentHere = ifs.kids.Top is Statement; if (indentHere) m_braceCount++; retstr += GenerateNode((SYMBOL)ifs.kids.Pop()); if (indentHere) m_braceCount--; } return retstr.ToString(); }
/// <summary> /// Generates the code for an IfStatement node. /// </summary> /// <param name="ifs">The IfStatement node.</param> /// <returns>String containing C# code for IfStatement ifs.</returns> private string GenerateIfStatement(IfStatement ifs) { StringBuilder retstr = new StringBuilder(); retstr.Append(GenerateIndented("if (", ifs)); retstr.Append(GenerateNode((SYMBOL) ifs.kids.Pop())); retstr.Append(GenerateLine(")")); // CompoundStatement handles indentation itself but we need to do it // otherwise. bool indentHere = ifs.kids.Top is Statement; if (indentHere) m_braceCount++; retstr.Append(GenerateNode((SYMBOL) ifs.kids.Pop())); if (indentHere) m_braceCount--; if (0 < ifs.kids.Count) // do it again for an else { retstr.Append(GenerateIndentedLine("else", ifs)); indentHere = ifs.kids.Top is Statement; if (indentHere) m_braceCount++; retstr.Append(GenerateNode((SYMBOL) ifs.kids.Pop())); if (indentHere) m_braceCount--; } return retstr.ToString(); }