Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public void AddVarible(string variableName, CSObject obj)
 {
     variableName = SkipAtMark(variableName);
     if (_variables.ContainsKey(variableName))
     {
         CSLog.E("Variable " + variableName + " already exists...");
         return;
     }
     _variables[variableName] = obj;
 }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
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);
            CSObject right = Right.Evaluate(state, left);

            return(right);
        }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 24
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(CSObject.ImmediateObject(this, typeof(float), _val));
 }
Ejemplo n.º 25
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(CSObject.StaticVariableObject(this, _type, _staticType, _variableName));
 }
Ejemplo n.º 26
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(CSObject.TempVariableObject(this, typeof(System.Type), _type));
 }
Ejemplo n.º 27
0
 public CSScope AddVariable(string variableName, CSObject obj)
 {
     Current.AddVarible(variableName, obj);
     return(Current);
 }
Ejemplo n.º 28
0
 public override CSObject Evaluate(CSState state, CSObject curObj)
 {
     return(null);
 }
Ejemplo n.º 29
0
 public int EvaluateIndex(CSState state, CSObject curObj)
 {
     return(Evaluate(state, curObj).GetAs <int> ());
 }
Ejemplo n.º 30
0
 public string EvaluateKey(CSState state, CSObject curObj)
 {
     return(Evaluate(state, curObj).GetAs <string> ());
 }