diff options
author | Melanie | 2013-01-24 00:25:08 +0000 |
---|---|---|
committer | Melanie | 2013-01-24 00:25:08 +0000 |
commit | be4c8c4931637b7b0849d12c634599c702483364 (patch) | |
tree | 9a49626efcc10f1272b37176616a41476b044045 /OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | |
parent | Merge branch 'master' into careminster (diff) | |
parent | Merge branch 'master' into cooptermination (diff) | |
download | opensim-SC-be4c8c4931637b7b0849d12c634599c702483364.zip opensim-SC-be4c8c4931637b7b0849d12c634599c702483364.tar.gz opensim-SC-be4c8c4931637b7b0849d12c634599c702483364.tar.bz2 opensim-SC-be4c8c4931637b7b0849d12c634599c702483364.tar.xz |
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index 03be2ab..002e852 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | |||
@@ -31,6 +31,7 @@ using System.Collections.Generic; | |||
31 | using System.Globalization; | 31 | using System.Globalization; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Linq; | ||
34 | using System.Text; | 35 | using System.Text; |
35 | using Microsoft.CSharp; | 36 | using Microsoft.CSharp; |
36 | //using Microsoft.JScript; | 37 | //using Microsoft.JScript; |
@@ -72,6 +73,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
72 | private bool CompileWithDebugInformation; | 73 | private bool CompileWithDebugInformation; |
73 | private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase); | 74 | private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase); |
74 | private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase); | 75 | private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase); |
76 | private bool m_insertCoopTerminationCalls; | ||
75 | 77 | ||
76 | private string FilePrefix; | 78 | private string FilePrefix; |
77 | private string ScriptEnginesPath = null; | 79 | private string ScriptEnginesPath = null; |
@@ -95,20 +97,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
95 | private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps = | 97 | private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps = |
96 | new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>(); | 98 | new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>(); |
97 | 99 | ||
100 | public bool in_startup = true; | ||
101 | |||
98 | public Compiler(IScriptEngine scriptEngine) | 102 | public Compiler(IScriptEngine scriptEngine) |
99 | { | 103 | { |
100 | m_scriptEngine = scriptEngine;; | 104 | m_scriptEngine = scriptEngine; |
101 | ScriptEnginesPath = scriptEngine.ScriptEnginePath; | 105 | ScriptEnginesPath = scriptEngine.ScriptEnginePath; |
102 | ReadConfig(); | 106 | ReadConfig(); |
103 | } | 107 | } |
104 | 108 | ||
105 | public bool in_startup = true; | ||
106 | public void ReadConfig() | 109 | public void ReadConfig() |
107 | { | 110 | { |
108 | // Get some config | 111 | // Get some config |
109 | WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false); | 112 | WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", false); |
110 | CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); | 113 | CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true); |
111 | bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true); | 114 | bool DeleteScriptsOnStartup = m_scriptEngine.Config.GetBoolean("DeleteScriptsOnStartup", true); |
115 | m_insertCoopTerminationCalls = m_scriptEngine.Config.GetString("ScriptStopStrategy", "abort") == "co-op"; | ||
112 | 116 | ||
113 | // Get file prefix from scriptengine name and make it file system safe: | 117 | // Get file prefix from scriptengine name and make it file system safe: |
114 | FilePrefix = "CommonCompiler"; | 118 | FilePrefix = "CommonCompiler"; |
@@ -386,7 +390,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
386 | if (language == enumCompileType.lsl) | 390 | if (language == enumCompileType.lsl) |
387 | { | 391 | { |
388 | // Its LSL, convert it to C# | 392 | // Its LSL, convert it to C# |
389 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms); | 393 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls); |
390 | compileScript = LSL_Converter.Convert(Script); | 394 | compileScript = LSL_Converter.Convert(Script); |
391 | 395 | ||
392 | // copy converter warnings into our warnings. | 396 | // copy converter warnings into our warnings. |
@@ -411,16 +415,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
411 | { | 415 | { |
412 | case enumCompileType.cs: | 416 | case enumCompileType.cs: |
413 | case enumCompileType.lsl: | 417 | case enumCompileType.lsl: |
414 | compileScript = CreateCSCompilerScript(compileScript); | 418 | compileScript = CreateCSCompilerScript( |
419 | compileScript, | ||
420 | m_scriptEngine.ScriptClassName, | ||
421 | m_scriptEngine.ScriptBaseClassName, | ||
422 | m_scriptEngine.ScriptBaseClassParameters); | ||
415 | break; | 423 | break; |
416 | case enumCompileType.vb: | 424 | case enumCompileType.vb: |
417 | compileScript = CreateVBCompilerScript(compileScript); | 425 | compileScript = CreateVBCompilerScript( |
426 | compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName); | ||
418 | break; | 427 | break; |
419 | // case enumCompileType.js: | 428 | // case enumCompileType.js: |
420 | // compileScript = CreateJSCompilerScript(compileScript); | 429 | // compileScript = CreateJSCompilerScript(compileScript, m_scriptEngine.ScriptBaseClassName); |
421 | // break; | 430 | // break; |
422 | case enumCompileType.yp: | 431 | case enumCompileType.yp: |
423 | compileScript = CreateYPCompilerScript(compileScript); | 432 | compileScript = CreateYPCompilerScript( |
433 | compileScript, m_scriptEngine.ScriptClassName,m_scriptEngine.ScriptBaseClassName); | ||
424 | break; | 434 | break; |
425 | } | 435 | } |
426 | 436 | ||
@@ -451,43 +461,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
451 | // return compileScript; | 461 | // return compileScript; |
452 | // } | 462 | // } |
453 | 463 | ||
454 | private static string CreateCSCompilerScript(string compileScript) | 464 | private static string CreateCSCompilerScript( |
465 | string compileScript, string className, string baseClassName, ParameterInfo[] constructorParameters) | ||
455 | { | 466 | { |
456 | compileScript = String.Empty + | 467 | compileScript = string.Format( |
457 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + | 468 | @"using OpenSim.Region.ScriptEngine.Shared; |
458 | String.Empty + "namespace SecondLife { " + | 469 | using System.Collections.Generic; |
459 | String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + | 470 | |
460 | @"public Script() { } " + | 471 | namespace SecondLife |
461 | compileScript + | 472 | {{ |
462 | "} }\r\n"; | 473 | public class {0} : {1} |
474 | {{ | ||
475 | public {0}({2}) : base({3}) {{}} | ||
476 | {4} | ||
477 | }} | ||
478 | }}", | ||
479 | className, | ||
480 | baseClassName, | ||
481 | constructorParameters != null | ||
482 | ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.ToString())) | ||
483 | : "", | ||
484 | constructorParameters != null | ||
485 | ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.Name)) | ||
486 | : "", | ||
487 | compileScript); | ||
488 | |||
463 | return compileScript; | 489 | return compileScript; |
464 | } | 490 | } |
465 | 491 | ||
466 | private static string CreateYPCompilerScript(string compileScript) | 492 | private static string CreateYPCompilerScript(string compileScript, string className, string baseClassName) |
467 | { | 493 | { |
468 | compileScript = String.Empty + | 494 | compileScript = String.Empty + |
469 | "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " + | 495 | "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " + |
470 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + | 496 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + |
471 | String.Empty + "namespace SecondLife { " + | 497 | String.Empty + "namespace SecondLife { " + |
472 | String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + | 498 | String.Empty + "public class " + className + " : " + baseClassName + " { \r\n" + |
473 | //@"public Script() { } " + | 499 | //@"public Script() { } " + |
474 | @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " + | 500 | @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " + |
475 | @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " + | 501 | @"public " + className + "() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " + |
476 | |||
477 | compileScript + | 502 | compileScript + |
478 | "} }\r\n"; | 503 | "} }\r\n"; |
504 | |||
479 | return compileScript; | 505 | return compileScript; |
480 | } | 506 | } |
481 | 507 | ||
482 | private static string CreateVBCompilerScript(string compileScript) | 508 | private static string CreateVBCompilerScript(string compileScript, string className, string baseClassName) |
483 | { | 509 | { |
484 | compileScript = String.Empty + | 510 | compileScript = String.Empty + |
485 | "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " + | 511 | "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " + |
486 | String.Empty + "NameSpace SecondLife:" + | 512 | String.Empty + "NameSpace SecondLife:" + |
487 | String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass: " + | 513 | String.Empty + "Public Class " + className + ": Inherits " + baseClassName + |
488 | "\r\nPublic Sub New()\r\nEnd Sub: " + | 514 | "\r\nPublic Sub New()\r\nEnd Sub: " + |
489 | compileScript + | 515 | compileScript + |
490 | ":End Class :End Namespace\r\n"; | 516 | ":End Class :End Namespace\r\n"; |
517 | |||
491 | return compileScript; | 518 | return compileScript; |
492 | } | 519 | } |
493 | 520 | ||
@@ -549,6 +576,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
549 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, | 576 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, |
550 | "OpenMetaverseTypes.dll")); | 577 | "OpenMetaverseTypes.dll")); |
551 | 578 | ||
579 | if (m_scriptEngine.ScriptReferencedAssemblies != null) | ||
580 | Array.ForEach<string>( | ||
581 | m_scriptEngine.ScriptReferencedAssemblies, | ||
582 | a => parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, a))); | ||
583 | |||
552 | if (lang == enumCompileType.yp) | 584 | if (lang == enumCompileType.yp) |
553 | { | 585 | { |
554 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, | 586 | parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, |