Fix issue 1860; exception thrown in the parser on if/if-else/for/while/do-while
statements with no body.0.6.0-stable
parent
1c8f490573
commit
eef3864278
|
@ -388,14 +388,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
|
|||
private string GenerateStatement(Statement s)
|
||||
{
|
||||
string retstr = String.Empty;
|
||||
|
||||
// Jump label prints its own colon, we don't need a semicolon.
|
||||
bool printSemicolon = !(s.kids.Top is JumpLabel);
|
||||
bool printSemicolon = true;
|
||||
|
||||
retstr += Indent();
|
||||
|
||||
foreach (SYMBOL kid in s.kids)
|
||||
retstr += GenerateNode(kid);
|
||||
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(";");
|
||||
|
|
|
@ -359,7 +359,7 @@ public override int yynum { get { return 114; }}
|
|||
public StateChange(Parser yyp):base(yyp){}}
|
||||
//%+IfStatement+115
|
||||
public class IfStatement : SYMBOL{
|
||||
private void AddStatement ( Statement s ){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
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 IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax
|
||||
|
@ -369,7 +369,7 @@ public class IfStatement : SYMBOL{
|
|||
public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax
|
||||
)yyp)){ kids . Add ( e );
|
||||
AddStatement ( ifs );
|
||||
if ( es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ());
|
||||
if (0< es . kids . Count && es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ());
|
||||
else AddStatement ( es );
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ public IfStatement(Parser yyp):base(yyp){}}
|
|||
public class WhileStatement : SYMBOL{
|
||||
public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
||||
)yyp)){ kids . Add ( e );
|
||||
if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
else kids . Add ( s );
|
||||
}
|
||||
|
||||
|
@ -390,7 +390,7 @@ public WhileStatement(Parser yyp):base(yyp){}}
|
|||
//%+DoWhileStatement+117
|
||||
public class DoWhileStatement : SYMBOL{
|
||||
public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
||||
)yyp)){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
)yyp)){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
else kids . Add ( s );
|
||||
kids . Add ( e );
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ public class ForLoop : SYMBOL{
|
|||
)yyp)){ kids . Add ( flsa );
|
||||
kids . Add ( e );
|
||||
kids . Add ( flsb );
|
||||
if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
else kids . Add ( s );
|
||||
}
|
||||
|
||||
|
|
|
@ -388,14 +388,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
private string GenerateStatement(Statement s)
|
||||
{
|
||||
string retstr = String.Empty;
|
||||
|
||||
// Jump label prints its own colon, we don't need a semicolon.
|
||||
bool printSemicolon = !(s.kids.Top is JumpLabel);
|
||||
bool printSemicolon = true;
|
||||
|
||||
retstr += Indent();
|
||||
|
||||
foreach (SYMBOL kid in s.kids)
|
||||
retstr += GenerateNode(kid);
|
||||
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(";");
|
||||
|
|
|
@ -359,7 +359,7 @@ public override int yynum { get { return 114; }}
|
|||
public StateChange(Parser yyp):base(yyp){}}
|
||||
//%+IfStatement+115
|
||||
public class IfStatement : SYMBOL{
|
||||
private void AddStatement ( Statement s ){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
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 IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax
|
||||
|
@ -369,7 +369,7 @@ public class IfStatement : SYMBOL{
|
|||
public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax
|
||||
)yyp)){ kids . Add ( e );
|
||||
AddStatement ( ifs );
|
||||
if ( es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ());
|
||||
if (0< es . kids . Count && es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ());
|
||||
else AddStatement ( es );
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ public IfStatement(Parser yyp):base(yyp){}}
|
|||
public class WhileStatement : SYMBOL{
|
||||
public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
||||
)yyp)){ kids . Add ( e );
|
||||
if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
else kids . Add ( s );
|
||||
}
|
||||
|
||||
|
@ -390,7 +390,7 @@ public WhileStatement(Parser yyp):base(yyp){}}
|
|||
//%+DoWhileStatement+117
|
||||
public class DoWhileStatement : SYMBOL{
|
||||
public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
||||
)yyp)){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
)yyp)){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
else kids . Add ( s );
|
||||
kids . Add ( e );
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ public class ForLoop : SYMBOL{
|
|||
)yyp)){ kids . Add ( flsa );
|
||||
kids . Add ( e );
|
||||
kids . Add ( flsb );
|
||||
if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
|
||||
else kids . Add ( s );
|
||||
}
|
||||
|
||||
|
|
|
@ -1394,6 +1394,131 @@ default
|
|||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWhileLoopWithNoBody()
|
||||
{
|
||||
string input = @"default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
while(1<0);
|
||||
}
|
||||
}";
|
||||
|
||||
string expected = @"
|
||||
public void default_event_state_entry()
|
||||
{
|
||||
while (1 < 0)
|
||||
;
|
||||
}
|
||||
";
|
||||
|
||||
CSCodeGenerator cg = new CSCodeGenerator();
|
||||
string output = cg.Convert(input);
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoWhileLoopWithNoBody()
|
||||
{
|
||||
string input = @"default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
do;
|
||||
while(1<0);
|
||||
}
|
||||
}";
|
||||
|
||||
string expected = @"
|
||||
public void default_event_state_entry()
|
||||
{
|
||||
do
|
||||
;
|
||||
while (1 < 0);
|
||||
}
|
||||
";
|
||||
|
||||
CSCodeGenerator cg = new CSCodeGenerator();
|
||||
string output = cg.Convert(input);
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIfWithNoBody()
|
||||
{
|
||||
string input = @"default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
if(1<0);
|
||||
}
|
||||
}";
|
||||
|
||||
string expected = @"
|
||||
public void default_event_state_entry()
|
||||
{
|
||||
if (1 < 0)
|
||||
;
|
||||
}
|
||||
";
|
||||
|
||||
CSCodeGenerator cg = new CSCodeGenerator();
|
||||
string output = cg.Convert(input);
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIfElseWithNoBody()
|
||||
{
|
||||
string input = @"default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
if(1<0);
|
||||
else;
|
||||
}
|
||||
}";
|
||||
|
||||
string expected = @"
|
||||
public void default_event_state_entry()
|
||||
{
|
||||
if (1 < 0)
|
||||
;
|
||||
else
|
||||
;
|
||||
}
|
||||
";
|
||||
|
||||
CSCodeGenerator cg = new CSCodeGenerator();
|
||||
string output = cg.Convert(input);
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestForLoopWithNoBody()
|
||||
{
|
||||
string input = @"default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
for(x = 4; 1<0; x += 2);
|
||||
}
|
||||
}";
|
||||
|
||||
string expected = @"
|
||||
public void default_event_state_entry()
|
||||
{
|
||||
for (x = 4; 1 < 0; x += 2)
|
||||
;
|
||||
}
|
||||
";
|
||||
|
||||
CSCodeGenerator cg = new CSCodeGenerator();
|
||||
string output = cg.Convert(input);
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("Tools.CSToolsException")]
|
||||
public void TestSyntaxError()
|
||||
|
|
Loading…
Reference in New Issue