PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Aurora/AuroraDotNetEngine4/CompilerTools/CSCodeGenerator.cs

http://github.com/aurora-sim/Aurora-Sim
C# | 1557 lines | 1279 code | 168 blank | 110 comment | 381 complexity | 09fb6ff86c6270c8c627eef61fd96c9e MD5 | raw file
Possible License(s): MIT, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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. using System;
  28. using System.IO;
  29. using System.Collections.Generic;
  30. using System.Collections;
  31. using System.Text;
  32. using Tools;
  33. namespace Aurora.ScriptEngine.AuroraDotNetEngine.CompilerTools
  34. {
  35. public static class Extension
  36. {
  37. public static bool CompareWildcards(this string WildString, string Mask, bool IgnoreCase)
  38. {
  39. int i = 0;
  40. if (String.IsNullOrEmpty(Mask))
  41. return false;
  42. if (Mask == "*")
  43. return true;
  44. while (i != Mask.Length)
  45. {
  46. if (CompareWildcard(WildString, Mask.Substring(i), IgnoreCase))
  47. return true;
  48. while (i != Mask.Length && Mask[i] != ';')
  49. i += 1;
  50. if (i != Mask.Length && Mask[i] == ';')
  51. {
  52. i += 1;
  53. while (i != Mask.Length && Mask[i] == ' ')
  54. i += 1;
  55. }
  56. }
  57. return false;
  58. }
  59. public static bool CompareWildcard(this string WildString, string Mask, bool IgnoreCase)
  60. {
  61. int i = 0, k = 0;
  62. while (k != WildString.Length)
  63. {
  64. if ((i + 1) > Mask.Length)
  65. return true;
  66. switch (Mask[i])
  67. {
  68. case '*':
  69. if ((i + 1) >= Mask.Length)
  70. return true;
  71. while (k != WildString.Length)
  72. {
  73. if (CompareWildcard(WildString.Substring(k + 1), Mask.Substring(i + 1), IgnoreCase))
  74. return true;
  75. k += 1;
  76. }
  77. return false;
  78. case '?':
  79. break;
  80. default:
  81. if (IgnoreCase == false && WildString[k] != Mask[i])
  82. return false;
  83. if (IgnoreCase && Char.ToLower(WildString[k]) != Char.ToLower(Mask[i]))
  84. return false;
  85. break;
  86. }
  87. i += 1;
  88. k += 1;
  89. }
  90. if (k == WildString.Length)
  91. {
  92. if (i == Mask.Length || Mask[i] == ';' || Mask[i] == '*')
  93. return true;
  94. }
  95. return false;
  96. }
  97. }
  98. public class CSCodeGenerator : IDisposable
  99. {
  100. private SYMBOL m_astRoot = null;
  101. private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
  102. private int m_indentWidth = 4; // for indentation
  103. private int m_braceCount; // for indentation
  104. private int m_CSharpLine; // the current line of generated C# code
  105. private int m_CSharpCol; // the current column of generated C# code
  106. private string OriginalScript = "";
  107. private Parser p = null;
  108. private Random random = new Random();
  109. private bool IsaGlobalVar = false;
  110. private class GlobalVar
  111. {
  112. public string Type;
  113. public string Value;
  114. }
  115. private HashSet<string> DTFunctions = new HashSet<string>();
  116. // public Dictionary<string, string> IenFunctions = new Dictionary<string, string>();
  117. public Dictionary<string, string> LocalMethods = new Dictionary<string, string>();
  118. public Dictionary<string, ObjectList> LocalMethodArguements = new Dictionary<string, ObjectList>();
  119. private Dictionary<string, GlobalVar> GlobalVariables = new Dictionary<string, GlobalVar>();
  120. /// <summary>
  121. /// This saves the variables in methods so that we can make sure multiple variables do not have the same name, and if they do, rename/assign them to the correct variable name
  122. /// </summary>
  123. private Dictionary<string, GlobalVar> MethodVariables = new Dictionary<string, GlobalVar>();
  124. private class VarRename
  125. {
  126. //public string NewVarName;
  127. //public bool HasBeenAssigned;
  128. //public string OldVarName;
  129. }
  130. /// <summary>
  131. /// This contains a list of variables that we need to rename because of some constraint
  132. /// </summary>
  133. private Dictionary<string, VarRename> VariablesToRename = new Dictionary<string, VarRename>();
  134. private List<string> FuncCalls = new List<string>();
  135. private List<string> MethodsToAdd = new List<string>();
  136. /// <summary>
  137. /// Param 1 - the API function name, Param 2 - the API name
  138. /// </summary>
  139. private Dictionary<string, IScriptApi> m_apiFunctions = new Dictionary<string, IScriptApi>();
  140. private Compiler m_compiler;
  141. /// <summary>
  142. /// Creates an 'empty' CSCodeGenerator instance.
  143. /// </summary>
  144. public CSCodeGenerator(Compiler compiler)
  145. {
  146. ResetCounters();
  147. m_compiler = compiler;
  148. IScriptApi[] apis = compiler.ScriptEngine.GetAPIs();
  149. foreach (IScriptApi api in apis)
  150. {
  151. List<string> FunctionNames = compiler.ScriptEngine.GetFunctionNames(api);
  152. foreach (string functionName in FunctionNames)
  153. {
  154. if (!m_apiFunctions.ContainsKey(functionName))
  155. m_apiFunctions.Add(functionName, api);
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// Get the mapping between LSL and C# line/column number.
  161. /// </summary>
  162. /// <returns>Dictionary\<KeyValuePair\<int, int\>, KeyValuePair\<int, int\>\>.</returns>
  163. public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> PositionMap
  164. {
  165. get { return m_positionMap; }
  166. }
  167. /// <summary>
  168. /// Get the mapping between LSL and C# line/column number.
  169. /// </summary>
  170. /// <returns>SYMBOL pointing to root of the abstract syntax tree.</returns>
  171. public SYMBOL ASTRoot
  172. {
  173. get { return m_astRoot; }
  174. }
  175. /// <summary>
  176. /// Resets various counters and metadata.
  177. /// </summary>
  178. private void ResetCounters()
  179. {
  180. //NOTE: This takes a VERY long time to rebuild. Ideally, this should be reset, but interesting errors are happening when it is reset..
  181. p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
  182. MethodVariables.Clear();
  183. VariablesToRename.Clear();
  184. GlobalVariables.Clear();
  185. m_braceCount = 0;
  186. m_CSharpLine = 15;
  187. m_CSharpCol = 1;
  188. m_positionMap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
  189. LocalMethods.Clear();
  190. m_astRoot = null;
  191. OriginalScript = "";
  192. lock (FuncCalls)
  193. FuncCalls.Clear();
  194. IsaGlobalVar = false;
  195. MethodsToAdd.Clear();
  196. LocalMethodArguements.Clear();
  197. }
  198. private string CreateCompilerScript(string ScriptClass)
  199. {
  200. string compiledScript = "";
  201. compiledScript += "using Aurora.ScriptEngine.AuroraDotNetEngine.Runtime;\n";
  202. compiledScript += "using Aurora.ScriptEngine.AuroraDotNetEngine;\n";
  203. compiledScript += "using Aurora.ScriptEngine.AuroraDotNetEngine.APIs.Interfaces;\n";
  204. compiledScript += "using System;\n";
  205. compiledScript += "using System.Collections.Generic;\n";
  206. compiledScript += "using System.Collections;\n";
  207. compiledScript += "using System.Reflection;\n";
  208. compiledScript += "using System.Timers;\n";
  209. foreach (IScriptApi api in m_compiler.ScriptEngine.GetAPIs())
  210. {
  211. foreach (string nameSpace in api.NamespaceAdditions)
  212. {
  213. compiledScript += "using " + nameSpace + ";\n";
  214. }
  215. }
  216. compiledScript += "namespace Script\n";
  217. compiledScript += "{\n";
  218. compiledScript += "[Serializable]\n";
  219. compiledScript += "public class ScriptClass : Aurora.ScriptEngine.AuroraDotNetEngine.Runtime.ScriptBaseClass\n";
  220. compiledScript += "{\n";
  221. compiledScript += ScriptClass;
  222. foreach(string method in MethodsToAdd)
  223. {
  224. compiledScript += method;
  225. }
  226. compiledScript += "}\n"; // Close Class
  227. compiledScript += "}\n"; // Close Namespace
  228. return compiledScript.ToString();
  229. }
  230. /// <summary>
  231. /// Generate the code from the AST we have.
  232. /// </summary>
  233. /// <param name="script">The LSL source as a string.</param>
  234. /// <returns>String containing the generated C# code.</returns>
  235. public string Convert(string script)
  236. {
  237. ResetCounters();
  238. LSL2CSCodeTransformer codeTransformer;
  239. try
  240. {
  241. // lock (p)
  242. {
  243. codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
  244. // p.m_lexer.Reset();
  245. }
  246. }
  247. catch (CSToolsException e)
  248. {
  249. string message;
  250. // LL start numbering lines at 0 - geeks!
  251. // Also need to subtract one line we prepend!
  252. //
  253. string emessage = e.Message;
  254. string slinfo = e.slInfo.ToString();
  255. // Remove wrong line number info
  256. //
  257. if (emessage.StartsWith(slinfo + ": "))
  258. emessage = emessage.Substring(slinfo.Length + 2);
  259. if (e.slInfo.lineNumber - 1 <= 0)
  260. e.slInfo.lineNumber = 2;
  261. if (e.slInfo.charPosition - 1 <= 0)
  262. e.slInfo.charPosition = 2;
  263. message = String.Format("({0},{1}) {2}",
  264. e.slInfo.lineNumber - 1,
  265. e.slInfo.charPosition - 1, emessage);
  266. m_compiler.AddError(message);
  267. // p.m_lexer.Reset();
  268. ResetCounters();
  269. return "Error parsing the script. " + message;
  270. }
  271. m_astRoot = codeTransformer.Transform(LocalMethods, LocalMethodArguements);
  272. OriginalScript = script;
  273. string returnstring = "";
  274. // line number
  275. //m_CSharpLine += 3;
  276. // here's the payload
  277. returnstring += GenerateLine();
  278. foreach (SYMBOL s in m_astRoot.kids)
  279. returnstring += GenerateNode(s);
  280. // Removes all carriage return characters which may be generated in Windows platform.
  281. //Is there a cleaner way of doing this?
  282. returnstring = returnstring.Replace("\r", "");
  283. CheckEventCasts(returnstring);
  284. return CreateCompilerScript(returnstring);
  285. }
  286. private string CheckFloatExponent(string script)
  287. {
  288. string[] SplitScript = script.Split('\n');
  289. List<string> ReconstructableScript = new List<string>();
  290. foreach (string line in SplitScript)
  291. {
  292. string AddLine = line;
  293. if (AddLine.Replace(" ", "") == "default")
  294. break; //We only check above default
  295. if (AddLine.Contains("float"))
  296. {
  297. if (line.Contains("e") && !line.Contains("(") && !line.Contains(")")) // Looking for exponents, but not for functions that have ()
  298. {
  299. //Should have this - float *** = 151e9;
  300. string[] SplitBeforeE = AddLine.Split('='); // Split at the e so we can look at the syntax
  301. if (SplitBeforeE.Length != 1)
  302. {
  303. string[] SplitBeforeESpace = SplitBeforeE[1].Split(';');
  304. //Should have something like this now - 151
  305. if (SplitBeforeESpace[0].Contains("e"))
  306. {
  307. if (!SplitBeforeESpace[0].Contains("."))
  308. {
  309. //Needs one then
  310. string[] Split = SplitBeforeESpace[0].Split('e'); // Split at the e so we can look at the syntax
  311. Split[0] += ".";
  312. AddLine = "";
  313. string TempString = "";
  314. foreach (string tempLine in Split)
  315. {
  316. TempString += tempLine + "e";
  317. }
  318. TempString = TempString.Remove(TempString.Length - 1, 1);
  319. SplitBeforeESpace[0] = TempString;
  320. TempString = "";
  321. foreach (string tempLine in SplitBeforeESpace)
  322. {
  323. TempString += tempLine + ";";
  324. }
  325. //Remove the last ;
  326. TempString = TempString.Remove(TempString.Length - 1, 1);
  327. SplitBeforeE[1] = TempString;
  328. foreach (string tempLine in SplitBeforeE)
  329. {
  330. AddLine += tempLine + "=";
  331. }
  332. //Remove the last e
  333. AddLine = AddLine.Remove(AddLine.Length - 1, 1);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. ReconstructableScript.Add(AddLine);
  340. }
  341. string RetVal = "";
  342. foreach (string line in ReconstructableScript)
  343. {
  344. RetVal += line + "\n";
  345. }
  346. return RetVal;
  347. }
  348. private string CheckForInlineVectors(string script)
  349. {
  350. string[] SplitScript = script.Split('\n');
  351. List<string> ReconstructableScript = new List<string>();
  352. foreach (string line in SplitScript)
  353. {
  354. string AddLine = line;
  355. if (AddLine.Contains("<") && AddLine.Contains(">"))
  356. {
  357. if (AddLine.Contains("\"")) // if it contains ", we need to be more careful
  358. {
  359. string[] SplitByParLine = AddLine.Split('\"');
  360. int lineNumber = 0;
  361. List<string> ReconstructableLine = new List<string>();
  362. foreach (string parline in SplitByParLine)
  363. {
  364. string AddInsideLine = parline;
  365. //throw out all odd numbered lines as they are inside ""
  366. if (lineNumber % 2 != 1)
  367. {
  368. string[] SplitLineA = AddLine.Split('<');
  369. if (SplitLineA.Length > 1)
  370. {
  371. string SplitLineB = SplitLineA[1].Split('>')[0];
  372. if (SplitLineB.CompareWildcard("*,*,*", true))
  373. {
  374. AddInsideLine = AddInsideLine.Replace("<", "(<");
  375. AddInsideLine = AddInsideLine.Replace(">", ">)");
  376. }
  377. }
  378. }
  379. ReconstructableLine.Add(AddInsideLine);
  380. lineNumber++;
  381. }
  382. AddLine = "";
  383. foreach (string insideline in ReconstructableLine)
  384. {
  385. AddLine += insideline + "\"";
  386. }
  387. AddLine = AddLine.Remove(AddLine.Length - 1, 1);
  388. }
  389. else
  390. {
  391. string[] SplitLineA = AddLine.Split('<');
  392. if (SplitLineA.Length > 1)
  393. {
  394. string SplitLineB = SplitLineA[1].Split('>')[0];
  395. if (SplitLineB.CompareWildcard("*,*,*", true))
  396. {
  397. AddLine = AddLine.Replace("<", "(<");
  398. AddLine = AddLine.Replace(">", ">)");
  399. }
  400. }
  401. }
  402. }
  403. ReconstructableScript.Add(AddLine);
  404. }
  405. string RetVal = "";
  406. foreach (string line in ReconstructableScript)
  407. {
  408. RetVal += line + "\n";
  409. }
  410. return RetVal;
  411. }
  412. /// <summary>
  413. /// Checks the C# script for the correct casts in events
  414. /// This stops errors from misformed events ex. 'touch(vector3 position)' instead of 'touch(int touch)'
  415. /// </summary>
  416. /// <param name="script"></param>
  417. private void CheckEventCasts(string script)
  418. {
  419. CheckEvent(script, "default");
  420. string[] States = OriginalScript.Split(new string[] { "state " }, StringSplitOptions.RemoveEmptyEntries);
  421. foreach (string state in States)
  422. {
  423. string stateName = state.Split(' ')[0];
  424. stateName = state.Split('\n')[0];
  425. if (!stateName.Contains("default"))
  426. CheckEvent(script, stateName);
  427. }
  428. }
  429. private void CheckEvent(string script, string state)
  430. {
  431. if (script.Contains(state + "_event_state_entry("))
  432. {
  433. string Valid = state + "_event_state_entry()";
  434. int charNum = script.IndexOf(state + "_event_state_entry(");
  435. string splitScript = script.Remove(0, charNum);
  436. charNum = splitScript.IndexOf('\n');
  437. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  438. if (splitScript != Valid)
  439. {
  440. FindLineNumbers("state_entry", "Too many arguments");
  441. }
  442. }
  443. if (script.Contains(state + "_event_touch_start("))
  444. {
  445. //Valid : default_event_touch_start(LSL_Types.LSLInteger number)
  446. int charNum = script.IndexOf(state + "_event_touch_start(");
  447. string splitScript = script.Remove(0, charNum);
  448. charNum = splitScript.IndexOf('\n');
  449. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  450. string arguments = splitScript.Split('(')[1];
  451. arguments = arguments.Split(')')[0];
  452. string[] AllArguments = arguments.Split(',');
  453. int i = 0;
  454. foreach (string argument in AllArguments)
  455. {
  456. if (i == 0)
  457. {
  458. if (!argument.Contains("LSL_Types.LSLInteger"))
  459. FindLineNumbers("touch_start", "Invalid argument");
  460. }
  461. i++;
  462. }
  463. if (i != 1)
  464. {
  465. FindLineNumbers("touch_start", "Too many arguments");
  466. }
  467. }
  468. if (script.Contains(state + "_event_at_rot_target("))
  469. {
  470. //Valid : default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)
  471. int charNum = script.IndexOf(state + "_event_at_rot_target(");
  472. string splitScript = script.Remove(0, charNum);
  473. charNum = splitScript.IndexOf('\n');
  474. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  475. string arguments = splitScript.Split('(')[1];
  476. arguments = arguments.Split(')')[0];
  477. string[] AllArguments = arguments.Split(',');
  478. int i = 0;
  479. foreach (string argument in AllArguments)
  480. {
  481. if (i == 0)
  482. if (!argument.Contains("LSL_Types.LSLInteger"))
  483. FindLineNumbers("at_rot_target", "Invalid argument");
  484. if (i == 1 || i == 2)
  485. if (!argument.Contains("LSL_Types.Quaternion"))
  486. FindLineNumbers("at_rot_target", "Invalid argument");
  487. i++;
  488. }
  489. if (i != 3)
  490. {
  491. FindLineNumbers("at_rot_target", "Too many arguments");
  492. }
  493. }
  494. if (script.Contains(state + "_event_at_target("))
  495. {
  496. //Valid : default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)
  497. int charNum = script.IndexOf(state + "_event_at_target(");
  498. string splitScript = script.Remove(0, charNum);
  499. charNum = splitScript.IndexOf('\n');
  500. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  501. string arguments = splitScript.Split('(')[1];
  502. arguments = arguments.Split(')')[0];
  503. string[] AllArguments = arguments.Split(',');
  504. int i = 0;
  505. foreach (string argument in AllArguments)
  506. {
  507. if (i == 0)
  508. if (!argument.Contains("LSL_Types.LSLInteger"))
  509. FindLineNumbers("at_target", "Invalid argument");
  510. if (i == 1 || i == 2)
  511. if (!argument.Contains("LSL_Types.Vector3"))
  512. FindLineNumbers("at_target", "Invalid argument");
  513. i++;
  514. }
  515. if (i != 3)
  516. {
  517. FindLineNumbers("at_target", "Too many arguments");
  518. }
  519. }
  520. if (script.Contains(state + "_event_not_at_target("))
  521. {
  522. int charNum = script.IndexOf(state + "_event_not_at_target(");
  523. string splitScript = script.Remove(0, charNum);
  524. charNum = splitScript.IndexOf('\n');
  525. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  526. string Valid = state + "_event_not_at_target()";
  527. if (splitScript != Valid)
  528. {
  529. FindLineNumbers("not_at_target", "Too many arguments");
  530. }
  531. }
  532. if (script.Contains(state + "_event_attach("))
  533. {
  534. int charNum = script.IndexOf(state + "_event_attach(");
  535. string splitScript = script.Remove(0, charNum);
  536. charNum = splitScript.IndexOf('\n');
  537. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  538. string arguments = splitScript.Split('(')[1];
  539. arguments = arguments.Split(')')[0];
  540. string[] AllArguments = arguments.Split(',');
  541. int i = 0;
  542. foreach (string argument in AllArguments)
  543. {
  544. if (i == 0)
  545. {
  546. if (!argument.Contains("LSL_Types.LSLString"))
  547. FindLineNumbers("attach", "Invalid argument");
  548. }
  549. i++;
  550. }
  551. if (i != 1)
  552. {
  553. FindLineNumbers("attach", "Too many arguments");
  554. }
  555. }
  556. if (script.Contains(state + "_event_changed("))
  557. {
  558. int charNum = script.IndexOf(state + "_event_changed(");
  559. string splitScript = script.Remove(0, charNum);
  560. charNum = splitScript.IndexOf('\n');
  561. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  562. string arguments = splitScript.Split('(')[1];
  563. arguments = arguments.Split(')')[0];
  564. string[] AllArguments = arguments.Split(',');
  565. int i = 0;
  566. foreach (string argument in AllArguments)
  567. {
  568. if (i == 0)
  569. {
  570. if (!argument.Contains("LSL_Types.LSLInteger"))
  571. FindLineNumbers("changed", "Invalid argument");
  572. }
  573. i++;
  574. }
  575. if (i != 1)
  576. {
  577. FindLineNumbers("changed", "Too many arguments");
  578. }
  579. }
  580. if (script.Contains(state + "_event_collision("))
  581. {
  582. int charNum = script.IndexOf(state + "_event_collision(");
  583. string splitScript = script.Remove(0, charNum);
  584. charNum = splitScript.IndexOf('\n');
  585. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  586. string arguments = splitScript.Split('(')[1];
  587. arguments = arguments.Split(')')[0];
  588. string[] AllArguments = arguments.Split(',');
  589. int i = 0;
  590. foreach (string argument in AllArguments)
  591. {
  592. if (i == 0)
  593. {
  594. if (!argument.Contains("LSL_Types.LSLInteger"))
  595. FindLineNumbers("collision", "Invalid argument");
  596. }
  597. i++;
  598. }
  599. if (i != 1)
  600. {
  601. FindLineNumbers("collision", "Too many arguments");
  602. }
  603. }
  604. if (script.Contains(state + "_event_collision_end("))
  605. {
  606. int charNum = script.IndexOf(state + "_event_collision_end(");
  607. string splitScript = script.Remove(0, charNum);
  608. charNum = splitScript.IndexOf('\n');
  609. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  610. string arguments = splitScript.Split('(')[1];
  611. arguments = arguments.Split(')')[0];
  612. string[] AllArguments = arguments.Split(',');
  613. int i = 0;
  614. foreach (string argument in AllArguments)
  615. {
  616. if (i == 0)
  617. {
  618. if (!argument.Contains("LSL_Types.LSLInteger"))
  619. FindLineNumbers("collision_end", "Invalid argument");
  620. }
  621. i++;
  622. }
  623. if (i != 1)
  624. {
  625. FindLineNumbers("collision_end", "Too many arguments");
  626. }
  627. }
  628. if (script.Contains(state + "_event_collision_start("))
  629. {
  630. int charNum = script.IndexOf(state + "_event_collision_start(");
  631. string splitScript = script.Remove(0, charNum);
  632. charNum = splitScript.IndexOf('\n');
  633. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  634. string arguments = splitScript.Split('(')[1];
  635. arguments = arguments.Split(')')[0];
  636. string[] AllArguments = arguments.Split(',');
  637. int i = 0;
  638. foreach (string argument in AllArguments)
  639. {
  640. if (i == 0)
  641. {
  642. if (!argument.Contains("LSL_Types.LSLInteger"))
  643. FindLineNumbers("collision_start", "Invalid argument");
  644. }
  645. i++;
  646. }
  647. if (i != 1)
  648. {
  649. FindLineNumbers("collision_start", "Too many arguments");
  650. }
  651. }
  652. if (script.Contains(state + "_event_run_time_permissions("))
  653. {
  654. int charNum = script.IndexOf(state + "_event_run_time_permissions(");
  655. string splitScript = script.Remove(0, charNum);
  656. charNum = splitScript.IndexOf('\n');
  657. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  658. string arguments = splitScript.Split('(')[1];
  659. arguments = arguments.Split(')')[0];
  660. string[] AllArguments = arguments.Split(',');
  661. int i = 0;
  662. foreach (string argument in AllArguments)
  663. {
  664. if (i == 0)
  665. {
  666. if (!argument.Contains("LSL_Types.LSLInteger"))
  667. FindLineNumbers("run_time_permissions", "Invalid argument");
  668. }
  669. i++;
  670. }
  671. if (i != 1)
  672. {
  673. FindLineNumbers("run_time_permissions", "Too many arguments");
  674. }
  675. }
  676. if (script.Contains(state + "_event_control("))
  677. {
  678. int charNum = script.IndexOf(state + "_event_control(");
  679. string splitScript = script.Remove(0, charNum);
  680. charNum = splitScript.IndexOf('\n');
  681. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  682. string arguments = splitScript.Split('(')[1];
  683. arguments = arguments.Split(')')[0];
  684. string[] AllArguments = arguments.Split(',');
  685. int i = 0;
  686. foreach (string argument in AllArguments)
  687. {
  688. if (i == 0)
  689. if (!argument.Contains("LSL_Types.LSLString"))
  690. FindLineNumbers("control", "Invalid argument");
  691. if (i == 1 || i == 2)
  692. if (!argument.Contains("LSL_Types.LSLInteger"))
  693. FindLineNumbers("control", "Invalid argument");
  694. i++;
  695. }
  696. if (i != 3)
  697. {
  698. FindLineNumbers("control", "Too many arguments");
  699. }
  700. }
  701. if (script.Contains(state + "_event_dataserver("))
  702. {
  703. int charNum = script.IndexOf(state + "_event_dataserver(");
  704. string splitScript = script.Remove(0, charNum);
  705. charNum = splitScript.IndexOf('\n');
  706. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  707. string arguments = splitScript.Split('(')[1];
  708. arguments = arguments.Split(')')[0];
  709. string[] AllArguments = arguments.Split(',');
  710. int i = 0;
  711. foreach (string argument in AllArguments)
  712. {
  713. if (i == 0 || i == 1)
  714. if (!argument.Contains("LSL_Types.LSLString"))
  715. FindLineNumbers("dataserver", "Invalid argument");
  716. i++;
  717. }
  718. if (i != 2)
  719. {
  720. FindLineNumbers("dataserver", "Too many arguments");
  721. }
  722. }
  723. if (script.Contains(state + "_event_timer("))
  724. {
  725. int charNum = script.IndexOf(state + "_event_timer(");
  726. string splitScript = script.Remove(0, charNum);
  727. charNum = splitScript.IndexOf('\n');
  728. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  729. string arguments = splitScript.Split('(')[1];
  730. arguments = arguments.Split(')')[0];
  731. string Valid = state + "_event_timer()";
  732. if (splitScript != Valid)
  733. {
  734. FindLineNumbers("timer", "Too many arguments");
  735. }
  736. }
  737. if (script.Contains(state + "_event_email("))
  738. {
  739. int charNum = script.IndexOf(state + "_event_email(");
  740. string splitScript = script.Remove(0, charNum);
  741. charNum = splitScript.IndexOf('\n');
  742. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  743. string arguments = splitScript.Split('(')[1];
  744. arguments = arguments.Split(')')[0];
  745. string[] AllArguments = arguments.Split(',');
  746. int i = 0;
  747. foreach (string argument in AllArguments)
  748. {
  749. if (i == 0 || i == 1 || i == 2 || i == 3)
  750. if (!argument.Contains("LSL_Types.LSLString"))
  751. FindLineNumbers("email", "Invalid argument");
  752. if (i == 4)
  753. if (!argument.Contains("LSL_Types.LSLInteger"))
  754. FindLineNumbers("email", "Invalid argument");
  755. i++;
  756. }
  757. if (i != 5)
  758. {
  759. FindLineNumbers("email", "Too many arguments");
  760. }
  761. }
  762. if (script.Contains(state + "_event_http_request("))
  763. {
  764. int charNum = script.IndexOf(state + "_event_http_request(");
  765. string splitScript = script.Remove(0, charNum);
  766. charNum = splitScript.IndexOf('\n');
  767. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  768. string arguments = splitScript.Split('(')[1];
  769. arguments = arguments.Split(')')[0];
  770. string[] AllArguments = arguments.Split(',');
  771. int i = 0;
  772. foreach (string argument in AllArguments)
  773. {
  774. if (i == 0 || i == 1 || i == 2)
  775. if (!argument.Contains("LSL_Types.LSLString"))
  776. FindLineNumbers("http_request", "Invalid argument");
  777. i++;
  778. }
  779. if (i != 3)
  780. {
  781. FindLineNumbers("http_request", "Too many arguments");
  782. }
  783. }
  784. if (script.Contains(state + "_event_http_response("))
  785. {
  786. int charNum = script.IndexOf(state + "_event_http_response(");
  787. string splitScript = script.Remove(0, charNum);
  788. charNum = splitScript.IndexOf('\n');
  789. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  790. string arguments = splitScript.Split('(')[1];
  791. arguments = arguments.Split(')')[0];
  792. string[] AllArguments = arguments.Split(',');
  793. int i = 0;
  794. foreach (string argument in AllArguments)
  795. {
  796. if (i == 0 || i == 3)
  797. if (!argument.Contains("LSL_Types.LSLString"))
  798. FindLineNumbers("http_response", "Invalid argument");
  799. if (i == 1)
  800. if (!argument.Contains("LSL_Types.LSLInteger"))
  801. FindLineNumbers("http_response", "Invalid argument");
  802. if (i == 2)
  803. if (!argument.Contains("LSL_Types.list"))
  804. FindLineNumbers("http_response", "Invalid argument");
  805. i++;
  806. }
  807. if (i != 4)
  808. {
  809. FindLineNumbers("http_response", "Too many arguments");
  810. }
  811. }
  812. if (script.Contains(state + "_event_land_collision_end("))
  813. {
  814. int charNum = script.IndexOf(state + "_event_land_collision_end(");
  815. string splitScript = script.Remove(0, charNum);
  816. charNum = splitScript.IndexOf('\n');
  817. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  818. string arguments = splitScript.Split('(')[1];
  819. arguments = arguments.Split(')')[0];
  820. string[] AllArguments = arguments.Split(',');
  821. int i = 0;
  822. foreach (string argument in AllArguments)
  823. {
  824. if (i == 0)
  825. if (!argument.Contains("LSL_Types.Vector3"))
  826. FindLineNumbers("land_collision_end", "Invalid argument");
  827. i++;
  828. }
  829. if (i != 1)
  830. {
  831. FindLineNumbers("land_collision_end", "Too many arguments");
  832. }
  833. }
  834. if (script.Contains(state + "_event_land_collision_start("))
  835. {
  836. int charNum = script.IndexOf(state + "_event_land_collision_start(");
  837. string splitScript = script.Remove(0, charNum);
  838. charNum = splitScript.IndexOf('\n');
  839. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  840. string arguments = splitScript.Split('(')[1];
  841. arguments = arguments.Split(')')[0];
  842. string[] AllArguments = arguments.Split(',');
  843. int i = 0;
  844. foreach (string argument in AllArguments)
  845. {
  846. if (i == 0)
  847. if (!argument.Contains("LSL_Types.Vector3"))
  848. FindLineNumbers("land_collision_start", "Invalid argument");
  849. i++;
  850. }
  851. if (i != 1)
  852. {
  853. FindLineNumbers("land_collision_start", "Too many arguments");
  854. }
  855. }
  856. if (script.Contains(state + "_event_link_message("))
  857. {
  858. int charNum = script.IndexOf(state + "_event_link_message(");
  859. string splitScript = script.Remove(0, charNum);
  860. charNum = splitScript.IndexOf('\n');
  861. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  862. string arguments = splitScript.Split('(')[1];
  863. arguments = arguments.Split(')')[0];
  864. string[] AllArguments = arguments.Split(',');
  865. int i = 0;
  866. foreach (string argument in AllArguments)
  867. {
  868. if (i == 0 || i == 1)
  869. if (!argument.Contains("LSL_Types.LSLInteger"))
  870. FindLineNumbers("link_message", "Invalid argument");
  871. if (i == 2 || i == 3)
  872. if (!argument.Contains("LSL_Types.LSLString"))
  873. FindLineNumbers("link_message", "Invalid argument");
  874. i++;
  875. }
  876. if (i != 4)
  877. {
  878. FindLineNumbers("link_message", "Too many arguments");
  879. }
  880. }
  881. if (script.Contains(state + "_event_listen("))
  882. {
  883. int charNum = script.IndexOf(state + "_event_listen(");
  884. string splitScript = script.Remove(0, charNum);
  885. charNum = splitScript.IndexOf('\n');
  886. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  887. string arguments = splitScript.Split('(')[1];
  888. arguments = arguments.Split(')')[0];
  889. string[] AllArguments = arguments.Split(',');
  890. int i = 0;
  891. foreach (string argument in AllArguments)
  892. {
  893. if (i == 0)
  894. if (!argument.Contains("LSL_Types.LSLInteger"))
  895. FindLineNumbers("listen", "Invalid argument");
  896. if (i == 1 || i == 2 || i == 3)
  897. if (!argument.Contains("LSL_Types.LSLString"))
  898. FindLineNumbers("listen", "Invalid argument");
  899. i++;
  900. }
  901. if (i != 4)
  902. {
  903. FindLineNumbers("listen", "Too many arguments");
  904. }
  905. }
  906. if (script.Contains(state + "_event_on_rez("))
  907. {
  908. int charNum = script.IndexOf(state + "_event_on_rez(");
  909. string splitScript = script.Remove(0, charNum);
  910. charNum = splitScript.IndexOf('\n');
  911. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  912. string arguments = splitScript.Split('(')[1];
  913. arguments = arguments.Split(')')[0];
  914. string[] AllArguments = arguments.Split(',');
  915. int i = 0;
  916. foreach (string argument in AllArguments)
  917. {
  918. if (i == 0)
  919. if (!argument.Contains("LSL_Types.LSLInteger"))
  920. FindLineNumbers("on_rez", "Invalid argument");
  921. i++;
  922. }
  923. if (i != 1)
  924. {
  925. FindLineNumbers("on_rez", "Too many arguments");
  926. }
  927. }
  928. if (script.Contains(state + "_event_money("))
  929. {
  930. int charNum = script.IndexOf(state + "_event_money(");
  931. string splitScript = script.Remove(0, charNum);
  932. charNum = splitScript.IndexOf('\n');
  933. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  934. string arguments = splitScript.Split('(')[1];
  935. arguments = arguments.Split(')')[0];
  936. string[] AllArguments = arguments.Split(',');
  937. int i = 0;
  938. foreach (string argument in AllArguments)
  939. {
  940. if (i == 0)
  941. if (!argument.Contains("LSL_Types.LSLString"))
  942. FindLineNumbers("money", "Invalid argument");
  943. if (i == 1)
  944. if (!argument.Contains("LSL_Types.LSLInteger"))
  945. FindLineNumbers("money", "Invalid argument");
  946. i++;
  947. }
  948. if (i != 2)
  949. {
  950. FindLineNumbers("money", "Too many arguments");
  951. }
  952. }
  953. if (script.Contains(state + "_event_moving_end("))
  954. {
  955. int charNum = script.IndexOf(state + "_event_moving_end(");
  956. string splitScript = script.Remove(0, charNum);
  957. charNum = splitScript.IndexOf('\n');
  958. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  959. string Valid = state + "_event_moving_end()";
  960. if (splitScript != Valid)
  961. {
  962. FindLineNumbers("moving_end", "Too many arguments");
  963. }
  964. }
  965. if (script.Contains(state + "_event_moving_start("))
  966. {
  967. int charNum = script.IndexOf(state + "_event_moving_start(");
  968. string splitScript = script.Remove(0, charNum);
  969. charNum = splitScript.IndexOf('\n');
  970. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  971. string Valid = state + "_event_moving_start()";
  972. if (splitScript != Valid)
  973. {
  974. FindLineNumbers("moving_start", "Too many arguments");
  975. }
  976. }
  977. if (script.Contains(state + "_event_no_sensor("))
  978. {
  979. int charNum = script.IndexOf(state + "_event_no_sensor(");
  980. string splitScript = script.Remove(0, charNum);
  981. charNum = splitScript.IndexOf('\n');
  982. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  983. string Valid = state + "_event_no_sensor()";
  984. if (splitScript != Valid)
  985. {
  986. FindLineNumbers("no_sensor", "Too many arguments");
  987. }
  988. }
  989. if (script.Contains(state + "_event_not_at_rot_target("))
  990. {
  991. int charNum = script.IndexOf(state + "_event_not_at_rot_target(");
  992. string splitScript = script.Remove(0, charNum);
  993. charNum = splitScript.IndexOf('\n');
  994. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  995. string Valid = state + "_event_not_at_rot_target()";
  996. if (splitScript != Valid)
  997. {
  998. FindLineNumbers("not_at_rot_target", "Too many arguments");
  999. }
  1000. }
  1001. if (script.Contains(state + "_event_object_rez("))
  1002. {
  1003. int charNum = script.IndexOf(state + "_event_object_rez(");
  1004. string splitScript = script.Remove(0, charNum);
  1005. charNum = splitScript.IndexOf('\n');
  1006. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  1007. string arguments = splitScript.Split('(')[1];
  1008. arguments = arguments.Split(')')[0];
  1009. string[] AllArguments = arguments.Split(',');
  1010. int i = 0;
  1011. foreach (string argument in AllArguments)
  1012. {
  1013. if (i == 0)
  1014. if (!argument.Contains("LSL_Types.LSLString"))
  1015. FindLineNumbers("object_rez", "Invalid argument");
  1016. i++;
  1017. }
  1018. if (i != 1)
  1019. {
  1020. FindLineNumbers("object_rez", "Too many arguments");
  1021. }
  1022. }
  1023. if (script.Contains(state + "_event_on_error("))
  1024. {
  1025. int charNum = script.IndexOf(state + "_event_on_error(");
  1026. string splitScript = script.Remove(0, charNum);
  1027. charNum = splitScript.IndexOf('\n');
  1028. splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
  1029. string arguments = splitScript.Split('(')[1];
  1030. arguments = arguments.Split(')')[0];
  1031. string[] AllArguments = arguments.Split(',');
  1032. int i = 0;
  1033. foreach (string argument in AllArguments)
  1034. {
  1035. if (i == 0)
  1036. if (!argument.Contains("LSL_Types.LSLString"))
  1037. FindLineNumbers("on_error", "Invalid argument");
  1038. i++;

Large files files are truncated, but you can click here to view the full file