Evaluation(AbstractSymbolValueProvider vp) { this.ValueProvider = vp; if(vp!=null) vp.ev = this; this.eval = true; this.ctxt = vp.ResolutionContext; }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { if (vp != null && vp.ev != null) { vp.ev.EvalError(null, "Cannot assign a value to a static property.", new[] { this, value }); } //TODO: What about array.length? }
/// <summary> /// Removes all variable references by resolving them via the given value provider. /// Useful when only the value is of interest, not its container or other things. /// </summary> public static ISymbolValue GetVariableContents(ISymbolValue v, AbstractSymbolValueProvider vp) { while (v is VariableValue) { v = vp[(v as VariableValue).Variable]; } return(v); }
Evaluation(AbstractSymbolValueProvider vp) { this.ValueProvider = vp; if (vp != null) { vp.ev = this; } this.eval = true; this.ctxt = vp.ResolutionContext; }
public static bool IsEqual(IExpression ex, IExpression ex2, AbstractSymbolValueProvider vp) { var val_x1 = Evaluation.EvaluateValue(ex, vp); var val_x2 = Evaluation.EvaluateValue(ex2, vp); //TEMPORARILY: Remove the string comparison if (val_x1 == null && val_x2 == null) return ex.ToString() == ex2.ToString(); return IsEqual(val_x1, val_x2); }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { var oldV = vp[Variable]; if (oldV is AssociativeArrayValue) { if (Key != null) { var aa = (AssociativeArrayValue)oldV; int itemToReplace = -1; for (int i = 0; i < aa.Elements.Count; i++) { if (SymbolValueComparer.IsEqual(aa.Elements[i].Key, Key)) { itemToReplace = i; break; } } // If we haven't found a matching key, add it to the array var newElements = new KeyValuePair <ISymbolValue, ISymbolValue> [aa.Elements.Count + (itemToReplace == -1 ? 1: 0)]; aa.Elements.CopyTo(newElements, 0); if (itemToReplace != -1) { newElements[itemToReplace] = new KeyValuePair <ISymbolValue, ISymbolValue>(newElements[itemToReplace].Key, value); } else { newElements[newElements.Length - 1] = new KeyValuePair <ISymbolValue, ISymbolValue>(Key, value); } // Finally, make a new associative array containing the new elements vp[Variable] = new AssociativeArrayValue(aa.RepresentedType as AssocArrayType, newElements); } else { if (vp.ev != null) { vp.ev.EvalError(null, "Key expression must not be null", Key); } } } else { if (vp.ev != null) { vp.ev.EvalError(null, "Type of accessed item must be an associative array", oldV); } } }
public static bool IsEqual(IExpression ex, IExpression ex2, AbstractSymbolValueProvider vp) { var val_x1 = Evaluation.EvaluateValue(ex, vp); var val_x2 = Evaluation.EvaluateValue(ex2, vp); //TEMPORARILY: Remove the string comparison if (val_x1 == null && val_x2 == null) { return(ex.ToString() == ex2.ToString()); } return(IsEqual(val_x1, val_x2)); }
public static ISymbolValue EvaluateValue(IExpression x, AbstractSymbolValueProvider vp) { if (vp == null) vp = new StandardValueProvider(null); var ev = new Evaluation(vp); var v = ev.E(x) as ISymbolValue; if(v == null && ev.Errors.Count != 0) return new ErrorValue(ev.Errors.ToArray()); return v; }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { var oldV = vp[Variable]; if (oldV is ArrayValue) { var av = (ArrayValue)oldV; //TODO: Immutability checks if (av.IsString) { } else { var at = av.RepresentedType as ArrayType; var newElements = new ISymbolValue[av.Elements.Length + (ItemNumber < 0 ? 1:0)]; av.Elements.CopyTo(newElements, 0); if (!ResultComparer.IsImplicitlyConvertible(value.RepresentedType, at.ValueType)) { if (vp.ev != null) { vp.ev.EvalError(null, value.ToCode() + " must be implicitly convertible to the array's value type!", value); } return; } // Add.. if (ItemNumber < 0) { av.Elements[av.Elements.Length - 1] = value; } else // or set the new value { av.Elements[ItemNumber] = value; } vp[Variable] = new ArrayValue(at, newElements); } } else { if (vp.ev != null) { vp.ev.EvalError(null, "Type of accessed item must be an array", oldV); } } }
public static ISymbolValue EvaluateValue(IExpression x, AbstractSymbolValueProvider vp) { if (vp == null) { vp = new StandardValueProvider(null); } var ev = new Evaluation(vp); var v = ev.E(x) as ISymbolValue; if (v == null && ev.Errors.Count != 0) { return(new ErrorValue(ev.Errors.ToArray())); } return(v); }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { var oldV = vp[Variable]; if (oldV is ArrayValue) { var av = (ArrayValue)oldV; //TODO: Immutability checks if (av.IsString) { } else { var at = av.RepresentedType as ArrayType; var newElements = new ISymbolValue[av.Elements.Length + (ItemNumber<0 ? 1:0)]; av.Elements.CopyTo(newElements, 0); if (!ResultComparer.IsImplicitlyConvertible(value.RepresentedType, at.ValueType)){ if(vp.ev!=null) vp.ev.EvalError(null,value.ToCode() + " must be implicitly convertible to the array's value type!", value); return; } // Add.. if (ItemNumber < 0) av.Elements[av.Elements.Length - 1] = value; else // or set the new value av.Elements[ItemNumber] = value; vp[Variable] = new ArrayValue(at, newElements); } } else{ if(vp.ev!=null) vp.ev.EvalError(null,"Type of accessed item must be an array", oldV); } }
public static ISymbolValue EvaluateValue(VariableValue v, AbstractSymbolValueProvider vp) { if (v.RepresentedType is TemplateParameterSymbol) { var tps = v.RepresentedType as TemplateParameterSymbol; if (tps.ParameterValue != null) { return(tps.ParameterValue); } } var bt = v.Member; var ctxt = vp.ResolutionContext; bool pop = false; if (bt != null) { //TODO: This is not tested entirely - but it makes test passing successfully! pop = true; ctxt.PushNewScope(bt.Definition.Parent as Dom.IBlockNode); ctxt.CurrentContext.IntroduceTemplateParameterTypes(bt); } var val = vp[v.Variable]; if (bt != null) { if (pop) { ctxt.Pop(); } vp.ResolutionContext.CurrentContext.RemoveParamTypesFromPreferredLocals(bt); } return(val ?? v); }
public static ISymbolValue TryEvalPropertyValue(AbstractSymbolValueProvider vp, ISemantic baseSymbol, int propName) { var props = Properties[PropOwnerType.Generic]; StaticPropertyInfo prop; if (props.TryGetValue(propName, out prop) || (Properties.TryGetValue(GetOwnerType(baseSymbol), out props) && props.TryGetValue(propName, out prop))) { if (prop.ValueGetter != null) return prop.ValueGetter(vp, baseSymbol); } return null; }
public abstract void Set(AbstractSymbolValueProvider vp, ISymbolValue value);
/// <summary> /// Removes all variable references by resolving them via the given value provider. /// Useful when only the value is of interest, not its container or other things. /// </summary> public static ISymbolValue GetVariableContents(ISymbolValue v, AbstractSymbolValueProvider vp) { while (v is VariableValue) v = vp[(v as VariableValue).Variable]; return v; }
public static ISymbolValue EvaluateValue(VariableValue v, AbstractSymbolValueProvider vp) { if(v.RepresentedType is TemplateParameterSymbol) { var tps = v.RepresentedType as TemplateParameterSymbol; if(tps.ParameterValue != null) return tps.ParameterValue; } var bt = v.Member; var ctxt = vp.ResolutionContext; bool pop=false; if(bt != null) { //TODO: This is not tested entirely - but it makes test passing successfully! pop = true; ctxt.PushNewScope (bt.Definition.Parent as Dom.IBlockNode); ctxt.CurrentContext.IntroduceTemplateParameterTypes(bt); } var val = vp[v.Variable]; if(bt != null) { if (pop) ctxt.Pop (); vp.ResolutionContext.CurrentContext.RemoveParamTypesFromPreferredLocals(bt); } return val ?? v; }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { vp[Variable] = value; }
public static ISymbolValue Execute(MemberSymbol method, ISymbolValue[] arguments, AbstractSymbolValueProvider vp) { return new ErrorValue(new EvaluationException("CTFE is not implemented yet.")); }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { var oldV = vp[Variable]; if (oldV is AssociativeArrayValue) { if (Key != null) { var aa = (AssociativeArrayValue)oldV; int itemToReplace = -1; for (int i = 0; i < aa.Elements.Count; i++) if (SymbolValueComparer.IsEqual(aa.Elements[i].Key, Key)) { itemToReplace = i; break; } // If we haven't found a matching key, add it to the array var newElements = new KeyValuePair<ISymbolValue, ISymbolValue>[aa.Elements.Count + (itemToReplace == -1 ? 1 : 0)]; aa.Elements.CopyTo(newElements, 0); if (itemToReplace != -1) newElements[itemToReplace] = new KeyValuePair<ISymbolValue, ISymbolValue>(newElements[itemToReplace].Key, value); else newElements[newElements.Length - 1] = new KeyValuePair<ISymbolValue, ISymbolValue>(Key, value); // Finally, make a new associative array containing the new elements vp[Variable] = new AssociativeArrayValue(aa.RepresentedType as AssocArrayType, newElements); } else{ if(vp.ev !=null) vp.ev.EvalError(null,"Key expression must not be null", Key); } } else{ if(vp.ev != null) vp.ev.EvalError(null,"Type of accessed item must be an associative array", oldV); } }
public abstract void Set(AbstractSymbolValueProvider vp, ISymbolValue value);
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { vp[Variable] = value; }
public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value) { if(vp != null && vp.ev != null) vp.ev.EvalError(null,"Cannot assign a value to a static property.", new[]{this, value}); //TODO: What about array.length? }