internal override ReferenceBTValue FromStack() { ReferenceBTValue val = new ReferenceBTValue(PrimitiveBTValue.PrimitiveType(), this.btType); val.Creators.AddCreators(this.crtrs); return(val); }
private string ToString(string format, IFormatProvider formatProvider, int depth) { if (depth > 0) { ReferenceBTValue val = this.findLeaf(); string s = "[" + val.btType.ToString() + "] {"; int i = 0; if (i < val.types.Count) { s += String.Format(formatProvider, "{0:" + format + "}", val.types[i]); } for (i++; i < val.types.Count; i++) { s += ", " + String.Format(formatProvider, "{0:" + format + "}", val.types[i]); } s += "} ["; foreach (object key in val.flds.Keys) { s += String.Format(formatProvider, "{0:" + format + "}", key) + " - " + (val.flds[key] as ReferenceBTValue).ToString(format, formatProvider, depth - 1) + ", "; } return(s + "]"); } else { return(""); } }
internal static Creators Merge(BTValue val1, BTValue val2) { if (val1 == null || val2 == null) { return(new Creators()); } else if (val1 is PrimitiveBTValue && val2 is PrimitiveBTValue) { return(PrimitiveBTValue.Merge(val1 as PrimitiveBTValue, val2 as PrimitiveBTValue)); } else if (val1 is ReferenceBTValue && val2 is ReferenceBTValue) { return(ReferenceBTValue.Merge(val1 as ReferenceBTValue, val2 as ReferenceBTValue)); } else if (val1 is PrimitiveBTValue) { return((val1 as PrimitiveBTValue).ToReferenceBTValueCreators()); } else if (val2 is PrimitiveBTValue) { return((val2 as PrimitiveBTValue).ToReferenceBTValueCreators()); } else { throw new InternalException(); } }
internal ReferenceBTValue(BTType btType) { this.next = null; this.types = new ArrayList(); this.btType = btType; this.flds = new Hashtable(); this.crtrs = new Creators(); }
private void setNext(ReferenceBTValue val) { this.next = val; val.crtrs.AddCreators(this.crtrs); foreach (Type type in this.types) { val.addType(type); } }
private static Creators pseudoMerge(ReferenceBTValue val1, ReferenceBTValue val2, BTValuePairs pairs) { val1 = val1.findLeaf(); val2 = val2.findLeaf(); bool flag = pairs[val1, val2]; if (!flag && val1 != val2 && val1.btType == BTType.Static && val2.btType == BTType.Static) { Creators crtrs = new Creators(); int count = 0; for (int i = 0; i < val1.types.Count; i++) { if (val2.types.Contains(val1.types[i])) { count++; } } if (val1.types.Count > count) { crtrs.AddCreators(val2.crtrs); } if (val2.types.Count > count) { crtrs.AddCreators(val1.crtrs); } foreach (object key in val2.flds.Keys) { ReferenceBTValue fld1 = val1.flds[key] as ReferenceBTValue; ReferenceBTValue fld2 = val2.flds[key] as ReferenceBTValue; if (fld1 != null) { crtrs.AddCreators(ReferenceBTValue.pseudoMerge(fld1, fld2, pairs)); } } return(crtrs); } else if (flag || val1.btType == val2.btType) { return(new Creators()); } else if (val1.btType == BTType.Static) { return(val1.crtrs); } else if (val2.btType == BTType.Static) { return(val2.crtrs); } else { throw new InternalException(); } }
internal ReferenceBTValue[] GetAllNotNullFieldBTValues() { ICollection vals = this.findLeaf().flds.Values; ReferenceBTValue[] arr = new ReferenceBTValue[vals.Count]; vals.CopyTo(arr, 0); return(arr); }
private ReferenceBTValue getField(object key) { ReferenceBTValue fld = this.flds[key] as ReferenceBTValue; if (fld == null) { this.flds[key] = fld = new ReferenceBTValue(this.btType); } return(fld); }
private ReferenceBTValue findLeaf() { if (this.next == null) { return(this); } else { return(this.next = this.next.findLeaf()); } }
internal BTValue ToStack(Type type) { ReferenceBTValue val = this.findLeaf(); if (PrimitiveBTValue.CheckType(type)) { val.addType(PrimitiveBTValue.PrimitiveType()); //!!!!!!!!!!!! return(new PrimitiveBTValue(val.btType)); } else { return(val); } }
public AnnotatedMethod GetAnnotatedMethod(MethodBase sMethod) { AnnotatedMethod aMethod = this.aMethods[sMethod] as AnnotatedMethod; if (aMethod == null) { ParameterInfo[] parms = sMethod.GetParameters(); EvaluationStack stack = new EvaluationStack(); if (!sMethod.IsStatic) { stack.Push(new ReferenceBTValue(BTType.Dynamic)); } for (int i = 0; i < parms.Length; i++) { stack.Push(new ReferenceBTValue(BTType.Dynamic)); } ParameterValues paramVals = stack.Perform_CallMethod(sMethod, false); ReferenceBTValue ret = ReferenceBTValue.NewReferenceBTValue(Annotation.GetReturnType(sMethod), BTType.Dynamic); this.aMethods[sMethod] = aMethod = new AnnotatedMethod(paramVals, ret); } return(aMethod); }
public override bool Equals(object o) { if (o is ReferenceBTValue) { ReferenceBTValue val1 = this.findLeaf(); ReferenceBTValue val2 = (o as ReferenceBTValue).findLeaf(); if (val1.btType == BTType.Dynamic && val2.btType == BTType.Dynamic) { return(true); } else if (val1.types.Count == 1 && val1.types[0] == PrimitiveBTValue.PrimitiveType() && val2.types.Count == 1 && val2.types[0] == PrimitiveBTValue.PrimitiveType()) { return(val1.btType == val2.btType); } else { return(val1 == val2); } } else { return(false); } }
internal ReferenceBTValue(Type type, BTType btType) { this.next = null; this.types = new ArrayList(); this.addType(type); this.btType = btType; this.flds = new Hashtable(); this.crtrs = new Creators(); }
internal static Creators Merge(ReferenceBTValue val1, ReferenceBTValue val2) { val1 = val1.findLeaf(); val2 = val2.findLeaf(); if (val1 != val2 && val1.btType == BTType.Static && val2.btType == BTType.Static) { Creators crtrs = new Creators(); int count = 0; for (int i = 0; i < val1.types.Count; i++) if (val2.types.Contains(val1.types[i])) count++; if (val1.types.Count > count) crtrs.AddCreators(val2.crtrs); if (val2.types.Count > count) crtrs.AddCreators(val1.crtrs); val2.setNext(val1); foreach (object key in val2.flds.Keys) { ReferenceBTValue fld1 = val1.flds[key] as ReferenceBTValue; ReferenceBTValue fld2 = val2.flds[key] as ReferenceBTValue; if (fld1 == null) val1.flds[key] = fld2; else crtrs.AddCreators(ReferenceBTValue.Merge(fld1, fld2)); } return crtrs; } else if (val1.btType == val2.btType) return new Creators(); else if (val1.btType == BTType.Static) { val1.setNext(val2); return val1.crtrs; } else if (val2.btType == BTType.Static) { val2.setNext(val1); return val2.crtrs; } else throw new InternalException(); }
internal AnnotatedMethod(ParameterValues paramVals, ReferenceBTValue ret) { this.ParamVals = paramVals; this.ReturnValue = ret; this.ControllingVisitor = null; }
internal override ReferenceBTValue FromStack() { ReferenceBTValue val = new ReferenceBTValue(PrimitiveBTValue.PrimitiveType(), this.btType); val.Creators.AddCreators(this.crtrs); return val; }
internal static Creators PseudoMerge(ReferenceBTValue val1, ReferenceBTValue val2) { return(ReferenceBTValue.pseudoMerge(val1, val2, new BTValuePairs())); }
internal AnnotatedMethod(ParameterValues paramVals, ReferenceBTValue ret) { this.ParamVals = paramVals; this.ReturnValue = ret; this.ControllingVisitor = null; }
private static void setReturnValue(Node upNode, ReferenceBTValue val) { upNode.Options["ReturnValue"] = val; }
private void callMethod(Node upNode, ParameterValues paramVals, ReferenceBTValue ret, bool isVirtCall) { bool flag; if (isVirtCall) { ReferenceBTValue thisObj = paramVals[0].Val as ReferenceBTValue; flag = thisObj.BTType == BTType.Dynamic; for (int i = 0; (! flag) && i < thisObj.Types.Length; i++) if (paramVals.Method.DeclaringType.IsAssignableFrom(thisObj.Types[i]) && thisObj.Types[i] != PrimitiveBTValue.PrimitiveType()) { ParameterValues exactParamVals = paramVals.Clone(); exactParamVals.ChooseVirtualMethod(thisObj.Types[i]); flag = ! this.holder.SourceHolder.ContainsMethodBody(exactParamVals.Method); } } else flag = ! this.holder.SourceHolder.ContainsMethodBody(paramVals.Method); if (flag) Annotation.SetNodeBTType(upNode, this.checkAnnotatedMethodForInvoke(new AnnotatedMethod(paramVals, ret))); else { if (isVirtCall) { foreach (Type type in (paramVals[0].Val as ReferenceBTValue).Types) if (paramVals.Method.DeclaringType.IsAssignableFrom(type) && type != PrimitiveBTValue.PrimitiveType()) { ParameterValues exactParamVals = paramVals.Clone(); exactParamVals.ChooseVirtualMethod(type); AnnotatedMethod method = new AnnotatedMethod(exactParamVals, ret); Annotation.SetAnnotatedMethod(upNode, type, this.checkAnnotatedMethodForCall(method)); } } else Annotation.SetAnnotatedMethod(upNode, this.checkAnnotatedMethodForCall(new AnnotatedMethod(paramVals, ret))); Annotation.SetNodeBTType(upNode, BTType.eXclusive); } }
protected override void VisitNewObject(NewObject upNode, object o) { State state = o as State; ReferenceBTValue obj = AnnotatingVisitor.GetNewBTValue(upNode); if (obj == null) { obj = new ReferenceBTValue(upNode.Constructor.DeclaringType, BTType.Static); AnnotatingVisitor.setNewBTValue(upNode, obj); obj.Creators[this].AddCreator(upNode); } ParameterValues paramVals = state.Stack.Perform_CreateObject(upNode.Constructor, obj); AnnotatingVisitor.patchUpParamVals(paramVals); this.callMethod(upNode, paramVals, null, false); state.Stack.Push(obj); }
internal static Creators Merge(ReferenceBTValue val1, ReferenceBTValue val2) { val1 = val1.findLeaf(); val2 = val2.findLeaf(); if (val1 != val2 && val1.btType == BTType.Static && val2.btType == BTType.Static) { Creators crtrs = new Creators(); int count = 0; for (int i = 0; i < val1.types.Count; i++) { if (val2.types.Contains(val1.types[i])) { count++; } } if (val1.types.Count > count) { crtrs.AddCreators(val2.crtrs); } if (val2.types.Count > count) { crtrs.AddCreators(val1.crtrs); } val2.setNext(val1); foreach (object key in val2.flds.Keys) { ReferenceBTValue fld1 = val1.flds[key] as ReferenceBTValue; ReferenceBTValue fld2 = val2.flds[key] as ReferenceBTValue; if (fld1 == null) { val1.flds[key] = fld2; } else { crtrs.AddCreators(ReferenceBTValue.Merge(fld1, fld2)); } } return(crtrs); } else if (val1.btType == val2.btType) { return(new Creators()); } else if (val1.btType == BTType.Static) { val1.setNext(val2); return(val1.crtrs); } else if (val2.btType == BTType.Static) { val2.setNext(val1); return(val2.crtrs); } else { throw new InternalException(); } }
private ReferenceBTValue getField(object key) { ReferenceBTValue fld = this.flds[key] as ReferenceBTValue; if (fld == null) this.flds[key] = fld = new ReferenceBTValue(this.btType); return fld; }
private static Creators pseudoMerge(ReferenceBTValue val1, ReferenceBTValue val2, BTValuePairs pairs) { val1 = val1.findLeaf(); val2 = val2.findLeaf(); bool flag = pairs[val1, val2]; if (! flag && val1 != val2 && val1.btType == BTType.Static && val2.btType == BTType.Static) { Creators crtrs = new Creators(); int count = 0; for (int i = 0; i < val1.types.Count; i++) if (val2.types.Contains(val1.types[i])) count++; if (val1.types.Count > count) crtrs.AddCreators(val2.crtrs); if (val2.types.Count > count) crtrs.AddCreators(val1.crtrs); foreach (object key in val2.flds.Keys) { ReferenceBTValue fld1 = val1.flds[key] as ReferenceBTValue; ReferenceBTValue fld2 = val2.flds[key] as ReferenceBTValue; if (fld1 != null) crtrs.AddCreators(ReferenceBTValue.pseudoMerge(fld1, fld2, pairs)); } return crtrs; } else if (flag || val1.btType == val2.btType) return new Creators(); else if (val1.btType == BTType.Static) return val1.crtrs; else if (val2.btType == BTType.Static) return val2.crtrs; else throw new InternalException(); }
internal static Creators PseudoMerge(ReferenceBTValue val1, ReferenceBTValue val2) { return ReferenceBTValue.pseudoMerge(val1, val2, new BTValuePairs()); }
internal ReferenceBTValue[] GetAllNotNullFieldBTValues() { ICollection vals = this.findLeaf().flds.Values; ReferenceBTValue[] arr = new ReferenceBTValue[vals.Count]; vals.CopyTo(arr, 0); return arr; }
internal AnnotatingVisitor(AnnotatedAssemblyHolder holder, AnnotatedMethod method, ControllingVisitor cVisitor, UpAndDownNodes upDownNodes) : base(holder.GraphProcessor, 0) { this.holder = holder; this.cVisitor = cVisitor; this.upDownNodes = upDownNodes; this.ret = method.ReturnValue; }
private ReferenceBTValue findLeaf() { if (this.next == null) return this; else return this.next = this.next.findLeaf(); }
protected override void VisitCallMethod(CallMethod upNode, object o) { State state = o as State; ParameterValues paramVals = state.Stack.Perform_CallMethod(upNode.Method, upNode.IsVirtCall); AnnotatingVisitor.patchUpParamVals(paramVals); Type retType = Annotation.GetReturnType(paramVals.Method); ReferenceBTValue ret = AnnotatingVisitor.getReturnValue(upNode); if (ret == null) { ret = ReferenceBTValue.NewReferenceBTValue(retType, BTType.Static); AnnotatingVisitor.setReturnValue(upNode, ret); } this.callMethod(upNode, paramVals, ret, upNode.IsVirtCall && upNode.Method.IsVirtual); if (ret != null) { ret.Creators[this].AddCreator(upNode); state.Stack.Push(ret.ToStack(retType)); } }
private void setNext(ReferenceBTValue val) { this.next = val; val.crtrs.AddCreators(this.crtrs); foreach (Type type in this.types) val.addType(type); }
protected override void VisitNewArray(NewArray upNode, object o) { State state = o as State; PrimitiveBTValue length = state.Stack.Pop() as PrimitiveBTValue; ReferenceBTValue arr = AnnotatingVisitor.GetNewBTValue(upNode); if (arr == null) { arr = new ReferenceBTValue(AnnotatingVisitor.makeArrayType(upNode.Type), BTType.Static); AnnotatingVisitor.setNewBTValue(upNode, arr); arr.Creators[this].AddCreator(upNode); } if (length.BTType == arr.BTType) { state.Stack.Push(arr); BTType btType; if (arr.BTType == BTType.Dynamic) btType = BTType.Dynamic; else btType = BTType.eXclusive; Annotation.SetNodeBTType(upNode, btType); } else if (length.BTType == BTType.Static) throw new LiftException(length); else if (arr.BTType == BTType.Static) throw new LiftException(arr); else throw new InternalException(); }