diff options
author | Teravus Ovares | 2008-04-30 03:36:13 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-04-30 03:36:13 +0000 |
commit | 36bf16d35e928a338c932feeec42c0c8f35d8846 (patch) | |
tree | 06f11a4c546fce85fe1504fce08a09dd4bdebb06 /OpenSim/Region/ScriptEngine/DotNetEngine | |
parent | * Disabled IntergridModule until a Mono bug can be isolated. (diff) | |
download | opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.zip opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.gz opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.bz2 opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.xz |
Patch from Melanie: 0001077: [PATCH] LSL types cannot be cast implicitly or explicitly in many cases Thanks Melanie!
* Also, I moved the event parser and re-writer to a separate static object. More work will be done here shortly.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine')
3 files changed, 499 insertions, 241 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index fc38ef2..dad1b23 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs | |||
@@ -319,6 +319,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
319 | 319 | ||
320 | private static string CreateCSCompilerScript(string compileScript) | 320 | private static string CreateCSCompilerScript(string compileScript) |
321 | { | 321 | { |
322 | compileScript = EventReaderRewriter.ReWriteScriptWithPublishedEventsCS(compileScript); | ||
323 | |||
322 | compileScript = String.Empty + | 324 | compileScript = String.Empty + |
323 | "using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;\r\n" + | 325 | "using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;\r\n" + |
324 | String.Empty + "namespace SecondLife { " + | 326 | String.Empty + "namespace SecondLife { " + |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs new file mode 100644 index 0000000..46ba850 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs | |||
@@ -0,0 +1,488 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text.RegularExpressions; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
34 | { | ||
35 | public static class EventReaderRewriter | ||
36 | { | ||
37 | |||
38 | |||
39 | public static string ReWriteScriptWithPublishedEventsCS(string Script) | ||
40 | { | ||
41 | Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>(); | ||
42 | // Finds out which events are in the script and writes a method call with the events in each state_entry event | ||
43 | |||
44 | // Note the (?:)? block optional, and not returning a group. Less greedy then .* | ||
45 | |||
46 | string[] eventmatches = new string[0]; | ||
47 | //Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{"); | ||
48 | eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^\{]+)?\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
49 | for (int pos = 0; pos < eventmatches.GetUpperBound(0); pos++) | ||
50 | { | ||
51 | pos++; // garbage | ||
52 | |||
53 | string statea = eventmatches[pos]; pos++; | ||
54 | string eventa = eventmatches[pos]; | ||
55 | scriptEvents storedEventsForState = scriptEvents.None; | ||
56 | if (state_events.ContainsKey(statea)) | ||
57 | { | ||
58 | storedEventsForState = state_events[statea]; | ||
59 | state_events[statea] |= convertnametoFlag(eventa); | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | state_events.Add(statea, convertnametoFlag(eventa)); | ||
64 | } | ||
65 | Console.WriteLine("State:" + statea + ", event: " + eventa); | ||
66 | } | ||
67 | Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0)); | ||
68 | // Add namespace, class name and inheritance | ||
69 | |||
70 | // Looking *ONLY* for state entry events | ||
71 | string scriptCopy = ""; | ||
72 | |||
73 | //Only match State_Entry events now | ||
74 | // Note the whole regex is a group, then we have the state this entry belongs to. | ||
75 | eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
76 | int endloop = eventmatches.GetUpperBound(0); | ||
77 | |||
78 | // Add all the states to a list of | ||
79 | List<string> unUsedStates = new List<string>(); | ||
80 | |||
81 | foreach (string state in state_events.Keys) | ||
82 | { | ||
83 | unUsedStates.Add(state); | ||
84 | } | ||
85 | |||
86 | // If endloop is 0, then there are no state entry events in the entire script. | ||
87 | // Stick a default state entry in there. | ||
88 | if (endloop == 0) | ||
89 | { | ||
90 | if (state_events.ContainsKey("default")) | ||
91 | { | ||
92 | scriptCopy = "public void default_event_state_entry() {osSetStateEvents((int)" + (int)state_events["default"] + "); } " + Script; | ||
93 | unUsedStates.Remove("default"); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details."); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | // Loop over state entry events and rewrite the first line to define the events the state listens for. | ||
102 | for (int pos = 0; pos < endloop; pos++) | ||
103 | { | ||
104 | // Returns text before state entry match, | ||
105 | scriptCopy += eventmatches[pos]; pos++; | ||
106 | |||
107 | // Returns text of state entry match, | ||
108 | scriptCopy += eventmatches[pos]; pos++; | ||
109 | |||
110 | // Returns which state we're matching and writes a method call to the end of the above state_entry | ||
111 | scriptCopy += "osSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++; | ||
112 | |||
113 | // Remove the state from the unused list. There might be more states matched then defined, so we | ||
114 | // check if the state was defined first | ||
115 | if (unUsedStates.Contains(eventmatches[pos])) | ||
116 | unUsedStates.Remove(eventmatches[pos]); | ||
117 | |||
118 | // adds the remainder of the script. | ||
119 | if ((pos + 1) == endloop) | ||
120 | { | ||
121 | pos++; | ||
122 | scriptCopy += eventmatches[pos++]; | ||
123 | } | ||
124 | |||
125 | } | ||
126 | |||
127 | // states with missing state_entry blocks won't publish their events, | ||
128 | // so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event | ||
129 | foreach (string state in unUsedStates) | ||
130 | { | ||
131 | // Write the remainder states out into a blank state entry with the event setting routine | ||
132 | scriptCopy = "public void " + state + "_event_state_entry() {tosSetStateEvents((int)" + (int)state_events[state] + ");} " + scriptCopy; | ||
133 | } | ||
134 | |||
135 | // save modified script. | ||
136 | unUsedStates.Clear(); | ||
137 | state_events.Clear(); | ||
138 | return scriptCopy; | ||
139 | } | ||
140 | |||
141 | public static string ReWriteScriptWithPublishedEventsJS(string Script) | ||
142 | { | ||
143 | Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>(); | ||
144 | // Finds out which events are in the script and writes a method call with the events in each state_entry event | ||
145 | |||
146 | // Note the (?:)? block optional, and not returning a group. Less greedy then .* | ||
147 | |||
148 | string[] eventmatches = new string[0]; | ||
149 | //Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{"); | ||
150 | eventmatches = Regex.Split(Script, @"function \s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^\{]+)?\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
151 | for (int pos = 0; pos < eventmatches.GetUpperBound(0); pos++) | ||
152 | { | ||
153 | pos++; // garbage | ||
154 | |||
155 | string statea = eventmatches[pos]; pos++; | ||
156 | string eventa = eventmatches[pos]; | ||
157 | scriptEvents storedEventsForState = scriptEvents.None; | ||
158 | if (state_events.ContainsKey(statea)) | ||
159 | { | ||
160 | storedEventsForState = state_events[statea]; | ||
161 | state_events[statea] |= convertnametoFlag(eventa); | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | state_events.Add(statea, convertnametoFlag(eventa)); | ||
166 | } | ||
167 | Console.WriteLine("State:" + statea + ", event: " + eventa); | ||
168 | } | ||
169 | Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0)); | ||
170 | // Add namespace, class name and inheritance | ||
171 | |||
172 | // Looking *ONLY* for state entry events | ||
173 | string scriptCopy = ""; | ||
174 | |||
175 | //Only match State_Entry events now | ||
176 | // Note the whole regex is a group, then we have the state this entry belongs to. | ||
177 | eventmatches = Regex.Split(Script, @"(function \s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
178 | int endloop = eventmatches.GetUpperBound(0); | ||
179 | |||
180 | // Add all the states to a list of | ||
181 | List<string> unUsedStates = new List<string>(); | ||
182 | |||
183 | foreach (string state in state_events.Keys) | ||
184 | { | ||
185 | unUsedStates.Add(state); | ||
186 | } | ||
187 | |||
188 | // If endloop is 0, then there are no state entry events in the entire script. | ||
189 | // Stick a default state entry in there. | ||
190 | if (endloop == 0) | ||
191 | { | ||
192 | if (state_events.ContainsKey("default")) | ||
193 | { | ||
194 | scriptCopy = "function default_event_state_entry() {osSetStateEvents(" + (int)state_events["default"] + "); } " + Script; | ||
195 | unUsedStates.Remove("default"); | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details."); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | // Loop over state entry events and rewrite the first line to define the events the state listens for. | ||
204 | for (int pos = 0; pos < endloop; pos++) | ||
205 | { | ||
206 | // Returns text before state entry match, | ||
207 | scriptCopy += eventmatches[pos]; pos++; | ||
208 | |||
209 | // Returns text of state entry match, | ||
210 | scriptCopy += eventmatches[pos]; pos++; | ||
211 | |||
212 | // Returns which state we're matching and writes a method call to the end of the above state_entry | ||
213 | scriptCopy += "osSetStateEvents(" + (int)state_events[eventmatches[pos]] + ");"; //pos++; | ||
214 | |||
215 | // Remove the state from the unused list. There might be more states matched then defined, so we | ||
216 | // check if the state was defined first | ||
217 | if (unUsedStates.Contains(eventmatches[pos])) | ||
218 | unUsedStates.Remove(eventmatches[pos]); | ||
219 | |||
220 | // adds the remainder of the script. | ||
221 | if ((pos + 1) == endloop) | ||
222 | { | ||
223 | pos++; | ||
224 | scriptCopy += eventmatches[pos++]; | ||
225 | } | ||
226 | |||
227 | } | ||
228 | |||
229 | // states with missing state_entry blocks won't publish their events, | ||
230 | // so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event | ||
231 | foreach (string state in unUsedStates) | ||
232 | { | ||
233 | // Write the remainder states out into a blank state entry with the event setting routine | ||
234 | scriptCopy = "function " + state + "_event_state_entry() {tosSetStateEvents(" + (int)state_events[state] + ");} " + scriptCopy; | ||
235 | } | ||
236 | |||
237 | // save modified script. | ||
238 | unUsedStates.Clear(); | ||
239 | state_events.Clear(); | ||
240 | return scriptCopy; | ||
241 | } | ||
242 | |||
243 | |||
244 | public static string ReWriteScriptWithPublishedEventsVB(string Script) | ||
245 | { | ||
246 | Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>(); | ||
247 | // Finds out which events are in the script and writes a method call with the events in each state_entry event | ||
248 | |||
249 | // Note the (?:)? block optional, and not returning a group. Less greedy then .* | ||
250 | |||
251 | string[] eventmatches = new string[0]; | ||
252 | //Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{"); | ||
253 | eventmatches = Regex.Split(Script, @"Public Sub\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^()])", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
254 | for (int pos = 0; pos < eventmatches.GetUpperBound(0); pos++) | ||
255 | { | ||
256 | pos++; // garbage | ||
257 | |||
258 | string statea = eventmatches[pos]; pos++; | ||
259 | string eventa = eventmatches[pos]; | ||
260 | scriptEvents storedEventsForState = scriptEvents.None; | ||
261 | if (state_events.ContainsKey(statea)) | ||
262 | { | ||
263 | storedEventsForState = state_events[statea]; | ||
264 | state_events[statea] |= convertnametoFlag(eventa); | ||
265 | } | ||
266 | else | ||
267 | { | ||
268 | state_events.Add(statea, convertnametoFlag(eventa)); | ||
269 | } | ||
270 | Console.WriteLine("State:" + statea + ", event: " + eventa); | ||
271 | } | ||
272 | Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0)); | ||
273 | // Add namespace, class name and inheritance | ||
274 | |||
275 | // Looking *ONLY* for state entry events | ||
276 | string scriptCopy = ""; | ||
277 | |||
278 | //Only match State_Entry events now | ||
279 | // Note the whole regex is a group, then we have the state this entry belongs to. | ||
280 | eventmatches = Regex.Split(Script, @"(Public Sub\s([^_]+)_event_state_entry(?:\s+)?\(\))", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
281 | int endloop = eventmatches.GetUpperBound(0); | ||
282 | |||
283 | // Add all the states to a list of | ||
284 | List<string> unUsedStates = new List<string>(); | ||
285 | |||
286 | foreach (string state in state_events.Keys) | ||
287 | { | ||
288 | unUsedStates.Add(state); | ||
289 | } | ||
290 | |||
291 | // If endloop is 0, then there are no state entry events in the entire script. | ||
292 | // Stick a default state entry in there. | ||
293 | if (endloop == 0) | ||
294 | { | ||
295 | if (state_events.ContainsKey("default")) | ||
296 | { | ||
297 | scriptCopy = "function default_event_state_entry() {osSetStateEvents(" + (int)state_events["default"] + "); } " + Script; | ||
298 | unUsedStates.Remove("default"); | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details."); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | // Loop over state entry events and rewrite the first line to define the events the state listens for. | ||
307 | for (int pos = 0; pos < endloop; pos++) | ||
308 | { | ||
309 | // Returns text before state entry match, | ||
310 | scriptCopy += eventmatches[pos]; pos++; | ||
311 | |||
312 | // Returns text of state entry match, | ||
313 | scriptCopy += eventmatches[pos]; pos++; | ||
314 | |||
315 | // Returns which state we're matching and writes a method call to the end of the above state_entry | ||
316 | scriptCopy += "osSetStateEvents(" + (int)state_events[eventmatches[pos]] + ");"; //pos++; | ||
317 | |||
318 | // Remove the state from the unused list. There might be more states matched then defined, so we | ||
319 | // check if the state was defined first | ||
320 | if (unUsedStates.Contains(eventmatches[pos])) | ||
321 | unUsedStates.Remove(eventmatches[pos]); | ||
322 | |||
323 | // adds the remainder of the script. | ||
324 | if ((pos + 1) == endloop) | ||
325 | { | ||
326 | pos++; | ||
327 | scriptCopy += eventmatches[pos++]; | ||
328 | } | ||
329 | |||
330 | } | ||
331 | |||
332 | // states with missing state_entry blocks won't publish their events, | ||
333 | // so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event | ||
334 | foreach (string state in unUsedStates) | ||
335 | { | ||
336 | // Write the remainder states out into a blank state entry with the event setting routine | ||
337 | scriptCopy = "function " + state + "_event_state_entry() {tosSetStateEvents(" + (int)state_events[state] + ");} " + scriptCopy; | ||
338 | } | ||
339 | |||
340 | // save modified script. | ||
341 | unUsedStates.Clear(); | ||
342 | state_events.Clear(); | ||
343 | return scriptCopy; | ||
344 | } | ||
345 | |||
346 | |||
347 | private static scriptEvents convertnametoFlag(string eventname) | ||
348 | { | ||
349 | switch (eventname) | ||
350 | { | ||
351 | case "attach": | ||
352 | return scriptEvents.attach; | ||
353 | //break; | ||
354 | // case "at_rot_target": | ||
355 | //return (long)scriptEvents.at_rot_target; | ||
356 | //break; | ||
357 | case "at_target": | ||
358 | return scriptEvents.at_target; | ||
359 | //break; | ||
360 | //case "changed": | ||
361 | //return (long)scriptEvents.changed; | ||
362 | //break; | ||
363 | case "collision": | ||
364 | return scriptEvents.collision; | ||
365 | // break; | ||
366 | case "collision_end": | ||
367 | return scriptEvents.collision_end; | ||
368 | //break; | ||
369 | case "collision_start": | ||
370 | return scriptEvents.collision_start; | ||
371 | // break; | ||
372 | case "control": | ||
373 | return scriptEvents.control; | ||
374 | //break; | ||
375 | case "dataserver": | ||
376 | return scriptEvents.dataserver; | ||
377 | // break; | ||
378 | case "email": | ||
379 | return scriptEvents.email; | ||
380 | // break; | ||
381 | case "http_response": | ||
382 | return scriptEvents.http_response; | ||
383 | // break; | ||
384 | case "land_collision": | ||
385 | return scriptEvents.land_collision; | ||
386 | // break; | ||
387 | case "land_collision_end": | ||
388 | return scriptEvents.land_collision_end; | ||
389 | // break; | ||
390 | case "land_collision_start": | ||
391 | return scriptEvents.land_collision_start; | ||
392 | // break; | ||
393 | //case "link_message": | ||
394 | //return scriptEvents.link_message; | ||
395 | // break; | ||
396 | case "listen": | ||
397 | return scriptEvents.listen; | ||
398 | // break; | ||
399 | case "money": | ||
400 | return scriptEvents.money; | ||
401 | // break; | ||
402 | case "moving_end": | ||
403 | return scriptEvents.moving_end; | ||
404 | // break; | ||
405 | case "moving_start": | ||
406 | return scriptEvents.moving_start; | ||
407 | // break; | ||
408 | case "not_at_rot_target": | ||
409 | return scriptEvents.not_at_rot_target; | ||
410 | // break; | ||
411 | case "not_at_target": | ||
412 | return scriptEvents.not_at_target; | ||
413 | // break; | ||
414 | // case "no_sensor": | ||
415 | //return (long)scriptEvents.no_sensor; | ||
416 | //break; | ||
417 | //case "on_rez": | ||
418 | //return (long)scriptEvents.on_rez; | ||
419 | // break; | ||
420 | case "remote_data": | ||
421 | return scriptEvents.remote_data; | ||
422 | // break; | ||
423 | case "run_time_permissions": | ||
424 | return scriptEvents.run_time_permissions; | ||
425 | // break; | ||
426 | //case "sensor": | ||
427 | //return (long)scriptEvents.sensor; | ||
428 | // break; | ||
429 | case "state_entry": | ||
430 | return scriptEvents.state_entry; | ||
431 | // break; | ||
432 | case "state_exit": | ||
433 | return scriptEvents.state_exit; | ||
434 | // break; | ||
435 | case "timer": | ||
436 | return scriptEvents.timer; | ||
437 | // break; | ||
438 | case "touch": | ||
439 | return scriptEvents.touch; | ||
440 | // break; | ||
441 | case "touch_end": | ||
442 | return scriptEvents.touch_end; | ||
443 | // break; | ||
444 | case "touch_start": | ||
445 | return scriptEvents.touch_start; | ||
446 | // break; | ||
447 | case "object_rez": | ||
448 | return scriptEvents.object_rez; | ||
449 | default: | ||
450 | return 0; | ||
451 | //break; | ||
452 | } | ||
453 | //return 0; | ||
454 | } | ||
455 | } | ||
456 | [Flags] | ||
457 | public enum scriptEvents : int | ||
458 | { | ||
459 | None = 0, | ||
460 | attach = 1, | ||
461 | collision = 15, | ||
462 | collision_end = 32, | ||
463 | collision_start = 64, | ||
464 | control = 128, | ||
465 | dataserver = 256, | ||
466 | email = 512, | ||
467 | http_response = 1024, | ||
468 | land_collision = 2048, | ||
469 | land_collision_end = 4096, | ||
470 | land_collision_start = 8192, | ||
471 | at_target = 16384, | ||
472 | listen = 32768, | ||
473 | money = 65536, | ||
474 | moving_end = 131072, | ||
475 | moving_start = 262144, | ||
476 | not_at_rot_target = 524288, | ||
477 | not_at_target = 1048576, | ||
478 | remote_data = 8388608, | ||
479 | run_time_permissions = 268435456, | ||
480 | state_entry = 1073741824, | ||
481 | state_exit = 2, | ||
482 | timer = 4, | ||
483 | touch = 8, | ||
484 | touch_end = 536870912, | ||
485 | touch_start = 2097152, | ||
486 | object_rez = 4194304 | ||
487 | } | ||
488 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index f1e6ebf..06be20e 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | |||
@@ -42,16 +42,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
42 | //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); | 42 | //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); |
43 | private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); | 43 | private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); |
44 | private Dictionary<string, string> quotes = new Dictionary<string, string>(); | 44 | private Dictionary<string, string> quotes = new Dictionary<string, string>(); |
45 | private Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>(); | 45 | |
46 | 46 | ||
47 | public LSL2CSConverter() | 47 | public LSL2CSConverter() |
48 | { | 48 | { |
49 | // Only the types we need to convert | 49 | // Only the types we need to convert |
50 | dataTypes.Add("void", "void"); | 50 | dataTypes.Add("void", "void"); |
51 | dataTypes.Add("integer", "int"); | 51 | dataTypes.Add("integer", "LSL_Types.LSLInteger"); |
52 | dataTypes.Add("float", "double"); | 52 | dataTypes.Add("float", "double"); |
53 | dataTypes.Add("string", "string"); | 53 | dataTypes.Add("string", "LSL_Types.LSLString"); |
54 | dataTypes.Add("key", "string"); | 54 | dataTypes.Add("key", "LSL_Types.LSLString"); |
55 | dataTypes.Add("vector", "LSL_Types.Vector3"); | 55 | dataTypes.Add("vector", "LSL_Types.Vector3"); |
56 | dataTypes.Add("rotation", "LSL_Types.Quaternion"); | 56 | dataTypes.Add("rotation", "LSL_Types.Quaternion"); |
57 | dataTypes.Add("list", "LSL_Types.list"); | 57 | dataTypes.Add("list", "LSL_Types.list"); |
@@ -314,100 +314,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | // Finds out which events are in the script and writes a method call with the events in each state_entry event | 317 | |
318 | |||
319 | // Note the (?:)? block optional, and not returning a group. Less greedy then .* | ||
320 | |||
321 | string[] eventmatches = new string[0]; | ||
322 | //Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{"); | ||
323 | eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^\{]+)?\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
324 | for (int pos = 0; pos<eventmatches.GetUpperBound(0);pos++) | ||
325 | { | ||
326 | pos++; // garbage | ||
327 | |||
328 | string statea = eventmatches[pos]; pos++; | ||
329 | string eventa = eventmatches[pos]; | ||
330 | scriptEvents storedEventsForState = scriptEvents.None; | ||
331 | if (state_events.ContainsKey(statea)) | ||
332 | { | ||
333 | storedEventsForState = state_events[statea]; | ||
334 | state_events[statea] |= convertnametoFlag(eventa); | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | state_events.Add(statea, convertnametoFlag(eventa)); | ||
339 | } | ||
340 | Console.WriteLine("State:" + statea + ", event: " + eventa); | ||
341 | } | ||
342 | Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0)); | ||
343 | // Add namespace, class name and inheritance | ||
344 | |||
345 | // Looking *ONLY* for state entry events | ||
346 | string scriptCopy = ""; | ||
347 | |||
348 | //Only match State_Entry events now | ||
349 | // Note the whole regex is a group, then we have the state this entry belongs to. | ||
350 | eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
351 | int endloop = eventmatches.GetUpperBound(0); | ||
352 | |||
353 | // Add all the states to a list of | ||
354 | List<string> unUsedStates = new List<string>(); | ||
355 | foreach (string state in state_events.Keys) | ||
356 | { | ||
357 | unUsedStates.Add(state); | ||
358 | } | ||
359 | |||
360 | // If endloop is 0, then there are no state entry events in the entire script. | ||
361 | // Stick a default state entry in there. | ||
362 | if (endloop == 0) | ||
363 | { | ||
364 | if (state_events.ContainsKey("default")) | ||
365 | { | ||
366 | scriptCopy = "\r\n// programmatically added this state entry event.\r\n\r\npublic void default_event_state_entry() {\r\n\tosSetStateEvents((int)" + (int)state_events["default"] + ");\r\n }\r\n\r\n " + Script; | ||
367 | unUsedStates.Remove("default"); | ||
368 | } | ||
369 | else | ||
370 | { | ||
371 | throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details."); | ||
372 | } | ||
373 | } | ||
374 | |||
375 | // Loop over state entry events and rewrite the first line to define the events the state listens for. | ||
376 | for (int pos = 0; pos < endloop; pos++) | ||
377 | { | ||
378 | // Returns text before state entry match, | ||
379 | scriptCopy += eventmatches[pos]; pos++; | ||
380 | |||
381 | // Returns text of state entry match, | ||
382 | scriptCopy += eventmatches[pos]; pos++; | ||
383 | |||
384 | // Returns which state we're matching and writes a method call to the end of the above state_entry | ||
385 | scriptCopy += "\r\n\t\tosSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++; | ||
386 | |||
387 | // Remove the state from the unused list. There might be more states matched then defined, so we | ||
388 | // check if the state was defined first | ||
389 | if (unUsedStates.Contains(eventmatches[pos])) | ||
390 | unUsedStates.Remove(eventmatches[pos]); | ||
391 | |||
392 | // adds the remainder of the script. | ||
393 | if ((pos + 1) == endloop) | ||
394 | { | ||
395 | pos++; | ||
396 | scriptCopy += eventmatches[pos++]; | ||
397 | } | ||
398 | |||
399 | } | ||
400 | |||
401 | // states with missing state_entry blocks won't publish their events, | ||
402 | // so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event | ||
403 | foreach (string state in unUsedStates) | ||
404 | { | ||
405 | // Write the remainder states out into a blank state entry with the event setting routine | ||
406 | scriptCopy = "\r\n// programmatically added this state entry event.\r\n\r\npublic void " + state + "_event_state_entry() {\r\n\tosSetStateEvents((int)" + (int)state_events[state] + ");\r\n}\r\n\r\n " + scriptCopy; | ||
407 | } | ||
408 | |||
409 | // save modified script. | ||
410 | Script = scriptCopy; | ||
411 | //System.Console.WriteLine(Script); | 318 | //System.Console.WriteLine(Script); |
412 | Return = String.Empty;// + | 319 | Return = String.Empty;// + |
413 | //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; | 320 | //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; |
@@ -421,152 +328,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
421 | //Return += @"public Script() { } "; | 328 | //Return += @"public Script() { } "; |
422 | Return += Script; | 329 | Return += Script; |
423 | //Return += "} }\r\n"; | 330 | //Return += "} }\r\n"; |
424 | unUsedStates.Clear(); | 331 | |
425 | state_events.Clear(); | ||
426 | quotes.Clear(); | 332 | quotes.Clear(); |
427 | 333 | ||
428 | return Return; | 334 | return Return; |
429 | } | 335 | } |
430 | public scriptEvents convertnametoFlag(string eventname) | 336 | |
431 | { | ||
432 | switch (eventname) | ||
433 | { | ||
434 | case "attach": | ||
435 | return scriptEvents.attach; | ||
436 | //break; | ||
437 | // case "at_rot_target": | ||
438 | //return (long)scriptEvents.at_rot_target; | ||
439 | //break; | ||
440 | case "at_target": | ||
441 | return scriptEvents.at_target; | ||
442 | //break; | ||
443 | //case "changed": | ||
444 | //return (long)scriptEvents.changed; | ||
445 | //break; | ||
446 | case "collision": | ||
447 | return scriptEvents.collision; | ||
448 | // break; | ||
449 | case "collision_end": | ||
450 | return scriptEvents.collision_end; | ||
451 | //break; | ||
452 | case "collision_start": | ||
453 | return scriptEvents.collision_start; | ||
454 | // break; | ||
455 | case "control": | ||
456 | return scriptEvents.control; | ||
457 | //break; | ||
458 | case "dataserver": | ||
459 | return scriptEvents.dataserver; | ||
460 | // break; | ||
461 | case "email": | ||
462 | return scriptEvents.email; | ||
463 | // break; | ||
464 | case "http_response": | ||
465 | return scriptEvents.http_response; | ||
466 | // break; | ||
467 | case "land_collision": | ||
468 | return scriptEvents.land_collision; | ||
469 | // break; | ||
470 | case "land_collision_end": | ||
471 | return scriptEvents.land_collision_end; | ||
472 | // break; | ||
473 | case "land_collision_start": | ||
474 | return scriptEvents.land_collision_start; | ||
475 | // break; | ||
476 | //case "link_message": | ||
477 | //return scriptEvents.link_message; | ||
478 | // break; | ||
479 | case "listen": | ||
480 | return scriptEvents.listen; | ||
481 | // break; | ||
482 | case "money": | ||
483 | return scriptEvents.money; | ||
484 | // break; | ||
485 | case "moving_end": | ||
486 | return scriptEvents.moving_end; | ||
487 | // break; | ||
488 | case "moving_start": | ||
489 | return scriptEvents.moving_start; | ||
490 | // break; | ||
491 | case "not_at_rot_target": | ||
492 | return scriptEvents.not_at_rot_target; | ||
493 | // break; | ||
494 | case "not_at_target": | ||
495 | return scriptEvents.not_at_target; | ||
496 | // break; | ||
497 | // case "no_sensor": | ||
498 | //return (long)scriptEvents.no_sensor; | ||
499 | //break; | ||
500 | //case "on_rez": | ||
501 | //return (long)scriptEvents.on_rez; | ||
502 | // break; | ||
503 | case "remote_data": | ||
504 | return scriptEvents.remote_data; | ||
505 | // break; | ||
506 | case "run_time_permissions": | ||
507 | return scriptEvents.run_time_permissions; | ||
508 | // break; | ||
509 | //case "sensor": | ||
510 | //return (long)scriptEvents.sensor; | ||
511 | // break; | ||
512 | case "state_entry": | ||
513 | return scriptEvents.state_entry; | ||
514 | // break; | ||
515 | case "state_exit": | ||
516 | return scriptEvents.state_exit; | ||
517 | // break; | ||
518 | case "timer": | ||
519 | return scriptEvents.timer; | ||
520 | // break; | ||
521 | case "touch": | ||
522 | return scriptEvents.touch; | ||
523 | // break; | ||
524 | case "touch_end": | ||
525 | return scriptEvents.touch_end; | ||
526 | // break; | ||
527 | case "touch_start": | ||
528 | return scriptEvents.touch_start; | ||
529 | // break; | ||
530 | case "object_rez": | ||
531 | return scriptEvents.object_rez; | ||
532 | default: | ||
533 | return 0; | ||
534 | //break; | ||
535 | } | ||
536 | //return 0; | ||
537 | } | ||
538 | } | 337 | } |
539 | 338 | ||
540 | [Flags] | 339 | |
541 | public enum scriptEvents : int | 340 | } |
542 | { | ||
543 | None = 0, | ||
544 | attach = 1, | ||
545 | collision = 15, | ||
546 | collision_end = 32, | ||
547 | collision_start = 64, | ||
548 | control = 128, | ||
549 | dataserver = 256, | ||
550 | email = 512, | ||
551 | http_response = 1024, | ||
552 | land_collision = 2048, | ||
553 | land_collision_end = 4096, | ||
554 | land_collision_start = 8192, | ||
555 | at_target = 16384, | ||
556 | listen = 32768, | ||
557 | money = 65536, | ||
558 | moving_end = 131072, | ||
559 | moving_start = 262144, | ||
560 | not_at_rot_target = 524288, | ||
561 | not_at_target = 1048576, | ||
562 | remote_data = 8388608, | ||
563 | run_time_permissions = 268435456, | ||
564 | state_entry = 1073741824, | ||
565 | state_exit = 2, | ||
566 | timer = 4, | ||
567 | touch = 8, | ||
568 | touch_end = 536870912, | ||
569 | touch_start = 2097152, | ||
570 | object_rez = 4194304 | ||
571 | } | ||
572 | } \ No newline at end of file | ||