Skip lone ident statments or for-loop assignments

SL's LSL supports lone idents:

    integer x;
    x;

as well as lone idents in for-loop assignments:

    for (x; x < 10; x++) { ... }

while those are errors in C# (MONO at least). This patch skips lone
idents in such places.

Fixes Mantis #3042.
This commit is contained in:
Mike Mazur
2009-06-07 10:22:55 +00:00
parent 48bc2f3a42
commit cda6b24668
2 changed files with 65 additions and 3 deletions

View File

@@ -132,6 +132,32 @@ state another_state
Assert.AreEqual(expected, output);
}
[Test]
public void TestLoneIdent()
{
// A lone ident should be removed completely as it's an error in C#
// (MONO at least).
string input = @"default
{
touch_start(integer num_detected)
{
integer x;
x;
}
}
";
string expected =
"\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
"\n {" +
"\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" +
"\n ;" +
"\n }\n";
CSCodeGenerator cg = new CSCodeGenerator();
string output = cg.Convert(input);
Assert.AreEqual(expected, output);
}
[Test]
public void TestAssignments()
{
@@ -1540,6 +1566,31 @@ default
Assert.AreEqual(expected, output);
}
[Test]
public void TestForLoopWithOnlyIdentInAssignment()
{
string input = @"default
{
state_entry()
{
integer x = 4;
for (x; 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()
{