From 5ac84a37935d8e1c62484032259d09f5ac95c0e7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 30 Jan 2013 03:44:56 +0000 Subject: Fix issue where lsl -> c# generation in co-operative termination mode did not correctly handle single statement versions of for, while and do-while loops. Add regression tests to validate the fix. This problem will not affect the default abort termination mode. --- .../Shared/CodeTools/CSCodeGenerator.cs | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 985e598..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; using System.Reflection; using log4net; using Tools; - using OpenSim.Region.Framework.Interfaces; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools @@ -479,20 +478,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { string retstr = String.Empty; bool printSemicolon = true; - - retstr += Indent(); + bool transformToBlock = false; if (m_insertCoopTerminationChecks) { - // We have to check in event functions as well because the user can manually call these. - if (previousSymbol is GlobalFunctionDefinition - || previousSymbol is WhileStatement + // A non-braced single line do while structure cannot contain multiple statements. + // So to insert the termination check we change this to a braced control structure instead. + if (previousSymbol is WhileStatement || previousSymbol is DoWhileStatement - || previousSymbol is ForLoop - || previousSymbol is StateEvent) - retstr += Generate(m_coopTerminationCheck); + || previousSymbol is ForLoop) + { + transformToBlock = true; + + // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented. + retstr += GenerateIndentedLine("{"); + + retstr += GenerateIndentedLine(m_coopTerminationCheck); + } } + retstr += Indent(); + if (0 < s.kids.Count) { // Jump label prints its own colon, we don't need a semicolon. @@ -508,6 +514,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if (printSemicolon) retstr += GenerateLine(";"); + if (transformToBlock) + { + // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent + retstr += GenerateIndentedLine("}"); + } + return retstr; } -- cgit v1.1