aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
diff options
context:
space:
mode:
authorSean Dague2007-09-17 12:52:03 +0000
committerSean Dague2007-09-17 12:52:03 +0000
commitb8d9737a47696952bedec33dface8f18df47341f (patch)
tree9279f45510f8a9285ac5b9c9165ab6c741009eac /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
parentI think this is the last bits for a consistant pristine (diff)
downloadopensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.zip
opensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.tar.gz
opensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.tar.bz2
opensim-SC_OLD-b8d9737a47696952bedec33dface8f18df47341f.tar.xz
fixing me some line endings
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs240
1 files changed, 120 insertions, 120 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index 78cfd21..6603323 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -1,120 +1,120 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.IO; 4using System.IO;
5using Microsoft.CSharp; 5using Microsoft.CSharp;
6using System.CodeDom.Compiler; 6using System.CodeDom.Compiler;
7using System.Reflection; 7using System.Reflection;
8 8
9namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL 9namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
10{ 10{
11 11
12 public class Compiler 12 public class Compiler
13 { 13 {
14 private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); 14 private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
15 private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); 15 private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
16 private static UInt64 scriptCompileCounter = 0; 16 private static UInt64 scriptCompileCounter = 0;
17 //private ICodeCompiler icc = codeProvider.CreateCompiler(); 17 //private ICodeCompiler icc = codeProvider.CreateCompiler();
18 public string CompileFromFile(string LSOFileName) 18 public string CompileFromFile(string LSOFileName)
19 { 19 {
20 switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) 20 switch (System.IO.Path.GetExtension(LSOFileName).ToLower())
21 { 21 {
22 case ".txt": 22 case ".txt":
23 case ".lsl": 23 case ".lsl":
24 Common.SendToDebug("Source code is LSL, converting to CS"); 24 Common.SendToDebug("Source code is LSL, converting to CS");
25 return CompileFromLSLText(File.ReadAllText(LSOFileName)); 25 return CompileFromLSLText(File.ReadAllText(LSOFileName));
26 case ".cs": 26 case ".cs":
27 Common.SendToDebug("Source code is CS"); 27 Common.SendToDebug("Source code is CS");
28 return CompileFromCSText(File.ReadAllText(LSOFileName)); 28 return CompileFromCSText(File.ReadAllText(LSOFileName));
29 default: 29 default:
30 throw new Exception("Unknown script type."); 30 throw new Exception("Unknown script type.");
31 } 31 }
32 } 32 }
33 /// <summary> 33 /// <summary>
34 /// Converts script from LSL to CS and calls CompileFromCSText 34 /// Converts script from LSL to CS and calls CompileFromCSText
35 /// </summary> 35 /// </summary>
36 /// <param name="Script">LSL script</param> 36 /// <param name="Script">LSL script</param>
37 /// <returns>Filename to .dll assembly</returns> 37 /// <returns>Filename to .dll assembly</returns>
38 public string CompileFromLSLText(string Script) 38 public string CompileFromLSLText(string Script)
39 { 39 {
40 if (Script.Substring(0, 4).ToLower() == "//c#") 40 if (Script.Substring(0, 4).ToLower() == "//c#")
41 { 41 {
42 return CompileFromCSText( Script ); 42 return CompileFromCSText( Script );
43 } 43 }
44 else 44 else
45 { 45 {
46 return CompileFromCSText(LSL_Converter.Convert(Script)); 46 return CompileFromCSText(LSL_Converter.Convert(Script));
47 } 47 }
48 } 48 }
49 /// <summary> 49 /// <summary>
50 /// Compile CS script to .Net assembly (.dll) 50 /// Compile CS script to .Net assembly (.dll)
51 /// </summary> 51 /// </summary>
52 /// <param name="Script">CS script</param> 52 /// <param name="Script">CS script</param>
53 /// <returns>Filename to .dll assembly</returns> 53 /// <returns>Filename to .dll assembly</returns>
54 public string CompileFromCSText(string Script) 54 public string CompileFromCSText(string Script)
55 { 55 {
56 56
57 57
58 // Output assembly name 58 // Output assembly name
59 scriptCompileCounter++; 59 scriptCompileCounter++;
60 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll"); 60 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll");
61 try 61 try
62 { 62 {
63 System.IO.File.Delete(OutFile); 63 System.IO.File.Delete(OutFile);
64 } 64 }
65 catch (Exception e) 65 catch (Exception e)
66 { 66 {
67 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString()); 67 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString());
68 } 68 }
69 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); 69 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
70 70
71 // DEBUG - write source to disk 71 // DEBUG - write source to disk
72 try 72 try
73 { 73 {
74 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script); 74 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
75 } 75 }
76 catch { } 76 catch { }
77 77
78 // Do actual compile 78 // Do actual compile
79 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); 79 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
80 parameters.IncludeDebugInformation = true; 80 parameters.IncludeDebugInformation = true;
81 // Add all available assemblies 81 // Add all available assemblies
82 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) 82 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
83 { 83 {
84 //Console.WriteLine("Adding assembly: " + asm.Location); 84 //Console.WriteLine("Adding assembly: " + asm.Location);
85 //parameters.ReferencedAssemblies.Add(asm.Location); 85 //parameters.ReferencedAssemblies.Add(asm.Location);
86 } 86 }
87 87
88 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); 88 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
89 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location); 89 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location);
90 //Console.WriteLine("Assembly location: " + rootPath); 90 //Console.WriteLine("Assembly location: " + rootPath);
91 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll")); 91 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll"));
92 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll")); 92 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll"));
93 93
94 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); 94 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
95 parameters.GenerateExecutable = false; 95 parameters.GenerateExecutable = false;
96 parameters.OutputAssembly = OutFile; 96 parameters.OutputAssembly = OutFile;
97 parameters.IncludeDebugInformation = false; 97 parameters.IncludeDebugInformation = false;
98 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script); 98 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);
99 99
100 // Go through errors 100 // Go through errors
101 // TODO: Return errors to user somehow 101 // TODO: Return errors to user somehow
102 if (results.Errors.Count > 0) 102 if (results.Errors.Count > 0)
103 { 103 {
104 104
105 string errtext = ""; 105 string errtext = "";
106 foreach (CompilerError CompErr in results.Errors) 106 foreach (CompilerError CompErr in results.Errors)
107 { 107 {
108 errtext += "Line number " + (CompErr.Line - 1) + 108 errtext += "Line number " + (CompErr.Line - 1) +
109 ", Error Number: " + CompErr.ErrorNumber + 109 ", Error Number: " + CompErr.ErrorNumber +
110 ", '" + CompErr.ErrorText + "'\r\n"; 110 ", '" + CompErr.ErrorText + "'\r\n";
111 } 111 }
112 throw new Exception(errtext); 112 throw new Exception(errtext);
113 } 113 }
114 114
115 115
116 return OutFile; 116 return OutFile;
117 } 117 }
118 118
119 } 119 }
120} 120}