aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs17
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs51
2 files changed, 65 insertions, 3 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index ab9968f..91747af 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -90,7 +90,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
90 m_warnings.Clear(); 90 m_warnings.Clear();
91 ResetCounters(); 91 ResetCounters();
92 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true)); 92 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
93 // Obviously this needs to be in a try/except block. 93
94 LSL2CSCodeTransformer codeTransformer; 94 LSL2CSCodeTransformer codeTransformer;
95 try 95 try
96 { 96 {
@@ -446,8 +446,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
446 // Jump label prints its own colon, we don't need a semicolon. 446 // Jump label prints its own colon, we don't need a semicolon.
447 printSemicolon = !(s.kids.Top is JumpLabel); 447 printSemicolon = !(s.kids.Top is JumpLabel);
448 448
449 foreach (SYMBOL kid in s.kids) 449 // If we encounter a lone Ident, we skip it, since that's a C#
450 retstr += GenerateNode(kid); 450 // (MONO) error.
451 if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count))
452 foreach (SYMBOL kid in s.kids)
453 retstr += GenerateNode(kid);
451 } 454 }
452 455
453 if (printSemicolon) 456 if (printSemicolon)
@@ -711,6 +714,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
711 714
712 int comma = fls.kids.Count - 1; // tells us whether to print a comma 715 int comma = fls.kids.Count - 1; // tells us whether to print a comma
713 716
717 // It's possible that all we have is an empty Ident, for example:
718 //
719 // for (x; x < 10; x++) { ... }
720 //
721 // Which is illegal in C# (MONO). We'll skip it.
722 if (fls.kids.Top is IdentExpression && 1 == fls.kids.Count)
723 return retstr;
724
714 foreach (SYMBOL s in fls.kids) 725 foreach (SYMBOL s in fls.kids)
715 { 726 {
716 retstr += GenerateNode(s); 727 retstr += GenerateNode(s);
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
index a7d4fa9..5dfbdbc 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
@@ -133,6 +133,32 @@ state another_state
133 } 133 }
134 134
135 [Test] 135 [Test]
136 public void TestLoneIdent()
137 {
138 // A lone ident should be removed completely as it's an error in C#
139 // (MONO at least).
140 string input = @"default
141{
142 touch_start(integer num_detected)
143 {
144 integer x;
145 x;
146 }
147}
148";
149 string expected =
150 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
151 "\n {" +
152 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" +
153 "\n ;" +
154 "\n }\n";
155
156 CSCodeGenerator cg = new CSCodeGenerator();
157 string output = cg.Convert(input);
158 Assert.AreEqual(expected, output);
159 }
160
161 [Test]
136 public void TestAssignments() 162 public void TestAssignments()
137 { 163 {
138 string input = @"default 164 string input = @"default
@@ -1541,6 +1567,31 @@ default
1541 } 1567 }
1542 1568
1543 [Test] 1569 [Test]
1570 public void TestForLoopWithOnlyIdentInAssignment()
1571 {
1572 string input = @"default
1573{
1574 state_entry()
1575 {
1576 integer x = 4;
1577 for (x; 1<0; x += 2);
1578 }
1579}";
1580
1581 string expected =
1582 "\n public void default_event_state_entry()" +
1583 "\n {" +
1584 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(4);" +
1585 "\n for (; new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" +
1586 "\n ;" +
1587 "\n }\n";
1588
1589 CSCodeGenerator cg = new CSCodeGenerator();
1590 string output = cg.Convert(input);
1591 Assert.AreEqual(expected, output);
1592 }
1593
1594 [Test]
1544 public void TestAssignmentInIfWhileDoWhile() 1595 public void TestAssignmentInIfWhileDoWhile()
1545 { 1596 {
1546 string input = @"default 1597 string input = @"default