/Aurora/AuroraDotNetEngine4/CompilerTools/CSCodeGenerator.cs
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
- /*
- * Copyright (c) Contributors, http://aurora-sim.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Aurora-Sim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Collections;
- using System.Text;
- using Tools;
-
- namespace Aurora.ScriptEngine.AuroraDotNetEngine.CompilerTools
- {
- public static class Extension
- {
- public static bool CompareWildcards(this string WildString, string Mask, bool IgnoreCase)
- {
- int i = 0;
-
- if (String.IsNullOrEmpty(Mask))
- return false;
- if (Mask == "*")
- return true;
-
- while (i != Mask.Length)
- {
- if (CompareWildcard(WildString, Mask.Substring(i), IgnoreCase))
- return true;
-
- while (i != Mask.Length && Mask[i] != ';')
- i += 1;
-
- if (i != Mask.Length && Mask[i] == ';')
- {
- i += 1;
-
- while (i != Mask.Length && Mask[i] == ' ')
- i += 1;
- }
- }
-
- return false;
- }
-
- public static bool CompareWildcard(this string WildString, string Mask, bool IgnoreCase)
- {
- int i = 0, k = 0;
-
- while (k != WildString.Length)
- {
- if ((i + 1) > Mask.Length)
- return true;
- switch (Mask[i])
- {
- case '*':
-
- if ((i + 1) >= Mask.Length)
- return true;
-
- while (k != WildString.Length)
- {
- if (CompareWildcard(WildString.Substring(k + 1), Mask.Substring(i + 1), IgnoreCase))
- return true;
-
- k += 1;
- }
-
- return false;
-
- case '?':
-
- break;
-
- default:
-
- if (IgnoreCase == false && WildString[k] != Mask[i])
- return false;
- if (IgnoreCase && Char.ToLower(WildString[k]) != Char.ToLower(Mask[i]))
- return false;
-
- break;
- }
-
- i += 1;
- k += 1;
- }
-
- if (k == WildString.Length)
- {
- if (i == Mask.Length || Mask[i] == ';' || Mask[i] == '*')
- return true;
- }
-
- return false;
- }
- }
-
- public class CSCodeGenerator : IDisposable
- {
- private SYMBOL m_astRoot = null;
- private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
- private int m_indentWidth = 4; // for indentation
- private int m_braceCount; // for indentation
- private int m_CSharpLine; // the current line of generated C# code
- private int m_CSharpCol; // the current column of generated C# code
- private string OriginalScript = "";
- private Parser p = null;
- private Random random = new Random();
- private bool IsaGlobalVar = false;
-
- private class GlobalVar
- {
- public string Type;
- public string Value;
- }
- private HashSet<string> DTFunctions = new HashSet<string>();
- // public Dictionary<string, string> IenFunctions = new Dictionary<string, string>();
- public Dictionary<string, string> LocalMethods = new Dictionary<string, string>();
- public Dictionary<string, ObjectList> LocalMethodArguements = new Dictionary<string, ObjectList>();
- private Dictionary<string, GlobalVar> GlobalVariables = new Dictionary<string, GlobalVar>();
-
- /// <summary>
- /// 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
- /// </summary>
- private Dictionary<string, GlobalVar> MethodVariables = new Dictionary<string, GlobalVar>();
-
- private class VarRename
- {
- //public string NewVarName;
- //public bool HasBeenAssigned;
- //public string OldVarName;
- }
- /// <summary>
- /// This contains a list of variables that we need to rename because of some constraint
- /// </summary>
- private Dictionary<string, VarRename> VariablesToRename = new Dictionary<string, VarRename>();
- private List<string> FuncCalls = new List<string>();
- private List<string> MethodsToAdd = new List<string>();
- /// <summary>
- /// Param 1 - the API function name, Param 2 - the API name
- /// </summary>
- private Dictionary<string, IScriptApi> m_apiFunctions = new Dictionary<string, IScriptApi>();
- private Compiler m_compiler;
-
- /// <summary>
- /// Creates an 'empty' CSCodeGenerator instance.
- /// </summary>
- public CSCodeGenerator(Compiler compiler)
- {
- ResetCounters();
- m_compiler = compiler;
-
- IScriptApi[] apis = compiler.ScriptEngine.GetAPIs();
-
- foreach (IScriptApi api in apis)
- {
- List<string> FunctionNames = compiler.ScriptEngine.GetFunctionNames(api);
- foreach (string functionName in FunctionNames)
- {
- if (!m_apiFunctions.ContainsKey(functionName))
- m_apiFunctions.Add(functionName, api);
- }
- }
- }
-
- /// <summary>
- /// Get the mapping between LSL and C# line/column number.
- /// </summary>
- /// <returns>Dictionary\<KeyValuePair\<int, int\>, KeyValuePair\<int, int\>\>.</returns>
- public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> PositionMap
- {
- get { return m_positionMap; }
- }
-
- /// <summary>
- /// Get the mapping between LSL and C# line/column number.
- /// </summary>
- /// <returns>SYMBOL pointing to root of the abstract syntax tree.</returns>
- public SYMBOL ASTRoot
- {
- get { return m_astRoot; }
- }
-
- /// <summary>
- /// Resets various counters and metadata.
- /// </summary>
- private void ResetCounters()
- {
- //NOTE: This takes a VERY long time to rebuild. Ideally, this should be reset, but interesting errors are happening when it is reset..
- p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
- MethodVariables.Clear();
- VariablesToRename.Clear();
- GlobalVariables.Clear();
- m_braceCount = 0;
- m_CSharpLine = 15;
- m_CSharpCol = 1;
- m_positionMap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
- LocalMethods.Clear();
- m_astRoot = null;
- OriginalScript = "";
- lock (FuncCalls)
- FuncCalls.Clear();
- IsaGlobalVar = false;
- MethodsToAdd.Clear();
- LocalMethodArguements.Clear();
- }
-
- private string CreateCompilerScript(string ScriptClass)
- {
- string compiledScript = "";
- compiledScript += "using Aurora.ScriptEngine.AuroraDotNetEngine.Runtime;\n";
- compiledScript += "using Aurora.ScriptEngine.AuroraDotNetEngine;\n";
- compiledScript += "using Aurora.ScriptEngine.AuroraDotNetEngine.APIs.Interfaces;\n";
- compiledScript += "using System;\n";
- compiledScript += "using System.Collections.Generic;\n";
- compiledScript += "using System.Collections;\n";
- compiledScript += "using System.Reflection;\n";
- compiledScript += "using System.Timers;\n";
- foreach (IScriptApi api in m_compiler.ScriptEngine.GetAPIs())
- {
- foreach (string nameSpace in api.NamespaceAdditions)
- {
- compiledScript += "using " + nameSpace + ";\n";
- }
- }
-
- compiledScript += "namespace Script\n";
- compiledScript += "{\n";
-
- compiledScript += "[Serializable]\n";
- compiledScript += "public class ScriptClass : Aurora.ScriptEngine.AuroraDotNetEngine.Runtime.ScriptBaseClass\n";
- compiledScript += "{\n";
-
- compiledScript += ScriptClass;
- foreach(string method in MethodsToAdd)
- {
- compiledScript += method;
- }
-
- compiledScript += "}\n"; // Close Class
-
- compiledScript += "}\n"; // Close Namespace
-
- return compiledScript.ToString();
- }
-
- /// <summary>
- /// Generate the code from the AST we have.
- /// </summary>
- /// <param name="script">The LSL source as a string.</param>
- /// <returns>String containing the generated C# code.</returns>
- public string Convert(string script)
- {
- ResetCounters();
-
- LSL2CSCodeTransformer codeTransformer;
- try
- {
- // lock (p)
- {
- codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
- // p.m_lexer.Reset();
- }
- }
- catch (CSToolsException e)
- {
- string message;
-
- // LL start numbering lines at 0 - geeks!
- // Also need to subtract one line we prepend!
- //
- string emessage = e.Message;
- string slinfo = e.slInfo.ToString();
-
- // Remove wrong line number info
- //
- if (emessage.StartsWith(slinfo + ": "))
- emessage = emessage.Substring(slinfo.Length + 2);
-
- if (e.slInfo.lineNumber - 1 <= 0)
- e.slInfo.lineNumber = 2;
- if (e.slInfo.charPosition - 1 <= 0)
- e.slInfo.charPosition = 2;
-
- message = String.Format("({0},{1}) {2}",
- e.slInfo.lineNumber - 1,
- e.slInfo.charPosition - 1, emessage);
-
- m_compiler.AddError(message);
- // p.m_lexer.Reset();
- ResetCounters();
- return "Error parsing the script. " + message;
- }
-
- m_astRoot = codeTransformer.Transform(LocalMethods, LocalMethodArguements);
- OriginalScript = script;
- string returnstring = "";
-
- // line number
- //m_CSharpLine += 3;
-
- // here's the payload
- returnstring += GenerateLine();
- foreach (SYMBOL s in m_astRoot.kids)
- returnstring += GenerateNode(s);
-
- // Removes all carriage return characters which may be generated in Windows platform.
- //Is there a cleaner way of doing this?
- returnstring = returnstring.Replace("\r", "");
-
- CheckEventCasts(returnstring);
- return CreateCompilerScript(returnstring);
- }
-
- private string CheckFloatExponent(string script)
- {
- string[] SplitScript = script.Split('\n');
- List<string> ReconstructableScript = new List<string>();
-
- foreach (string line in SplitScript)
- {
- string AddLine = line;
- if (AddLine.Replace(" ", "") == "default")
- break; //We only check above default
-
- if (AddLine.Contains("float"))
- {
- if (line.Contains("e") && !line.Contains("(") && !line.Contains(")")) // Looking for exponents, but not for functions that have ()
- {
- //Should have this - float *** = 151e9;
- string[] SplitBeforeE = AddLine.Split('='); // Split at the e so we can look at the syntax
- if (SplitBeforeE.Length != 1)
- {
- string[] SplitBeforeESpace = SplitBeforeE[1].Split(';');
- //Should have something like this now - 151
- if (SplitBeforeESpace[0].Contains("e"))
- {
- if (!SplitBeforeESpace[0].Contains("."))
- {
- //Needs one then
- string[] Split = SplitBeforeESpace[0].Split('e'); // Split at the e so we can look at the syntax
- Split[0] += ".";
- AddLine = "";
- string TempString = "";
- foreach (string tempLine in Split)
- {
- TempString += tempLine + "e";
- }
- TempString = TempString.Remove(TempString.Length - 1, 1);
- SplitBeforeESpace[0] = TempString;
- TempString = "";
- foreach (string tempLine in SplitBeforeESpace)
- {
- TempString += tempLine + ";";
- }
- //Remove the last ;
- TempString = TempString.Remove(TempString.Length - 1, 1);
- SplitBeforeE[1] = TempString;
- foreach (string tempLine in SplitBeforeE)
- {
- AddLine += tempLine + "=";
- }
- //Remove the last e
- AddLine = AddLine.Remove(AddLine.Length - 1, 1);
- }
- }
- }
- }
- }
- ReconstructableScript.Add(AddLine);
- }
- string RetVal = "";
- foreach (string line in ReconstructableScript)
- {
- RetVal += line + "\n";
- }
- return RetVal;
- }
-
- private string CheckForInlineVectors(string script)
- {
- string[] SplitScript = script.Split('\n');
- List<string> ReconstructableScript = new List<string>();
- foreach (string line in SplitScript)
- {
- string AddLine = line;
- if (AddLine.Contains("<") && AddLine.Contains(">"))
- {
- if (AddLine.Contains("\"")) // if it contains ", we need to be more careful
- {
- string[] SplitByParLine = AddLine.Split('\"');
- int lineNumber = 0;
- List<string> ReconstructableLine = new List<string>();
- foreach (string parline in SplitByParLine)
- {
- string AddInsideLine = parline;
- //throw out all odd numbered lines as they are inside ""
- if (lineNumber % 2 != 1)
- {
- string[] SplitLineA = AddLine.Split('<');
- if (SplitLineA.Length > 1)
- {
- string SplitLineB = SplitLineA[1].Split('>')[0];
- if (SplitLineB.CompareWildcard("*,*,*", true))
- {
- AddInsideLine = AddInsideLine.Replace("<", "(<");
- AddInsideLine = AddInsideLine.Replace(">", ">)");
- }
- }
- }
- ReconstructableLine.Add(AddInsideLine);
- lineNumber++;
- }
- AddLine = "";
- foreach (string insideline in ReconstructableLine)
- {
- AddLine += insideline + "\"";
- }
- AddLine = AddLine.Remove(AddLine.Length - 1, 1);
- }
- else
- {
- string[] SplitLineA = AddLine.Split('<');
- if (SplitLineA.Length > 1)
- {
- string SplitLineB = SplitLineA[1].Split('>')[0];
- if (SplitLineB.CompareWildcard("*,*,*", true))
- {
- AddLine = AddLine.Replace("<", "(<");
- AddLine = AddLine.Replace(">", ">)");
- }
- }
- }
- }
- ReconstructableScript.Add(AddLine);
- }
- string RetVal = "";
- foreach (string line in ReconstructableScript)
- {
- RetVal += line + "\n";
- }
- return RetVal;
- }
-
- /// <summary>
- /// Checks the C# script for the correct casts in events
- /// This stops errors from misformed events ex. 'touch(vector3 position)' instead of 'touch(int touch)'
- /// </summary>
- /// <param name="script"></param>
- private void CheckEventCasts(string script)
- {
- CheckEvent(script, "default");
- string[] States = OriginalScript.Split(new string[] { "state " }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string state in States)
- {
- string stateName = state.Split(' ')[0];
- stateName = state.Split('\n')[0];
- if (!stateName.Contains("default"))
- CheckEvent(script, stateName);
- }
- }
-
- private void CheckEvent(string script, string state)
- {
- if (script.Contains(state + "_event_state_entry("))
- {
- string Valid = state + "_event_state_entry()";
- int charNum = script.IndexOf(state + "_event_state_entry(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
- if (splitScript != Valid)
- {
- FindLineNumbers("state_entry", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_touch_start("))
- {
- //Valid : default_event_touch_start(LSL_Types.LSLInteger number)
- int charNum = script.IndexOf(state + "_event_touch_start(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("touch_start", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("touch_start", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_at_rot_target("))
- {
- //Valid : default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)
- int charNum = script.IndexOf(state + "_event_at_rot_target(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("at_rot_target", "Invalid argument");
- if (i == 1 || i == 2)
- if (!argument.Contains("LSL_Types.Quaternion"))
- FindLineNumbers("at_rot_target", "Invalid argument");
- i++;
- }
- if (i != 3)
- {
- FindLineNumbers("at_rot_target", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_at_target("))
- {
- //Valid : default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)
- int charNum = script.IndexOf(state + "_event_at_target(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("at_target", "Invalid argument");
- if (i == 1 || i == 2)
- if (!argument.Contains("LSL_Types.Vector3"))
- FindLineNumbers("at_target", "Invalid argument");
- i++;
- }
- if (i != 3)
- {
- FindLineNumbers("at_target", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_not_at_target("))
- {
- int charNum = script.IndexOf(state + "_event_not_at_target(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string Valid = state + "_event_not_at_target()";
- if (splitScript != Valid)
- {
- FindLineNumbers("not_at_target", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_attach("))
- {
- int charNum = script.IndexOf(state + "_event_attach(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("attach", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("attach", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_changed("))
- {
- int charNum = script.IndexOf(state + "_event_changed(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("changed", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("changed", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_collision("))
- {
- int charNum = script.IndexOf(state + "_event_collision(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("collision", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("collision", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_collision_end("))
- {
- int charNum = script.IndexOf(state + "_event_collision_end(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("collision_end", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("collision_end", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_collision_start("))
- {
- int charNum = script.IndexOf(state + "_event_collision_start(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("collision_start", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("collision_start", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_run_time_permissions("))
- {
- int charNum = script.IndexOf(state + "_event_run_time_permissions(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- {
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("run_time_permissions", "Invalid argument");
- }
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("run_time_permissions", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_control("))
- {
- int charNum = script.IndexOf(state + "_event_control(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("control", "Invalid argument");
- if (i == 1 || i == 2)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("control", "Invalid argument");
- i++;
- }
- if (i != 3)
- {
- FindLineNumbers("control", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_dataserver("))
- {
- int charNum = script.IndexOf(state + "_event_dataserver(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0 || i == 1)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("dataserver", "Invalid argument");
- i++;
- }
- if (i != 2)
- {
- FindLineNumbers("dataserver", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_timer("))
- {
- int charNum = script.IndexOf(state + "_event_timer(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string Valid = state + "_event_timer()";
- if (splitScript != Valid)
- {
- FindLineNumbers("timer", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_email("))
- {
- int charNum = script.IndexOf(state + "_event_email(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0 || i == 1 || i == 2 || i == 3)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("email", "Invalid argument");
- if (i == 4)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("email", "Invalid argument");
- i++;
- }
- if (i != 5)
- {
- FindLineNumbers("email", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_http_request("))
- {
- int charNum = script.IndexOf(state + "_event_http_request(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0 || i == 1 || i == 2)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("http_request", "Invalid argument");
- i++;
- }
- if (i != 3)
- {
- FindLineNumbers("http_request", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_http_response("))
- {
- int charNum = script.IndexOf(state + "_event_http_response(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0 || i == 3)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("http_response", "Invalid argument");
- if (i == 1)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("http_response", "Invalid argument");
- if (i == 2)
- if (!argument.Contains("LSL_Types.list"))
- FindLineNumbers("http_response", "Invalid argument");
- i++;
- }
- if (i != 4)
- {
- FindLineNumbers("http_response", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_land_collision_end("))
- {
- int charNum = script.IndexOf(state + "_event_land_collision_end(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.Vector3"))
- FindLineNumbers("land_collision_end", "Invalid argument");
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("land_collision_end", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_land_collision_start("))
- {
- int charNum = script.IndexOf(state + "_event_land_collision_start(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.Vector3"))
- FindLineNumbers("land_collision_start", "Invalid argument");
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("land_collision_start", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_link_message("))
- {
- int charNum = script.IndexOf(state + "_event_link_message(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0 || i == 1)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("link_message", "Invalid argument");
- if (i == 2 || i == 3)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("link_message", "Invalid argument");
- i++;
- }
- if (i != 4)
- {
- FindLineNumbers("link_message", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_listen("))
- {
- int charNum = script.IndexOf(state + "_event_listen(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("listen", "Invalid argument");
- if (i == 1 || i == 2 || i == 3)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("listen", "Invalid argument");
- i++;
- }
- if (i != 4)
- {
- FindLineNumbers("listen", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_on_rez("))
- {
- int charNum = script.IndexOf(state + "_event_on_rez(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("on_rez", "Invalid argument");
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("on_rez", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_money("))
- {
- int charNum = script.IndexOf(state + "_event_money(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("money", "Invalid argument");
- if (i == 1)
- if (!argument.Contains("LSL_Types.LSLInteger"))
- FindLineNumbers("money", "Invalid argument");
- i++;
- }
- if (i != 2)
- {
- FindLineNumbers("money", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_moving_end("))
- {
- int charNum = script.IndexOf(state + "_event_moving_end(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string Valid = state + "_event_moving_end()";
- if (splitScript != Valid)
- {
- FindLineNumbers("moving_end", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_moving_start("))
- {
- int charNum = script.IndexOf(state + "_event_moving_start(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string Valid = state + "_event_moving_start()";
- if (splitScript != Valid)
- {
- FindLineNumbers("moving_start", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_no_sensor("))
- {
- int charNum = script.IndexOf(state + "_event_no_sensor(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string Valid = state + "_event_no_sensor()";
- if (splitScript != Valid)
- {
- FindLineNumbers("no_sensor", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_not_at_rot_target("))
- {
- int charNum = script.IndexOf(state + "_event_not_at_rot_target(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string Valid = state + "_event_not_at_rot_target()";
- if (splitScript != Valid)
- {
- FindLineNumbers("not_at_rot_target", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_object_rez("))
- {
- int charNum = script.IndexOf(state + "_event_object_rez(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("object_rez", "Invalid argument");
- i++;
- }
- if (i != 1)
- {
- FindLineNumbers("object_rez", "Too many arguments");
- }
- }
- if (script.Contains(state + "_event_on_error("))
- {
- int charNum = script.IndexOf(state + "_event_on_error(");
- string splitScript = script.Remove(0, charNum);
- charNum = splitScript.IndexOf('\n');
- splitScript = splitScript.Remove(charNum, splitScript.Length - charNum);
-
- string arguments = splitScript.Split('(')[1];
- arguments = arguments.Split(')')[0];
-
- string[] AllArguments = arguments.Split(',');
-
- int i = 0;
- foreach (string argument in AllArguments)
- {
- if (i == 0)
- if (!argument.Contains("LSL_Types.LSLString"))
- FindLineNumbers("on_error", "Invalid argument");
- i++;
- …
Large files files are truncated, but you can click here to view the full file