aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs')
-rw-r--r--OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs144
1 files changed, 0 insertions, 144 deletions
diff --git a/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
deleted file mode 100644
index 353d59e..0000000
--- a/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ /dev/null
@@ -1,144 +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
28using System;
29using System.CodeDom.Compiler;
30using System.IO;
31using System.Reflection;
32using Microsoft.CSharp;
33
34namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL
35{
36 public class Compiler
37 {
38 private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
39 private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
40 private static UInt64 scriptCompileCounter = 0;
41 //private ICodeCompiler icc = codeProvider.CreateCompiler();
42 public string CompileFromFile(string LSOFileName)
43 {
44 switch (Path.GetExtension(LSOFileName).ToLower())
45 {
46 case ".txt":
47 case ".lsl":
48 Common.SendToDebug("Source code is LSL, converting to CS");
49 return CompileFromLSLText(File.ReadAllText(LSOFileName));
50 case ".cs":
51 Common.SendToDebug("Source code is CS");
52 return CompileFromCSText(File.ReadAllText(LSOFileName));
53 default:
54 throw new Exception("Unknown script type.");
55 }
56 }
57
58 /// <summary>
59 /// Converts script from LSL to CS and calls CompileFromCSText
60 /// </summary>
61 /// <param name="Script">LSL script</param>
62 /// <returns>Filename to .dll assembly</returns>
63 public string CompileFromLSLText(string Script)
64 {
65 if (Script.Substring(0, 4).ToLower() == "//c#")
66 {
67 return CompileFromCSText(Script);
68 }
69 else
70 {
71 return CompileFromCSText(LSL_Converter.Convert(Script));
72 }
73 }
74
75 /// <summary>
76 /// Compile CS script to .Net assembly (.dll)
77 /// </summary>
78 /// <param name="Script">CS script</param>
79 /// <returns>Filename to .dll assembly</returns>
80 public string CompileFromCSText(string Script)
81 {
82 // Output assembly name
83 scriptCompileCounter++;
84 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll");
85 try
86 {
87 File.Delete(OutFile);
88 }
89 catch (Exception e)
90 {
91 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString());
92 }
93 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
94
95 // DEBUG - write source to disk
96 try
97 {
98 File.WriteAllText(
99 Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
100 }
101 catch
102 {
103 }
104
105 // Do actual compile
106 CompilerParameters parameters = new CompilerParameters();
107 parameters.IncludeDebugInformation = true;
108 // Add all available assemblies
109 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
110 {
111 //Console.WriteLine("Adding assembly: " + asm.Location);
112 //parameters.ReferencedAssemblies.Add(asm.Location);
113 }
114
115 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
116 string rootPathSE = Path.GetDirectoryName(GetType().Assembly.Location);
117 //Console.WriteLine("Assembly location: " + rootPath);
118 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll"));
119 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Grid.ScriptEngine.DotNetEngine.dll"));
120
121 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
122 parameters.GenerateExecutable = false;
123 parameters.OutputAssembly = OutFile;
124 parameters.IncludeDebugInformation = false;
125 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);
126
127 // Go through errors
128 // TODO: Return errors to user somehow
129 if (results.Errors.Count > 0)
130 {
131 string errtext = "";
132 foreach (CompilerError CompErr in results.Errors)
133 {
134 errtext += "Line number " + (CompErr.Line - 1) +
135 ", Error Number: " + CompErr.ErrorNumber +
136 ", '" + CompErr.ErrorText + "'\r\n";
137 }
138 throw new Exception(errtext);
139 }
140
141 return OutFile;
142 }
143 }
144}