static string TypeToString(CLRType type) { switch (type) { case CLRType.Desktop: return dnSpy_Debugger_Resources.Process_CLR_Desktop; case CLRType.CoreCLR: return dnSpy_Debugger_Resources.Process_CLR_CoreCLR; default: Debug.Fail("Unknown CLR type"); return "???"; } }
static string TypeToString(CLRType type) { switch (type) { case CLRType.Desktop: return "Desktop"; case CLRType.CoreCLR: return "CoreCLR"; default: Debug.Fail("Unknown CLR type"); return "???"; } }
int CountValueTypeManaged(IType type) { int res = 0; if (type is ILType) { ILType t = (ILType)type; for (int i = 0; i < t.FieldTypes.Length; i++) { var ft = t.FieldTypes[i]; if (!ft.IsPrimitive && !ft.IsEnum) { if (ft.IsValueType) { if (!(ft is ILType) && ((CLRType)ft).ValueTypeBinder == null) { res++; } } else { res++; } } } if (type.BaseType != null && type.BaseType is ILType) { res += CountValueTypeManaged((ILType)type.BaseType); } } else { CLRType t = (CLRType)type; var cnt = t.TotalFieldCount; for (int i = 0; i < cnt; i++) { var it = t.OrderedFieldTypes[i] as CLRType; if (!it.IsPrimitive && it.IsEnum) { if (it.IsValueType) { if (it.ValueTypeBinder == null) { res++; } } else { res++; } } } } return(res); }
internal CLRMethod(ConstructorInfo def, CLRType type, ILRuntime.Runtime.Enviorment.AppDomain domain) { this.cDef = def; declaringType = type; this.appdomain = domain; if (!def.ContainsGenericParameters) { ReturnType = type; } isConstructor = true; }
public void RegisterCrossBindingAdaptor(CrossBindingAdaptor adaptor) { var bType = adaptor.BaseCLRType; if (bType != null) { if (!crossAdaptors.ContainsKey(bType)) { var t = adaptor.AdaptorType; var res = GetType(t); if (res == null) { res = new CLRType(t, this); mapType[res.FullName] = res; mapType[t.AssemblyQualifiedName] = res; clrTypeMapping[t] = res; } adaptor.RuntimeType = res; crossAdaptors[bType] = adaptor; } else { throw new Exception("Crossbinding Adapter for " + bType.FullName + " is already added."); } } else { var bTypes = adaptor.BaseCLRTypes; var t = adaptor.AdaptorType; var res = GetType(t); if (res == null) { res = new CLRType(t, this); mapType[res.FullName] = res; mapType[t.AssemblyQualifiedName] = res; clrTypeMapping[t] = res; } adaptor.RuntimeType = res; foreach (var i in bTypes) { if (!crossAdaptors.ContainsKey(i)) { crossAdaptors[i] = adaptor; } else { throw new Exception("Crossbinding Adapter for " + i.FullName + " is already added."); } } } }
static string TypeToString(CLRType type) { switch (type) { case CLRType.Desktop: return("Desktop"); case CLRType.CoreCLR: return("CoreCLR"); default: Debug.Fail("Unknown CLR type"); return("???"); } }
static string TypeToString(CLRType type) { switch (type) { case CLRType.Desktop: return(dnSpy_Debugger_Resources.Process_CLR_Desktop); case CLRType.CoreCLR: return(dnSpy_Debugger_Resources.Process_CLR_CoreCLR); default: Debug.Fail("Unknown CLR type"); return("???"); } }
public GType MakeArray() { if (IsCLRType) { GType array = Repository.RegisterType(CLRType.MakeArrayType()); array.ArrayElement = this; return(array); } else { Class arrClass = JNIEnv.ThreadEnv.NewObjectArray(0, JVMType, null).getClass(); GType array = Repository.RegisterClass(arrClass); array.ArrayElement = this; return(array); } }
public unsafe void AssignFieldNoClone(int index, object value) { if (index < fields.Length && index >= 0) { fixed(StackObject *ptr = fields) { StackObject *esp = &ptr[index]; if (value != null) { var vt = value.GetType(); if (vt.IsPrimitive) { ILIntepreter.UnboxObject(esp, value, managedObjs, type.AppDomain); } else if (vt.IsEnum) { esp->ObjectType = ObjectTypes.Integer; esp->Value = value.ToInt32(); esp->ValueLow = 0; } else { esp->ObjectType = ObjectTypes.Object; esp->Value = index; managedObjs[index] = value; } } else { *esp = StackObject.Null; } } } else { if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor) { CLRType clrType = type.AppDomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType; clrType.SetFieldValue(index, ref clrInstance, value); } else { throw new TypeLoadException(); } } }
internal CLRMethod(ConstructorInfo def, CLRType type, ILRuntime.Runtime.Enviorment.AppDomain domain) { this.cDef = def; declaringType = type; this.appdomain = domain; param = def.GetParameters(); if (!def.ContainsGenericParameters) { ReturnType = type; } isConstructor = true; if (def != null) { appdomain.RedirectMap.TryGetValue(cDef, out redirect); } }
public void RegisterCrossBindingAdaptor(CrossBindingAdaptor adaptor) { if (!crossAdaptors.ContainsKey(adaptor.BaseCLRType)) { var t = adaptor.AdaptorType; var res = GetType(t); if (res == null) { res = new CLRType(t, this); mapType[res.FullName] = res; mapType[t.AssemblyQualifiedName] = res; clrTypeMapping[t] = res; } adaptor.RuntimeType = res; crossAdaptors[adaptor.BaseCLRType] = adaptor; } }
public ILType GetType(Type clrType) { if (clrType == null) { return(null); } lock (this) { ILType type; if (TypeToILType.TryGetValue(clrType, out type)) { return(type); } type = CLRType.Create(clrType, this); return(CacheTypeInternal(type)); } }
internal unsafe void PushToStack(int fieldIdx, StackObject *esp, Enviorment.AppDomain appdomain, IList <object> managedStack) { if (fieldIdx < fields.Length && fieldIdx >= 0) { PushToStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack); } else { if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor) { CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType; ILIntepreter.PushObject(esp, managedStack, clrType.GetFieldValue(fieldIdx, clrInstance)); } else { throw new TypeLoadException(); } } }
internal CLRMethod(MethodInfo def, CLRType type, ILRuntime.Runtime.Enviorment.AppDomain domain) { this.def = def; declaringType = type; this.appdomain = domain; if (!def.ContainsGenericParameters) { ReturnType = domain.GetType(def.ReturnType.FullName); if (ReturnType == null) { ReturnType = domain.GetType(def.ReturnType.AssemblyQualifiedName); } } if (type.IsDelegate && def.Name == "Invoke") { isDelegateInvoke = true; } isConstructor = false; }
internal unsafe void AssignFromStack(int fieldIdx, StackObject *esp, Enviorment.AppDomain appdomain, List <object> managedStack) { if (fieldIdx < fields.Length && fieldIdx >= 0) { AssignFromStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack); } else { if (Type.BaseType != null && Type.BaseType is Enviorment.CrossBindingAdaptor) { CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.BaseType).BaseCLRType) as CLRType; var field = clrType.Fields[fieldIdx]; field.SetValue(clrInstance, field.FieldType.CheckCLRTypes(appdomain, esp->ToObject(appdomain, managedStack))); } else { throw new TypeLoadException(); } } }
internal unsafe void AssignFromStack(int fieldIdx, StackObject *esp, Enviorment.AppDomain appdomain, IList <object> managedStack) { if (fieldIdx < fields.Length && fieldIdx >= 0) { AssignFromStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack); } else { if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor) { CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType; var field = clrType.GetField(fieldIdx); clrType.SetFieldValue(fieldIdx, ref clrInstance, field.FieldType.CheckCLRTypes(ILIntepreter.CheckAndCloneValueType(StackObject.ToObject(esp, appdomain, managedStack), appdomain))); } else { throw new TypeLoadException(); } } }
private void Prewarm(HashSet <ILMethod> alreadyPrewarmed) { if (alreadyPrewarmed != null && alreadyPrewarmed.Add(this) == false) { return; } if (GenericParameterCount > 0 && !IsGenericInstance) { return; } //当前方法用到的CLR局部变量,提前InitializeFields()、GetTypeFlags() for (int i = 0; i < LocalVariableCount; i++) { var v = Variables[i]; var vt = v.VariableType; IType t; if (vt.IsGenericParameter) { t = FindGenericArgument(vt.Name); } else { t = appdomain.GetType(v.VariableType, DeclearingType, this); } if (t is CLRType) { CLRType ct = (CLRType)t; var fields = ct.Fields; ILRuntime.CLR.Utils.Extensions.GetTypeFlags(ct.TypeForCLR); } } if (jitImmediately || jitOnDemand) { PrewarmBodyRegister(alreadyPrewarmed); } else { PrewarmBody(alreadyPrewarmed); } }
public override Delegate CreateDelegate(Type t) { if (t is ILRuntimeType) { ILType it = ((ILRuntimeType)t).ILType; if (it.IsDelegate) { var ilMethod = ILMethod; if (ilMethod.DelegateAdapter == null) { var m = it.GetMethod("Invoke") as ILMethod; ilMethod.DelegateAdapter = appdomain.DelegateManager.FindDelegateAdapter(null, ilMethod, m); } return(ilMethod.DelegateAdapter.Delegate); } else { throw new NotSupportedException(string.Format("{0} is not Delegate", t.FullName)); } } else if (t is ILRuntimeWrapperType) { ILRuntimeWrapperType iwt = (ILRuntimeWrapperType)t; return(appdomain.DelegateManager.FindDelegateAdapter(iwt.CLRType, null, ILMethod).Delegate); } else { CLRType clrType = appdomain.GetType(t) as CLRType; if (clrType != null) { return(appdomain.DelegateManager.FindDelegateAdapter(clrType, null, ILMethod).Delegate); } else { throw new NotSupportedException(); } } }
internal CLRMethod(MethodInfo def, CLRType type, ILRuntime.Runtime.Enviorment.AppDomain domain) { this.def = def; declaringType = type; this.appdomain = domain; param = def.GetParameters(); if (!def.ContainsGenericParameters) { ReturnType = domain.GetType(def.ReturnType.FullName); if (ReturnType == null) { ReturnType = domain.GetType(def.ReturnType.AssemblyQualifiedName); } } if (type.IsDelegate && def.Name == "Invoke") { isDelegateInvoke = true; } isConstructor = false; if (def != null) { if (def.IsGenericMethod && !def.IsGenericMethodDefinition) { //Redirection of Generic method Definition will be prioritized if (!appdomain.RedirectMap.TryGetValue(def.GetGenericMethodDefinition(), out redirect)) { appdomain.RedirectMap.TryGetValue(def, out redirect); } } else { appdomain.RedirectMap.TryGetValue(def, out redirect); } } }
public ILRuntimeWrapperType(CLRType t) { type = t; et = t.TypeForCLR; }
public IType GetType(string fullname) { IType res; if (fullname == null) { return(null); } if (mapType.TryGetValue(fullname, out res)) { return(res); } string baseType; List <string> genericParams; bool isArray; ParseGenericType(fullname, out baseType, out genericParams, out isArray); bool isByRef = baseType.EndsWith("&"); if (isByRef) { baseType = baseType.Substring(0, baseType.Length - 1); } if (genericParams != null || isArray || isByRef) { IType bt = GetType(baseType); if (bt == null) { bt = GetType(baseType.Replace("/", "+")); } if (bt == null) { return(null); } if (genericParams != null) { KeyValuePair <string, IType>[] genericArguments = new KeyValuePair <string, IType> [genericParams.Count]; for (int i = 0; i < genericArguments.Length; i++) { string key = "!" + i; IType val = GetType(genericParams[i]); if (val == null) { return(null); } genericArguments[i] = new KeyValuePair <string, IType>(key, val); } bt = bt.MakeGenericInstance(genericArguments); mapType[bt.FullName] = bt; StringBuilder sb = new StringBuilder(); sb.Append(baseType); sb.Append('<'); for (int i = 0; i < genericParams.Count; i++) { if (i > 0) { sb.Append(","); } if (genericParams[i].Contains(",")) { sb.Append(genericParams[i].Substring(0, genericParams[i].IndexOf(','))); } else { sb.Append(genericParams[i]); } } sb.Append('>'); var asmName = sb.ToString(); if (bt.FullName != asmName) { mapType[asmName] = bt; } } if (isByRef) { bt = bt.MakeByRefType(); mapType[bt.FullName] = bt; if (!isArray) { mapType[fullname] = bt; return(bt); } } if (isArray) { res = bt.MakeArrayType(); mapType[fullname] = res; mapType[res.FullName] = res; return(res); } else { return(bt); } } else { Type t = Type.GetType(fullname); if (t != null) { res = new CLRType(t, this); mapType[fullname] = res; mapType[res.FullName] = res; mapType[t.AssemblyQualifiedName] = res; clrTypeMapping[t] = res; return(res); } } return(null); }
internal void InitializeValueTypeObject(IType type, StackObject *ptr, bool register, ref int managedIdx) { ptr->ObjectType = ObjectTypes.ValueTypeDescriptor; ptr->Value = type.GetHashCode(); ptr->ValueLow = type.TotalFieldCount; StackObject *endPtr = ptr - (type.TotalFieldCount + 1); if (type is ILType) { ILType t = (ILType)type; for (int i = 0; i < t.FieldTypes.Length; i++) { var ft = t.FieldTypes[i]; StackObject *val = ILIntepreter.Minus(ptr, t.FieldStartIndex + i + 1); if (ft.IsPrimitive || ft.IsEnum) { StackObject.Initialized(val, ft); } else { if (ft.IsValueType) { if (ft is ILType || ((CLRType)ft).ValueTypeBinder != null) { val->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&val->Value = (long)endPtr; InitializeValueTypeObject(ft, endPtr, register, ref managedIdx); int size, mCnt; ft.GetValueTypeSize(out size, out mCnt); endPtr -= size; } else { val->ObjectType = ObjectTypes.Object; val->Value = managedIdx; if (managedIdx < managedStack.Count) { managedStack[managedIdx] = ((CLRType)ft).CreateDefaultInstance(); } else { managedStack.Add(((CLRType)ft).CreateDefaultInstance()); } managedIdx++; } } else { val->ObjectType = ObjectTypes.Object; val->Value = managedIdx; if (managedIdx < managedStack.Count) { managedStack[managedIdx] = null; } else { managedStack.Add(null); } managedIdx++; } } } if (type.BaseType != null && type.BaseType is ILType) { InitializeValueTypeObject((ILType)type.BaseType, ptr, register, ref managedIdx); } } else { CLRType t = (CLRType)type; var cnt = t.TotalFieldCount; for (int i = 0; i < cnt; i++) { var it = t.OrderedFieldTypes[i] as CLRType; StackObject *val = ILIntepreter.Minus(ptr, i + 1); if (it.IsPrimitive || it.IsEnum) { StackObject.Initialized(val, it); } else { if (it.IsValueType) { if (it.ValueTypeBinder != null) { val->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&val->Value = (long)endPtr; InitializeValueTypeObject(it, endPtr, register, ref managedIdx); int size, mCnt; it.GetValueTypeSize(out size, out mCnt); endPtr -= size; } else { val->ObjectType = ObjectTypes.Object; val->Value = managedIdx; if (managedIdx < managedStack.Count) { managedStack[managedIdx] = it.CreateDefaultInstance(); } else { managedStack.Add(it.CreateDefaultInstance()); } managedIdx++; } } else { val->ObjectType = ObjectTypes.Object; val->Value = managedIdx; if (managedIdx < managedStack.Count) { managedStack[managedIdx] = null; } else { managedStack.Add(null); } managedIdx++; } } } } }
public CSHotFixWrapperType(CLRType t) { type = t; et = t.TypeForCLR; }
void InitializeValueTypeObject(IType type, StackObject *ptr) { if (type is ILType) { ILType t = (ILType)type; for (int i = 0; i < t.FieldTypes.Length; i++) { var ft = t.FieldTypes[i]; StackObject *val = ILIntepreter.Minus(ptr, t.FieldStartIndex + i + 1); if (ft.IsPrimitive || ft.IsEnum) { StackObject.Initialized(val, ft); } else { if (ft.IsValueType) { if (ft is ILType || ((CLRType)ft).ValueTypeBinder != null) { AllocValueType(val, ft); } else { val->ObjectType = ObjectTypes.Object; val->Value = managedStack.Count; managedStack.Add(((CLRType)ft).CreateDefaultInstance()); } } else { val->ObjectType = ObjectTypes.Object; val->Value = managedStack.Count; managedStack.Add(null); } } } if (type.BaseType != null && type.BaseType is ILType) { InitializeValueTypeObject((ILType)type.BaseType, ptr); } } else { CLRType t = (CLRType)type; var cnt = t.TotalFieldCount; for (int i = 0; i < cnt; i++) { var it = t.OrderedFieldTypes[i] as CLRType; StackObject *val = ILIntepreter.Minus(ptr, i + 1); if (it.IsPrimitive) { StackObject.Initialized(val, it); } else { if (it.IsValueType) { if (it.ValueTypeBinder != null) { AllocValueType(val, it); } else { val->ObjectType = ObjectTypes.Object; val->Value = managedStack.Count; managedStack.Add(it.CreateDefaultInstance()); } } else { val->ObjectType = ObjectTypes.Object; val->Value = managedStack.Count; managedStack.Add(null); } } } } }
private ILType CreateTypeInternal(ITypeSymbol symbol) { var pointerSymbol = symbol as PointerSymbol; if (pointerSymbol != null) { var element = GetTypeInternal(pointerSymbol.Element); if (element == null) { return(null); } var type = element.CreatePointerType(); return(CacheTypeInternal(type)); } var refSymbol = symbol as RefSymbol; if (refSymbol != null) { var element = GetTypeInternal(refSymbol.Element); if (element == null) { return(null); } var type = element.CreateByRefType(); return(CacheTypeInternal(type)); } var arraySymbol = symbol as ArraySymbol; if (arraySymbol != null) { var element = GetTypeInternal(arraySymbol.Element); if (element == null) { return(null); } var type = element.CreateArrayType(arraySymbol.Rank); return(CacheTypeInternal(type)); } var genericSymbol = symbol as GenericSymbol; if (genericSymbol != null) { var elementType = GetTypeInternal(genericSymbol.Element); if (elementType == null) { return(null); } var genericArugments = new FastList <ILType>(genericSymbol.GenericParameters.Count); foreach (var generic in genericSymbol.GenericParameters) { var genericType = GetTypeInternal(generic); if (genericType == null) { return(null); } genericArugments.Add(genericType); } var type = elementType.CreateGenericType(genericArugments); return(CacheTypeInternal(type)); } var nameSymbol = symbol as NameSymbol; if (nameSymbol != null) { var clr = TypeSupport.GetType(nameSymbol.AssemblyQualifiedName); if (clr == null) { return(null); } var type = CLRType.Create(clr, this); return(CacheTypeInternal(type)); } return(null); }
public void CheckGenericType(CLRType clrType, Type[] args) { if (clrType.IsDelegate) { return; } if (clrType.FullName.Contains("ReadOnlyCollection")) { return; } if (clrType.FullName.Contains("Enumerator")) { return; } if (clrType.FullName.Contains("IEnumerable")) { return; } if (clrType.FullName.Contains("IEqualityComparer")) { return; } if (clrType.FullName.Contains("KeyCollection")) { return; } if (clrType.FullName.Contains("ValueCollection")) { return; } if (clrType.FullName.Contains("KeyValuePair")) { return; } if (clrType.FullName.Contains("IComparer")) { return; } //检查是否注册过 for (int i = 0, cnt = s_genericTypes.Count; i < cnt; ++i) { Type t = s_genericTypes[i]; Type[] types = t.GetGenericArguments(); if (types.Length != args.Length) { continue; } if (clrType.TypeForCLR.Name != t.Name) { continue; } bool isSame = true; for (int j = 0; j < types.Length; ++j) { if (types[j] != args[j]) { isSame = false; break; } } if (isSame) { return; } } //没有注册过 StringBuilder sb = new StringBuilder(); sb.Append(clrType.FullName + "<"); for (int i = 0; i < args.Length; i++) { sb.Append(args[i].FullName); if (i != args.Length - 1) { sb.Append(","); } } sb.Append(">"); if (false == registerList.ContainsKey(sb.ToString())) { string outStr = sb.ToString().Replace("`1", ""); outStr = outStr.Replace("`2", ""); registerList.Add(sb.ToString(), 1); // this.LogMessageInfo("register = ", outStr); } else { var count = registerList[sb.ToString()]; count++; registerList[sb.ToString()] = count; } // this.LogMessageInfo("register = ", sb.ToString()); throw new Exception("没有注册的新类型 = " + sb.ToString()); }
public void UpdateNames() { foreach (GType ifc in Interfaces) { foreach (GType inIfc in ifc.AllInterfaces) { if (!AllInterfaces.Contains(inIfc)) { AllInterfaces.Add(inIfc); } } } if (IsCLRType) { CLRNamespace = CLRType.Namespace; Name = CLRType.Name; if (!IsJVMType && JVMFullName == null) { JVMNamespace = CLRNamespace.ToLowerInvariant(); if (CLRType.IsGenericType) { bool rref = typeof(Ref <>).IsAssignableFrom(CLRType.GetGenericTypeDefinition()); bool oout = typeof(Out <>).IsAssignableFrom(CLRType.GetGenericTypeDefinition()); if (rref || oout) { JVMFullName = JVMNamespace + (rref ? ".Ref<" : ".Out<"); Type[] genericArguments = CLRType.GetGenericArguments(); for (int i = 0; i < genericArguments.Length; i++) { Type argument = genericArguments[i]; if (argument.IsPrimitive) { String objName = Repository.jvmPrimitives[argument].getName(); JVMFullName += objName; } else { GType real = Repository.RegisterType(argument); real.UpdateNames(); JVMFullName += real.JVMResolved; } if (i + 1 < genericArguments.Length) { JVMFullName += ","; } } JVMFullName += ">"; } } else { JVMFullName = JVMNamespace + "." + CLRType.Name; } } } if (IsJVMType) { JVMNamespace = JVMType.PackageName; Name = JVMType.ShortName; if (!IsCLRType) { CLRNamespace = JVMNamespace; if (IsArray) { CLRFullName = JVMType.getComponentType().getName() + "[]"; } else { CLRFullName = JVMType.FullName; } } } JVMNamespaceExt = JVMNamespace; CLRNamespaceExt = CLRNamespace; if (JVMNamespace.StartsWith("java.")) { JVMNamespaceExt = "java_." + JVMNamespace.Substring(5); } /* TODO * if (IsJVMGenerate) * { * if (Base!=null && !Base.IsJVMType && !Base.IsJVMGenerate) * { * Console.WriteLine("you should add " + Base.Name); * } * foreach (GType ifc in Interfaces) * { * if (!ifc.IsJVMType && !ifc.IsJVMGenerate) * { * Console.WriteLine("you should add " + ifc.Name); * } * } * } * * if (IsCLRGenerate && CLRType!=typeof(IClrProxy)) * { * if (Base != null && !Base.IsCLRType && !Base.IsCLRGenerate) * { * Console.WriteLine("you should add " + Base.Name); * } * foreach (GType ifc in Interfaces) * { * if (!ifc.IsCLRType && !ifc.IsCLRGenerate) * { * Console.WriteLine("you should add " + ifc.Name); * } * } * }*/ }
public void ClearValueTypeObject(IType type, StackObject *ptr) { if (type is ILType) { ILType t = (ILType)type; for (int i = 0; i < t.FieldTypes.Length; i++) { var ft = t.FieldTypes[i]; StackObject *val = ILIntepreter.Minus(ptr, t.FieldStartIndex + i + 1); if (ft.IsPrimitive || ft.IsEnum) { StackObject.Initialized(val, ft); } else { switch (val->ObjectType) { case ObjectTypes.ValueTypeObjectReference: ClearValueTypeObject(ft, ILIntepreter.ResolveReference(val)); break; default: if (ft.IsValueType) { if (ft is ILType) { throw new NotImplementedException(); } else { managedStack[val->Value] = ((CLRType)ft).CreateDefaultInstance(); } } else { managedStack[val->Value] = null; } break; } } } if (type.BaseType != null && type.BaseType is ILType) { ClearValueTypeObject((ILType)type.BaseType, ptr); } } else { CLRType t = (CLRType)type; var cnt = t.TotalFieldCount; for (int i = 0; i < cnt; i++) { var vt = t.OrderedFieldTypes[i] as CLRType; StackObject *val = ILIntepreter.Minus(ptr, i + 1); if (vt.IsPrimitive) { StackObject.Initialized(val, vt); } else { switch (val->ObjectType) { case ObjectTypes.ValueTypeObjectReference: { var dst = ILIntepreter.ResolveReference(val); ClearValueTypeObject(vt, dst); } break; default: if (vt.IsValueType) { managedStack[val->Value] = vt.CreateDefaultInstance(); } else { managedStack[val->Value] = null; } break; } } } } }
public CLRConstructor(ConstructorInfo constructor, CLRType type) { this.constructor = constructor; declaringType = type; }
public unsafe object this[int index] { get { if (index < fields.Length && index >= 0) { fixed(StackObject *ptr = fields) { StackObject *esp = &ptr[index]; return(StackObject.ToObject(esp, null, managedObjs)); } } else { if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor) { CLRType clrType = type.AppDomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType; return(clrType.GetFieldValue(index, clrInstance)); } else { throw new TypeLoadException(); } } } set { value = ILIntepreter.CheckAndCloneValueType(value, type.AppDomain); if (index < fields.Length && index >= 0) { fixed(StackObject *ptr = fields) { StackObject *esp = &ptr[index]; if (value != null) { if (value.GetType().IsPrimitive) { ILIntepreter.UnboxObject(esp, value, managedObjs, type.AppDomain); } else { esp->ObjectType = ObjectTypes.Object; esp->Value = index; managedObjs[index] = value; } } else { *esp = StackObject.Null; } } } else { if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor) { CLRType clrType = type.AppDomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType; clrType.SetFieldValue(index, ref clrInstance, value); } else { throw new TypeLoadException(); } } } }
public CLRMethod(MethodInfo method, CLRType type) { this.method = method; declaringType = type; }