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); } }
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)); }
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); }
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); }
public override CSObject Evaluate(CSState state, CSObject curObj) { if (IsIndexed) { return(IndexNode.Evaluate(state, curObj)); } else { return(CSObject.ImmediateObject(this, typeof(int), -1)); } }
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); }
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); }
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)); } }
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); }
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)); }
public override CSObject Evaluate(CSState state, CSObject curObj) { return(CSObject.TempVariableObject(this, typeof(System.Type), _type)); }
public override CSObject Evaluate(CSState state, CSObject curObj) { return(null); }
public CSObject Evaluate() { CSState state = new CSState(); return(Evaluate(state, null)); }
public string EvaluateKey(CSState state, CSObject curObj) { return(Evaluate(state, curObj).GetAs <string> ()); }
public int EvaluateIndex(CSState state, CSObject curObj) { return(Evaluate(state, curObj).GetAs <int> ()); }
public override CSObject Evaluate(CSState state, CSObject curObj) { return(CSObject.StaticVariableObject(this, _type, _staticType, _variableName)); }
public override CSObject Evaluate(CSState state, CSObject curObj) { return(CSObject.ImmediateObject(this, typeof(float), _val)); }
public override CSObject Evaluate(CSState state, CSObject curObj) { if (ChildCount != 6) { CSLog.E(this, "new operator has invalid # of children..."); return(null); } if (NewType == null || NewType._type == null) { CSLog.E(this, "new operator does not have a proper type..."); return(null); } object newInstance = null; System.Type type = NewType._type; if (IsArray) { System.Type innerType = type.GetElementType(); int count = ArrayIndex.EvaluateIndex(null, null); if (ArrayInitializer != null) { object[] elements = ArrayInitializer.EvaluateElements(state, curObj, innerType); int len = elements.Length; int allocCount = (len > count? len : count); newInstance = System.Activator.CreateInstance(type, allocCount); System.Array array = newInstance as System.Array; for (int i = 0; i < len; ++i) { array.SetValue(elements[i], i); } } else { if (count < 0) { throw new System.ArgumentException("array needs an initializer or count"); } else { newInstance = System.Activator.CreateInstance(type, count); } } } else { object[] parameters = null; if (NewParameters != null && NewParameters.ChildCount > 0) { CSNode[] pchildren = NewParameters._children; int pCount = pchildren.Length; parameters = new object[pCount]; for (int i = 0; i < pCount; ++i) { parameters[i] = pchildren[i].Evaluate(state, curObj).Value; } } if (parameters == null) { newInstance = System.Activator.CreateInstance(type); } else { newInstance = System.Activator.CreateInstance(type, parameters); } CSDictionaryInitializerNode dictInitializer = DictionaryInitializer; if (dictInitializer != null) { IDictionary dict = newInstance as IDictionary; if (dict == null) { throw new System.InvalidOperationException("you cannot use a dictionary initializer on non dictionary object"); } System.Type keyType = typeof(object); System.Type valueType = typeof(object); System.Type[] genericTypes = NewType._type.GetGenericArguments(); if (genericTypes != null) { if (genericTypes.Length > 2) { keyType = genericTypes[0]; valueType = genericTypes[1]; } } int len = dictInitializer.Count; for (int i = 0; i < len; ++i) { KeyValuePair <object, object> element = dictInitializer.Evaluate(state, curObj, i, keyType, valueType); dict.Add(element.Key, element.Value); } } CSClassInitializerNode classInitializer = ClassInitializer; if (classInitializer != null) { int len = classInitializer.Count; for (int i = 0; i < len; ++i) { KeyValuePair <string, object> element = classInitializer.Evaluate(state, curObj, i, newInstance); ReflectionUtil.Set(newInstance, element.Key, element.Value); } } CSArrayInitializerNode arrayInitializer = ArrayInitializer; IList list = newInstance as IList; if (ArrayInitializer != null) { if (list == null) { CSLog.E("array initializer cannot used for : " + type.ToString()); } else { System.Type elementType = ReflectionUtil.GetIListElementType(NewType._type); if (elementType == null) { CSLog.E("array initializer cannot used for : " + type.ToString()); } object[] elements = ArrayInitializer.EvaluateElements(state, curObj, elementType); int len = elements.Length; for (int i = 0; i < len; ++i) { list.Add(elements[i]); } } } } CSObject obj = CSObject.TempVariableObject(this, type, newInstance); return(obj); }