public static StackTypes DoMergeStacks(StackTypes s,StackTypes t) { //assert(s!=null && t!=null) if (s.Count != t.Count) throw new VerifierException(); //different lengths StackTypes u = new StackTypes(); for (int i = 0; i < s.Count; i++) { u.Push(TypeChecker.MergeTypes(s[i],t[i])); } return(u); }
public static void ProcessNot(StackTypes stack) { TypeEx t = stack.Pop(); if(!t.type.IsPrimitive || t.boxed || TypeFixer.IsFloatOrCompatible(t)) throw new VerifierException(); stack.Push(TypeFixer.FixType(t)); }
public static void ProcessBinOp(OpType opType, StackTypes stack) { switch(opType) { case OpType.Shift: { TypeEx shift = stack.Pop(); TypeEx t = stack.Pop(); if(!(TypeFixer.IsInt32OrCompatible(shift) || TypeFixer.IsIntPtrOrCompatible(shift))) throw new VerifierException(); if(!(TypeFixer.IsInt32OrCompatible(shift) || TypeFixer.IsIntPtrOrCompatible(shift) || TypeFixer.IsInt64OrCompatible(shift))) throw new VerifierException(); stack.Push(t); } break; case OpType.FloatOrInt: case OpType.Int: { TypeEx t1 = stack.Pop(); TypeEx t2 = stack.Pop(); TypeEx t3 = Arithmetics.GetReturnType(t1,t2,opType == OpType.FloatOrInt); stack.Push(t3); } break; case OpType.Compare: { TypeEx t1 = stack.Pop(); TypeEx t2 = stack.Pop(); Arithmetics.CheckTypes(t1,t2); stack.Push(typeof(int)); } break; } }
public static void ProcessEndFilter(StackTypes stack) { TypeEx t = stack.Pop(); if(!TypeFixer.IsInt32OrCompatible(t)) throw new VerifierException(); if(stack.Count != 0) throw new VerifierException(); }
public static void ProcessBox(StackTypes stack, Type T) { TypeEx valueType = stack.Pop(); if(! valueType.IsBoxable || valueType.boxed) throw new VerifierException(); TypeChecker.CheckAssignment(new TypeEx(T), valueType); // Skor >> this code was wrong ! //stack.Push(new TypeEx(valueType.type , true )); stack.Push(new TypeEx(T, true)); }
public static void ProcessStInd(Type T, StackTypes stack) { TypeEx val = stack.Pop(); TypeEx addr = stack.Pop(); if(!addr.type.IsByRef) throw new VerifierException(); TypeEx targetType = new TypeEx(addr.type.GetElementType()); TypeEx sourceType = new TypeEx(T); TypeChecker.CheckAssignment(targetType,val); CheckPrimitiveIndirectAssignment(targetType,sourceType); }
public static void ProcessStElem(StackTypes stack, TypeEx desiredArrayElem) { TypeEx elemValue = stack.Pop(); TypeEx index = stack.Pop(); TypeEx array = stack.Pop(); TypeEx arrayElem = ProcessLdStElem(array,desiredArrayElem,index); TypeChecker.CheckAssignment(arrayElem,elemValue); }
public static void ProcessSwitch(StackTypes stack) { TypeEx t = stack.Pop(); if(!TypeFixer.IsInt32OrCompatible(t)) throw new VerifierException(); }
public static void ProcessLeave(StackTypes stack) { if(stack.Count != 0) throw new VerifierException(); }
public static void ProcessBrTrueFalse(StackTypes stack) { TypeEx t = stack.Pop(); TypeChecker.CheckBrTrueFalseType(t); }
private static void ProcessSwitch(int iNum,MethodEx method,StackTypes stack) { int[] INums = (int[])method[iNum].Param; for(int i = 0;i<INums.Length;i++) { CheckSameBlock(method.EHClauses, iNum, INums[i]); ProcessBranch(iNum,INums[i],method,stack); } }
private static void ProcessBr(int iNum,MethodEx method,StackTypes stack) { CheckSameBlock(method.EHClauses, iNum, (int)method[iNum].Param); ProcessBranch(iNum, (int)method[iNum].Param, method, stack); }
private static void ProcessBranch(int iNum,int INum,MethodEx method,StackTypes stack) { Instruction I = method[INum]; if(INum > iNum) I.SetStack(MergeStacks(I.Stack,stack)); else CheckStacks(I.Stack,stack); }
private static StackTypes MergeStacks(StackTypes s,StackTypes t) { if(s == null) if(t == null) //both null return new StackTypes(); //Andrew: we assume the stack to be empty in this case else //t != null return(t); else if(t == null) //s != null return(s); else //both != null return DoMergeStacks(s,t); }
public static void ProcessSt(TypeEx T, StackTypes stack) { TypeEx t = stack.Pop(); TypeChecker.CheckAssignment(T,t); }
private static void ProcessLeave(int iNum,MethodEx method,StackTypes stack) { CheckCanLeave(method.EHClauses, iNum, (int)method[iNum].Param); ProcessLeave(stack); ProcessBranch(iNum,(int)method[iNum].Param,method,stack); }
public static void ProcessStFld(StackTypes stack, FieldInfo field) { TypeEx fldValue = stack.Pop(); TypeEx obj = stack.Pop(); if(obj.type.IsByRef) //STFLD accepts both objects and managed pointers on value-types { if(! field.DeclaringType.Equals(obj.type.GetElementType()) || !field.DeclaringType.IsValueType ) throw new VerifierException(); } else TypeChecker.CheckAssignment(new TypeEx(field.DeclaringType),obj); TypeChecker.CheckAssignment(new TypeEx(field.FieldType),fldValue); }
public static void ProcessRet(TypeEx returnType, StackTypes stack) { if(!returnType.type.Equals(typeof(void))) { TypeEx t = stack.Pop(); TypeChecker.CheckAssignment(returnType, t); } if(stack.Count != 0) throw new VerifierException(); }
public static void ProcessLdElem(StackTypes stack,TypeEx desiredArrayElem,bool loadAddress) { TypeEx index = stack.Pop(); TypeEx array = stack.Pop(); TypeEx arrayElem = ProcessLdStElem(array,desiredArrayElem,index); if(loadAddress) arrayElem = arrayElem.BuildRefType(); stack.Push(arrayElem); }
public static void ProcessThrow(StackTypes stack) { TypeEx t = stack.Pop(); TypeChecker.CheckAssignment(new TypeEx(typeof(Exception)), t); }
public static void ProcessLdLen(StackTypes stack) { TypeEx array = stack.Pop(); if(!array.type.IsArray) throw new VerifierException(); stack.Push(typeof(int)); }
public static void ProcessCallOrNewobj(MethodInfoExtention method,StackTypes stack, bool isNewObj) { for(int i = method.ArgCount-1; i >= (isNewObj ? 1 : 0); i--) { //when we are creating a new object `this` is not on stack TypeEx sourceType = stack.Pop(); TypeEx targetType = method.GetArgType(i); TypeChecker.CheckAssignment(targetType, sourceType); } TypeEx returnType = method.GetReturnType(); if(isNewObj) stack.Push(method.DeclaringType); //Wow! Value-types can be created on stack with NEWOBJ instruction -- not boxed else if(!returnType.type.Equals(typeof(void))) stack.Push(returnType); }
public static void ProcessCastClass(StackTypes stack, TypeEx t) { TypeEx T = stack.Pop(); if(T.IsBoxable && !T.boxed) throw new VerifierException(); stack.Push(t); }
public static void ProcessNewArr(StackTypes stack, Type T) { TypeEx t = stack.Pop(); if(!TypeFixer.IsInt32OrCompatible(t) && !TypeFixer.IsIntPtrOrCompatible(t)) throw new VerifierException(); stack.Push( TypeEx.BuildArrayType(T) ); }
public static void ProcessUnBox(StackTypes stack, Type T) { TypeEx objType = stack.Pop(); Type valueType = T; if(! ((objType.IsBoxable && objType.boxed) || !objType.IsBoxable) ) throw new VerifierException(); if(! valueType.IsValueType ) throw new VerifierException(); stack.Push( TypeEx.BuildRefType(valueType) ); }
public static void ProcessLdFld(StackTypes stack, FieldInfo field, bool loadAddress) { TypeEx obj = stack.Pop(); if(obj.type != null) //LDNULL LDFLD -- crazy! { if(obj.type.IsByRef) //LDFLD to the structure accepts this structure address { if(! field.DeclaringType.Equals(obj.type.GetElementType()) || !field.DeclaringType.IsValueType ) throw new VerifierException(); } else TypeChecker.CheckAssignment(new TypeEx(field.DeclaringType),obj); } Type fieldType = field.FieldType; if(loadAddress) fieldType = TypeEx.BuildRefType(fieldType); stack.Push(fieldType); }
public static void ProcessNeg(StackTypes stack) { TypeEx t = stack.Pop(); if(!t.type.IsPrimitive || t.boxed) throw new VerifierException(); stack.Push(TypeFixer.FixType(t)); }
static public void ProcessLdInd(Type T, StackTypes stack) { TypeEx addr = stack.Pop(); if(!addr.type.IsByRef) throw new VerifierException(); TypeEx sourceType = new TypeEx(addr.type.GetElementType()); TypeEx targetType = new TypeEx(T); if(targetType.type.Equals(typeof(object))) //.ref suffix stack.Push(sourceType); else { TypeChecker.CheckAssignment(targetType,sourceType); stack.Push(targetType); } }
private static void SetNodeStack(Node node, StackTypes stack) { node.Options["StackTypes"] = stack; }
private static void CheckStacks(StackTypes s,StackTypes t) { if(! IsStackMoreGeneral(s,t)) throw new VerifierException(); }