PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/Aurora/AuroraDotNetEngine/CompilerTools/CSCodeGenerator.cs

https://bitbucket.org/VirtualReality/aurora-sim
C# | 3413 lines | 2479 code | 407 blank | 527 comment | 602 complexity | 7996c0e698533e0a6ab24dd9d668b6c2 MD5 | raw file

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

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