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)
|
private string GenerateStatement(Statement s)
|
||||||
{
|
{
|
||||||
string retstr = String.Empty;
|
string retstr = String.Empty;
|
||||||
|
bool printSemicolon = true;
|
||||||
// Jump label prints its own colon, we don't need a semicolon.
|
|
||||||
bool printSemicolon = !(s.kids.Top is JumpLabel);
|
|
||||||
|
|
||||||
retstr += Indent();
|
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)
|
foreach (SYMBOL kid in s.kids)
|
||||||
retstr += GenerateNode(kid);
|
retstr += GenerateNode(kid);
|
||||||
|
}
|
||||||
|
|
||||||
if (printSemicolon)
|
if (printSemicolon)
|
||||||
retstr += GenerateLine(";");
|
retstr += GenerateLine(";");
|
||||||
|
|
|
@ -359,7 +359,7 @@ public override int yynum { get { return 114; }}
|
||||||
public StateChange(Parser yyp):base(yyp){}}
|
public StateChange(Parser yyp):base(yyp){}}
|
||||||
//%+IfStatement+115
|
//%+IfStatement+115
|
||||||
public class IfStatement : SYMBOL{
|
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 );
|
else kids . Add ( s );
|
||||||
}
|
}
|
||||||
public IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax
|
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
|
public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax
|
||||||
)yyp)){ kids . Add ( e );
|
)yyp)){ kids . Add ( e );
|
||||||
AddStatement ( ifs );
|
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 );
|
else AddStatement ( es );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ public IfStatement(Parser yyp):base(yyp){}}
|
||||||
public class WhileStatement : SYMBOL{
|
public class WhileStatement : SYMBOL{
|
||||||
public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
||||||
)yyp)){ kids . Add ( e );
|
)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 );
|
else kids . Add ( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ public WhileStatement(Parser yyp):base(yyp){}}
|
||||||
//%+DoWhileStatement+117
|
//%+DoWhileStatement+117
|
||||||
public class DoWhileStatement : SYMBOL{
|
public class DoWhileStatement : SYMBOL{
|
||||||
public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
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 );
|
else kids . Add ( s );
|
||||||
kids . Add ( e );
|
kids . Add ( e );
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ public class ForLoop : SYMBOL{
|
||||||
)yyp)){ kids . Add ( flsa );
|
)yyp)){ kids . Add ( flsa );
|
||||||
kids . Add ( e );
|
kids . Add ( e );
|
||||||
kids . Add ( flsb );
|
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 );
|
else kids . Add ( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -388,14 +388,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
private string GenerateStatement(Statement s)
|
private string GenerateStatement(Statement s)
|
||||||
{
|
{
|
||||||
string retstr = String.Empty;
|
string retstr = String.Empty;
|
||||||
|
bool printSemicolon = true;
|
||||||
// Jump label prints its own colon, we don't need a semicolon.
|
|
||||||
bool printSemicolon = !(s.kids.Top is JumpLabel);
|
|
||||||
|
|
||||||
retstr += Indent();
|
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)
|
foreach (SYMBOL kid in s.kids)
|
||||||
retstr += GenerateNode(kid);
|
retstr += GenerateNode(kid);
|
||||||
|
}
|
||||||
|
|
||||||
if (printSemicolon)
|
if (printSemicolon)
|
||||||
retstr += GenerateLine(";");
|
retstr += GenerateLine(";");
|
||||||
|
|
|
@ -359,7 +359,7 @@ public override int yynum { get { return 114; }}
|
||||||
public StateChange(Parser yyp):base(yyp){}}
|
public StateChange(Parser yyp):base(yyp){}}
|
||||||
//%+IfStatement+115
|
//%+IfStatement+115
|
||||||
public class IfStatement : SYMBOL{
|
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 );
|
else kids . Add ( s );
|
||||||
}
|
}
|
||||||
public IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax
|
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
|
public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax
|
||||||
)yyp)){ kids . Add ( e );
|
)yyp)){ kids . Add ( e );
|
||||||
AddStatement ( ifs );
|
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 );
|
else AddStatement ( es );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ public IfStatement(Parser yyp):base(yyp){}}
|
||||||
public class WhileStatement : SYMBOL{
|
public class WhileStatement : SYMBOL{
|
||||||
public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
||||||
)yyp)){ kids . Add ( e );
|
)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 );
|
else kids . Add ( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ public WhileStatement(Parser yyp):base(yyp){}}
|
||||||
//%+DoWhileStatement+117
|
//%+DoWhileStatement+117
|
||||||
public class DoWhileStatement : SYMBOL{
|
public class DoWhileStatement : SYMBOL{
|
||||||
public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
|
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 );
|
else kids . Add ( s );
|
||||||
kids . Add ( e );
|
kids . Add ( e );
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ public class ForLoop : SYMBOL{
|
||||||
)yyp)){ kids . Add ( flsa );
|
)yyp)){ kids . Add ( flsa );
|
||||||
kids . Add ( e );
|
kids . Add ( e );
|
||||||
kids . Add ( flsb );
|
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 );
|
else kids . Add ( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1394,6 +1394,131 @@ default
|
||||||
Assert.AreEqual(expected, output);
|
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]
|
[Test]
|
||||||
[ExpectedException("Tools.CSToolsException")]
|
[ExpectedException("Tools.CSToolsException")]
|
||||||
public void TestSyntaxError()
|
public void TestSyntaxError()
|
||||||
|
|
Loading…
Reference in New Issue