mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 06:06:06 +08:00
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:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user