コード例 #1
0
        public override CSObject Evaluate(CSState state, CSObject curObj)
        {
            if (ChildCount != 2)
            {
                CSLog.E(this, "assigngment operator has invalid # of children...");
                return(null);
            }
            CSObject left = Left.Evaluate(state, curObj);

            if (left.CanCast <IList> ())
            {
                int         index = IndexNode.EvaluateIndex(state, curObj);
                System.Type type  = ReflectionUtil.GetIListElementType(left.Type);
                return(CSObject.ArrayVariableObject(this, type, left.Value, index));
            }
            else if (left.CanCast <IDictionary> ())
            {
                string      key  = IndexNode.EvaluateKey(state, curObj);
                System.Type type = ReflectionUtil.GetIDictionaryElementType(left.Type);
                return(CSObject.DictionaryVariableObject(this, type, left.Value, key));
            }
            else
            {
                CSLog.E(this, "you cannot use an index to non IList object");
                return(null);
            }
        }
コード例 #2
0
        public override CSObject Evaluate(CSState state, CSObject curObj)
        {
            if (curObj == null)
            {
                CSLog.E(this, "curObj is missing");
                return(null);
            }

            int    len = _selectors.Length;
            object obj = curObj.Value;

            for (int i = 0; i < len - 1; ++i)
            {
                if (obj == null)
                {
                    CSLog.E(this, "object is not assgined");
                    return(null);
                }

                obj = ReflectionUtil.Get(obj, _selectors[i]);
            }

            if (obj == null)
            {
                CSLog.E(this, "object is not assgined");
                return(null);
            }
            string variableName = _selectors[len - 1];

            System.Type type = ReflectionUtil.GetFieldType(obj, variableName);

            return(CSObject.InstanceVariableObject(this, type, obj, variableName));
        }
コード例 #3
0
        public KeyValuePair <object, object> Evaluate(CSState state, CSObject curObj, int index, System.Type keyType, System.Type valueType)
        {
            KeyValuePair <object, object> element = new KeyValuePair <object, object> (
                _keys[index].Evaluate(state, curObj).GetAs(keyType),
                _children[index].Evaluate(state, curObj).GetAs(valueType));

            return(element);
        }
コード例 #4
0
        public KeyValuePair <string, object> Evaluate(CSState state, CSObject curObj, int index, object target)
        {
            KeyValuePair <string, object> element = new KeyValuePair <string, object> (
                _variableNames[index],
                _children[index].Evaluate(state, curObj).Value);

            return(element);
        }
コード例 #5
0
ファイル: CSScope.cs プロジェクト: masakinomura/csscript
 public void AddVarible(string variableName, CSObject obj)
 {
     variableName = SkipAtMark(variableName);
     if (_variables.ContainsKey(variableName))
     {
         CSLog.E("Variable " + variableName + " already exists...");
         return;
     }
     _variables[variableName] = obj;
 }
コード例 #6
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     if (IsIndexed)
     {
         return(IndexNode.Evaluate(state, curObj));
     }
     else
     {
         return(CSObject.ImmediateObject(this, typeof(int), -1));
     }
 }
コード例 #7
0
ファイル: CSScope.cs プロジェクト: masakinomura/csscript
 public object SetVariable(string variableName, CSObject val)
 {
     variableName = SkipAtMark(variableName);
     if (!_variables.ContainsKey(variableName))
     {
         CSLog.E("Variable " + variableName + " does not exist...");
         return(null);
     }
     _variables[variableName] = val;
     return(val);
 }
コード例 #8
0
ファイル: CSScope.cs プロジェクト: masakinomura/csscript
        public object GetVariable(string variableName)
        {
            variableName = SkipAtMark(variableName);
            CSObject val = null;

            if (!_variables.TryGetValue(variableName, out val))
            {
                CSLog.E("Variable: " + variableName + " does not exist...");
            }
            return(val);
        }
コード例 #9
0
ファイル: CSOPDotNode.cs プロジェクト: masakinomura/csscript
        public override CSObject Evaluate(CSState state, CSObject curObj)
        {
            if (ChildCount != 2)
            {
                CSLog.E(this, "assigngment operator has invalid # of children...");
                return(null);
            }
            CSObject left  = Left.Evaluate(state, curObj);
            CSObject right = Right.Evaluate(state, left);

            return(right);
        }
コード例 #10
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     if (_declaration)
     {
         CSObject obj = CSObject.LocalVariableObject(this, _type, _variableName, null);
         state.AddVariable(_variableName, obj);
         return(obj);
     }
     else
     {
         return(state.GetVariable(_variableName));
     }
 }
コード例 #11
0
        public object[] EvaluateElements(CSState state, CSObject curObj, System.Type type)
        {
            int len = ChildCount;

            object[] elements = new object[len];

            for (int i = 0; i < len; ++i)
            {
                CSObject obj = _children[i].Evaluate(state, curObj);
                elements[i] = obj.GetAs(type);
            }
            return(elements);
        }
コード例 #12
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject StaticVariableObject(CSNode node, System.Type type, System.Type staticType, string name)
        {
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = null,
                _type       = type,
                _objectType = ObjectType.STATIC,
                _name       = name,
                _staticType = staticType,
                _arrayIndex = -1,
            };

            return(obj);
        }
コード例 #13
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject LocalVariableObject(CSNode node, System.Type type, string name, object val)
        {
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = val,
                _type       = type,
                _objectType = ObjectType.LOCAL,
                _name       = name,
                _staticType = null,
                _arrayIndex = -1,
            };

            return(obj);
        }
コード例 #14
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject InstanceVariableObject(CSNode node, System.Type type, object parent, string name)
        {
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = parent,
                _type       = type,
                _objectType = ObjectType.VARIABLE,
                _name       = name,
                _staticType = null,
                _arrayIndex = -1,
            };

            return(obj);
        }
コード例 #15
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject DictionaryVariableObject(CSNode node, System.Type type, object dictionary, string name)
        {
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = dictionary,
                _type       = type,
                _objectType = ObjectType.DICTIONARY,
                _name       = name,
                _staticType = null,
                _arrayIndex = -1,
            };

            return(obj);
        }
コード例 #16
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject ArrayVariableObject(CSNode node, System.Type type, object array, int index)
        {
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = array,
                _type       = type,
                _objectType = ObjectType.ARRAY,
                _name       = "array",
                _staticType = null,
                _arrayIndex = index,
            };

            return(obj);
        }
コード例 #17
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject TempVariableObject(CSNode node, System.Type type, object val)
        {
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = val,
                _type       = type,
                _objectType = ObjectType.TEMP,
                _name       = "temp",
                _staticType = null,
                _arrayIndex = -1,
            };

            return(obj);
        }
コード例 #18
0
        public bool TryGetVariable(string variableName, out CSObject obj)
        {
            CSScope  next = Current;
            CSObject val;

            while (next != null)
            {
                if (next.TryGetVariable(variableName, out val))
                {
                    obj = val;
                    return(true);
                }
                next = next._parent;
            }
            obj = null;
            return(false);
        }
コード例 #19
0
ファイル: CSNode.cs プロジェクト: masakinomura/csscript
        public virtual CSObject Evaluate(CSState state, CSObject curObj)
        {
            if (_children == null)
            {
                return(null);
            }

            CSObject lastResult = null;

            int len = _children.Length;

            for (int i = 0; i < len; ++i)
            {
                lastResult = _children[i].Evaluate(state, curObj);
            }

            return(lastResult);
        }
コード例 #20
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public CSObject Assign(CSObject obj)
        {
            switch (ObjectType)
            {
            case ObjectType.VARIABLE:
                ReflectionUtil.Set(_object, _name, obj.GetAs(_type));
                break;

            case ObjectType.STATIC:
                ReflectionUtil.Set(_staticType, _name, obj.GetAs(_type));
                break;

            case ObjectType.ARRAY:
                IList array = (IList)_object;
                array[_arrayIndex] = obj.GetAs(_type);
                break;

            case ObjectType.DICTIONARY:
                IDictionary dictionary = (IDictionary)_object;
                dictionary[_name] = obj.GetAs(_type);
                break;

            case ObjectType.TEMP:
            case ObjectType.LOCAL:
                if (_type == null)
                {
                    _object = obj.Value;
                    _type   = obj.Type;
                }
                else
                {
                    _object = obj.GetAs(_type);
                }
                break;

            default:
                CSLog.E(_node, "cannot assign to " + _objectType.ToString());
                break;
            }

            return(this);
        }
コード例 #21
0
ファイル: CSObject.cs プロジェクト: masakinomura/csscript
        public static CSObject ImmediateObject(CSNode node, System.Type type, object val)
        {
            if (val == null)
            {
                CSLog.E(node, "val cannot be null");
                return(null);
            }
            CSObject obj = new CSObject()
            {
                _node       = node,
                _object     = val,
                _type       = val.GetType(),
                _objectType = ObjectType.IMMEDIATE,
                _name       = "immedidate",
                _staticType = null,
                _arrayIndex = -1,
            };

            return(obj);
        }
コード例 #22
0
        public override CSObject Evaluate(CSState state, CSObject curObj)
        {
            CSObject selectedObj = Selectors.Evaluate(state, curObj);

            object[] parameters = null;

            if (Parameters.ChildCount > 0)
            {
                CSNode[] children = Parameters._children;
                int      clen     = children.Length;
                parameters = new object[clen];

                for (int i = 0; i < clen; ++i)
                {
                    CSObject next = children[i].Evaluate(state, curObj);
                    parameters[i] = next.Value;
                }
            }

            System.Type[] types = null;
            if (_genericParameters != null)
            {
                int glen = _genericParameters.Length;
                types = new System.Type[glen];
                for (int i = 0; i < glen; ++i)
                {
                    types[i] = _genericParameters[i]._type;
                }
            }

            System.Type retType;

            object retVal = ReflectionUtil.CallMethod(selectedObj.Value, _functionName, types, out retType, parameters);

            return(CSObject.TempVariableObject(this, retType, retVal));
        }
コード例 #23
0
        public override CSNode VisitVarDeclExp(CSScriptParser.VarDeclExpContext context)
        {
            CSLocalVariableNode variableNode = new CSLocalVariableNode(context.Start.Line, context.Start.Column);

            variableNode._declaration  = true;
            variableNode._variableName = context.NAME().GetText();

            CSScriptParser.TypeContext vartypes = context.type();
            if (vartypes != null)
            {
                CSTypeNode typeNode = Visit(vartypes) as CSTypeNode;
                if (typeNode == null)
                {
                    CSLog.E(variableNode, "failed to get the type");
                }
                variableNode._type = typeNode._type;
            }

            CSObject objForComplier = CSObject.LocalVariableObject(variableNode, variableNode._type, variableNode._variableName, null);

            _state.AddVariable(variableNode._variableName, objForComplier);

            return(variableNode);
        }
コード例 #24
0
ファイル: CSFloatNode.cs プロジェクト: masakinomura/csscript
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(CSObject.ImmediateObject(this, typeof(float), _val));
 }
コード例 #25
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(CSObject.StaticVariableObject(this, _type, _staticType, _variableName));
 }
コード例 #26
0
ファイル: CSTypeNode.cs プロジェクト: masakinomura/csscript
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(CSObject.TempVariableObject(this, typeof(System.Type), _type));
 }
コード例 #27
0
 public CSScope AddVariable(string variableName, CSObject obj)
 {
     Current.AddVarible(variableName, obj);
     return(Current);
 }
コード例 #28
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(null);
 }
コード例 #29
0
 public int EvaluateIndex(CSState state, CSObject curObj)
 {
     return(Evaluate(state, curObj).GetAs <int> ());
 }
コード例 #30
0
 public string EvaluateKey(CSState state, CSObject curObj)
 {
     return(Evaluate(state, curObj).GetAs <string> ());
 }