/// <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> 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()); } } } }*/ StringBuilder retVal = new StringBuilder(), tmpVal = new StringBuilder(); bool DoBrace = false; bool marc = FuncCallsMarc(); tmpVal.Append(GenerateIndented("if (", ifs)); tmpVal.Append(GenerateNode((SYMBOL)ifs.kids.Pop())); tmpVal.Append(GenerateLine(")")); retVal.Append(DumpFunc(marc)); retVal.Append(tmpVal.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) retVal.Append(GenerateLine("{")); retVal.Append(GenerateNode((SYMBOL)ifs.kids.Pop())); // if (indentHere) m_braceCount--; if (DoBrace) retVal.Append(GenerateLine("}")); if (0 < ifs.kids.Count) // do it again for an else { retVal.Append(GenerateIndentedLine("else", ifs)); // indentHere = ifs.kids.Top is Statement; // if (indentHere) m_braceCount++; DoBrace = !(ifs.kids.Top is CompoundStatement); if (DoBrace) retVal.Append(GenerateLine("{")); retVal.Append(GenerateNode((SYMBOL)ifs.kids.Pop())); if (DoBrace) retVal.Append(GenerateLine("}")); // if (indentHere) m_braceCount--; } retVal.Append(DumpAfterFunc(marc)); return retVal.ToString(); }
public Statement(Parser yyp, IfStatement ifs) : base((yyp)) { kids.Add(ifs); }