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
Mike Mazur 2009-06-07 10:22:41 +00:00
parent a3c91de17d
commit 48bc2f3a42
5 changed files with 7976 additions and 7756 deletions

View File

@ -671,9 +671,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
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++ )
// ^^^^^^^
retstr += GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop());
ForLoopStatement s = (ForLoopStatement) fl.kids.Pop();
if (null != s)
{
retstr += GenerateForLoopStatement(s);
}
retstr += Generate("; ");
// for ( x = 0 ; x < 10 ; x++ )
// ^^^^^^^^

View File

@ -92,10 +92,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
for (int i = 0; i < s.kids.Count; i++)
{
if (!(s is Assignment || s is ArgumentDeclarationList) && s.kids[i] is Declaration)
AddImplicitInitialization(s, 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)
AddImplicitInitialization(s, i);
TransformNode((SYMBOL) s.kids[i]);
TransformNode((SYMBOL) s.kids[i]);
}
}
}

View File

@ -1515,6 +1515,31 @@ default
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]
public void TestAssignmentInIfWhileDoWhile()
{

View File

@ -18785,6 +18785,7 @@ public override TOKEN OldAction(Lexer yym,ref string yytext,int action, ref bool
case 946: { ((LSLTokens)yym).str += yytext; }
break;
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"); }
break;
case 1027: { yym.yy_begin("YYINITIAL"); }

File diff suppressed because it is too large Load Diff