diff options
Diffstat (limited to 'OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs')
-rw-r--r-- | OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 32188d2..9046db3 100644 --- a/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | |||
@@ -26,9 +26,7 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | ||
30 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
31 | using System.Text; | ||
32 | using System.Text.RegularExpressions; | 30 | using System.Text.RegularExpressions; |
33 | 31 | ||
34 | namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | 32 | namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL |
@@ -51,9 +49,8 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
51 | dataTypes.Add("rotation", "LSL_Types.Quaternion"); | 49 | dataTypes.Add("rotation", "LSL_Types.Quaternion"); |
52 | dataTypes.Add("list", "list"); | 50 | dataTypes.Add("list", "list"); |
53 | dataTypes.Add("null", "null"); | 51 | dataTypes.Add("null", "null"); |
54 | |||
55 | } | 52 | } |
56 | 53 | ||
57 | public string Convert(string Script) | 54 | public string Convert(string Script) |
58 | { | 55 | { |
59 | string Return = ""; | 56 | string Return = ""; |
@@ -81,7 +78,6 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
81 | int quote_replaced_count = 0; | 78 | int quote_replaced_count = 0; |
82 | for (int p = 0; p < Script.Length; p++) | 79 | for (int p = 0; p < Script.Length; p++) |
83 | { | 80 | { |
84 | |||
85 | C = Script.Substring(p, 1); | 81 | C = Script.Substring(p, 1); |
86 | while (true) | 82 | while (true) |
87 | { | 83 | { |
@@ -99,10 +95,13 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
99 | if (quote == "") | 95 | if (quote == "") |
100 | { | 96 | { |
101 | // We didn't replace quote, probably because of empty string? | 97 | // We didn't replace quote, probably because of empty string? |
102 | _Script += quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]); | 98 | _Script += quote_replacement_string + |
99 | quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]); | ||
103 | } | 100 | } |
104 | // We just left a quote | 101 | // We just left a quote |
105 | quotes.Add(quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]), quote); | 102 | quotes.Add( |
103 | quote_replacement_string + | ||
104 | quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]), quote); | ||
106 | quote = ""; | 105 | quote = ""; |
107 | } | 106 | } |
108 | break; | 107 | break; |
@@ -112,7 +111,6 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
112 | { | 111 | { |
113 | // We are not inside a quote | 112 | // We are not inside a quote |
114 | quote_replaced = false; | 113 | quote_replaced = false; |
115 | |||
116 | } | 114 | } |
117 | else | 115 | else |
118 | { | 116 | { |
@@ -120,7 +118,8 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
120 | if (!quote_replaced) | 118 | if (!quote_replaced) |
121 | { | 119 | { |
122 | // Replace quote | 120 | // Replace quote |
123 | _Script += quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]); | 121 | _Script += quote_replacement_string + |
122 | quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]); | ||
124 | quote_replaced = true; | 123 | quote_replaced = true; |
125 | } | 124 | } |
126 | quote += C; | 125 | quote += C; |
@@ -141,7 +140,6 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
141 | // | 140 | // |
142 | 141 | ||
143 | 142 | ||
144 | |||
145 | // | 143 | // |
146 | // PROCESS STATES | 144 | // PROCESS STATES |
147 | // Remove state definitions and add state names to start of each event within state | 145 | // Remove state definitions and add state names to start of each event within state |
@@ -170,7 +168,9 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
170 | if (ilevel == 1 && lastlevel == 0) | 168 | if (ilevel == 1 && lastlevel == 0) |
171 | { | 169 | { |
172 | // 0 => 1: Get last | 170 | // 0 => 1: Get last |
173 | Match m = Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 171 | Match m = |
172 | Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{", | ||
173 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
174 | 174 | ||
175 | in_state = false; | 175 | in_state = false; |
176 | if (m.Success) | 176 | if (m.Success) |
@@ -179,7 +179,11 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
179 | in_state = true; | 179 | in_state = true; |
180 | current_statename = m.Groups[1].Captures[0].Value; | 180 | current_statename = m.Groups[1].Captures[0].Value; |
181 | //Console.WriteLine("Current statename: " + current_statename); | 181 | //Console.WriteLine("Current statename: " + current_statename); |
182 | cache = Regex.Replace(cache, @"(?<s1>(?![a-zA-Z_]+)\s*)" + @"([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){", "${s1}${s2}", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 182 | cache = |
183 | Regex.Replace(cache, | ||
184 | @"(?<s1>(?![a-zA-Z_]+)\s*)" + @"([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){", | ||
185 | "${s1}${s2}", | ||
186 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
183 | } | 187 | } |
184 | ret += cache; | 188 | ret += cache; |
185 | cache = ""; | 189 | cache = ""; |
@@ -196,7 +200,11 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
196 | // void dataserver(key query_id, string data) { | 200 | // void dataserver(key query_id, string data) { |
197 | //cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 201 | //cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); |
198 | //Console.WriteLine("Replacing using statename: " + current_statename); | 202 | //Console.WriteLine("Replacing using statename: " + current_statename); |
199 | cache = Regex.Replace(cache, @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1public " + current_statename + "_event_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 203 | cache = |
204 | Regex.Replace(cache, | ||
205 | @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", | ||
206 | @"$1public " + current_statename + "_event_$2", | ||
207 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
200 | } | 208 | } |
201 | 209 | ||
202 | ret += cache; | 210 | ret += cache; |
@@ -216,32 +224,48 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
216 | ret = ""; | 224 | ret = ""; |
217 | 225 | ||
218 | 226 | ||
219 | |||
220 | foreach (string key in dataTypes.Keys) | 227 | foreach (string key in dataTypes.Keys) |
221 | { | 228 | { |
222 | string val; | 229 | string val; |
223 | dataTypes.TryGetValue(key, out val); | 230 | dataTypes.TryGetValue(key, out val); |
224 | 231 | ||
225 | // Replace CAST - (integer) with (int) | 232 | // Replace CAST - (integer) with (int) |
226 | Script = Regex.Replace(Script, @"\(" + key + @"\)", @"(" + val + ")", RegexOptions.Compiled | RegexOptions.Multiline); | 233 | Script = |
234 | Regex.Replace(Script, @"\(" + key + @"\)", @"(" + val + ")", | ||
235 | RegexOptions.Compiled | RegexOptions.Multiline); | ||
227 | // Replace return types and function variables - integer a() and f(integer a, integer a) | 236 | // Replace return types and function variables - integer a() and f(integer a, integer a) |
228 | Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)", @"$1$2" + val + "$3", RegexOptions.Compiled | RegexOptions.Multiline); | 237 | Script = |
238 | Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)", @"$1$2" + val + "$3", | ||
239 | RegexOptions.Compiled | RegexOptions.Multiline); | ||
229 | } | 240 | } |
230 | 241 | ||
231 | // Add "void" in front of functions that needs it | 242 | // Add "void" in front of functions that needs it |
232 | Script = Regex.Replace(Script, @"^(\s*public\s+)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 243 | Script = |
244 | Regex.Replace(Script, | ||
245 | @"^(\s*public\s+)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", | ||
246 | @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
233 | 247 | ||
234 | // Replace <x,y,z> and <x,y,z,r> | 248 | // Replace <x,y,z> and <x,y,z,r> |
235 | Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new LSL_Types.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 249 | Script = |
236 | Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"new LSL_Types.Vector3($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 250 | Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new LSL_Types.Quaternion($1)", |
251 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
252 | Script = | ||
253 | Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"new LSL_Types.Vector3($1)", | ||
254 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
237 | 255 | ||
238 | // Replace List []'s | 256 | // Replace List []'s |
239 | Script = Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 257 | Script = |
258 | Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", | ||
259 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
240 | 260 | ||
241 | 261 | ||
242 | // Replace (string) to .ToString() // | 262 | // Replace (string) to .ToString() // |
243 | Script = Regex.Replace(Script, @"\(string\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.ToString()", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 263 | Script = |
244 | Script = Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.Parse($2)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 264 | Regex.Replace(Script, @"\(string\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.ToString()", |
265 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
266 | Script = | ||
267 | Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.Parse($2)", | ||
268 | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
245 | 269 | ||
246 | 270 | ||
247 | // REPLACE BACK QUOTES | 271 | // REPLACE BACK QUOTES |
@@ -256,7 +280,7 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
256 | // Add namespace, class name and inheritance | 280 | // Add namespace, class name and inheritance |
257 | 281 | ||
258 | Return = "" + | 282 | Return = "" + |
259 | "using OpenSim.Region.ScriptEngine.Common;"; | 283 | "using OpenSim.Region.ScriptEngine.Common;"; |
260 | //"using System; " + | 284 | //"using System; " + |
261 | //"using System.Collections.Generic; " + | 285 | //"using System.Collections.Generic; " + |
262 | //"using System.Text; " + | 286 | //"using System.Text; " + |
@@ -278,17 +302,15 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
278 | 302 | ||
279 | 303 | ||
280 | Return += "" + | 304 | Return += "" + |
281 | "namespace SecondLife { "; | 305 | "namespace SecondLife { "; |
282 | Return += "" + | 306 | Return += "" + |
283 | //"[Serializable] " + | 307 | //"[Serializable] " + |
284 | "public class Script : OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass { "; | 308 | "public class Script : OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass { "; |
285 | Return += @"public Script() { } "; | 309 | Return += @"public Script() { } "; |
286 | Return += Script; | 310 | Return += Script; |
287 | Return += "} }\r\n"; | 311 | Return += "} }\r\n"; |
288 | 312 | ||
289 | return Return; | 313 | return Return; |
290 | } | 314 | } |
291 | |||
292 | |||
293 | } | 315 | } |
294 | } | 316 | } \ No newline at end of file |