aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs488
2 files changed, 1 insertions, 489 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index dad1b23..944f9e7 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -319,7 +319,7 @@ 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); 322
323 323
324 compileScript = String.Empty + 324 compileScript = String.Empty +
325 "using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;\r\n" + 325 "using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;\r\n" +
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs
deleted file mode 100644
index 46ba850..0000000
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/EventReaderRewriter.cs
+++ /dev/null
@@ -1,488 +0,0 @@
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
29using System;
30using System.Collections.Generic;
31using System.Text.RegularExpressions;
32
33namespace 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}