aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-04-30 03:36:13 +0000
committerTeravus Ovares2008-04-30 03:36:13 +0000
commit36bf16d35e928a338c932feeec42c0c8f35d8846 (patch)
tree06f11a4c546fce85fe1504fce08a09dd4bdebb06 /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
parent* Disabled IntergridModule until a Mono bug can be isolated. (diff)
downloadopensim-SC-36bf16d35e928a338c932feeec42c0c8f35d8846.zip
opensim-SC-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.gz
opensim-SC-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.bz2
opensim-SC-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 '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs250
1 files changed, 9 insertions, 241 deletions
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