Exemplo n.º 1
0
        public static void AddLocalVariable(ParserFunction local)
        {
            NormalizeValue(local);
            local.m_isGlobal = false;
            StackLevel locals = null;

            lock (s_variables)
            {
                if (s_lastExecutionLevel == null)
                {
                    s_lastExecutionLevel = new StackLevel();
                    s_locals.Push(s_lastExecutionLevel);
                }
                else
                {
                    locals = s_lastExecutionLevel;
                }
            }

            var name = Constants.ConvertName(local.Name);

            local.Name = Constants.GetRealName(name);
            if (local is GetVarFunction)
            {
                ((GetVarFunction)local).Value.ParamName = local.Name;
            }
            locals.Variables[name] = local;
#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
            Translation.AddTempKeyword(name);
#endif
        }
Exemplo n.º 2
0
        public static void AddGlobalOrLocalVariable(string name, GetVarFunction function, ParsingScript script = null)
        {
            name = Constants.ConvertName(name);
            if (Constants.CheckReserved(name))
            {
                Utils.ThrowErrorMsg(name + " is a reserved name.", script, name);
            }

            Dictionary <string, ParserFunction> lastLevel = GetLastLevel();

            if (lastLevel != null && s_lastExecutionLevel.IsNamespace && !string.IsNullOrWhiteSpace(s_namespace))
            {
                name = s_namespacePrefix + name;
            }

            function.Name            = Constants.GetRealName(name);
            function.Value.ParamName = function.Name;
            if (script != null && script.StackLevel != null && !GlobalNameExists(name))
            {
                script.StackLevel.Variables[name] = function;
                var handle = OnVariableChange;
                if (handle != null)
                {
                    handle.Invoke(function.Name, function.Value, false);
                }
            }
            else if (s_locals.Count > StackLevelDelta && (LocalNameExists(name) || !GlobalNameExists(name)))
            {
                AddLocalVariable(function);
            }
            else
            {
                AddGlobal(name, function, false /* not native */);
            }
        }
Exemplo n.º 3
0
        public static void RegisterFunction(string name, ParserFunction function,
                                            bool isNative = true)
        {
            name = Constants.ConvertName(name);
            if (s_functions.TryGetValue(name, out ParserFunction old))
            {
                var msg = "Warning: Overriding function [" + old.Name + "].";
                System.Diagnostics.Debug.WriteLine(msg);
            }
            function.Name = Constants.GetRealName(name);

            if (!string.IsNullOrWhiteSpace(s_namespace))
            {
                StackLevel level;
                if (s_namespaces.TryGetValue(s_namespace, out level) &&
                    function is CustomFunction)
                {
                    ((CustomFunction)function).NamespaceData = level;
                    name = s_namespacePrefix + name;
                }
            }

            s_functions[name] = function;
            function.isNative = isNative;
        }
Exemplo n.º 4
0
        public static void AddGlobal(string name, ParserFunction function,
                                     bool isNative = true)
        {
            Utils.CheckLegalName(name);
            name = Constants.ConvertName(name);
            NormalizeValue(function);
            function.isNative = isNative;

            var  handle = OnVariableChange;
            bool exists = handle != null && s_variables.ContainsKey(name);

            s_variables[name] = function;

            function.Name = Constants.GetRealName(name);
#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
            if (!isNative)
            {
                Translation.AddTempKeyword(name);
            }
#endif
            if (handle != null && function is GetVarFunction)
            {
                handle.Invoke(function.Name, ((GetVarFunction)function).Value, exists);
            }
        }
Exemplo n.º 5
0
        public static void AddGlobalOrLocalVariable(string name, GetVarFunction function,
                                                    ParsingScript script = null, bool localIfPossible = false)
        {
            name = Constants.ConvertName(name);
            if (Constants.CheckReserved(name))
            {
                Utils.ThrowErrorMsg(name + " is a reserved name.", script, name);
            }

            bool globalOnly = !localIfPossible && !LocalNameExists(name);
            Dictionary <string, ParserFunction> lastLevel = GetLastLevel();

            if (!globalOnly && lastLevel != null && s_lastExecutionLevel.IsNamespace && !string.IsNullOrWhiteSpace(s_namespace))
            {
                name = s_namespacePrefix + name;
            }

            function.Name            = Constants.GetRealName(name);
            function.Value.ParamName = function.Name;

            if (!globalOnly && !localIfPossible && script != null && script.StackLevel != null && !GlobalNameExists(name))
            {
                script.StackLevel.Variables[name] = function;
            }

            if (!globalOnly && s_locals.Count > StackLevelDelta &&
                (localIfPossible || LocalNameExists(name) || !GlobalNameExists(name)))
            {
                AddLocalVariable(function);
            }
            else
            {
                AddGlobal(name, function, false /* not native */);
            }
        }
Exemplo n.º 6
0
        public static void AddLocalVariable(ParserFunction local, string varName = "")
        {
            NormalizeValue(local);
            local.m_isGlobal = false;

            lock (s_variables)
            {
                if (s_lastExecutionLevel == null)
                {
                    s_lastExecutionLevel = new StackLevel();
                    s_locals.Push(s_lastExecutionLevel);
                }
            }

            var name = Constants.ConvertName(string.IsNullOrWhiteSpace(varName) ? local.Name : varName);

            local.Name = Constants.GetRealName(name);
            if (local is GetVarFunction)
            {
                ((GetVarFunction)local).Value.ParamName = local.Name;
            }

            var  handle = OnVariableChange;
            bool exists = handle != null && s_lastExecutionLevel.Variables.ContainsKey(name);

            s_lastExecutionLevel.Variables[name] = local;
#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
            Translation.AddTempKeyword(name);
#endif
            if (handle != null && local is GetVarFunction)
            {
                handle.Invoke(local.Name, ((GetVarFunction)local).Value, exists);
            }
        }
Exemplo n.º 7
0
 public static void CheckNotNull(object obj, string name, ParsingScript script)
 {
     if (obj == null)
     {
         string realName = Constants.GetRealName(name);
         ThrowErrorMsg("Object [" + realName + "] doesn't exist.", script, name);
     }
 }
Exemplo n.º 8
0
 public static void CheckNotEmpty(string varName, string name)
 {
     if (string.IsNullOrEmpty(varName))
     {
         string realName = Constants.GetRealName(name);
         ThrowErrorMsg("Incomplete arguments for [" + realName + "]", null, name);
     }
 }
Exemplo n.º 9
0
 public static void CheckNotEnd(ParsingScript script, string name)
 {
     if (!script.StillValid())
     {
         string realName = Constants.GetRealName(name);
         throw new ArgumentException("Incomplete arguments for [" + realName + "]");
     }
 }
Exemplo n.º 10
0
 public static void CheckNotNull(string name, ParserFunction func)
 {
     if (func == null)
     {
         string realName = Constants.GetRealName(name);
         throw new ArgumentException("Variable or function [" + realName + "] doesn't exist");
     }
 }
Exemplo n.º 11
0
 public static void CheckNotEnd(ParsingScript script, string name)
 {
     if (!script.StillValid())
     {
         string realName = Constants.GetRealName(name);
         ThrowErrorMsg("Incomplete arguments for [" + realName + "]", script, script.Prev.ToString());
     }
 }
Exemplo n.º 12
0
 public static void CheckNotEmpty(string varName, string name)
 {
     if (string.IsNullOrEmpty(varName))
     {
         string realName = Constants.GetRealName(name);
         throw new ArgumentException("Incomplete arguments for [" + realName + "]");
     }
 }
Exemplo n.º 13
0
 public static void CheckNotNull(string name, ParserFunction func, ParsingScript script)
 {
     if (func == null)
     {
         string realName = Constants.GetRealName(name);
         ThrowErrorMsg("Variable or function [" + realName + "] doesn't exist.", script, name);
     }
 }
Exemplo n.º 14
0
 public static void CheckNotEmpty(ParsingScript script, string varName, string name)
 {
     if (!script.StillValid() || string.IsNullOrWhiteSpace(varName))
     {
         string realName = Constants.GetRealName(name);
         ThrowErrorMsg("Incomplete arguments for [" + realName + "].", script, name);
     }
 }
Exemplo n.º 15
0
 public static void CheckPosInt(int number, string name)
 {
     if (number < 0)
     {
         string realName = Constants.GetRealName(name);
         throw new ArgumentException("Expected a positive integer instead of [" +
                                     number + "] in [" + realName + "]");
     }
 }
Exemplo n.º 16
0
 public static void CheckArray(Variable variable, string name)
 {
     if (variable.Tuple == null)
     {
         string realName = Constants.GetRealName(name);
         throw new ArgumentException("An array expected for variable [" +
                                     realName + "]");
     }
 }
Exemplo n.º 17
0
 public static void CheckNotNull(object obj, string name, int index = -1)
 {
     if (obj == null)
     {
         string indexStr = index >= 0 ? " in position " + (index + 1) : "";
         string realName = Constants.GetRealName(name);
         throw new ArgumentException("Invalid argument " + indexStr +
                                     " in function [" + realName + "]");
     }
 }
Exemplo n.º 18
0
 public static void CheckNotNull(object obj, string name, ParsingScript script, int index = -1)
 {
     if (obj == null)
     {
         string indexStr = index >= 0 ? " in position " + (index + 1) : "";
         string realName = Constants.GetRealName(name);
         ThrowErrorMsg("Invalid argument " + indexStr +
                       " in function [" + realName + "].", script, name);
     }
 }
Exemplo n.º 19
0
        public static void ProcessErrorMsg(string str, ParsingScript script)
        {
            char   ch     = script.TryPrev();
            string entity = ch == '(' ? "function":
                            ch == '[' ? "array"   :
                            ch == '{' ? "operand" :
                            "variable";
            string token = Constants.GetRealName(str);

            string msg = "Couldn't find " + entity + " [" + token + "].";

            ThrowErrorMsg(msg, script, str);
        }
Exemplo n.º 20
0
        public static void AddGlobal(string name, ParserFunction function,
                                     bool isNative = true)
        {
            name = Constants.ConvertName(name);
            NormalizeValue(function);
            function.isNative = isNative;
            s_variables[name] = function;

            function.Name = Constants.GetRealName(name);
#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
            if (!isNative)
            {
                Translation.AddTempKeyword(name);
            }
#endif
        }
Exemplo n.º 21
0
        public static void RegisterFunction(string name, ParserFunction function,
                                            bool isNative = true)
        {
            name          = Constants.ConvertName(name);
            function.Name = Constants.GetRealName(name);

            if (!string.IsNullOrWhiteSpace(s_namespace))
            {
                StackLevel level;
                if (s_namespaces.TryGetValue(s_namespace, out level) &&
                    function is CustomFunction)
                {
                    ((CustomFunction)function).NamespaceData = level;
                    name = s_namespacePrefix + name;
                }
            }

            s_functions[name] = function;
            function.isNative = isNative;
        }
Exemplo n.º 22
0
        public static void AddLocalScopeVariable(string name, string scopeName, ParserFunction variable)
        {
            name = Constants.ConvertName(name);
            variable.isNative = false;
            variable.Name     = Constants.GetRealName(name);

            if (scopeName == null)
            {
                scopeName = "";
            }

            Dictionary <string, ParserFunction> localScope;

            if (!s_localScope.TryGetValue(scopeName, out localScope))
            {
                localScope = new Dictionary <string, ParserFunction>();
            }
            localScope[name]        = variable;
            s_localScope[scopeName] = localScope;
        }
Exemplo n.º 23
0
        public static void AddGlobalOrLocalVariable(string name, GetVarFunction function)
        {
            name = Constants.ConvertName(name);

            Dictionary <string, ParserFunction> lastLevel = GetLastLevel();

            if (lastLevel != null && s_locals.Peek().IsNamespace&& !string.IsNullOrWhiteSpace(s_namespace))
            {
                name = s_namespacePrefix + name;
            }

            function.Name = Constants.GetRealName(name);
            if (s_locals.Count > StackLevelDelta && (LocalNameExists(name) || !GlobalNameExists(name)))
            {
                AddLocalVariable(function);
            }
            else
            {
                AddGlobal(name, function, false /* not native */);
            }
        }
Exemplo n.º 24
0
        public static string GetActualPropertyName(string propName, List <string> properties,
                                                   string baseName = "", Variable root = null)
        {
            string match = properties.FirstOrDefault(element => element.Equals(propName,
                                                                               StringComparison.OrdinalIgnoreCase));

            if (string.IsNullOrWhiteSpace(match))
            {
                match = "";
                if (root != null)
                {
                    string objName = !string.IsNullOrWhiteSpace(baseName) ? baseName + "." : "";
                    if (string.IsNullOrWhiteSpace(objName))
                    {
                        CSCSClass.ClassInstance obj = root.m_object as CSCSClass.ClassInstance;
                        objName = obj != null ? obj.InstanceName + "." : "";
                    }
                    match = Constants.GetRealName(objName + propName);
                    match = match.Substring(objName.Length);
                }
            }
            return(match);
        }
Exemplo n.º 25
0
        public static void AddLocalVariable(ParserFunction local)
        {
            NormalizeValue(local);
            local.m_isGlobal = false;
            StackLevel locals = null;

            if (s_locals.Count == 0)
            {
                locals = new StackLevel();
                s_locals.Push(locals);
            }
            else
            {
                locals = s_locals.Peek();
            }

            var name = Constants.ConvertName(local.Name);

            local.Name             = Constants.GetRealName(name);
            locals.Variables[name] = local;
#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
            Translation.AddTempKeyword(name);
#endif
        }