Allow empty assignment in for-loop
For loops with no assignment are no longer syntax errors. For example, this is now valid: for ( ; i < 10; i++) { ... } Corresponding changes to lsl.{lexer,parser} in r99 in opensim-libs. Fixes Mantis #2501. Fixes Mantis #2884.0.6.6-post-fixes
parent
a3c91de17d
commit
48bc2f3a42
|
@ -671,9 +671,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
|
|
||||||
retstr += GenerateIndented("for (", fl);
|
retstr += GenerateIndented("for (", fl);
|
||||||
|
|
||||||
|
// It's possible that we don't have an assignment, in which case
|
||||||
|
// the child will be null and we only print the semicolon.
|
||||||
// for ( x = 0 ; x < 10 ; x++ )
|
// for ( x = 0 ; x < 10 ; x++ )
|
||||||
// ^^^^^^^
|
// ^^^^^^^
|
||||||
retstr += GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop());
|
ForLoopStatement s = (ForLoopStatement) fl.kids.Pop();
|
||||||
|
if (null != s)
|
||||||
|
{
|
||||||
|
retstr += GenerateForLoopStatement(s);
|
||||||
|
}
|
||||||
retstr += Generate("; ");
|
retstr += Generate("; ");
|
||||||
// for ( x = 0 ; x < 10 ; x++ )
|
// for ( x = 0 ; x < 10 ; x++ )
|
||||||
// ^^^^^^^^
|
// ^^^^^^^^
|
||||||
|
|
|
@ -91,6 +91,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
((GlobalFunctionDefinition) s).ReturnType = m_datatypeLSL2OpenSim[((GlobalFunctionDefinition) s).ReturnType];
|
((GlobalFunctionDefinition) s).ReturnType = m_datatypeLSL2OpenSim[((GlobalFunctionDefinition) s).ReturnType];
|
||||||
|
|
||||||
for (int i = 0; i < s.kids.Count; i++)
|
for (int i = 0; i < s.kids.Count; i++)
|
||||||
|
{
|
||||||
|
// It's possible that a child is null, for instance when the
|
||||||
|
// assignment part in a for-loop is left out, ie:
|
||||||
|
//
|
||||||
|
// for ( ; i < 10; i++)
|
||||||
|
// {
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// We need to check for that here.
|
||||||
|
if (null != s.kids[i])
|
||||||
{
|
{
|
||||||
if (!(s is Assignment || s is ArgumentDeclarationList) && s.kids[i] is Declaration)
|
if (!(s is Assignment || s is ArgumentDeclarationList) && s.kids[i] is Declaration)
|
||||||
AddImplicitInitialization(s, i);
|
AddImplicitInitialization(s, i);
|
||||||
|
@ -98,6 +109,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
TransformNode((SYMBOL) s.kids[i]);
|
TransformNode((SYMBOL) s.kids[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces an instance of the node at s.kids[didx] with an assignment
|
/// Replaces an instance of the node at s.kids[didx] with an assignment
|
||||||
|
|
|
@ -1515,6 +1515,31 @@ default
|
||||||
Assert.AreEqual(expected, output);
|
Assert.AreEqual(expected, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestForLoopWithNoAssignment()
|
||||||
|
{
|
||||||
|
string input = @"default
|
||||||
|
{
|
||||||
|
state_entry()
|
||||||
|
{
|
||||||
|
integer x = 4;
|
||||||
|
for (; 1<0; x += 2);
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
string expected =
|
||||||
|
"\n public void default_event_state_entry()" +
|
||||||
|
"\n {" +
|
||||||
|
"\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(4);" +
|
||||||
|
"\n for (; new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" +
|
||||||
|
"\n ;" +
|
||||||
|
"\n }\n";
|
||||||
|
|
||||||
|
CSCodeGenerator cg = new CSCodeGenerator();
|
||||||
|
string output = cg.Convert(input);
|
||||||
|
Assert.AreEqual(expected, output);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestAssignmentInIfWhileDoWhile()
|
public void TestAssignmentInIfWhileDoWhile()
|
||||||
{
|
{
|
||||||
|
|
|
@ -18785,6 +18785,7 @@ public override TOKEN OldAction(Lexer yym,ref string yytext,int action, ref bool
|
||||||
case 946: { ((LSLTokens)yym).str += yytext; }
|
case 946: { ((LSLTokens)yym).str += yytext; }
|
||||||
break;
|
break;
|
||||||
case 1010: { yym.yy_begin("YYINITIAL"); ((LSLTokens)yym).yytext = ((LSLTokens)yym).str; ((LSLTokens)yym).str = String.Empty; return new STRING_CONSTANT(yym); }
|
case 1010: { yym.yy_begin("YYINITIAL"); ((LSLTokens)yym).yytext = ((LSLTokens)yym).str; ((LSLTokens)yym).str = String.Empty; return new STRING_CONSTANT(yym); }
|
||||||
|
break;
|
||||||
case 1015: { yym.yy_begin("COMMENT"); }
|
case 1015: { yym.yy_begin("COMMENT"); }
|
||||||
break;
|
break;
|
||||||
case 1027: { yym.yy_begin("YYINITIAL"); }
|
case 1027: { yym.yy_begin("YYINITIAL"); }
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue