diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools')
5 files changed, 157 insertions, 71 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 97dd0f6..9e32f40 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs | |||
@@ -31,7 +31,6 @@ using System.Collections.Generic; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using log4net; | 32 | using log4net; |
33 | using Tools; | 33 | using Tools; |
34 | |||
35 | using OpenSim.Region.Framework.Interfaces; | 34 | using OpenSim.Region.Framework.Interfaces; |
36 | 35 | ||
37 | namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | 36 | namespace OpenSim.Region.ScriptEngine.Shared.CodeTools |
@@ -49,6 +48,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
49 | private List<string> m_warnings = new List<string>(); | 48 | private List<string> m_warnings = new List<string>(); |
50 | private IScriptModuleComms m_comms = null; | 49 | private IScriptModuleComms m_comms = null; |
51 | 50 | ||
51 | private bool m_insertCoopTerminationChecks; | ||
52 | private static string m_coopTerminationCheck = "opensim_reserved_CheckForCoopTermination();"; | ||
53 | |||
54 | /// <summary> | ||
55 | /// Keep a record of the previous node when we do the parsing. | ||
56 | /// </summary> | ||
57 | /// <remarks> | ||
58 | /// We do this here because the parser generated by CSTools does not retain a reference to its parent node. | ||
59 | /// The previous node is required so we can correctly insert co-op termination checks when required. | ||
60 | /// </remarks> | ||
61 | // private SYMBOL m_previousNode; | ||
62 | |||
52 | /// <summary> | 63 | /// <summary> |
53 | /// Creates an 'empty' CSCodeGenerator instance. | 64 | /// Creates an 'empty' CSCodeGenerator instance. |
54 | /// </summary> | 65 | /// </summary> |
@@ -58,9 +69,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
58 | ResetCounters(); | 69 | ResetCounters(); |
59 | } | 70 | } |
60 | 71 | ||
61 | public CSCodeGenerator(IScriptModuleComms comms) | 72 | public CSCodeGenerator(IScriptModuleComms comms, bool insertCoopTerminationChecks) |
62 | { | 73 | { |
63 | m_comms = comms; | 74 | m_comms = comms; |
75 | m_insertCoopTerminationChecks = insertCoopTerminationChecks; | ||
64 | ResetCounters(); | 76 | ResetCounters(); |
65 | } | 77 | } |
66 | 78 | ||
@@ -155,7 +167,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
155 | // here's the payload | 167 | // here's the payload |
156 | retstr += GenerateLine(); | 168 | retstr += GenerateLine(); |
157 | foreach (SYMBOL s in m_astRoot.kids) | 169 | foreach (SYMBOL s in m_astRoot.kids) |
158 | retstr += GenerateNode(s); | 170 | retstr += GenerateNode(m_astRoot, s); |
159 | 171 | ||
160 | // close braces! | 172 | // close braces! |
161 | m_braceCount--; | 173 | m_braceCount--; |
@@ -165,7 +177,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
165 | 177 | ||
166 | // Removes all carriage return characters which may be generated in Windows platform. Is there | 178 | // Removes all carriage return characters which may be generated in Windows platform. Is there |
167 | // cleaner way of doing this? | 179 | // cleaner way of doing this? |
168 | retstr=retstr.Replace("\r", ""); | 180 | retstr = retstr.Replace("\r", ""); |
169 | 181 | ||
170 | return retstr; | 182 | return retstr; |
171 | } | 183 | } |
@@ -191,9 +203,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
191 | /// Recursively called to generate each type of node. Will generate this | 203 | /// Recursively called to generate each type of node. Will generate this |
192 | /// node, then all it's children. | 204 | /// node, then all it's children. |
193 | /// </summary> | 205 | /// </summary> |
206 | /// <param name="previousSymbol">The parent node.</param> | ||
194 | /// <param name="s">The current node to generate code for.</param> | 207 | /// <param name="s">The current node to generate code for.</param> |
195 | /// <returns>String containing C# code for SYMBOL s.</returns> | 208 | /// <returns>String containing C# code for SYMBOL s.</returns> |
196 | private string GenerateNode(SYMBOL s) | 209 | private string GenerateNode(SYMBOL previousSymbol, SYMBOL s) |
197 | { | 210 | { |
198 | string retstr = String.Empty; | 211 | string retstr = String.Empty; |
199 | 212 | ||
@@ -207,11 +220,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
207 | else if (s is State) | 220 | else if (s is State) |
208 | retstr += GenerateState((State) s); | 221 | retstr += GenerateState((State) s); |
209 | else if (s is CompoundStatement) | 222 | else if (s is CompoundStatement) |
210 | retstr += GenerateCompoundStatement((CompoundStatement) s); | 223 | retstr += GenerateCompoundStatement(previousSymbol, (CompoundStatement) s); |
211 | else if (s is Declaration) | 224 | else if (s is Declaration) |
212 | retstr += GenerateDeclaration((Declaration) s); | 225 | retstr += GenerateDeclaration((Declaration) s); |
213 | else if (s is Statement) | 226 | else if (s is Statement) |
214 | retstr += GenerateStatement((Statement) s); | 227 | retstr += GenerateStatement(previousSymbol, (Statement) s); |
215 | else if (s is ReturnStatement) | 228 | else if (s is ReturnStatement) |
216 | retstr += GenerateReturnStatement((ReturnStatement) s); | 229 | retstr += GenerateReturnStatement((ReturnStatement) s); |
217 | else if (s is JumpLabel) | 230 | else if (s is JumpLabel) |
@@ -261,7 +274,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
261 | else | 274 | else |
262 | { | 275 | { |
263 | foreach (SYMBOL kid in s.kids) | 276 | foreach (SYMBOL kid in s.kids) |
264 | retstr += GenerateNode(kid); | 277 | retstr += GenerateNode(s, kid); |
265 | } | 278 | } |
266 | 279 | ||
267 | return retstr; | 280 | return retstr; |
@@ -295,7 +308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
295 | retstr += GenerateLine(")"); | 308 | retstr += GenerateLine(")"); |
296 | 309 | ||
297 | foreach (SYMBOL kid in remainingKids) | 310 | foreach (SYMBOL kid in remainingKids) |
298 | retstr += GenerateNode(kid); | 311 | retstr += GenerateNode(gf, kid); |
299 | 312 | ||
300 | return retstr; | 313 | return retstr; |
301 | } | 314 | } |
@@ -312,7 +325,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
312 | foreach (SYMBOL s in gv.kids) | 325 | foreach (SYMBOL s in gv.kids) |
313 | { | 326 | { |
314 | retstr += Indent(); | 327 | retstr += Indent(); |
315 | retstr += GenerateNode(s); | 328 | retstr += GenerateNode(gv, s); |
316 | retstr += GenerateLine(";"); | 329 | retstr += GenerateLine(";"); |
317 | } | 330 | } |
318 | 331 | ||
@@ -365,7 +378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
365 | retstr += GenerateLine(")"); | 378 | retstr += GenerateLine(")"); |
366 | 379 | ||
367 | foreach (SYMBOL kid in remainingKids) | 380 | foreach (SYMBOL kid in remainingKids) |
368 | retstr += GenerateNode(kid); | 381 | retstr += GenerateNode(se, kid); |
369 | 382 | ||
370 | return retstr; | 383 | return retstr; |
371 | } | 384 | } |
@@ -404,7 +417,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
404 | 417 | ||
405 | foreach (SYMBOL s in al.kids) | 418 | foreach (SYMBOL s in al.kids) |
406 | { | 419 | { |
407 | retstr += GenerateNode(s); | 420 | retstr += GenerateNode(al, s); |
408 | if (0 < comma--) | 421 | if (0 < comma--) |
409 | retstr += Generate(", "); | 422 | retstr += Generate(", "); |
410 | } | 423 | } |
@@ -417,7 +430,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
417 | /// </summary> | 430 | /// </summary> |
418 | /// <param name="cs">The CompoundStatement node.</param> | 431 | /// <param name="cs">The CompoundStatement node.</param> |
419 | /// <returns>String containing C# code for CompoundStatement cs.</returns> | 432 | /// <returns>String containing C# code for CompoundStatement cs.</returns> |
420 | private string GenerateCompoundStatement(CompoundStatement cs) | 433 | private string GenerateCompoundStatement(SYMBOL previousSymbol, CompoundStatement cs) |
421 | { | 434 | { |
422 | string retstr = String.Empty; | 435 | string retstr = String.Empty; |
423 | 436 | ||
@@ -425,8 +438,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
425 | retstr += GenerateIndentedLine("{"); | 438 | retstr += GenerateIndentedLine("{"); |
426 | m_braceCount++; | 439 | m_braceCount++; |
427 | 440 | ||
441 | if (m_insertCoopTerminationChecks) | ||
442 | { | ||
443 | // We have to check in event functions as well because the user can manually call these. | ||
444 | if (previousSymbol is GlobalFunctionDefinition | ||
445 | || previousSymbol is WhileStatement | ||
446 | || previousSymbol is DoWhileStatement | ||
447 | || previousSymbol is ForLoop | ||
448 | || previousSymbol is StateEvent) | ||
449 | retstr += GenerateIndentedLine(m_coopTerminationCheck); | ||
450 | } | ||
451 | |||
428 | foreach (SYMBOL kid in cs.kids) | 452 | foreach (SYMBOL kid in cs.kids) |
429 | retstr += GenerateNode(kid); | 453 | retstr += GenerateNode(cs, kid); |
430 | 454 | ||
431 | // closing brace | 455 | // closing brace |
432 | m_braceCount--; | 456 | m_braceCount--; |
@@ -450,10 +474,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
450 | /// </summary> | 474 | /// </summary> |
451 | /// <param name="s">The Statement node.</param> | 475 | /// <param name="s">The Statement node.</param> |
452 | /// <returns>String containing C# code for Statement s.</returns> | 476 | /// <returns>String containing C# code for Statement s.</returns> |
453 | private string GenerateStatement(Statement s) | 477 | private string GenerateStatement(SYMBOL previousSymbol, Statement s) |
454 | { | 478 | { |
455 | string retstr = String.Empty; | 479 | string retstr = String.Empty; |
456 | bool printSemicolon = true; | 480 | bool printSemicolon = true; |
481 | bool transformToBlock = false; | ||
482 | |||
483 | if (m_insertCoopTerminationChecks) | ||
484 | { | ||
485 | // A non-braced single line do while structure cannot contain multiple statements. | ||
486 | // So to insert the termination check we change this to a braced control structure instead. | ||
487 | if (previousSymbol is WhileStatement | ||
488 | || previousSymbol is DoWhileStatement | ||
489 | || previousSymbol is ForLoop) | ||
490 | { | ||
491 | transformToBlock = true; | ||
492 | |||
493 | // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented. | ||
494 | retstr += GenerateIndentedLine("{"); | ||
495 | |||
496 | retstr += GenerateIndentedLine(m_coopTerminationCheck); | ||
497 | } | ||
498 | } | ||
457 | 499 | ||
458 | retstr += Indent(); | 500 | retstr += Indent(); |
459 | 501 | ||
@@ -466,12 +508,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
466 | // (MONO) error. | 508 | // (MONO) error. |
467 | if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count)) | 509 | if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count)) |
468 | foreach (SYMBOL kid in s.kids) | 510 | foreach (SYMBOL kid in s.kids) |
469 | retstr += GenerateNode(kid); | 511 | retstr += GenerateNode(s, kid); |
470 | } | 512 | } |
471 | 513 | ||
472 | if (printSemicolon) | 514 | if (printSemicolon) |
473 | retstr += GenerateLine(";"); | 515 | retstr += GenerateLine(";"); |
474 | 516 | ||
517 | if (transformToBlock) | ||
518 | { | ||
519 | // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent | ||
520 | retstr += GenerateIndentedLine("}"); | ||
521 | } | ||
522 | |||
475 | return retstr; | 523 | return retstr; |
476 | } | 524 | } |
477 | 525 | ||
@@ -487,10 +535,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
487 | List<string> identifiers = new List<string>(); | 535 | List<string> identifiers = new List<string>(); |
488 | checkForMultipleAssignments(identifiers, a); | 536 | checkForMultipleAssignments(identifiers, a); |
489 | 537 | ||
490 | retstr += GenerateNode((SYMBOL) a.kids.Pop()); | 538 | retstr += GenerateNode(a, (SYMBOL) a.kids.Pop()); |
491 | retstr += Generate(String.Format(" {0} ", a.AssignmentType), a); | 539 | retstr += Generate(String.Format(" {0} ", a.AssignmentType), a); |
492 | foreach (SYMBOL kid in a.kids) | 540 | foreach (SYMBOL kid in a.kids) |
493 | retstr += GenerateNode(kid); | 541 | retstr += GenerateNode(a, kid); |
494 | 542 | ||
495 | return retstr; | 543 | return retstr; |
496 | } | 544 | } |
@@ -563,7 +611,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
563 | retstr += Generate("return ", rs); | 611 | retstr += Generate("return ", rs); |
564 | 612 | ||
565 | foreach (SYMBOL kid in rs.kids) | 613 | foreach (SYMBOL kid in rs.kids) |
566 | retstr += GenerateNode(kid); | 614 | retstr += GenerateNode(rs, kid); |
567 | 615 | ||
568 | return retstr; | 616 | return retstr; |
569 | } | 617 | } |
@@ -575,7 +623,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
575 | /// <returns>String containing C# code for JumpLabel jl.</returns> | 623 | /// <returns>String containing C# code for JumpLabel jl.</returns> |
576 | private string GenerateJumpLabel(JumpLabel jl) | 624 | private string GenerateJumpLabel(JumpLabel jl) |
577 | { | 625 | { |
578 | return Generate(String.Format("{0}:", CheckName(jl.LabelName)), jl) + " NoOp();\n"; | 626 | string labelStatement; |
627 | |||
628 | if (m_insertCoopTerminationChecks) | ||
629 | labelStatement = m_coopTerminationCheck + "\n"; | ||
630 | else | ||
631 | labelStatement = "NoOp();\n"; | ||
632 | |||
633 | return Generate(String.Format("{0}: ", CheckName(jl.LabelName)), jl) + labelStatement; | ||
579 | } | 634 | } |
580 | 635 | ||
581 | /// <summary> | 636 | /// <summary> |
@@ -598,14 +653,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
598 | string retstr = String.Empty; | 653 | string retstr = String.Empty; |
599 | 654 | ||
600 | retstr += GenerateIndented("if (", ifs); | 655 | retstr += GenerateIndented("if (", ifs); |
601 | retstr += GenerateNode((SYMBOL) ifs.kids.Pop()); | 656 | retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); |
602 | retstr += GenerateLine(")"); | 657 | retstr += GenerateLine(")"); |
603 | 658 | ||
604 | // CompoundStatement handles indentation itself but we need to do it | 659 | // CompoundStatement handles indentation itself but we need to do it |
605 | // otherwise. | 660 | // otherwise. |
606 | bool indentHere = ifs.kids.Top is Statement; | 661 | bool indentHere = ifs.kids.Top is Statement; |
607 | if (indentHere) m_braceCount++; | 662 | if (indentHere) m_braceCount++; |
608 | retstr += GenerateNode((SYMBOL) ifs.kids.Pop()); | 663 | retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); |
609 | if (indentHere) m_braceCount--; | 664 | if (indentHere) m_braceCount--; |
610 | 665 | ||
611 | if (0 < ifs.kids.Count) // do it again for an else | 666 | if (0 < ifs.kids.Count) // do it again for an else |
@@ -614,7 +669,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
614 | 669 | ||
615 | indentHere = ifs.kids.Top is Statement; | 670 | indentHere = ifs.kids.Top is Statement; |
616 | if (indentHere) m_braceCount++; | 671 | if (indentHere) m_braceCount++; |
617 | retstr += GenerateNode((SYMBOL) ifs.kids.Pop()); | 672 | retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); |
618 | if (indentHere) m_braceCount--; | 673 | if (indentHere) m_braceCount--; |
619 | } | 674 | } |
620 | 675 | ||
@@ -641,14 +696,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
641 | string retstr = String.Empty; | 696 | string retstr = String.Empty; |
642 | 697 | ||
643 | retstr += GenerateIndented("while (", ws); | 698 | retstr += GenerateIndented("while (", ws); |
644 | retstr += GenerateNode((SYMBOL) ws.kids.Pop()); | 699 | retstr += GenerateNode(ws, (SYMBOL) ws.kids.Pop()); |
645 | retstr += GenerateLine(")"); | 700 | retstr += GenerateLine(")"); |
646 | 701 | ||
647 | // CompoundStatement handles indentation itself but we need to do it | 702 | // CompoundStatement handles indentation itself but we need to do it |
648 | // otherwise. | 703 | // otherwise. |
649 | bool indentHere = ws.kids.Top is Statement; | 704 | bool indentHere = ws.kids.Top is Statement; |
650 | if (indentHere) m_braceCount++; | 705 | if (indentHere) m_braceCount++; |
651 | retstr += GenerateNode((SYMBOL) ws.kids.Pop()); | 706 | retstr += GenerateNode(ws, (SYMBOL) ws.kids.Pop()); |
652 | if (indentHere) m_braceCount--; | 707 | if (indentHere) m_braceCount--; |
653 | 708 | ||
654 | return retstr; | 709 | return retstr; |
@@ -669,11 +724,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
669 | // otherwise. | 724 | // otherwise. |
670 | bool indentHere = dws.kids.Top is Statement; | 725 | bool indentHere = dws.kids.Top is Statement; |
671 | if (indentHere) m_braceCount++; | 726 | if (indentHere) m_braceCount++; |
672 | retstr += GenerateNode((SYMBOL) dws.kids.Pop()); | 727 | retstr += GenerateNode(dws, (SYMBOL) dws.kids.Pop()); |
673 | if (indentHere) m_braceCount--; | 728 | if (indentHere) m_braceCount--; |
674 | 729 | ||
675 | retstr += GenerateIndented("while (", dws); | 730 | retstr += GenerateIndented("while (", dws); |
676 | retstr += GenerateNode((SYMBOL) dws.kids.Pop()); | 731 | retstr += GenerateNode(dws, (SYMBOL) dws.kids.Pop()); |
677 | retstr += GenerateLine(");"); | 732 | retstr += GenerateLine(");"); |
678 | 733 | ||
679 | return retstr; | 734 | return retstr; |
@@ -702,7 +757,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
702 | retstr += Generate("; "); | 757 | retstr += Generate("; "); |
703 | // for (x = 0; x < 10; x++) | 758 | // for (x = 0; x < 10; x++) |
704 | // ^^^^^^ | 759 | // ^^^^^^ |
705 | retstr += GenerateNode((SYMBOL) fl.kids.Pop()); | 760 | retstr += GenerateNode(fl, (SYMBOL) fl.kids.Pop()); |
706 | retstr += Generate("; "); | 761 | retstr += Generate("; "); |
707 | // for (x = 0; x < 10; x++) | 762 | // for (x = 0; x < 10; x++) |
708 | // ^^^ | 763 | // ^^^ |
@@ -713,7 +768,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
713 | // otherwise. | 768 | // otherwise. |
714 | bool indentHere = fl.kids.Top is Statement; | 769 | bool indentHere = fl.kids.Top is Statement; |
715 | if (indentHere) m_braceCount++; | 770 | if (indentHere) m_braceCount++; |
716 | retstr += GenerateNode((SYMBOL) fl.kids.Pop()); | 771 | retstr += GenerateNode(fl, (SYMBOL) fl.kids.Pop()); |
717 | if (indentHere) m_braceCount--; | 772 | if (indentHere) m_braceCount--; |
718 | 773 | ||
719 | return retstr; | 774 | return retstr; |
@@ -758,7 +813,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
758 | while (s is ParenthesisExpression) | 813 | while (s is ParenthesisExpression) |
759 | s = (SYMBOL)s.kids.Pop(); | 814 | s = (SYMBOL)s.kids.Pop(); |
760 | 815 | ||
761 | retstr += GenerateNode(s); | 816 | retstr += GenerateNode(fls, s); |
762 | if (0 < comma--) | 817 | if (0 < comma--) |
763 | retstr += Generate(", "); | 818 | retstr += Generate(", "); |
764 | } | 819 | } |
@@ -779,20 +834,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
779 | { | 834 | { |
780 | // special case handling for logical and/or, see Mantis 3174 | 835 | // special case handling for logical and/or, see Mantis 3174 |
781 | retstr += "((bool)("; | 836 | retstr += "((bool)("; |
782 | retstr += GenerateNode((SYMBOL)be.kids.Pop()); | 837 | retstr += GenerateNode(be, (SYMBOL)be.kids.Pop()); |
783 | retstr += "))"; | 838 | retstr += "))"; |
784 | retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be); | 839 | retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be); |
785 | retstr += "((bool)("; | 840 | retstr += "((bool)("; |
786 | foreach (SYMBOL kid in be.kids) | 841 | foreach (SYMBOL kid in be.kids) |
787 | retstr += GenerateNode(kid); | 842 | retstr += GenerateNode(be, kid); |
788 | retstr += "))"; | 843 | retstr += "))"; |
789 | } | 844 | } |
790 | else | 845 | else |
791 | { | 846 | { |
792 | retstr += GenerateNode((SYMBOL)be.kids.Pop()); | 847 | retstr += GenerateNode(be, (SYMBOL)be.kids.Pop()); |
793 | retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol), be); | 848 | retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol), be); |
794 | foreach (SYMBOL kid in be.kids) | 849 | foreach (SYMBOL kid in be.kids) |
795 | retstr += GenerateNode(kid); | 850 | retstr += GenerateNode(be, kid); |
796 | } | 851 | } |
797 | 852 | ||
798 | return retstr; | 853 | return retstr; |
@@ -808,7 +863,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
808 | string retstr = String.Empty; | 863 | string retstr = String.Empty; |
809 | 864 | ||
810 | retstr += Generate(ue.UnarySymbol, ue); | 865 | retstr += Generate(ue.UnarySymbol, ue); |
811 | retstr += GenerateNode((SYMBOL) ue.kids.Pop()); | 866 | retstr += GenerateNode(ue, (SYMBOL) ue.kids.Pop()); |
812 | 867 | ||
813 | return retstr; | 868 | return retstr; |
814 | } | 869 | } |
@@ -824,7 +879,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
824 | 879 | ||
825 | retstr += Generate("("); | 880 | retstr += Generate("("); |
826 | foreach (SYMBOL kid in pe.kids) | 881 | foreach (SYMBOL kid in pe.kids) |
827 | retstr += GenerateNode(kid); | 882 | retstr += GenerateNode(pe, kid); |
828 | retstr += Generate(")"); | 883 | retstr += Generate(")"); |
829 | 884 | ||
830 | return retstr; | 885 | return retstr; |
@@ -861,7 +916,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
861 | 916 | ||
862 | // we wrap all typecasted statements in parentheses | 917 | // we wrap all typecasted statements in parentheses |
863 | retstr += Generate(String.Format("({0}) (", te.TypecastType), te); | 918 | retstr += Generate(String.Format("({0}) (", te.TypecastType), te); |
864 | retstr += GenerateNode((SYMBOL) te.kids.Pop()); | 919 | retstr += GenerateNode(te, (SYMBOL) te.kids.Pop()); |
865 | retstr += Generate(")"); | 920 | retstr += Generate(")"); |
866 | 921 | ||
867 | return retstr; | 922 | return retstr; |
@@ -931,7 +986,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
931 | } | 986 | } |
932 | 987 | ||
933 | foreach (SYMBOL kid in fc.kids) | 988 | foreach (SYMBOL kid in fc.kids) |
934 | retstr += GenerateNode(kid); | 989 | retstr += GenerateNode(fc, kid); |
935 | 990 | ||
936 | retstr += Generate(")"); | 991 | retstr += Generate(")"); |
937 | 992 | ||
@@ -980,11 +1035,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
980 | string retstr = String.Empty; | 1035 | string retstr = String.Empty; |
981 | 1036 | ||
982 | retstr += Generate(String.Format("new {0}(", vc.Type), vc); | 1037 | retstr += Generate(String.Format("new {0}(", vc.Type), vc); |
983 | retstr += GenerateNode((SYMBOL) vc.kids.Pop()); | 1038 | retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); |
984 | retstr += Generate(", "); | 1039 | retstr += Generate(", "); |
985 | retstr += GenerateNode((SYMBOL) vc.kids.Pop()); | 1040 | retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); |
986 | retstr += Generate(", "); | 1041 | retstr += Generate(", "); |
987 | retstr += GenerateNode((SYMBOL) vc.kids.Pop()); | 1042 | retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); |
988 | retstr += Generate(")"); | 1043 | retstr += Generate(")"); |
989 | 1044 | ||
990 | return retstr; | 1045 | return retstr; |
@@ -1000,13 +1055,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
1000 | string retstr = String.Empty; | 1055 | string retstr = String.Empty; |
1001 | 1056 | ||
1002 | retstr += Generate(String.Format("new {0}(", rc.Type), rc); | 1057 | retstr += Generate(String.Format("new {0}(", rc.Type), rc); |
1003 | retstr += GenerateNode((SYMBOL) rc.kids.Pop()); | 1058 | retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); |
1004 | retstr += Generate(", "); | 1059 | retstr += Generate(", "); |
1005 | retstr += GenerateNode((SYMBOL) rc.kids.Pop()); | 1060 | retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); |
1006 | retstr += Generate(", "); | 1061 | retstr += Generate(", "); |
1007 | retstr += GenerateNode((SYMBOL) rc.kids.Pop()); | 1062 | retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); |
1008 | retstr += Generate(", "); | 1063 | retstr += Generate(", "); |
1009 | retstr += GenerateNode((SYMBOL) rc.kids.Pop()); | 1064 | retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); |
1010 | retstr += Generate(")"); | 1065 | retstr += Generate(")"); |
1011 | 1066 | ||
1012 | return retstr; | 1067 | return retstr; |
@@ -1024,7 +1079,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
1024 | retstr += Generate(String.Format("new {0}(", lc.Type), lc); | 1079 | retstr += Generate(String.Format("new {0}(", lc.Type), lc); |
1025 | 1080 | ||
1026 | foreach (SYMBOL kid in lc.kids) | 1081 | foreach (SYMBOL kid in lc.kids) |
1027 | retstr += GenerateNode(kid); | 1082 | retstr += GenerateNode(lc, kid); |
1028 | 1083 | ||
1029 | retstr += Generate(")"); | 1084 | retstr += Generate(")"); |
1030 | 1085 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index 03be2ab..9d20c9e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | |||
@@ -72,6 +72,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
72 | private bool CompileWithDebugInformation; | 72 | private bool CompileWithDebugInformation; |
73 | private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase); | 73 | private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase); |
74 | private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase); | 74 | private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase); |
75 | private bool m_insertCoopTerminationCalls; | ||
75 | 76 | ||
76 | private string FilePrefix; | 77 | private string FilePrefix; |
77 | private string ScriptEnginesPath = null; | 78 | private string ScriptEnginesPath = null; |
@@ -95,20 +96,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
95 | private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps = | 96 | private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps = |
96 | new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>(); | 97 | new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>(); |
97 | 98 | ||
99 | public bool in_startup = true; | ||
100 | |||
98 | public Compiler(IScriptEngine scriptEngine) | 101 | public Compiler(IScriptEngine scriptEngine) |
99 | { | 102 | { |
100 | m_scriptEngine = scriptEngine;; | 103 | m_scriptEngine = scriptEngine; |
101 | ScriptEnginesPath = scriptEngine.ScriptEnginePath; | 104 | ScriptEnginesPath = scriptEngine.ScriptEnginePath; |
102 | ReadConfig(); | 105 | ReadConfig(); |
103 | } | 106 | } |
104 | 107 | ||
105 | public bool in_startup = true; | ||
106 | public void ReadConfig() | 108 | public void ReadConfig() |
107 | { | 109 | { |
108 | // Get some config | 110 | // Get some config |
109 | WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false); | 111 | WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false); |
110 | CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); | 112 | CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); |
111 | bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true); | 113 | bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true); |
114 | m_insertCoopTerminationCalls = m_scriptEngine.Config.GetString("ScriptStopStrategy", "abort") == "co-op"; | ||
112 | 115 | ||
113 | // Get file prefix from scriptengine name and make it file system safe: | 116 | // Get file prefix from scriptengine name and make it file system safe: |
114 | FilePrefix = "CommonCompiler"; | 117 | FilePrefix = "CommonCompiler"; |
@@ -386,7 +389,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
386 | if (language == enumCompileType.lsl) | 389 | if (language == enumCompileType.lsl) |
387 | { | 390 | { |
388 | // Its LSL, convert it to C# | 391 | // Its LSL, convert it to C# |
389 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms); | 392 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls); |
390 | compileScript = LSL_Converter.Convert(Script); | 393 | compileScript = LSL_Converter.Convert(Script); |
391 | 394 | ||
392 | // copy converter warnings into our warnings. | 395 | // copy converter warnings into our warnings. |
@@ -411,16 +414,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
411 | { | 414 | { |
412 | case enumCompileType.cs: | 415 | case enumCompileType.cs: |
413 | case enumCompileType.lsl: | 416 | case enumCompileType.lsl: |
414 | compileScript = CreateCSCompilerScript(compileScript); | 417 | compileScript = CreateCSCompilerScript( |
418 | compileScript, | ||
419 | m_scriptEngine.ScriptClassName, | ||
420 | m_scriptEngine.ScriptBaseClassName, | ||
421 | m_scriptEngine.ScriptBaseClassParameters); | ||
415 | break; | 422 | break; |
416 | case enumCompileType.vb: | 423 | case enumCompileType.vb: |
417 | compileScript = CreateVBCompilerScript(compileScript); | 424 | compileScript = CreateVBCompilerScript( |
425 | compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName); | ||
418 | break; | 426 | break; |
419 | // case enumCompileType.js: | 427 | // case enumCompileType.js: |
420 | // compileScript = CreateJSCompilerScript(compileScript); | 428 | // compileScript = CreateJSCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName); |
421 | // break; | 429 | // break; |
422 | case enumCompileType.yp: | 430 | case enumCompileType.yp: |
423 | compileScript = CreateYPCompilerScript(compileScript); | 431 | compileScript = CreateYPCompilerScript( |
432 | compileScript, m_scriptEngine.ScriptClassName,m_scriptEngine.ScriptBaseClassName); | ||
424 | break; | 433 | break; |
425 | } | 434 | } |
426 | 435 | ||
@@ -451,43 +460,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
451 | // return compileScript; | 460 | // return compileScript; |
452 | // } | 461 | // } |
453 | 462 | ||
454 | private static string CreateCSCompilerScript(string compileScript) | 463 | private static string CreateCSCompilerScript( |
464 | string compileScript, string className, string baseClassName, ParameterInfo[] constructorParameters) | ||
455 | { | 465 | { |
456 | compileScript = String.Empty + | 466 | compileScript = string.Format( |
457 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + | 467 | @"using OpenSim.Region.ScriptEngine.Shared; |
458 | String.Empty + "namespace SecondLife { " + | 468 | using System.Collections.Generic; |
459 | String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + | 469 | |
460 | @"public Script() { } " + | 470 | namespace SecondLife |
461 | compileScript + | 471 | {{ |
462 | "} }\r\n"; | 472 | public class {0} : {1} |
473 | {{ | ||
474 | public {0}({2}) : base({3}) {{}} | ||
475 | {4} | ||
476 | }} | ||
477 | }}", | ||
478 | className, | ||
479 | baseClassName, | ||
480 | constructorParameters != null | ||
481 | ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.ToString())) | ||
482 | : "", | ||
483 | constructorParameters != null | ||
484 | ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.Name)) | ||
485 | : "", | ||
486 | compileScript); | ||
487 | |||
463 | return compileScript; | 488 | return compileScript; |
464 | } | 489 | } |
465 | 490 | ||
466 | private static string CreateYPCompilerScript(string compileScript) | 491 | private static string CreateYPCompilerScript(string compileScript, string className, string baseClassName) |
467 | { | 492 | { |
468 | compileScript = String.Empty + | 493 | compileScript = String.Empty + |
469 | "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " + | 494 | "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " + |
470 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + | 495 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + |
471 | String.Empty + "namespace SecondLife { " + | 496 | String.Empty + "namespace SecondLife { " + |
472 | String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + | 497 | String.Empty + "public class " + className + " : " + baseClassName + " { \r\n" + |
473 | //@"public Script() { } " + | 498 | //@"public Script() { } " + |
474 | @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " + | 499 | @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " + |
475 | @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " + | 500 | @"public " + className + "() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " + |
476 | |||
477 | compileScript + | 501 | compileScript + |
478 | "} }\r\n"; | 502 | "} }\r\n"; |
503 | |||
479 | return compileScript; | 504 | return compileScript; |
480 | } | 505 | } |
481 | 506 | ||
482 | private static string CreateVBCompilerScript(string compileScript) | 507 | private static string CreateVBCompilerScript(string compileScript, string className, string baseClassName) |
483 | { | 508 | { |
484 | compileScript = String.Empty + | 509 | compileScript = String.Empty + |
485 | "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " + | 510 | "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " + |
486 | String.Empty + "NameSpace SecondLife:" + | 511 | String.Empty + "NameSpace SecondLife:" + |
487 | String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass: " + | 512 | String.Empty + "Public Class " + className + ": Inherits " + baseClassName + |
488 | "\r\nPublic Sub New()\r\nEnd Sub: " + | 513 | "\r\nPublic Sub New()\r\nEnd Sub: " + |
489 | compileScript + | 514 | compileScript + |
490 | ":End Class :End Namespace\r\n"; | 515 | ":End Class :End Namespace\r\n"; |
516 | |||
491 | return compileScript; | 517 | return compileScript; |
492 | } | 518 | } |
493 | 519 | ||
@@ -549,6 +575,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
549 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, | 575 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, |
550 | "OpenMetaverseTypes.dll")); | 576 | "OpenMetaverseTypes.dll")); |
551 | 577 | ||
578 | if (m_scriptEngine.ScriptReferencedAssemblies != null) | ||
579 | Array.ForEach<string>( | ||
580 | m_scriptEngine.ScriptReferencedAssemblies, | ||
581 | a => parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, a))); | ||
582 | |||
552 | if (lang == enumCompileType.yp) | 583 | if (lang == enumCompileType.yp) |
553 | { | 584 | { |
554 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, | 585 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Properties/AssemblyInfo.cs index c65caa8..5b5c4fd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Properties/AssemblyInfo.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Properties/AssemblyInfo.cs | |||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices; | |||
29 | // Build Number | 29 | // Build Number |
30 | // Revision | 30 | // Revision |
31 | // | 31 | // |
32 | [assembly: AssemblyVersion("0.7.5.*")] | 32 | [assembly: AssemblyVersion("0.7.6.*")] |
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | 33 | |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index 7763619..77e087c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | |||
@@ -39,7 +39,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
39 | /// The generated C# code is compared against the expected C# code. | 39 | /// The generated C# code is compared against the expected C# code. |
40 | /// </summary> | 40 | /// </summary> |
41 | [TestFixture] | 41 | [TestFixture] |
42 | public class CSCodeGeneratorTest | 42 | public class CSCodeGeneratorTest : OpenSimTestCase |
43 | { | 43 | { |
44 | [Test] | 44 | [Test] |
45 | public void TestDefaultState() | 45 | public void TestDefaultState() |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index 1fa6954..05a8756 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs | |||
@@ -41,7 +41,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
41 | /// the LSL source. | 41 | /// the LSL source. |
42 | /// </summary> | 42 | /// </summary> |
43 | [TestFixture] | 43 | [TestFixture] |
44 | public class CompilerTest | 44 | public class CompilerTest : OpenSimTestCase |
45 | { | 45 | { |
46 | private string m_testDir; | 46 | private string m_testDir; |
47 | private CSharpCodeProvider m_CSCodeProvider; | 47 | private CSharpCodeProvider m_CSCodeProvider; |