aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMike Mazur2008-07-31 01:27:33 +0000
committerMike Mazur2008-07-31 01:27:33 +0000
commiteef386427863e27a40cb22a424ddb5ceeb6c7a56 (patch)
tree331ca69428a9ece47d412556a366839f76ffded2
parentMore LSL_Types implicit/explicit cast changes. Fix issue 1854. (diff)
downloadopensim-SC-eef386427863e27a40cb22a424ddb5ceeb6c7a56.zip
opensim-SC-eef386427863e27a40cb22a424ddb5ceeb6c7a56.tar.gz
opensim-SC-eef386427863e27a40cb22a424ddb5ceeb6c7a56.tar.bz2
opensim-SC-eef386427863e27a40cb22a424ddb5ceeb6c7a56.tar.xz
Fix issue 1860; exception thrown in the parser on if/if-else/for/while/do-while
statements with no body.
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/CSCodeGenerator.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/lsl.parser.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs10
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs125
5 files changed, 153 insertions, 20 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/CSCodeGenerator.cs
index f129859..631aa54 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/CSCodeGenerator.cs
@@ -388,14 +388,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
388 private string GenerateStatement(Statement s) 388 private string GenerateStatement(Statement s)
389 { 389 {
390 string retstr = String.Empty; 390 string retstr = String.Empty;
391 391 bool printSemicolon = true;
392 // Jump label prints its own colon, we don't need a semicolon.
393 bool printSemicolon = !(s.kids.Top is JumpLabel);
394 392
395 retstr += Indent(); 393 retstr += Indent();
396 394
397 foreach (SYMBOL kid in s.kids) 395 if (0 < s.kids.Count)
398 retstr += GenerateNode(kid); 396 {
397 // Jump label prints its own colon, we don't need a semicolon.
398 printSemicolon = !(s.kids.Top is JumpLabel);
399
400 foreach (SYMBOL kid in s.kids)
401 retstr += GenerateNode(kid);
402 }
399 403
400 if (printSemicolon) 404 if (printSemicolon)
401 retstr += GenerateLine(";"); 405 retstr += GenerateLine(";");
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/lsl.parser.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/lsl.parser.cs
index 178eed1..14c090d 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/lsl.parser.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/lsl.parser.cs
@@ -359,7 +359,7 @@ public override int yynum { get { return 114; }}
359public StateChange(Parser yyp):base(yyp){}} 359public StateChange(Parser yyp):base(yyp){}}
360//%+IfStatement+115 360//%+IfStatement+115
361public class IfStatement : SYMBOL{ 361public class IfStatement : SYMBOL{
362 private void AddStatement ( Statement s ){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 362 private void AddStatement ( Statement s ){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
363 else kids . Add ( s ); 363 else kids . Add ( s );
364} 364}
365 public IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax 365 public IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax
@@ -369,7 +369,7 @@ public class IfStatement : SYMBOL{
369 public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax 369 public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax
370)yyp)){ kids . Add ( e ); 370)yyp)){ kids . Add ( e );
371 AddStatement ( ifs ); 371 AddStatement ( ifs );
372 if ( es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ()); 372 if (0< es . kids . Count && es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ());
373 else AddStatement ( es ); 373 else AddStatement ( es );
374} 374}
375 375
@@ -380,7 +380,7 @@ public IfStatement(Parser yyp):base(yyp){}}
380public class WhileStatement : SYMBOL{ 380public class WhileStatement : SYMBOL{
381 public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax 381 public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
382)yyp)){ kids . Add ( e ); 382)yyp)){ kids . Add ( e );
383 if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 383 if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
384 else kids . Add ( s ); 384 else kids . Add ( s );
385} 385}
386 386
@@ -390,7 +390,7 @@ public WhileStatement(Parser yyp):base(yyp){}}
390//%+DoWhileStatement+117 390//%+DoWhileStatement+117
391public class DoWhileStatement : SYMBOL{ 391public class DoWhileStatement : SYMBOL{
392 public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax 392 public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
393)yyp)){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 393)yyp)){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
394 else kids . Add ( s ); 394 else kids . Add ( s );
395 kids . Add ( e ); 395 kids . Add ( e );
396} 396}
@@ -404,7 +404,7 @@ public class ForLoop : SYMBOL{
404)yyp)){ kids . Add ( flsa ); 404)yyp)){ kids . Add ( flsa );
405 kids . Add ( e ); 405 kids . Add ( e );
406 kids . Add ( flsb ); 406 kids . Add ( flsb );
407 if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 407 if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
408 else kids . Add ( s ); 408 else kids . Add ( s );
409} 409}
410 410
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index 3bdad4d..2226673 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -388,14 +388,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
388 private string GenerateStatement(Statement s) 388 private string GenerateStatement(Statement s)
389 { 389 {
390 string retstr = String.Empty; 390 string retstr = String.Empty;
391 391 bool printSemicolon = true;
392 // Jump label prints its own colon, we don't need a semicolon.
393 bool printSemicolon = !(s.kids.Top is JumpLabel);
394 392
395 retstr += Indent(); 393 retstr += Indent();
396 394
397 foreach (SYMBOL kid in s.kids) 395 if (0 < s.kids.Count)
398 retstr += GenerateNode(kid); 396 {
397 // Jump label prints its own colon, we don't need a semicolon.
398 printSemicolon = !(s.kids.Top is JumpLabel);
399
400 foreach (SYMBOL kid in s.kids)
401 retstr += GenerateNode(kid);
402 }
399 403
400 if (printSemicolon) 404 if (printSemicolon)
401 retstr += GenerateLine(";"); 405 retstr += GenerateLine(";");
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs
index e9b3886..9778245 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs
@@ -359,7 +359,7 @@ public override int yynum { get { return 114; }}
359public StateChange(Parser yyp):base(yyp){}} 359public StateChange(Parser yyp):base(yyp){}}
360//%+IfStatement+115 360//%+IfStatement+115
361public class IfStatement : SYMBOL{ 361public class IfStatement : SYMBOL{
362 private void AddStatement ( Statement s ){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 362 private void AddStatement ( Statement s ){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
363 else kids . Add ( s ); 363 else kids . Add ( s );
364} 364}
365 public IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax 365 public IfStatement (Parser yyp, Expression e , Statement ifs ):base(((LSLSyntax
@@ -369,7 +369,7 @@ public class IfStatement : SYMBOL{
369 public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax 369 public IfStatement (Parser yyp, Expression e , Statement ifs , Statement es ):base(((LSLSyntax
370)yyp)){ kids . Add ( e ); 370)yyp)){ kids . Add ( e );
371 AddStatement ( ifs ); 371 AddStatement ( ifs );
372 if ( es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ()); 372 if (0< es . kids . Count && es . kids . Top is IfStatement ) kids . Add ( es . kids . Pop ());
373 else AddStatement ( es ); 373 else AddStatement ( es );
374} 374}
375 375
@@ -380,7 +380,7 @@ public IfStatement(Parser yyp):base(yyp){}}
380public class WhileStatement : SYMBOL{ 380public class WhileStatement : SYMBOL{
381 public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax 381 public WhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
382)yyp)){ kids . Add ( e ); 382)yyp)){ kids . Add ( e );
383 if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 383 if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
384 else kids . Add ( s ); 384 else kids . Add ( s );
385} 385}
386 386
@@ -390,7 +390,7 @@ public WhileStatement(Parser yyp):base(yyp){}}
390//%+DoWhileStatement+117 390//%+DoWhileStatement+117
391public class DoWhileStatement : SYMBOL{ 391public class DoWhileStatement : SYMBOL{
392 public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax 392 public DoWhileStatement (Parser yyp, Expression e , Statement s ):base(((LSLSyntax
393)yyp)){ if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 393)yyp)){ if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
394 else kids . Add ( s ); 394 else kids . Add ( s );
395 kids . Add ( e ); 395 kids . Add ( e );
396} 396}
@@ -404,7 +404,7 @@ public class ForLoop : SYMBOL{
404)yyp)){ kids . Add ( flsa ); 404)yyp)){ kids . Add ( flsa );
405 kids . Add ( e ); 405 kids . Add ( e );
406 kids . Add ( flsb ); 406 kids . Add ( flsb );
407 if ( s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ()); 407 if (0< s . kids . Count && s . kids . Top is CompoundStatement ) kids . Add ( s . kids . Pop ());
408 else kids . Add ( s ); 408 else kids . Add ( s );
409} 409}
410 410
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs
index 9547b0b..6e4d029 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGeneratorTest.cs
@@ -1395,6 +1395,131 @@ default
1395 } 1395 }
1396 1396
1397 [Test] 1397 [Test]
1398 public void TestWhileLoopWithNoBody()
1399 {
1400 string input = @"default
1401{
1402 state_entry()
1403 {
1404 while(1<0);
1405 }
1406}";
1407
1408 string expected = @"
1409 public void default_event_state_entry()
1410 {
1411 while (1 < 0)
1412 ;
1413 }
1414";
1415
1416 CSCodeGenerator cg = new CSCodeGenerator();
1417 string output = cg.Convert(input);
1418 Assert.AreEqual(expected, output);
1419 }
1420
1421 [Test]
1422 public void TestDoWhileLoopWithNoBody()
1423 {
1424 string input = @"default
1425{
1426 state_entry()
1427 {
1428 do;
1429 while(1<0);
1430 }
1431}";
1432
1433 string expected = @"
1434 public void default_event_state_entry()
1435 {
1436 do
1437 ;
1438 while (1 < 0);
1439 }
1440";
1441
1442 CSCodeGenerator cg = new CSCodeGenerator();
1443 string output = cg.Convert(input);
1444 Assert.AreEqual(expected, output);
1445 }
1446
1447 [Test]
1448 public void TestIfWithNoBody()
1449 {
1450 string input = @"default
1451{
1452 state_entry()
1453 {
1454 if(1<0);
1455 }
1456}";
1457
1458 string expected = @"
1459 public void default_event_state_entry()
1460 {
1461 if (1 < 0)
1462 ;
1463 }
1464";
1465
1466 CSCodeGenerator cg = new CSCodeGenerator();
1467 string output = cg.Convert(input);
1468 Assert.AreEqual(expected, output);
1469 }
1470
1471 [Test]
1472 public void TestIfElseWithNoBody()
1473 {
1474 string input = @"default
1475{
1476 state_entry()
1477 {
1478 if(1<0);
1479 else;
1480 }
1481}";
1482
1483 string expected = @"
1484 public void default_event_state_entry()
1485 {
1486 if (1 < 0)
1487 ;
1488 else
1489 ;
1490 }
1491";
1492
1493 CSCodeGenerator cg = new CSCodeGenerator();
1494 string output = cg.Convert(input);
1495 Assert.AreEqual(expected, output);
1496 }
1497
1498 [Test]
1499 public void TestForLoopWithNoBody()
1500 {
1501 string input = @"default
1502{
1503 state_entry()
1504 {
1505 for(x = 4; 1<0; x += 2);
1506 }
1507}";
1508
1509 string expected = @"
1510 public void default_event_state_entry()
1511 {
1512 for (x = 4; 1 < 0; x += 2)
1513 ;
1514 }
1515";
1516
1517 CSCodeGenerator cg = new CSCodeGenerator();
1518 string output = cg.Convert(input);
1519 Assert.AreEqual(expected, output);
1520 }
1521
1522 [Test]
1398 [ExpectedException("Tools.CSToolsException")] 1523 [ExpectedException("Tools.CSToolsException")]
1399 public void TestSyntaxError() 1524 public void TestSyntaxError()
1400 { 1525 {