aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs84
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs44
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs564
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs133
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs6
12 files changed, 463 insertions, 415 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ce0e59c..66cb30c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -4323,6 +4323,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4323 return; 4323 return;
4324 4324
4325 SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID); 4325 SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
4326 if (targetPart == null)
4327 return;
4326 4328
4327 if (targetPart.ParentGroup.AttachmentPoint != 0) 4329 if (targetPart.ParentGroup.AttachmentPoint != 0)
4328 return; // Fail silently if attached 4330 return; // Fail silently if attached
@@ -4332,24 +4334,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4332 4334
4333 SceneObjectGroup parentPrim = null, childPrim = null; 4335 SceneObjectGroup parentPrim = null, childPrim = null;
4334 4336
4335 if (targetPart != null) 4337 if (parent != 0)
4336 { 4338 {
4337 if (parent != 0) 4339 parentPrim = m_host.ParentGroup;
4338 { 4340 childPrim = targetPart.ParentGroup;
4339 parentPrim = m_host.ParentGroup; 4341 }
4340 childPrim = targetPart.ParentGroup; 4342 else
4341 } 4343 {
4342 else 4344 parentPrim = targetPart.ParentGroup;
4343 { 4345 childPrim = m_host.ParentGroup;
4344 parentPrim = targetPart.ParentGroup;
4345 childPrim = m_host.ParentGroup;
4346 }
4347
4348 // Required for linking
4349 childPrim.RootPart.ClearUpdateSchedule();
4350 parentPrim.LinkToGroup(childPrim, true);
4351 } 4346 }
4352 4347
4348 // Required for linking
4349 childPrim.RootPart.ClearUpdateSchedule();
4350 parentPrim.LinkToGroup(childPrim, true);
4351
4352
4353 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 4353 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
4354 parentPrim.RootPart.CreateSelected = true; 4354 parentPrim.RootPart.CreateSelected = true;
4355 parentPrim.HasGroupChanged = true; 4355 parentPrim.HasGroupChanged = true;
@@ -4741,20 +4741,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4741 { 4741 {
4742 m_host.AddScriptLPS(1); 4742 m_host.AddScriptLPS(1);
4743 Vector3 av3 = Util.Clip(color, 0.0f, 1.0f); 4743 Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
4744 if (text.Length > 254)
4745 text = text.Remove(254);
4746
4747 byte[] data; 4744 byte[] data;
4748 do 4745 data = Util.StringToBytes256(text);
4749 { 4746 text = Util.UTF8.GetString(data);
4750 data = Util.UTF8.GetBytes(text);
4751 if (data.Length > 254)
4752 text = text.Substring(0, text.Length - 1);
4753 } while (data.Length > 254);
4754
4755 m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f)); 4747 m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
4756 //m_host.ParentGroup.HasGroupChanged = true;
4757 //m_host.ParentGroup.ScheduleGroupForFullUpdate();
4758 } 4748 }
4759 4749
4760 public LSL_Float llWater(LSL_Vector offset) 4750 public LSL_Float llWater(LSL_Vector offset)
@@ -5118,13 +5108,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5118 { 5108 {
5119 m_host.CollisionSoundVolume = (float)impact_volume; 5109 m_host.CollisionSoundVolume = (float)impact_volume;
5120 m_host.CollisionSound = m_host.invalidCollisionSoundUUID; 5110 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
5121 m_host.CollisionSoundType = 0; 5111 m_host.CollisionSoundType = -1; // disable all sounds
5112 m_host.aggregateScriptEvents();
5122 return; 5113 return;
5123 } 5114 }
5115
5124 // TODO: Parameter check logic required. 5116 // TODO: Parameter check logic required.
5125 m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound); 5117 UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
5126 m_host.CollisionSoundVolume = (float)impact_volume; 5118 if(soundId != UUID.Zero)
5127 m_host.CollisionSoundType = 1; 5119 {
5120 m_host.CollisionSound = soundId;
5121 m_host.CollisionSoundVolume = (float)impact_volume;
5122 m_host.CollisionSoundType = 1;
5123 }
5124 else
5125 m_host.CollisionSoundType = -1;
5126
5127 m_host.aggregateScriptEvents();
5128 } 5128 }
5129 5129
5130 public LSL_String llGetAnimation(string id) 5130 public LSL_String llGetAnimation(string id)
@@ -14679,13 +14679,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
14679 msAvailable -= m_castRayCalls[i].UsedMs; 14679 msAvailable -= m_castRayCalls[i].UsedMs;
14680 } 14680 }
14681 } 14681 }
14682 }
14683 14682
14684 // Return failure if not enough available time 14683 // Return failure if not enough available time
14685 if (msAvailable < m_msMinInCastRay) 14684 if (msAvailable < m_msMinInCastRay)
14686 { 14685 {
14687 result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED)); 14686 result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
14688 return result; 14687 return result;
14688 }
14689 } 14689 }
14690 14690
14691 // Initialize 14691 // Initialize
@@ -15073,13 +15073,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
15073 15073
15074 // Add to throttle data 15074 // Add to throttle data
15075 stopWatch.Stop(); 15075 stopWatch.Stop();
15076 CastRayCall castRayCall = new CastRayCall();
15077 castRayCall.RegionId = regionId;
15078 castRayCall.UserId = userId;
15079 castRayCall.CalledMs = calledMs;
15080 castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds;
15081 lock (m_castRayCalls) 15076 lock (m_castRayCalls)
15082 { 15077 {
15078 CastRayCall castRayCall = new CastRayCall();
15079 castRayCall.RegionId = regionId;
15080 castRayCall.UserId = userId;
15081 castRayCall.CalledMs = calledMs;
15082 castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds;
15083 m_castRayCalls.Add(castRayCall); 15083 m_castRayCalls.Add(castRayCall);
15084 } 15084 }
15085 15085
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index e525a2e..4af4339 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -45,6 +45,7 @@ using OpenSim.Framework;
45using OpenSim.Framework.Console; 45using OpenSim.Framework.Console;
46using OpenSim.Region.Framework.Interfaces; 46using OpenSim.Region.Framework.Interfaces;
47using OpenSim.Region.Framework.Scenes; 47using OpenSim.Region.Framework.Scenes;
48using OpenSim.Region.Framework.Scenes.Scripting;
48using OpenSim.Region.ScriptEngine.Shared; 49using OpenSim.Region.ScriptEngine.Shared;
49using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 50using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
50using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 51using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
@@ -4250,5 +4251,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4250 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString(); 4251 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4251 return UUID.Zero.ToString(); 4252 return UUID.Zero.ToString();
4252 } 4253 }
4254
4255 public void osCollisionSound(string impact_sound, double impact_volume)
4256 {
4257 m_host.AddScriptLPS(1);
4258
4259 if(impact_sound == "")
4260 {
4261 m_host.CollisionSoundVolume = (float)impact_volume;
4262 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
4263 if(impact_volume == 0.0)
4264 m_host.CollisionSoundType = -1; // disable all sounds
4265 else if(impact_volume == 1.0f)
4266 m_host.CollisionSoundType = 0; // full return to default sounds
4267 else
4268 m_host.CollisionSoundType = 2; // default sounds with volume
4269 m_host.aggregateScriptEvents();
4270 return;
4271 }
4272 // TODO: Parameter check logic required.
4273 UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
4274 if(soundId != UUID.Zero)
4275 {
4276 m_host.CollisionSound = soundId;
4277 m_host.CollisionSoundVolume = (float)impact_volume;
4278 m_host.CollisionSoundType = 1;
4279 }
4280 else
4281 m_host.CollisionSoundType = -1;
4282
4283 m_host.aggregateScriptEvents();
4284 }
4285
4286 // still not very usefull, detector is lost on rez, restarts, etc
4287 public void osVolumeDetect(int detect)
4288 {
4289 m_host.AddScriptLPS(1);
4290
4291 if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted || m_host.ParentGroup.IsAttachment)
4292 return;
4293
4294 m_host.ScriptSetVolumeDetect(detect != 0);
4295 }
4296
4253 } 4297 }
4254} 4298}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index c99679e..5ce859e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -476,5 +476,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
476 476
477 LSL_String osRequestURL(LSL_List options); 477 LSL_String osRequestURL(LSL_List options);
478 LSL_String osRequestSecureURL(LSL_List options); 478 LSL_String osRequestSecureURL(LSL_List options);
479 void osCollisionSound(string impact_sound, double impact_volume);
480 void osVolumeDetect(int detect);
479 } 481 }
480} 482}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 35eee59..c5cb88e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -1089,5 +1089,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1089 { 1089 {
1090 return m_OSSL_Functions.osRequestSecureURL(options); 1090 return m_OSSL_Functions.osRequestSecureURL(options);
1091 } 1091 }
1092
1093 public void osCollisionSound(string impact_sound, double impact_volume)
1094 {
1095 m_OSSL_Functions.osCollisionSound(impact_sound, impact_volume);
1096 }
1097
1098 public void osVolumeDetect(int detect)
1099 {
1100 m_OSSL_Functions.osVolumeDetect(detect);
1101 }
1092 } 1102 }
1093} 1103}
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index 4e0c273..bc6ce4f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Text;
29using System.IO; 30using System.IO;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.Reflection; 32using System.Reflection;
@@ -39,9 +40,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
39 { 40 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 41// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 42
43 private static yyLSLSyntax yyLSL = new yyLSLSyntax();
42 private SYMBOL m_astRoot = null; 44 private SYMBOL m_astRoot = null;
43 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap; 45 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
44 private int m_indentWidth = 4; // for indentation
45 private int m_braceCount; // for indentation 46 private int m_braceCount; // for indentation
46 private int m_CSharpLine; // the current line of generated C# code 47 private int m_CSharpLine; // the current line of generated C# code
47 private int m_CSharpCol; // the current column of generated C# code 48 private int m_CSharpCol; // the current column of generated C# code
@@ -94,6 +95,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
94 get { return m_astRoot; } 95 get { return m_astRoot; }
95 } 96 }
96 97
98 public void Clear()
99 {
100 m_astRoot.kids = null;
101 m_astRoot.yylx = null;
102 m_astRoot.yyps = null;
103 m_astRoot = null;
104 m_positionMap = null;
105 m_warnings.Clear();
106 m_comms = null;
107 }
97 /// <summary> 108 /// <summary>
98 /// Resets various counters and metadata. 109 /// Resets various counters and metadata.
99 /// </summary> 110 /// </summary>
@@ -106,18 +117,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
106 m_astRoot = null; 117 m_astRoot = null;
107 } 118 }
108 119
120 public string Convert(string script)
121 {
122 StringBuilder sb = new StringBuilder(4096);
123 Convert(script, sb);
124 return sb.ToString();
125 }
126
109 /// <summary> 127 /// <summary>
110 /// Generate the code from the AST we have. 128 /// Generate the code from the AST we have.
111 /// </summary> 129 /// </summary>
112 /// <param name="script">The LSL source as a string.</param> 130 /// <param name="script">The LSL source as a string.</param>
113 /// <returns>String containing the generated C# code.</returns> 131 /// <returns>String containing the generated C# code.</returns>
114 public string Convert(string script) 132 public void Convert(string script, StringBuilder sb)
115 { 133 {
116// m_log.DebugFormat("[CS CODE GENERATOR]: Converting to C#\n{0}", script); 134// m_log.DebugFormat("[CS CODE GENERATOR]: Converting to C#\n{0}", script);
117 135
118 m_warnings.Clear(); 136 m_warnings.Clear();
119 ResetCounters(); 137 ResetCounters();
120 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true)); 138 ErrorHandler errorHandler = new ErrorHandler(true);
139 Parser p = new LSLSyntax(yyLSL, errorHandler);
121 140
122 LSL2CSCodeTransformer codeTransformer; 141 LSL2CSCodeTransformer codeTransformer;
123 try 142 try
@@ -148,38 +167,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
148 167
149 m_astRoot = codeTransformer.Transform(); 168 m_astRoot = codeTransformer.Transform();
150 169
151 string retstr = String.Empty;
152 170
153 // standard preamble 171 // standard preamble
154 //retstr = GenerateLine("using OpenSim.Region.ScriptEngine.Common;"); 172
155 //retstr += GenerateLine("using System.Collections.Generic;"); 173
156 //retstr += GenerateLine(""); 174
157 //retstr += GenerateLine("namespace SecondLife");
158 //retstr += GenerateLine("{");
159 m_braceCount++; 175 m_braceCount++;
160 //retstr += GenerateIndentedLine("public class Script : OpenSim.Region.ScriptEngine.Common");
161 //retstr += GenerateIndentedLine("{");
162 m_braceCount++; 176 m_braceCount++;
163 177
164 // line number 178 // line number
165 m_CSharpLine += 9; 179 m_CSharpLine += 10;
166 180
167 // here's the payload 181 // here's the payload
168 retstr += GenerateLine(); 182 sb.Append("\n");
169 foreach (SYMBOL s in m_astRoot.kids) 183 foreach (SYMBOL s in m_astRoot.kids)
170 retstr += GenerateNode(m_astRoot, s); 184 GenerateNodeToSB(m_astRoot, s, sb);
185
186 codeTransformer = null;
187 p.m_lexer.m_buf=null;
188 p.m_lexer.yytext = null;
189 p.m_lexer = null;
190 p.m_symbols = null;
191 p = null;
192 errorHandler = null;
171 193
172 // close braces! 194 // close braces!
173 m_braceCount--; 195// m_braceCount--;
174 //retstr += GenerateIndentedLine("}"); 196 //retstr += GenerateIndentedLine("}");
175 m_braceCount--; 197// m_braceCount--;
176 //retstr += GenerateLine("}"); 198 //retstr += GenerateLine("}");
177 199
178 // Removes all carriage return characters which may be generated in Windows platform. Is there 200 // Removes all carriage return characters which may be generated in Windows platform. Is there
179 // cleaner way of doing this? 201 // cleaner way of doing this?
180 retstr = retstr.Replace("\r", ""); 202// sb.Replace("\r", "");
181
182 return retstr;
183 } 203 }
184 204
185 /// <summary> 205 /// <summary>
@@ -206,78 +226,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
206 /// <param name="previousSymbol">The parent node.</param> 226 /// <param name="previousSymbol">The parent node.</param>
207 /// <param name="s">The current node to generate code for.</param> 227 /// <param name="s">The current node to generate code for.</param>
208 /// <returns>String containing C# code for SYMBOL s.</returns> 228 /// <returns>String containing C# code for SYMBOL s.</returns>
209 private string GenerateNode(SYMBOL previousSymbol, SYMBOL s) 229 private void GenerateNodeToSB(SYMBOL previousSymbol, SYMBOL s, StringBuilder sb)
210 { 230 {
211 string retstr = String.Empty;
212
213 // make sure to put type lower in the inheritance hierarchy first 231 // make sure to put type lower in the inheritance hierarchy first
214 // ie: since IdentArgument and ExpressionArgument inherit from 232 // ie: since IdentArgument and ExpressionArgument inherit from
215 // Argument, put IdentArgument and ExpressionArgument before Argument 233 // Argument, put IdentArgument and ExpressionArgument before Argument
216 if (s is GlobalFunctionDefinition) 234 if (s is GlobalFunctionDefinition)
217 retstr += GenerateGlobalFunctionDefinition((GlobalFunctionDefinition) s); 235 GenerateGlobalFunctionDefinition((GlobalFunctionDefinition) s, sb);
218 else if (s is GlobalVariableDeclaration) 236 else if (s is GlobalVariableDeclaration)
219 retstr += GenerateGlobalVariableDeclaration((GlobalVariableDeclaration) s); 237 GenerateGlobalVariableDeclaration((GlobalVariableDeclaration) s , sb);
220 else if (s is State) 238 else if (s is State)
221 retstr += GenerateState((State) s); 239 GenerateState((State) s, sb);
222 else if (s is CompoundStatement) 240 else if (s is CompoundStatement)
223 retstr += GenerateCompoundStatement(previousSymbol, (CompoundStatement) s); 241 GenerateCompoundStatement(previousSymbol, (CompoundStatement) s, sb);
224 else if (s is Declaration) 242 else if (s is Declaration)
225 retstr += GenerateDeclaration((Declaration) s); 243 GenerateDeclaration((Declaration) s, sb);
226 else if (s is Statement) 244 else if (s is Statement)
227 retstr += GenerateStatement(previousSymbol, (Statement) s); 245 GenerateStatement(previousSymbol, (Statement) s, sb);
228 else if (s is ReturnStatement) 246 else if (s is ReturnStatement)
229 retstr += GenerateReturnStatement((ReturnStatement) s); 247 GenerateReturnStatement((ReturnStatement) s, sb);
230 else if (s is JumpLabel) 248 else if (s is JumpLabel)
231 retstr += GenerateJumpLabel((JumpLabel) s); 249 GenerateJumpLabel((JumpLabel) s, sb);
232 else if (s is JumpStatement) 250 else if (s is JumpStatement)
233 retstr += GenerateJumpStatement((JumpStatement) s); 251 GenerateJumpStatement((JumpStatement) s, sb);
234 else if (s is StateChange) 252 else if (s is StateChange)
235 retstr += GenerateStateChange((StateChange) s); 253 GenerateStateChange((StateChange) s, sb);
236 else if (s is IfStatement) 254 else if (s is IfStatement)
237 retstr += GenerateIfStatement((IfStatement) s); 255 GenerateIfStatement((IfStatement) s, sb);
238 else if (s is WhileStatement) 256 else if (s is WhileStatement)
239 retstr += GenerateWhileStatement((WhileStatement) s); 257 GenerateWhileStatement((WhileStatement) s, sb);
240 else if (s is DoWhileStatement) 258 else if (s is DoWhileStatement)
241 retstr += GenerateDoWhileStatement((DoWhileStatement) s); 259 GenerateDoWhileStatement((DoWhileStatement) s, sb);
242 else if (s is ForLoop) 260 else if (s is ForLoop)
243 retstr += GenerateForLoop((ForLoop) s); 261 GenerateForLoop((ForLoop) s, sb);
244 else if (s is ArgumentList) 262 else if (s is ArgumentList)
245 retstr += GenerateArgumentList((ArgumentList) s); 263 GenerateArgumentList((ArgumentList) s, sb);
246 else if (s is Assignment) 264 else if (s is Assignment)
247 retstr += GenerateAssignment((Assignment) s); 265 GenerateAssignment((Assignment) s, sb);
248 else if (s is BinaryExpression) 266 else if (s is BinaryExpression)
249 retstr += GenerateBinaryExpression((BinaryExpression) s); 267 GenerateBinaryExpression((BinaryExpression) s, sb);
250 else if (s is ParenthesisExpression) 268 else if (s is ParenthesisExpression)
251 retstr += GenerateParenthesisExpression((ParenthesisExpression) s); 269 GenerateParenthesisExpression((ParenthesisExpression) s, sb);
252 else if (s is UnaryExpression) 270 else if (s is UnaryExpression)
253 retstr += GenerateUnaryExpression((UnaryExpression) s); 271 GenerateUnaryExpression((UnaryExpression) s, sb);
254 else if (s is IncrementDecrementExpression) 272 else if (s is IncrementDecrementExpression)
255 retstr += GenerateIncrementDecrementExpression((IncrementDecrementExpression) s); 273 GenerateIncrementDecrementExpression((IncrementDecrementExpression) s, sb);
256 else if (s is TypecastExpression) 274 else if (s is TypecastExpression)
257 retstr += GenerateTypecastExpression((TypecastExpression) s); 275 GenerateTypecastExpression((TypecastExpression) s, sb);
258 else if (s is FunctionCall) 276 else if (s is FunctionCall)
259 retstr += GenerateFunctionCall((FunctionCall) s); 277 GenerateFunctionCall((FunctionCall) s, sb);
260 else if (s is VectorConstant) 278 else if (s is VectorConstant)
261 retstr += GenerateVectorConstant((VectorConstant) s); 279 GenerateVectorConstant((VectorConstant) s, sb);
262 else if (s is RotationConstant) 280 else if (s is RotationConstant)
263 retstr += GenerateRotationConstant((RotationConstant) s); 281 GenerateRotationConstant((RotationConstant) s, sb);
264 else if (s is ListConstant) 282 else if (s is ListConstant)
265 retstr += GenerateListConstant((ListConstant) s); 283 GenerateListConstant((ListConstant) s, sb);
266 else if (s is Constant) 284 else if (s is Constant)
267 retstr += GenerateConstant((Constant) s); 285 GenerateConstant((Constant) s, sb);
268 else if (s is IdentDotExpression) 286 else if (s is IdentDotExpression)
269 retstr += Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s); 287 Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s, sb);
270 else if (s is IdentExpression) 288 else if (s is IdentExpression)
271 retstr += GenerateIdentifier(((IdentExpression) s).Name, s); 289 GenerateIdentifier(((IdentExpression) s).Name, s, sb);
272 else if (s is IDENT) 290 else if (s is IDENT)
273 retstr += Generate(CheckName(((TOKEN) s).yytext), s); 291 Generate(CheckName(((TOKEN) s).yytext), s, sb);
274 else 292 else
275 { 293 {
276 foreach (SYMBOL kid in s.kids) 294 foreach (SYMBOL kid in s.kids)
277 retstr += GenerateNode(s, kid); 295 GenerateNodeToSB(s, kid,sb);
278 } 296 }
279 297
280 return retstr; 298 return;
281 } 299 }
282 300
283 /// <summary> 301 /// <summary>
@@ -285,10 +303,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
285 /// </summary> 303 /// </summary>
286 /// <param name="gf">The GlobalFunctionDefinition node.</param> 304 /// <param name="gf">The GlobalFunctionDefinition node.</param>
287 /// <returns>String containing C# code for GlobalFunctionDefinition gf.</returns> 305 /// <returns>String containing C# code for GlobalFunctionDefinition gf.</returns>
288 private string GenerateGlobalFunctionDefinition(GlobalFunctionDefinition gf) 306 private void GenerateGlobalFunctionDefinition(GlobalFunctionDefinition gf, StringBuilder sb)
289 { 307 {
290 string retstr = String.Empty;
291
292 // we need to separate the argument declaration list from other kids 308 // we need to separate the argument declaration list from other kids
293 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>(); 309 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>();
294 List<SYMBOL> remainingKids = new List<SYMBOL>(); 310 List<SYMBOL> remainingKids = new List<SYMBOL>();
@@ -299,18 +315,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
299 else 315 else
300 remainingKids.Add(kid); 316 remainingKids.Add(kid);
301 317
302 retstr += GenerateIndented(String.Format("{0} {1}(", gf.ReturnType, CheckName(gf.Name)), gf); 318 GenerateIndented(String.Format("{0} {1}(", gf.ReturnType, CheckName(gf.Name)), gf, sb);
303 319
304 // print the state arguments, if any 320 // print the state arguments, if any
305 foreach (SYMBOL kid in argumentDeclarationListKids) 321 foreach (SYMBOL kid in argumentDeclarationListKids)
306 retstr += GenerateArgumentDeclarationList((ArgumentDeclarationList) kid); 322 GenerateArgumentDeclarationList((ArgumentDeclarationList) kid, sb);
307 323
308 retstr += GenerateLine(")"); 324 GenerateLine(")", sb);
309 325
310 foreach (SYMBOL kid in remainingKids) 326 foreach (SYMBOL kid in remainingKids)
311 retstr += GenerateNode(gf, kid); 327 GenerateNodeToSB(gf, kid,sb);
312
313 return retstr;
314 } 328 }
315 329
316 /// <summary> 330 /// <summary>
@@ -318,18 +332,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
318 /// </summary> 332 /// </summary>
319 /// <param name="gv">The GlobalVariableDeclaration node.</param> 333 /// <param name="gv">The GlobalVariableDeclaration node.</param>
320 /// <returns>String containing C# code for GlobalVariableDeclaration gv.</returns> 334 /// <returns>String containing C# code for GlobalVariableDeclaration gv.</returns>
321 private string GenerateGlobalVariableDeclaration(GlobalVariableDeclaration gv) 335 private void GenerateGlobalVariableDeclaration(GlobalVariableDeclaration gv, StringBuilder sb)
322 { 336 {
323 string retstr = String.Empty;
324
325 foreach (SYMBOL s in gv.kids) 337 foreach (SYMBOL s in gv.kids)
326 { 338 {
327 retstr += Indent(); 339 Indent(sb);
328 retstr += GenerateNode(gv, s); 340 GenerateNodeToSB(gv, s ,sb);
329 retstr += GenerateLine(";"); 341 GenerateLine(";", sb);
330 } 342 }
331
332 return retstr;
333 } 343 }
334 344
335 /// <summary> 345 /// <summary>
@@ -337,15 +347,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
337 /// </summary> 347 /// </summary>
338 /// <param name="s">The State node.</param> 348 /// <param name="s">The State node.</param>
339 /// <returns>String containing C# code for State s.</returns> 349 /// <returns>String containing C# code for State s.</returns>
340 private string GenerateState(State s) 350 private void GenerateState(State s, StringBuilder sb)
341 { 351 {
342 string retstr = String.Empty;
343
344 foreach (SYMBOL kid in s.kids) 352 foreach (SYMBOL kid in s.kids)
345 if (kid is StateEvent) 353 if (kid is StateEvent)
346 retstr += GenerateStateEvent((StateEvent) kid, s.Name); 354 GenerateStateEvent((StateEvent) kid, s.Name, sb);
347
348 return retstr;
349 } 355 }
350 356
351 /// <summary> 357 /// <summary>
@@ -354,10 +360,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
354 /// <param name="se">The StateEvent node.</param> 360 /// <param name="se">The StateEvent node.</param>
355 /// <param name="parentStateName">The name of the parent state.</param> 361 /// <param name="parentStateName">The name of the parent state.</param>
356 /// <returns>String containing C# code for StateEvent se.</returns> 362 /// <returns>String containing C# code for StateEvent se.</returns>
357 private string GenerateStateEvent(StateEvent se, string parentStateName) 363 private void GenerateStateEvent(StateEvent se, string parentStateName, StringBuilder sb)
358 { 364 {
359 string retstr = String.Empty;
360
361 // we need to separate the argument declaration list from other kids 365 // we need to separate the argument declaration list from other kids
362 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>(); 366 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>();
363 List<SYMBOL> remainingKids = new List<SYMBOL>(); 367 List<SYMBOL> remainingKids = new List<SYMBOL>();
@@ -369,18 +373,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
369 remainingKids.Add(kid); 373 remainingKids.Add(kid);
370 374
371 // "state" (function) declaration 375 // "state" (function) declaration
372 retstr += GenerateIndented(String.Format("public void {0}_event_{1}(", parentStateName, se.Name), se); 376 GenerateIndented(String.Format("public void {0}_event_{1}(", parentStateName, se.Name), se , sb);
373 377
374 // print the state arguments, if any 378 // print the state arguments, if any
375 foreach (SYMBOL kid in argumentDeclarationListKids) 379 foreach (SYMBOL kid in argumentDeclarationListKids)
376 retstr += GenerateArgumentDeclarationList((ArgumentDeclarationList) kid); 380 GenerateArgumentDeclarationList((ArgumentDeclarationList) kid, sb);
377 381
378 retstr += GenerateLine(")"); 382 GenerateLine(")", sb);
379 383
380 foreach (SYMBOL kid in remainingKids) 384 foreach (SYMBOL kid in remainingKids)
381 retstr += GenerateNode(se, kid); 385 GenerateNodeToSB(se, kid, sb);
382
383 return retstr;
384 } 386 }
385 387
386 /// <summary> 388 /// <summary>
@@ -388,20 +390,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
388 /// </summary> 390 /// </summary>
389 /// <param name="adl">The ArgumentDeclarationList node.</param> 391 /// <param name="adl">The ArgumentDeclarationList node.</param>
390 /// <returns>String containing C# code for ArgumentDeclarationList adl.</returns> 392 /// <returns>String containing C# code for ArgumentDeclarationList adl.</returns>
391 private string GenerateArgumentDeclarationList(ArgumentDeclarationList adl) 393 private void GenerateArgumentDeclarationList(ArgumentDeclarationList adl, StringBuilder sb)
392 { 394 {
393 string retstr = String.Empty;
394
395 int comma = adl.kids.Count - 1; // tells us whether to print a comma 395 int comma = adl.kids.Count - 1; // tells us whether to print a comma
396 396
397 foreach (Declaration d in adl.kids) 397 foreach (Declaration d in adl.kids)
398 { 398 {
399 retstr += Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d); 399 Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d, sb);
400 if (0 < comma--) 400 if (0 < comma--)
401 retstr += Generate(", "); 401 Generate(", ", sb);
402 } 402 }
403
404 return retstr;
405 } 403 }
406 404
407 /// <summary> 405 /// <summary>
@@ -409,20 +407,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
409 /// </summary> 407 /// </summary>
410 /// <param name="al">The ArgumentList node.</param> 408 /// <param name="al">The ArgumentList node.</param>
411 /// <returns>String containing C# code for ArgumentList al.</returns> 409 /// <returns>String containing C# code for ArgumentList al.</returns>
412 private string GenerateArgumentList(ArgumentList al) 410 private void GenerateArgumentList(ArgumentList al, StringBuilder sb)
413 { 411 {
414 string retstr = String.Empty;
415
416 int comma = al.kids.Count - 1; // tells us whether to print a comma 412 int comma = al.kids.Count - 1; // tells us whether to print a comma
417 413
418 foreach (SYMBOL s in al.kids) 414 foreach (SYMBOL s in al.kids)
419 { 415 {
420 retstr += GenerateNode(al, s); 416 GenerateNodeToSB(al, s, sb);
421 if (0 < comma--) 417 if (0 < comma--)
422 retstr += Generate(", "); 418 Generate(", ", sb);
423 } 419 }
424
425 return retstr;
426 } 420 }
427 421
428 /// <summary> 422 /// <summary>
@@ -430,12 +424,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
430 /// </summary> 424 /// </summary>
431 /// <param name="cs">The CompoundStatement node.</param> 425 /// <param name="cs">The CompoundStatement node.</param>
432 /// <returns>String containing C# code for CompoundStatement cs.</returns> 426 /// <returns>String containing C# code for CompoundStatement cs.</returns>
433 private string GenerateCompoundStatement(SYMBOL previousSymbol, CompoundStatement cs) 427 private void GenerateCompoundStatement(SYMBOL previousSymbol, CompoundStatement cs, StringBuilder sb)
434 { 428 {
435 string retstr = String.Empty;
436
437 // opening brace 429 // opening brace
438 retstr += GenerateIndentedLine("{"); 430 GenerateIndentedLine("{", sb);
439 m_braceCount++; 431 m_braceCount++;
440 432
441 if (m_insertCoopTerminationChecks) 433 if (m_insertCoopTerminationChecks)
@@ -446,17 +438,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
446 || previousSymbol is DoWhileStatement 438 || previousSymbol is DoWhileStatement
447 || previousSymbol is ForLoop 439 || previousSymbol is ForLoop
448 || previousSymbol is StateEvent) 440 || previousSymbol is StateEvent)
449 retstr += GenerateIndentedLine(m_coopTerminationCheck); 441 GenerateIndentedLine(m_coopTerminationCheck, sb);
450 } 442 }
451 443
452 foreach (SYMBOL kid in cs.kids) 444 foreach (SYMBOL kid in cs.kids)
453 retstr += GenerateNode(cs, kid); 445 GenerateNodeToSB(cs, kid, sb);
454 446
455 // closing brace 447 // closing brace
456 m_braceCount--; 448 m_braceCount--;
457 retstr += GenerateIndentedLine("}"); 449 GenerateIndentedLine("}", sb);
458
459 return retstr;
460 } 450 }
461 451
462 /// <summary> 452 /// <summary>
@@ -464,9 +454,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
464 /// </summary> 454 /// </summary>
465 /// <param name="d">The Declaration node.</param> 455 /// <param name="d">The Declaration node.</param>
466 /// <returns>String containing C# code for Declaration d.</returns> 456 /// <returns>String containing C# code for Declaration d.</returns>
467 private string GenerateDeclaration(Declaration d) 457 private void GenerateDeclaration(Declaration d, StringBuilder sb)
468 { 458 {
469 return Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d); 459 Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d, sb);
470 } 460 }
471 461
472 /// <summary> 462 /// <summary>
@@ -474,7 +464,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
474 /// </summary> 464 /// </summary>
475 /// <param name="s">The Statement node.</param> 465 /// <param name="s">The Statement node.</param>
476 /// <returns>String containing C# code for Statement s.</returns> 466 /// <returns>String containing C# code for Statement s.</returns>
477 private string GenerateStatement(SYMBOL previousSymbol, Statement s) 467 private void GenerateStatement(SYMBOL previousSymbol, Statement s, StringBuilder sb)
478 { 468 {
479 string retstr = String.Empty; 469 string retstr = String.Empty;
480 bool printSemicolon = true; 470 bool printSemicolon = true;
@@ -491,13 +481,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
491 transformToBlock = true; 481 transformToBlock = true;
492 482
493 // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented. 483 // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented.
494 retstr += GenerateIndentedLine("{"); 484 GenerateIndentedLine("{", sb);
495 485
496 retstr += GenerateIndentedLine(m_coopTerminationCheck); 486 GenerateIndentedLine(m_coopTerminationCheck, sb);
497 } 487 }
498 } 488 }
499 489
500 retstr += Indent(); 490 Indent(sb);
501 491
502 if (0 < s.kids.Count) 492 if (0 < s.kids.Count)
503 { 493 {
@@ -508,19 +498,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
508 // (MONO) error. 498 // (MONO) error.
509 if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count)) 499 if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count))
510 foreach (SYMBOL kid in s.kids) 500 foreach (SYMBOL kid in s.kids)
511 retstr += GenerateNode(s, kid); 501 GenerateNodeToSB(s, kid, sb);
512 } 502 }
513 503
514 if (printSemicolon) 504 if (printSemicolon)
515 retstr += GenerateLine(";"); 505 GenerateLine(";", sb);
516 506
517 if (transformToBlock) 507 if (transformToBlock)
518 { 508 {
519 // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent 509 // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent
520 retstr += GenerateIndentedLine("}"); 510 GenerateIndentedLine("}", sb);
521 } 511 }
522
523 return retstr;
524 } 512 }
525 513
526 /// <summary> 514 /// <summary>
@@ -528,19 +516,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
528 /// </summary> 516 /// </summary>
529 /// <param name="a">The Assignment node.</param> 517 /// <param name="a">The Assignment node.</param>
530 /// <returns>String containing C# code for Assignment a.</returns> 518 /// <returns>String containing C# code for Assignment a.</returns>
531 private string GenerateAssignment(Assignment a) 519 private void GenerateAssignment(Assignment a, StringBuilder sb)
532 { 520 {
533 string retstr = String.Empty;
534
535 List<string> identifiers = new List<string>(); 521 List<string> identifiers = new List<string>();
536 checkForMultipleAssignments(identifiers, a); 522 checkForMultipleAssignments(identifiers, a);
537 523
538 retstr += GenerateNode(a, (SYMBOL) a.kids.Pop()); 524 GenerateNodeToSB(a, (SYMBOL) a.kids.Pop(), sb);
539 retstr += Generate(String.Format(" {0} ", a.AssignmentType), a); 525 Generate(String.Format(" {0} ", a.AssignmentType), a, sb);
540 foreach (SYMBOL kid in a.kids) 526 foreach (SYMBOL kid in a.kids)
541 retstr += GenerateNode(a, kid); 527 GenerateNodeToSB(a, kid, sb);
542
543 return retstr;
544 } 528 }
545 529
546 // This code checks for LSL of the following forms, and generates a 530 // This code checks for LSL of the following forms, and generates a
@@ -604,16 +588,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
604 /// </summary> 588 /// </summary>
605 /// <param name="rs">The ReturnStatement node.</param> 589 /// <param name="rs">The ReturnStatement node.</param>
606 /// <returns>String containing C# code for ReturnStatement rs.</returns> 590 /// <returns>String containing C# code for ReturnStatement rs.</returns>
607 private string GenerateReturnStatement(ReturnStatement rs) 591 private void GenerateReturnStatement(ReturnStatement rs, StringBuilder sb)
608 { 592 {
609 string retstr = String.Empty; 593 Generate("return ", rs, sb);
610
611 retstr += Generate("return ", rs);
612 594
613 foreach (SYMBOL kid in rs.kids) 595 foreach (SYMBOL kid in rs.kids)
614 retstr += GenerateNode(rs, kid); 596 GenerateNodeToSB(rs, kid, sb);
615
616 return retstr;
617 } 597 }
618 598
619 /// <summary> 599 /// <summary>
@@ -621,7 +601,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
621 /// </summary> 601 /// </summary>
622 /// <param name="jl">The JumpLabel node.</param> 602 /// <param name="jl">The JumpLabel node.</param>
623 /// <returns>String containing C# code for JumpLabel jl.</returns> 603 /// <returns>String containing C# code for JumpLabel jl.</returns>
624 private string GenerateJumpLabel(JumpLabel jl) 604 private void GenerateJumpLabel(JumpLabel jl, StringBuilder sb)
625 { 605 {
626 string labelStatement; 606 string labelStatement;
627 607
@@ -630,7 +610,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
630 else 610 else
631 labelStatement = "NoOp();"; 611 labelStatement = "NoOp();";
632 612
633 return GenerateLine(String.Format("{0}: {1}", CheckName(jl.LabelName), labelStatement), jl); 613 GenerateLine(String.Format("{0}: {1}", CheckName(jl.LabelName), labelStatement), jl, sb);
634 } 614 }
635 615
636 /// <summary> 616 /// <summary>
@@ -638,9 +618,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
638 /// </summary> 618 /// </summary>
639 /// <param name="js">The JumpStatement node.</param> 619 /// <param name="js">The JumpStatement node.</param>
640 /// <returns>String containing C# code for JumpStatement js.</returns> 620 /// <returns>String containing C# code for JumpStatement js.</returns>
641 private string GenerateJumpStatement(JumpStatement js) 621 private void GenerateJumpStatement(JumpStatement js, StringBuilder sb)
642 { 622 {
643 return Generate(String.Format("goto {0}", CheckName(js.TargetName)), js); 623 Generate(String.Format("goto {0}", CheckName(js.TargetName)), js, sb);
644 } 624 }
645 625
646 /// <summary> 626 /// <summary>
@@ -648,32 +628,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
648 /// </summary> 628 /// </summary>
649 /// <param name="ifs">The IfStatement node.</param> 629 /// <param name="ifs">The IfStatement node.</param>
650 /// <returns>String containing C# code for IfStatement ifs.</returns> 630 /// <returns>String containing C# code for IfStatement ifs.</returns>
651 private string GenerateIfStatement(IfStatement ifs) 631 private void GenerateIfStatement(IfStatement ifs, StringBuilder sb)
652 { 632 {
653 string retstr = String.Empty; 633 GenerateIndented("if (", ifs, sb);
654 634 GenerateNodeToSB(ifs, (SYMBOL) ifs.kids.Pop(), sb);
655 retstr += GenerateIndented("if (", ifs); 635 GenerateLine(")", sb);
656 retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop());
657 retstr += GenerateLine(")");
658 636
659 // CompoundStatement handles indentation itself but we need to do it 637 // CompoundStatement handles indentation itself but we need to do it
660 // otherwise. 638 // otherwise.
661 bool indentHere = ifs.kids.Top is Statement; 639 bool indentHere = ifs.kids.Top is Statement;
662 if (indentHere) m_braceCount++; 640 if (indentHere) m_braceCount++;
663 retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); 641 GenerateNodeToSB(ifs, (SYMBOL) ifs.kids.Pop(), sb);
664 if (indentHere) m_braceCount--; 642 if (indentHere) m_braceCount--;
665 643
666 if (0 < ifs.kids.Count) // do it again for an else 644 if (0 < ifs.kids.Count) // do it again for an else
667 { 645 {
668 retstr += GenerateIndentedLine("else", ifs); 646 GenerateIndentedLine("else", ifs, sb);
669 647
670 indentHere = ifs.kids.Top is Statement; 648 indentHere = ifs.kids.Top is Statement;
671 if (indentHere) m_braceCount++; 649 if (indentHere) m_braceCount++;
672 retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); 650 GenerateNodeToSB(ifs, (SYMBOL) ifs.kids.Pop(), sb);
673 if (indentHere) m_braceCount--; 651 if (indentHere) m_braceCount--;
674 } 652 }
675
676 return retstr;
677 } 653 }
678 654
679 /// <summary> 655 /// <summary>
@@ -681,9 +657,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
681 /// </summary> 657 /// </summary>
682 /// <param name="sc">The StateChange node.</param> 658 /// <param name="sc">The StateChange node.</param>
683 /// <returns>String containing C# code for StateChange sc.</returns> 659 /// <returns>String containing C# code for StateChange sc.</returns>
684 private string GenerateStateChange(StateChange sc) 660 private void GenerateStateChange(StateChange sc, StringBuilder sb)
685 { 661 {
686 return Generate(String.Format("state(\"{0}\")", sc.NewState), sc); 662 Generate(String.Format("state(\"{0}\")", sc.NewState), sc, sb);
687 } 663 }
688 664
689 /// <summary> 665 /// <summary>
@@ -691,22 +667,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
691 /// </summary> 667 /// </summary>
692 /// <param name="ws">The WhileStatement node.</param> 668 /// <param name="ws">The WhileStatement node.</param>
693 /// <returns>String containing C# code for WhileStatement ws.</returns> 669 /// <returns>String containing C# code for WhileStatement ws.</returns>
694 private string GenerateWhileStatement(WhileStatement ws) 670 private void GenerateWhileStatement(WhileStatement ws, StringBuilder sb)
695 { 671 {
696 string retstr = String.Empty; 672 GenerateIndented("while (", ws, sb);
697 673 GenerateNodeToSB(ws, (SYMBOL) ws.kids.Pop(), sb);
698 retstr += GenerateIndented("while (", ws); 674 GenerateLine(")", sb);
699 retstr += GenerateNode(ws, (SYMBOL) ws.kids.Pop());
700 retstr += GenerateLine(")");
701 675
702 // CompoundStatement handles indentation itself but we need to do it 676 // CompoundStatement handles indentation itself but we need to do it
703 // otherwise. 677 // otherwise.
704 bool indentHere = ws.kids.Top is Statement; 678 bool indentHere = ws.kids.Top is Statement;
705 if (indentHere) m_braceCount++; 679 if (indentHere) m_braceCount++;
706 retstr += GenerateNode(ws, (SYMBOL) ws.kids.Pop()); 680 GenerateNodeToSB(ws, (SYMBOL) ws.kids.Pop(), sb);
707 if (indentHere) m_braceCount--; 681 if (indentHere) m_braceCount--;
708
709 return retstr;
710 } 682 }
711 683
712 /// <summary> 684 /// <summary>
@@ -714,24 +686,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
714 /// </summary> 686 /// </summary>
715 /// <param name="dws">The DoWhileStatement node.</param> 687 /// <param name="dws">The DoWhileStatement node.</param>
716 /// <returns>String containing C# code for DoWhileStatement dws.</returns> 688 /// <returns>String containing C# code for DoWhileStatement dws.</returns>
717 private string GenerateDoWhileStatement(DoWhileStatement dws) 689 private void GenerateDoWhileStatement(DoWhileStatement dws, StringBuilder sb)
718 { 690 {
719 string retstr = String.Empty; 691 GenerateIndentedLine("do", dws, sb);
720
721 retstr += GenerateIndentedLine("do", dws);
722 692
723 // CompoundStatement handles indentation itself but we need to do it 693 // CompoundStatement handles indentation itself but we need to do it
724 // otherwise. 694 // otherwise.
725 bool indentHere = dws.kids.Top is Statement; 695 bool indentHere = dws.kids.Top is Statement;
726 if (indentHere) m_braceCount++; 696 if (indentHere) m_braceCount++;
727 retstr += GenerateNode(dws, (SYMBOL) dws.kids.Pop()); 697 GenerateNodeToSB(dws, (SYMBOL) dws.kids.Pop(), sb);
728 if (indentHere) m_braceCount--; 698 if (indentHere) m_braceCount--;
729 699
730 retstr += GenerateIndented("while (", dws); 700 GenerateIndented("while (", dws ,sb);
731 retstr += GenerateNode(dws, (SYMBOL) dws.kids.Pop()); 701 GenerateNodeToSB(dws, (SYMBOL) dws.kids.Pop(), sb);
732 retstr += GenerateLine(");"); 702 GenerateLine(");", sb);
733
734 return retstr;
735 } 703 }
736 704
737 /// <summary> 705 /// <summary>
@@ -739,11 +707,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
739 /// </summary> 707 /// </summary>
740 /// <param name="fl">The ForLoop node.</param> 708 /// <param name="fl">The ForLoop node.</param>
741 /// <returns>String containing C# code for ForLoop fl.</returns> 709 /// <returns>String containing C# code for ForLoop fl.</returns>
742 private string GenerateForLoop(ForLoop fl) 710 private void GenerateForLoop(ForLoop fl, StringBuilder sb)
743 { 711 {
744 string retstr = String.Empty; 712 GenerateIndented("for (", fl, sb);
745
746 retstr += GenerateIndented("for (", fl);
747 713
748 // It's possible that we don't have an assignment, in which case 714 // It's possible that we don't have an assignment, in which case
749 // the child will be null and we only print the semicolon. 715 // the child will be null and we only print the semicolon.
@@ -752,26 +718,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
752 ForLoopStatement s = (ForLoopStatement) fl.kids.Pop(); 718 ForLoopStatement s = (ForLoopStatement) fl.kids.Pop();
753 if (null != s) 719 if (null != s)
754 { 720 {
755 retstr += GenerateForLoopStatement(s); 721 GenerateForLoopStatement(s, sb);
756 } 722 }
757 retstr += Generate("; "); 723 Generate("; ", sb);
758 // for (x = 0; x < 10; x++) 724 // for (x = 0; x < 10; x++)
759 // ^^^^^^ 725 // ^^^^^^
760 retstr += GenerateNode(fl, (SYMBOL) fl.kids.Pop()); 726 GenerateNodeToSB(fl, (SYMBOL) fl.kids.Pop(), sb);
761 retstr += Generate("; "); 727 Generate("; ", sb);
762 // for (x = 0; x < 10; x++) 728 // for (x = 0; x < 10; x++)
763 // ^^^ 729 // ^^^
764 retstr += GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop()); 730 GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop(), sb);
765 retstr += GenerateLine(")"); 731 GenerateLine(")", sb);
766 732
767 // CompoundStatement handles indentation itself but we need to do it 733 // CompoundStatement handles indentation itself but we need to do it
768 // otherwise. 734 // otherwise.
769 bool indentHere = fl.kids.Top is Statement; 735 bool indentHere = fl.kids.Top is Statement;
770 if (indentHere) m_braceCount++; 736 if (indentHere) m_braceCount++;
771 retstr += GenerateNode(fl, (SYMBOL) fl.kids.Pop()); 737 GenerateNodeToSB(fl, (SYMBOL) fl.kids.Pop(), sb);
772 if (indentHere) m_braceCount--; 738 if (indentHere) m_braceCount--;
773
774 return retstr;
775 } 739 }
776 740
777 /// <summary> 741 /// <summary>
@@ -779,10 +743,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
779 /// </summary> 743 /// </summary>
780 /// <param name="fls">The ForLoopStatement node.</param> 744 /// <param name="fls">The ForLoopStatement node.</param>
781 /// <returns>String containing C# code for ForLoopStatement fls.</returns> 745 /// <returns>String containing C# code for ForLoopStatement fls.</returns>
782 private string GenerateForLoopStatement(ForLoopStatement fls) 746 private void GenerateForLoopStatement(ForLoopStatement fls, StringBuilder sb)
783 { 747 {
784 string retstr = String.Empty;
785
786 int comma = fls.kids.Count - 1; // tells us whether to print a comma 748 int comma = fls.kids.Count - 1; // tells us whether to print a comma
787 749
788 // It's possible that all we have is an empty Ident, for example: 750 // It's possible that all we have is an empty Ident, for example:
@@ -791,7 +753,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
791 // 753 //
792 // Which is illegal in C# (MONO). We'll skip it. 754 // Which is illegal in C# (MONO). We'll skip it.
793 if (fls.kids.Top is IdentExpression && 1 == fls.kids.Count) 755 if (fls.kids.Top is IdentExpression && 1 == fls.kids.Count)
794 return retstr; 756 return;
795 757
796 for (int i = 0; i < fls.kids.Count; i++) 758 for (int i = 0; i < fls.kids.Count; i++)
797 { 759 {
@@ -813,12 +775,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
813 while (s is ParenthesisExpression) 775 while (s is ParenthesisExpression)
814 s = (SYMBOL)s.kids.Pop(); 776 s = (SYMBOL)s.kids.Pop();
815 777
816 retstr += GenerateNode(fls, s); 778 GenerateNodeToSB(fls, s, sb);
817 if (0 < comma--) 779 if (0 < comma--)
818 retstr += Generate(", "); 780 Generate(", ", sb);
819 } 781 }
820
821 return retstr;
822 } 782 }
823 783
824 /// <summary> 784 /// <summary>
@@ -826,31 +786,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
826 /// </summary> 786 /// </summary>
827 /// <param name="be">The BinaryExpression node.</param> 787 /// <param name="be">The BinaryExpression node.</param>
828 /// <returns>String containing C# code for BinaryExpression be.</returns> 788 /// <returns>String containing C# code for BinaryExpression be.</returns>
829 private string GenerateBinaryExpression(BinaryExpression be) 789 private void GenerateBinaryExpression(BinaryExpression be, StringBuilder sb)
830 { 790 {
831 string retstr = String.Empty;
832
833 if (be.ExpressionSymbol.Equals("&&") || be.ExpressionSymbol.Equals("||")) 791 if (be.ExpressionSymbol.Equals("&&") || be.ExpressionSymbol.Equals("||"))
834 { 792 {
835 // special case handling for logical and/or, see Mantis 3174 793 // special case handling for logical and/or, see Mantis 3174
836 retstr += "((bool)("; 794 sb.Append("((bool)(");
837 retstr += GenerateNode(be, (SYMBOL)be.kids.Pop()); 795 GenerateNodeToSB(be, (SYMBOL)be.kids.Pop(), sb);
838 retstr += "))"; 796 sb.Append("))");
839 retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be); 797 Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be, sb);
840 retstr += "((bool)("; 798 sb.Append("((bool)(");
841 foreach (SYMBOL kid in be.kids) 799 foreach (SYMBOL kid in be.kids)
842 retstr += GenerateNode(be, kid); 800 GenerateNodeToSB(be, kid, sb);
843 retstr += "))"; 801 sb.Append("))");
844 } 802 }
845 else 803 else
846 { 804 {
847 retstr += GenerateNode(be, (SYMBOL)be.kids.Pop()); 805 GenerateNodeToSB(be, (SYMBOL)be.kids.Pop(), sb);
848 retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol), be); 806 Generate(String.Format(" {0} ", be.ExpressionSymbol), be, sb);
849 foreach (SYMBOL kid in be.kids) 807 foreach (SYMBOL kid in be.kids)
850 retstr += GenerateNode(be, kid); 808 GenerateNodeToSB(be, kid, sb);
851 } 809 }
852
853 return retstr;
854 } 810 }
855 811
856 /// <summary> 812 /// <summary>
@@ -858,14 +814,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
858 /// </summary> 814 /// </summary>
859 /// <param name="ue">The UnaryExpression node.</param> 815 /// <param name="ue">The UnaryExpression node.</param>
860 /// <returns>String containing C# code for UnaryExpression ue.</returns> 816 /// <returns>String containing C# code for UnaryExpression ue.</returns>
861 private string GenerateUnaryExpression(UnaryExpression ue) 817 private void GenerateUnaryExpression(UnaryExpression ue, StringBuilder sb)
862 { 818 {
863 string retstr = String.Empty; 819 Generate(ue.UnarySymbol, ue, sb);
864 820 GenerateNodeToSB(ue, (SYMBOL) ue.kids.Pop(), sb);
865 retstr += Generate(ue.UnarySymbol, ue);
866 retstr += GenerateNode(ue, (SYMBOL) ue.kids.Pop());
867
868 return retstr;
869 } 821 }
870 822
871 /// <summary> 823 /// <summary>
@@ -873,16 +825,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
873 /// </summary> 825 /// </summary>
874 /// <param name="pe">The ParenthesisExpression node.</param> 826 /// <param name="pe">The ParenthesisExpression node.</param>
875 /// <returns>String containing C# code for ParenthesisExpression pe.</returns> 827 /// <returns>String containing C# code for ParenthesisExpression pe.</returns>
876 private string GenerateParenthesisExpression(ParenthesisExpression pe) 828 private void GenerateParenthesisExpression(ParenthesisExpression pe, StringBuilder sb)
877 { 829 {
878 string retstr = String.Empty; 830 string retstr = String.Empty;
879 831
880 retstr += Generate("("); 832 Generate("(", sb);
881 foreach (SYMBOL kid in pe.kids) 833 foreach (SYMBOL kid in pe.kids)
882 retstr += GenerateNode(pe, kid); 834 GenerateNodeToSB(pe, kid, sb);
883 retstr += Generate(")"); 835 Generate(")", sb);
884
885 return retstr;
886 } 836 }
887 837
888 /// <summary> 838 /// <summary>
@@ -890,19 +840,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
890 /// </summary> 840 /// </summary>
891 /// <param name="ide">The IncrementDecrementExpression node.</param> 841 /// <param name="ide">The IncrementDecrementExpression node.</param>
892 /// <returns>String containing C# code for IncrementDecrementExpression ide.</returns> 842 /// <returns>String containing C# code for IncrementDecrementExpression ide.</returns>
893 private string GenerateIncrementDecrementExpression(IncrementDecrementExpression ide) 843 private void GenerateIncrementDecrementExpression(IncrementDecrementExpression ide, StringBuilder sb)
894 { 844 {
895 string retstr = String.Empty;
896
897 if (0 < ide.kids.Count) 845 if (0 < ide.kids.Count)
898 { 846 {
899 IdentDotExpression dot = (IdentDotExpression) ide.kids.Top; 847 IdentDotExpression dot = (IdentDotExpression) ide.kids.Top;
900 retstr += Generate(String.Format("{0}", ide.PostOperation ? CheckName(dot.Name) + "." + dot.Member + ide.Operation : ide.Operation + CheckName(dot.Name) + "." + dot.Member), ide); 848 Generate(String.Format("{0}", ide.PostOperation ? CheckName(dot.Name) + "." + dot.Member + ide.Operation : ide.Operation + CheckName(dot.Name) + "." + dot.Member), ide, sb);
901 } 849 }
902 else 850 else
903 retstr += Generate(String.Format("{0}", ide.PostOperation ? CheckName(ide.Name) + ide.Operation : ide.Operation + CheckName(ide.Name)), ide); 851 Generate(String.Format("{0}", ide.PostOperation ? CheckName(ide.Name) + ide.Operation : ide.Operation + CheckName(ide.Name)), ide, sb);
904
905 return retstr;
906 } 852 }
907 853
908 /// <summary> 854 /// <summary>
@@ -910,16 +856,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
910 /// </summary> 856 /// </summary>
911 /// <param name="te">The TypecastExpression node.</param> 857 /// <param name="te">The TypecastExpression node.</param>
912 /// <returns>String containing C# code for TypecastExpression te.</returns> 858 /// <returns>String containing C# code for TypecastExpression te.</returns>
913 private string GenerateTypecastExpression(TypecastExpression te) 859 private void GenerateTypecastExpression(TypecastExpression te, StringBuilder sb)
914 { 860 {
915 string retstr = String.Empty;
916
917 // we wrap all typecasted statements in parentheses 861 // we wrap all typecasted statements in parentheses
918 retstr += Generate(String.Format("({0}) (", te.TypecastType), te); 862 Generate(String.Format("({0}) (", te.TypecastType), te, sb);
919 retstr += GenerateNode(te, (SYMBOL) te.kids.Pop()); 863 GenerateNodeToSB(te, (SYMBOL) te.kids.Pop(), sb);
920 retstr += Generate(")"); 864 Generate(")", sb);
921
922 return retstr;
923 } 865 }
924 866
925 /// <summary> 867 /// <summary>
@@ -928,7 +870,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
928 /// <param name="id">The symbol name</param> 870 /// <param name="id">The symbol name</param>
929 /// <param name="s">The Symbol node.</param> 871 /// <param name="s">The Symbol node.</param>
930 /// <returns>String containing C# code for identifier reference.</returns> 872 /// <returns>String containing C# code for identifier reference.</returns>
931 private string GenerateIdentifier(string id, SYMBOL s) 873 private void GenerateIdentifier(string id, SYMBOL s, StringBuilder sb)
932 { 874 {
933 if (m_comms != null) 875 if (m_comms != null)
934 { 876 {
@@ -950,11 +892,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
950 retval = String.Format("new LSL_Types.Quaternion(\"{0}\")",((OpenMetaverse.Quaternion)value).ToString()); 892 retval = String.Format("new LSL_Types.Quaternion(\"{0}\")",((OpenMetaverse.Quaternion)value).ToString());
951 else retval = id; 893 else retval = id;
952 894
953 return Generate(retval, s); 895 Generate(retval, s, sb);
896 return;
954 } 897 }
955 } 898 }
956 899
957 return Generate(CheckName(id), s); 900 Generate(CheckName(id), s, sb);
901 return;
958 } 902 }
959 903
960 /// <summary> 904 /// <summary>
@@ -962,10 +906,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
962 /// </summary> 906 /// </summary>
963 /// <param name="fc">The FunctionCall node.</param> 907 /// <param name="fc">The FunctionCall node.</param>
964 /// <returns>String containing C# code for FunctionCall fc.</returns> 908 /// <returns>String containing C# code for FunctionCall fc.</returns>
965 private string GenerateFunctionCall(FunctionCall fc) 909 private void GenerateFunctionCall(FunctionCall fc, StringBuilder sb)
966 { 910 {
967 string retstr = String.Empty;
968
969 string modinvoke = null; 911 string modinvoke = null;
970 if (m_comms != null) 912 if (m_comms != null)
971 modinvoke = m_comms.LookupModInvocation(fc.Id); 913 modinvoke = m_comms.LookupModInvocation(fc.Id);
@@ -975,22 +917,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
975 if (fc.kids[0] is ArgumentList) 917 if (fc.kids[0] is ArgumentList)
976 { 918 {
977 if ((fc.kids[0] as ArgumentList).kids.Count == 0) 919 if ((fc.kids[0] as ArgumentList).kids.Count == 0)
978 retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc); 920 Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc, sb);
979 else 921 else
980 retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc); 922 Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc, sb);
981 } 923 }
982 } 924 }
983 else 925 else
984 { 926 {
985 retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc); 927 Generate(String.Format("{0}(", CheckName(fc.Id)), fc, sb);
986 } 928 }
987 929
988 foreach (SYMBOL kid in fc.kids) 930 foreach (SYMBOL kid in fc.kids)
989 retstr += GenerateNode(fc, kid); 931 GenerateNodeToSB(fc, kid, sb);
990
991 retstr += Generate(")");
992 932
993 return retstr; 933 Generate(")", sb);
994 } 934 }
995 935
996 /// <summary> 936 /// <summary>
@@ -998,10 +938,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
998 /// </summary> 938 /// </summary>
999 /// <param name="c">The Constant node.</param> 939 /// <param name="c">The Constant node.</param>
1000 /// <returns>String containing C# code for Constant c.</returns> 940 /// <returns>String containing C# code for Constant c.</returns>
1001 private string GenerateConstant(Constant c) 941 private void GenerateConstant(Constant c, StringBuilder sb)
1002 { 942 {
1003 string retstr = String.Empty;
1004
1005 // Supprt LSL's weird acceptance of floats with no trailing digits 943 // Supprt LSL's weird acceptance of floats with no trailing digits
1006 // after the period. Turn float x = 10.; into float x = 10.0; 944 // after the period. Turn float x = 10.; into float x = 10.0;
1007 if ("LSL_Types.LSLFloat" == c.Type) 945 if ("LSL_Types.LSLFloat" == c.Type)
@@ -1020,9 +958,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1020 c.Value = "new LSL_Types.LSLString(\""+c.Value+"\")"; 958 c.Value = "new LSL_Types.LSLString(\""+c.Value+"\")";
1021 } 959 }
1022 960
1023 retstr += Generate(c.Value, c); 961 Generate(c.Value, c, sb);
1024
1025 return retstr;
1026 } 962 }
1027 963
1028 /// <summary> 964 /// <summary>
@@ -1030,19 +966,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1030 /// </summary> 966 /// </summary>
1031 /// <param name="vc">The VectorConstant node.</param> 967 /// <param name="vc">The VectorConstant node.</param>
1032 /// <returns>String containing C# code for VectorConstant vc.</returns> 968 /// <returns>String containing C# code for VectorConstant vc.</returns>
1033 private string GenerateVectorConstant(VectorConstant vc) 969 private void GenerateVectorConstant(VectorConstant vc, StringBuilder sb)
1034 { 970 {
1035 string retstr = String.Empty; 971 Generate(String.Format("new {0}(", vc.Type), vc, sb);
1036 972 GenerateNodeToSB(vc, (SYMBOL) vc.kids.Pop(), sb);
1037 retstr += Generate(String.Format("new {0}(", vc.Type), vc); 973 Generate(", ", sb);
1038 retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); 974 GenerateNodeToSB(vc, (SYMBOL) vc.kids.Pop(), sb);
1039 retstr += Generate(", "); 975 Generate(", ", sb);
1040 retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); 976 GenerateNodeToSB(vc, (SYMBOL) vc.kids.Pop(), sb);
1041 retstr += Generate(", "); 977 Generate(")", sb);
1042 retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop());
1043 retstr += Generate(")");
1044
1045 return retstr;
1046 } 978 }
1047 979
1048 /// <summary> 980 /// <summary>
@@ -1050,21 +982,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1050 /// </summary> 982 /// </summary>
1051 /// <param name="rc">The RotationConstant node.</param> 983 /// <param name="rc">The RotationConstant node.</param>
1052 /// <returns>String containing C# code for RotationConstant rc.</returns> 984 /// <returns>String containing C# code for RotationConstant rc.</returns>
1053 private string GenerateRotationConstant(RotationConstant rc) 985 private void GenerateRotationConstant(RotationConstant rc, StringBuilder sb)
1054 { 986 {
1055 string retstr = String.Empty; 987 Generate(String.Format("new {0}(", rc.Type), rc, sb);
1056 988 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1057 retstr += Generate(String.Format("new {0}(", rc.Type), rc); 989 Generate(", ", sb);
1058 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); 990 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1059 retstr += Generate(", "); 991 Generate(", ", sb);
1060 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); 992 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1061 retstr += Generate(", "); 993 Generate(", ", sb);
1062 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); 994 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1063 retstr += Generate(", "); 995 Generate(")", sb);
1064 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop());
1065 retstr += Generate(")");
1066
1067 return retstr;
1068 } 996 }
1069 997
1070 /// <summary> 998 /// <summary>
@@ -1072,27 +1000,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1072 /// </summary> 1000 /// </summary>
1073 /// <param name="lc">The ListConstant node.</param> 1001 /// <param name="lc">The ListConstant node.</param>
1074 /// <returns>String containing C# code for ListConstant lc.</returns> 1002 /// <returns>String containing C# code for ListConstant lc.</returns>
1075 private string GenerateListConstant(ListConstant lc) 1003 private void GenerateListConstant(ListConstant lc, StringBuilder sb)
1076 { 1004 {
1077 string retstr = String.Empty; 1005 Generate(String.Format("new {0}(", lc.Type), lc, sb);
1078
1079 retstr += Generate(String.Format("new {0}(", lc.Type), lc);
1080 1006
1081 foreach (SYMBOL kid in lc.kids) 1007 foreach (SYMBOL kid in lc.kids)
1082 retstr += GenerateNode(lc, kid); 1008 GenerateNodeToSB(lc, kid, sb);
1083 1009
1084 retstr += Generate(")"); 1010 Generate(")", sb);
1085
1086 return retstr;
1087 } 1011 }
1088 1012
1089 /// <summary> 1013 /// <summary>
1090 /// Prints a newline. 1014 /// Prints a newline.
1091 /// </summary> 1015 /// </summary>
1092 /// <returns>A newline.</returns> 1016 /// <returns>A newline.</returns>
1093 private string GenerateLine() 1017 private void GenerateLine(StringBuilder sb)
1094 { 1018 {
1095 return GenerateLine(""); 1019 sb.Append("\n");
1020 m_CSharpLine++;
1021 m_CSharpCol = 1;
1096 } 1022 }
1097 1023
1098 /// <summary> 1024 /// <summary>
@@ -1100,9 +1026,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1100 /// </summary> 1026 /// </summary>
1101 /// <param name="s">String of text to print.</param> 1027 /// <param name="s">String of text to print.</param>
1102 /// <returns>String s followed by newline.</returns> 1028 /// <returns>String s followed by newline.</returns>
1103 private string GenerateLine(string s) 1029 private void GenerateLine(string s, StringBuilder sb)
1104 { 1030 {
1105 return GenerateLine(s, null); 1031 sb.Append(s);
1032 sb.Append("\n");
1033 m_CSharpLine++;
1034 m_CSharpCol = 1;
1106 } 1035 }
1107 1036
1108 /// <summary> 1037 /// <summary>
@@ -1112,14 +1041,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1112 /// <param name="sym">Symbol being generated to extract original line 1041 /// <param name="sym">Symbol being generated to extract original line
1113 /// number and column from.</param> 1042 /// number and column from.</param>
1114 /// <returns>String s followed by newline.</returns> 1043 /// <returns>String s followed by newline.</returns>
1115 private string GenerateLine(string s, SYMBOL sym) 1044 private void GenerateLine(string s, SYMBOL sym, StringBuilder sb)
1116 { 1045 {
1117 string retstr = Generate(s, sym) + "\n"; 1046 Generate(s, sym, sb);
1047 sb.Append("\n");
1118 1048
1119 m_CSharpLine++; 1049 m_CSharpLine++;
1120 m_CSharpCol = 1; 1050 m_CSharpCol = 1;
1121
1122 return retstr;
1123 } 1051 }
1124 1052
1125 /// <summary> 1053 /// <summary>
@@ -1127,9 +1055,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1127 /// </summary> 1055 /// </summary>
1128 /// <param name="s">String of text to print.</param> 1056 /// <param name="s">String of text to print.</param>
1129 /// <returns>String s.</returns> 1057 /// <returns>String s.</returns>
1130 private string Generate(string s) 1058 private void Generate(string s, StringBuilder sb)
1131 { 1059 {
1132 return Generate(s, null); 1060 sb.Append(s);
1061 m_CSharpCol += s.Length;
1133 } 1062 }
1134 1063
1135 /// <summary> 1064 /// <summary>
@@ -1139,14 +1068,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1139 /// <param name="sym">Symbol being generated to extract original line 1068 /// <param name="sym">Symbol being generated to extract original line
1140 /// number and column from.</param> 1069 /// number and column from.</param>
1141 /// <returns>String s.</returns> 1070 /// <returns>String s.</returns>
1142 private string Generate(string s, SYMBOL sym) 1071 private void Generate(string s, SYMBOL sym, StringBuilder sb)
1143 { 1072 {
1073 sb.Append(s);
1144 if (null != sym) 1074 if (null != sym)
1145 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position)); 1075 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position));
1146 1076
1147 m_CSharpCol += s.Length; 1077 m_CSharpCol += s.Length;
1148
1149 return s;
1150 } 1078 }
1151 1079
1152 /// <summary> 1080 /// <summary>
@@ -1154,9 +1082,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1154 /// </summary> 1082 /// </summary>
1155 /// <param name="s">String of text to print.</param> 1083 /// <param name="s">String of text to print.</param>
1156 /// <returns>Properly indented string s followed by newline.</returns> 1084 /// <returns>Properly indented string s followed by newline.</returns>
1157 private string GenerateIndentedLine(string s) 1085 private void GenerateIndentedLine(string s, StringBuilder sb)
1158 { 1086 {
1159 return GenerateIndentedLine(s, null); 1087 GenerateIndentedLine(s, null, sb);
1160 } 1088 }
1161 1089
1162 /// <summary> 1090 /// <summary>
@@ -1166,14 +1094,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1166 /// <param name="sym">Symbol being generated to extract original line 1094 /// <param name="sym">Symbol being generated to extract original line
1167 /// number and column from.</param> 1095 /// number and column from.</param>
1168 /// <returns>Properly indented string s followed by newline.</returns> 1096 /// <returns>Properly indented string s followed by newline.</returns>
1169 private string GenerateIndentedLine(string s, SYMBOL sym) 1097 private void GenerateIndentedLine(string s, SYMBOL sym, StringBuilder sb)
1170 { 1098 {
1171 string retstr = GenerateIndented(s, sym) + "\n"; 1099 GenerateIndented(s, sym , sb );
1172 1100 sb.Append("\n");
1173 m_CSharpLine++; 1101 m_CSharpLine++;
1174 m_CSharpCol = 1; 1102 m_CSharpCol = 1;
1175
1176 return retstr;
1177 } 1103 }
1178 1104
1179 /// <summary> 1105 /// <summary>
@@ -1194,34 +1120,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1194 /// <param name="sym">Symbol being generated to extract original line 1120 /// <param name="sym">Symbol being generated to extract original line
1195 /// number and column from.</param> 1121 /// number and column from.</param>
1196 /// <returns>Properly indented string s.</returns> 1122 /// <returns>Properly indented string s.</returns>
1197 private string GenerateIndented(string s, SYMBOL sym) 1123 private void GenerateIndented(string s, SYMBOL sym, StringBuilder sb)
1198 { 1124 {
1199 string retstr = Indent() + s; 1125 Indent(sb);
1200 1126 sb.Append(s);
1127
1201 if (null != sym) 1128 if (null != sym)
1202 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position)); 1129 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position));
1203 1130
1204 m_CSharpCol += s.Length; 1131 m_CSharpCol += s.Length;
1205
1206 return retstr;
1207 } 1132 }
1208 1133
1209 /// <summary> 1134 /// <summary>
1210 /// Prints correct indentation. 1135 /// Prints correct indentation.
1211 /// </summary> 1136 /// </summary>
1212 /// <returns>Indentation based on brace count.</returns> 1137 /// <returns>Indentation based on brace count.</returns>
1213 private string Indent() 1138 private void Indent(StringBuilder sb)
1214 { 1139 {
1215 string retstr = String.Empty;
1216
1217 for (int i = 0; i < m_braceCount; i++) 1140 for (int i = 0; i < m_braceCount; i++)
1218 for (int j = 0; j < m_indentWidth; j++) 1141 {
1219 { 1142 sb.Append(" ");
1220 retstr += " "; 1143 m_CSharpCol += 4;
1221 m_CSharpCol++; 1144 }
1222 }
1223
1224 return retstr;
1225 } 1145 }
1226 1146
1227 /// <summary> 1147 /// <summary>
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index af324bf..f632cb0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -81,8 +81,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
81 81
82 // private object m_syncy = new object(); 82 // private object m_syncy = new object();
83 83
84 private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); 84// private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
85 private static VBCodeProvider VBcodeProvider = new VBCodeProvider(); 85// private static VBCodeProvider VBcodeProvider = new VBCodeProvider();
86 86
87 // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files 87 // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files
88 private static UInt64 scriptCompileCounter = 0; // And a counter 88 private static UInt64 scriptCompileCounter = 0; // And a counter
@@ -356,14 +356,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
356 throw new Exception(errtext); 356 throw new Exception(errtext);
357 } 357 }
358 358
359 string compileScript = source; 359 string compileScript = string.Empty;
360 360
361 if (language == enumCompileType.lsl) 361 if (language == enumCompileType.lsl)
362 { 362 {
363 // Its LSL, convert it to C# 363 // Its LSL, convert it to C#
364
365 StringBuilder sb = new StringBuilder(16394);
366
364 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls); 367 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls);
365 compileScript = LSL_Converter.Convert(source); 368 AddCSScriptHeader(
369 m_scriptEngine.ScriptClassName,
370 m_scriptEngine.ScriptBaseClassName,
371 m_scriptEngine.ScriptBaseClassParameters,
372 sb);
366 373
374 LSL_Converter.Convert(source,sb);
375 AddCSScriptTail(sb);
376 compileScript = sb.ToString();
367 // copy converter warnings into our warnings. 377 // copy converter warnings into our warnings.
368 foreach (string warning in LSL_Converter.GetWarnings()) 378 foreach (string warning in LSL_Converter.GetWarnings())
369 { 379 {
@@ -374,22 +384,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
374 // Write the linemap to a file and save it in our dictionary for next time. 384 // Write the linemap to a file and save it in our dictionary for next time.
375 m_lineMaps[assembly] = linemap; 385 m_lineMaps[assembly] = linemap;
376 WriteMapFile(assembly + ".map", linemap); 386 WriteMapFile(assembly + ".map", linemap);
387 LSL_Converter.Clear();
377 } 388 }
378 389 else
379 switch (language) 390 {
380 { 391 switch (language)
381 case enumCompileType.cs: 392 {
382 case enumCompileType.lsl: 393 case enumCompileType.cs:
383 compileScript = CreateCSCompilerScript( 394 compileScript = CreateCSCompilerScript(
384 compileScript, 395 compileScript,
385 m_scriptEngine.ScriptClassName, 396 m_scriptEngine.ScriptClassName,
386 m_scriptEngine.ScriptBaseClassName, 397 m_scriptEngine.ScriptBaseClassName,
387 m_scriptEngine.ScriptBaseClassParameters); 398 m_scriptEngine.ScriptBaseClassParameters);
388 break; 399 break;
389 case enumCompileType.vb: 400 case enumCompileType.vb:
390 compileScript = CreateVBCompilerScript( 401 compileScript = CreateVBCompilerScript(
391 compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName); 402 compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName);
392 break; 403 break;
404 }
393 } 405 }
394 406
395 assembly = CompileFromDotNetText(compileScript, language, asset, assembly); 407 assembly = CompileFromDotNetText(compileScript, language, asset, assembly);
@@ -419,6 +431,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
419// return compileScript; 431// return compileScript;
420// } 432// }
421 433
434 public static void AddCSScriptHeader(string className, string baseClassName, ParameterInfo[] constructorParameters, StringBuilder sb)
435 {
436 sb.Append(string.Format(
437@"using OpenSim.Region.ScriptEngine.Shared;
438using System.Collections.Generic;
439
440namespace SecondLife
441{{
442 public class {0} : {1}
443 {{
444 public {0}({2}) : base({3}) {{}}
445",
446 className,
447 baseClassName,
448 constructorParameters != null
449 ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.ToString()))
450 : "",
451 constructorParameters != null
452 ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.Name))
453 : ""
454 ));
455 }
456
457 public static void AddCSScriptTail(StringBuilder sb)
458 {
459 sb.Append(string.Format(" }}\n}}\n"));
460 }
461
422 public static string CreateCSCompilerScript( 462 public static string CreateCSCompilerScript(
423 string compileScript, string className, string baseClassName, ParameterInfo[] constructorParameters) 463 string compileScript, string className, string baseClassName, ParameterInfo[] constructorParameters)
424 { 464 {
@@ -511,8 +551,6 @@ namespace SecondLife
511 // Do actual compile 551 // Do actual compile
512 CompilerParameters parameters = new CompilerParameters(); 552 CompilerParameters parameters = new CompilerParameters();
513 553
514 parameters.IncludeDebugInformation = true;
515
516 string rootPath = AppDomain.CurrentDomain.BaseDirectory; 554 string rootPath = AppDomain.CurrentDomain.BaseDirectory;
517 555
518 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 556 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
@@ -532,26 +570,44 @@ namespace SecondLife
532 parameters.IncludeDebugInformation = CompileWithDebugInformation; 570 parameters.IncludeDebugInformation = CompileWithDebugInformation;
533 //parameters.WarningLevel = 1; // Should be 4? 571 //parameters.WarningLevel = 1; // Should be 4?
534 parameters.TreatWarningsAsErrors = false; 572 parameters.TreatWarningsAsErrors = false;
535 573 parameters.GenerateInMemory = false;
574
536 CompilerResults results; 575 CompilerResults results;
576
577 CodeDomProvider provider;
537 switch (lang) 578 switch (lang)
538 { 579 {
539 case enumCompileType.vb: 580 case enumCompileType.vb:
540 results = VBcodeProvider.CompileAssemblyFromSource( 581// results = VBcodeProvider.CompileAssemblyFromSource(
541 parameters, Script); 582// parameters, Script);
583 provider = CodeDomProvider.CreateProvider("VisualBasic");
542 break; 584 break;
543 case enumCompileType.cs: 585 case enumCompileType.cs:
544 case enumCompileType.lsl: 586 case enumCompileType.lsl:
587 provider = CodeDomProvider.CreateProvider("CSharp");
588 break;
589 default:
590 throw new Exception("Compiler is not able to recongnize " +
591 "language type \"" + lang.ToString() + "\"");
592 }
593
594 if(provider == null)
595 throw new Exception("Compiler failed to load ");
596
597
545 bool complete = false; 598 bool complete = false;
546 bool retried = false; 599 bool retried = false;
600
547 do 601 do
548 { 602 {
549 lock (CScodeProvider) 603// lock (CScodeProvider)
550 { 604// {
551 results = CScodeProvider.CompileAssemblyFromSource( 605// results = CScodeProvider.CompileAssemblyFromSource(
606// parameters, Script);
607// }
608
609 results = provider.CompileAssemblyFromSource(
552 parameters, Script); 610 parameters, Script);
553 }
554
555 // Deal with an occasional segv in the compiler. 611 // Deal with an occasional segv in the compiler.
556 // Rarely, if ever, occurs twice in succession. 612 // Rarely, if ever, occurs twice in succession.
557 // Line # == 0 and no file name are indications that 613 // Line # == 0 and no file name are indications that
@@ -575,11 +631,11 @@ namespace SecondLife
575 complete = true; 631 complete = true;
576 } 632 }
577 } while (!complete); 633 } while (!complete);
578 break; 634// break;
579 default: 635// default:
580 throw new Exception("Compiler is not able to recongnize " + 636// throw new Exception("Compiler is not able to recongnize " +
581 "language type \"" + lang.ToString() + "\""); 637// "language type \"" + lang.ToString() + "\"");
582 } 638// }
583 639
584// foreach (Type type in results.CompiledAssembly.GetTypes()) 640// foreach (Type type in results.CompiledAssembly.GetTypes())
585// { 641// {
@@ -628,6 +684,8 @@ namespace SecondLife
628 } 684 }
629 } 685 }
630 686
687 provider.Dispose();
688
631 if (hadErrors) 689 if (hadErrors)
632 { 690 {
633 throw new Exception(errtext); 691 throw new Exception(errtext);
@@ -785,15 +843,16 @@ namespace SecondLife
785 843
786 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) 844 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
787 { 845 {
788 string mapstring = String.Empty; 846 StringBuilder mapbuilder = new StringBuilder(1024);
847
789 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in linemap) 848 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in linemap)
790 { 849 {
791 KeyValuePair<int, int> k = kvp.Key; 850 KeyValuePair<int, int> k = kvp.Key;
792 KeyValuePair<int, int> v = kvp.Value; 851 KeyValuePair<int, int> v = kvp.Value;
793 mapstring += String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value); 852 mapbuilder.Append(String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value));
794 } 853 }
795 854
796 Byte[] mapbytes = Encoding.ASCII.GetBytes(mapstring); 855 Byte[] mapbytes = Encoding.ASCII.GetBytes(mapbuilder.ToString());
797 856
798 using (FileStream mfs = File.Create(filename)) 857 using (FileStream mfs = File.Create(filename))
799 mfs.Write(mapbytes, 0, mapbytes.Length); 858 mfs.Write(mapbytes, 0, mapbytes.Length);
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs
index 84e8ab2..076caad 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs
@@ -27,12 +27,15 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Text;
30 31
31namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 32namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
32{ 33{
33 public interface ICodeConverter 34 public interface ICodeConverter
34 { 35 {
35 string Convert(string script); 36 string Convert(string script);
37 void Convert(string script, StringBuilder sb);
36 string[] GetWarnings(); 38 string[] GetWarnings();
39 void Clear();
37 } 40 }
38} 41}
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs
index 0fb3574..0585f8b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs
@@ -191,7 +191,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
191 Constant rca = new Constant(p, "float", "0.0"); 191 Constant rca = new Constant(p, "float", "0.0");
192 Constant rcb = new Constant(p, "float", "0.0"); 192 Constant rcb = new Constant(p, "float", "0.0");
193 Constant rcc = new Constant(p, "float", "0.0"); 193 Constant rcc = new Constant(p, "float", "0.0");
194 Constant rcd = new Constant(p, "float", "0.0"); 194 Constant rcd = new Constant(p, "float", "1.0");
195 ConstantExpression rcea = new ConstantExpression(p, rca); 195 ConstantExpression rcea = new ConstantExpression(p, rca);
196 ConstantExpression rceb = new ConstantExpression(p, rcb); 196 ConstantExpression rceb = new ConstantExpression(p, rcb);
197 ConstantExpression rcec = new ConstantExpression(p, rcc); 197 ConstantExpression rcec = new ConstantExpression(p, rcc);
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
index b92f3a3..a9f3283 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs
@@ -1388,7 +1388,7 @@ default
1388 "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3));" + 1388 "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3));" +
1389 "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" + 1389 "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" +
1390 "\n LSL_Types.Vector3 w = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.5));" + 1390 "\n LSL_Types.Vector3 w = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.5));" +
1391 "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" + 1391 "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(1.0));" +
1392 "\n LSL_Types.Quaternion u = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.8), new LSL_Types.LSLFloat(0.7), new LSL_Types.LSLFloat(0.6), llSomeFunc());" + 1392 "\n LSL_Types.Quaternion u = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.8), new LSL_Types.LSLFloat(0.7), new LSL_Types.LSLFloat(0.6), llSomeFunc());" +
1393 "\n LSL_Types.LSLString k = new LSL_Types.LSLString(\"\");" + 1393 "\n LSL_Types.LSLString k = new LSL_Types.LSLString(\"\");" +
1394 "\n LSL_Types.LSLString n = new LSL_Types.LSLString(\"ping\");" + 1394 "\n LSL_Types.LSLString n = new LSL_Types.LSLString(\"ping\");" +
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
index b476e32..ad4ccf0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs
@@ -37,6 +37,7 @@ using OpenSim.Tests.Common;
37 37
38namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests 38namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
39{ 39{
40
40 /// <summary> 41 /// <summary>
41 /// Tests the LSL compiler. Among other things, test that error messages 42 /// Tests the LSL compiler. Among other things, test that error messages
42 /// generated by the C# compiler can be mapped to prper lines/columns in 43 /// generated by the C# compiler can be mapped to prper lines/columns in
@@ -132,7 +133,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
132 133
133 return compilerResults; 134 return compilerResults;
134 } 135 }
135 136/* test too depedent on counting lines and columns maping code generation changes
137erros position is better tested on viewers
136 /// <summary> 138 /// <summary>
137 /// Test that line number errors are resolved as expected when preceding code contains a jump. 139 /// Test that line number errors are resolved as expected when preceding code contains a jump.
138 /// </summary> 140 /// </summary>
@@ -159,6 +161,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
159 positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); 161 positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]);
160 } 162 }
161 163
164
162 /// <summary> 165 /// <summary>
163 /// Test the C# compiler error message can be mapped to the correct 166 /// Test the C# compiler error message can be mapped to the correct
164 /// line/column in the LSL source when an undeclared variable is used. 167 /// line/column in the LSL source when an undeclared variable is used.
@@ -183,7 +186,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
183 new KeyValuePair<int, int>(5, 21), 186 new KeyValuePair<int, int>(5, 21),
184 positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]); 187 positionMap[new KeyValuePair<int, int>(compilerResults.Errors[0].Line, compilerResults.Errors[0].Column)]);
185 } 188 }
186 189*/
187 /// <summary> 190 /// <summary>
188 /// Test that a string can be cast to string and another string 191 /// Test that a string can be cast to string and another string
189 /// concatenated. 192 /// concatenated.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 674144b..611df58 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -416,7 +416,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
416 PostEvent(new EventParams("on_rez", 416 PostEvent(new EventParams("on_rez",
417 new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0])); 417 new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0]));
418 } 418 }
419
420 if (m_stateSource == StateSource.AttachedRez) 419 if (m_stateSource == StateSource.AttachedRez)
421 { 420 {
422 PostEvent(new EventParams("attach", 421 PostEvent(new EventParams("attach",
@@ -457,7 +456,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
457 PostEvent(new EventParams("attach", 456 PostEvent(new EventParams("attach",
458 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 457 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
459 } 458 }
460
461 } 459 }
462 } 460 }
463 461
@@ -807,9 +805,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
807 lock (EventQueue) 805 lock (EventQueue)
808 { 806 {
809 data = (EventParams)EventQueue.Dequeue(); 807 data = (EventParams)EventQueue.Dequeue();
810 if (data == null) // Shouldn't happen 808 if (data == null)
811 { 809 {
812 if (EventQueue.Count > 0 && Running && !ShuttingDown) 810 // check if a null event was enqueued or if its really empty
811 if (EventQueue.Count > 0 && Running && !ShuttingDown && !m_InSelfDelete)
813 { 812 {
814 m_CurrentWorkItem = Engine.QueueEventHandler(this); 813 m_CurrentWorkItem = Engine.QueueEventHandler(this);
815 } 814 }
@@ -870,13 +869,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
870 } 869 }
871 else 870 else
872 { 871 {
872 Exception e = null;
873
873 if (Engine.World.PipeEventsForScript(LocalID) || 874 if (Engine.World.PipeEventsForScript(LocalID) ||
874 data.EventName == "control") // Don't freeze avies! 875 data.EventName == "control") // Don't freeze avies!
875 { 876 {
876 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", 877 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
877 // PrimName, ScriptName, data.EventName, State); 878 // PrimName, ScriptName, data.EventName, State);
878 879
879
880 try 880 try
881 { 881 {
882 m_CurrentEvent = data.EventName; 882 m_CurrentEvent = data.EventName;
@@ -891,6 +891,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
891 { 891 {
892 m_InEvent = false; 892 m_InEvent = false;
893 m_CurrentEvent = String.Empty; 893 m_CurrentEvent = String.Empty;
894 lock (EventQueue)
895 m_CurrentWorkItem = null; // no longer in a event that can be canceled
894 } 896 }
895 897
896 if (m_SaveState) 898 if (m_SaveState)
@@ -903,7 +905,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
903 m_SaveState = false; 905 m_SaveState = false;
904 } 906 }
905 } 907 }
906 catch (Exception e) 908 catch (Exception exx)
909 {
910 e = exx;
911 }
912
913 if(e != null)
907 { 914 {
908 // m_log.DebugFormat( 915 // m_log.DebugFormat(
909 // "[SCRIPT] Exception in script {0} {1}: {2}{3}", 916 // "[SCRIPT] Exception in script {0} {1}: {2}{3}",
@@ -979,7 +986,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
979 ScriptTask.ItemID, ScriptTask.AssetID, data.EventName, EventsProcessed); 986 ScriptTask.ItemID, ScriptTask.AssetID, data.EventName, EventsProcessed);
980 } 987 }
981 988
982 if (EventQueue.Count > 0 && Running && !ShuttingDown) 989 if (EventQueue.Count > 0 && Running && !ShuttingDown && !m_InSelfDelete)
983 { 990 {
984 m_CurrentWorkItem = Engine.QueueEventHandler(this); 991 m_CurrentWorkItem = Engine.QueueEventHandler(this);
985 } 992 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index d501979..9fb1e2c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -339,7 +339,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
339 y = (float)Quat.y; 339 y = (float)Quat.y;
340 z = (float)Quat.z; 340 z = (float)Quat.z;
341 s = (float)Quat.s; 341 s = (float)Quat.s;
342 if (x == 0 && y == 0 && z == 0 && s == 0) 342 if (s == 0 && x == 0 && y == 0 && z == 0)
343 s = 1; 343 s = 1;
344 } 344 }
345 345
@@ -349,7 +349,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
349 y = Y; 349 y = Y;
350 z = Z; 350 z = Z;
351 s = S; 351 s = S;
352 if (x == 0 && y == 0 && z == 0 && s == 0) 352 if (s == 0 && x == 0 && y == 0 && z == 0)
353 s = 1; 353 s = 1;
354 } 354 }
355 355
@@ -368,7 +368,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
368 res = res & Double.TryParse(tmps[1], NumberStyles.Float, Culture.NumberFormatInfo, out y); 368 res = res & Double.TryParse(tmps[1], NumberStyles.Float, Culture.NumberFormatInfo, out y);
369 res = res & Double.TryParse(tmps[2], NumberStyles.Float, Culture.NumberFormatInfo, out z); 369 res = res & Double.TryParse(tmps[2], NumberStyles.Float, Culture.NumberFormatInfo, out z);
370 res = res & Double.TryParse(tmps[3], NumberStyles.Float, Culture.NumberFormatInfo, out s); 370 res = res & Double.TryParse(tmps[3], NumberStyles.Float, Culture.NumberFormatInfo, out s);
371 if (x == 0 && y == 0 && z == 0 && s == 0) 371 if (s == 0 && x == 0 && y == 0 && z == 0)
372 s = 1; 372 s = 1;
373 } 373 }
374 374