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.0.6.6-post-fixes
parent
48bc2f3a42
commit
cda6b24668
|
@ -90,7 +90,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
m_warnings.Clear();
|
m_warnings.Clear();
|
||||||
ResetCounters();
|
ResetCounters();
|
||||||
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
|
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
|
||||||
// Obviously this needs to be in a try/except block.
|
|
||||||
LSL2CSCodeTransformer codeTransformer;
|
LSL2CSCodeTransformer codeTransformer;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -446,6 +446,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
// Jump label prints its own colon, we don't need a semicolon.
|
// Jump label prints its own colon, we don't need a semicolon.
|
||||||
printSemicolon = !(s.kids.Top is JumpLabel);
|
printSemicolon = !(s.kids.Top is JumpLabel);
|
||||||
|
|
||||||
|
// If we encounter a lone Ident, we skip it, since that's a C#
|
||||||
|
// (MONO) error.
|
||||||
|
if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count))
|
||||||
foreach (SYMBOL kid in s.kids)
|
foreach (SYMBOL kid in s.kids)
|
||||||
retstr += GenerateNode(kid);
|
retstr += GenerateNode(kid);
|
||||||
}
|
}
|
||||||
|
@ -711,6 +714,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
|
|
||||||
int comma = fls.kids.Count - 1; // tells us whether to print a comma
|
int comma = fls.kids.Count - 1; // tells us whether to print a comma
|
||||||
|
|
||||||
|
// It's possible that all we have is an empty Ident, for example:
|
||||||
|
//
|
||||||
|
// for (x; x < 10; x++) { ... }
|
||||||
|
//
|
||||||
|
// Which is illegal in C# (MONO). We'll skip it.
|
||||||
|
if (fls.kids.Top is IdentExpression && 1 == fls.kids.Count)
|
||||||
|
return retstr;
|
||||||
|
|
||||||
foreach (SYMBOL s in fls.kids)
|
foreach (SYMBOL s in fls.kids)
|
||||||
{
|
{
|
||||||
retstr += GenerateNode(s);
|
retstr += GenerateNode(s);
|
||||||
|
|
|
@ -132,6 +132,32 @@ state another_state
|
||||||
Assert.AreEqual(expected, output);
|
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]
|
[Test]
|
||||||
public void TestAssignments()
|
public void TestAssignments()
|
||||||
{
|
{
|
||||||
|
@ -1540,6 +1566,31 @@ default
|
||||||
Assert.AreEqual(expected, output);
|
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]
|
[Test]
|
||||||
public void TestAssignmentInIfWhileDoWhile()
|
public void TestAssignmentInIfWhileDoWhile()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue