private void InitFields(AbcCode code, IType type, IType elemType, Action getArr) { if (getArr == null) { throw new ArgumentNullException("getArr"); } int typeIndex = _generator.Reflection.GetTypeId(type); getArr(); code.PushInt(typeIndex); code.SetProperty("m_type"); var box = GetBoxMethod(elemType); if (box != null) { getArr(); code.GetStaticFunction(box); code.SetProperty("m_box"); } var unbox = GetUnboxMethod(elemType); if (unbox != null) { getArr(); code.GetStaticFunction(unbox); code.SetProperty("m_unbox"); } }
private void NewMethodInfo(AbcCode code, AbcInstance instance, IMethod method, int varMethod, int varParams, int varParam, IType mtype, int index) { var ctor = mtype.FindConstructor(0); if (ctor == null) { throw new InvalidOperationException(".ctor not found"); } var abcMethod = method.AbcMethod(); if (abcMethod == null) { throw new InvalidOperationException(); } abcMethod.MethodInfoIndex = index; code.NewObject(ctor, () => { }); code.SetLocal(varMethod); code.GetLocal(varMethod); code.PushString(method.Name); code.SetField(FieldId.MethodBase_Name); code.GetLocal(varMethod); var wrapper = DefineMetodWrapper(method, true); code.GetStaticFunction(wrapper); code.SetField(FieldId.MethodBase_Function); if (method.IsConstructor) { code.GetLocal(varMethod); wrapper = DefineMetodWrapper(method, false); code.GetStaticFunction(wrapper); code.SetField(FieldId.ConstructorInfo_CreateFunction); } var mattrs = (int)GetMethodAttributes(method); code.GetLocal(varMethod); code.PushInt(mattrs); code.SetField(FieldId.MethodBase_Attributes); code.GetLocal(varMethod); code.NewArray(varParams, mtype, method.Parameters, param => NewParameterInfo(code, instance, param, varMethod, varParam)); code.SetField(FieldId.MethodBase_Parameters); InitCustomAttributes(code, instance, method, varMethod); code.GetLocal(varMethod); }
private void InitProperties(AbcCode code, AbcInstance instance, IType type, int varObj) { var propertiesInitializer = DefinePropertiesInitializer(instance, type); code.GetLocal(varObj); code.GetStaticFunction(propertiesInitializer); code.SetProperty(Const.Type.PropertiesInit); }
private void InitMethods(AbcCode code, AbcInstance instance, IType type, int var) { var init = DefineMethodsInitializer(instance, type, false); code.GetLocal(var); code.GetStaticFunction(init); code.SetProperty(Const.Type.MethodsInit); }
private void InitCustomAttributes(AbcCode code, AbcInstance instance, ICustomAttributeProvider provider, int var) { var init = DefineCustomAttributesInitializer(instance, provider); code.GetLocal(var); code.GetStaticFunction(init); code.SetProperty(Const.MemberInfo.CustomAttrsInit); }
private void InitConstructors(AbcCode code, AbcInstance instance, IType type, int var) { // TODO: problem is here var init = DefineMethodsInitializer(instance, type, true); code.GetLocal(var); code.GetStaticFunction(init); code.SetProperty(Const.Type.ConstructorsInit); }
private void InitTypeFuncs(AbcCode code, IType type, AbcInstance instance) { var f = _generator.Boxing.Box(type); if (f != null) { code.GetLocal(varType); code.GetStaticFunction(f); code.SetProperty(Const.Type.BoxFunction); } f = _generator.Boxing.Unbox(type, false); if (f != null) { code.GetLocal(varType); code.GetStaticFunction(f); code.SetProperty(Const.Type.UnboxFunction); } f = CopyImpl.StaticCopy(instance); if (f != null) { code.GetLocal(varType); code.GetStaticFunction(f); code.SetProperty(Const.Type.CopyFunction); } var ctor = type.FindParameterlessConstructor(); if (ctor != null) { f = _generator.MethodBuilder.Build(ctor) as AbcMethod; if (f != null && !f.IsInitializer) { f = _generator.TypeBuilder.DefineCtorStaticCall(ctor); Debug.Assert(f != null); code.GetLocal(varType); code.GetStaticFunction(f); code.SetProperty(Const.Type.CreateFunction); } } }
private void RunTest(AbcCode code, IMethod test) { var testFixture = test.DeclaringType; var testType = GetType(NUnitTypeId.Test); var testInstance = GetInstance(NUnitTypeId.Test); const int varTest = 1; code.CreateInstance(testInstance); code.SetLocal(varTest); code.GetLocal(varTest); code.PushString(test.FullName); code.SetProperty(testType, "Name"); code.GetLocal(varTest); code.PushString(testFixture.FullName); code.SetProperty(testType, "SuiteName"); string desc = test.GetTestDescription(); if (!string.IsNullOrEmpty(desc)) { code.GetLocal(varTest); code.PushString(desc); code.SetProperty(testType, "Description"); } desc = testFixture.GetTestDescription(); if (!string.IsNullOrEmpty(desc)) { code.GetLocal(varTest); code.PushString(desc); code.SetProperty(testType, "SuiteDescription"); } var func = DefineTestRunner(test); code.GetLocal(varTest); code.GetStaticFunction(func); //code.CallSetter(testType, "Func"); code.SetField(testType, "Func"); //register test in FlashTestRunner code.CallStatic(GetMethod(NUnitMethodId.TestRunner_Register), () => code.GetLocal(varTest)); }
private void InitFields(AbcCode code, AbcInstance instance, IType type) { if (!MustInitFields) { return; } if (type.IsInterface) { return; } var init = DefineMyFieldsInitializer(instance, type); if (init != null) { code.GetLocal(varType); code.GetStaticFunction(init); code.SetProperty(Const.Type.MyFieldsInit); } }
private void InitTypeInfo(AbcCode code, IType type, int typeId) { var instance = _generator.TypeBuilder.BuildInstance(type); //NOTE: typeId is assigned in corlib in Assembly.GetType //code.GetLocal(varType); //code.PushInt(typeId); //code.SetProperty("index"); //WARNING: Sync field names with Type in corlib. code.GetLocal(varType); code.PushString(type.Namespace); code.SetProperty(Const.Type.Namespace); code.GetLocal(varType); code.PushNamespace(instance.Name.Namespace); code.SetProperty(Const.Type.NamespaceObject); code.GetLocal(varType); code.PushString(type.NestedName); code.SetProperty(Const.Type.Name); int baseIndex = GetTypeId(type.BaseType); code.GetLocal(varType); code.PushInt(baseIndex); code.SetProperty(Const.Type.BaseType); int typeKind = type.GetCorlibKind(); if (typeKind != 0) { code.GetLocal(varType); code.PushInt(typeKind); code.SetProperty(Const.Type.Kind); } if (type.IsArray) { code.GetLocal(varType); code.PushInt(type.ArrayDimensions.Count + 1); code.SetProperty(Const.Type.Rank); } if (type.ElementType != null) { var elemType = type.ElementType; int elemTypeIndex = GetTypeId(elemType); if (elemTypeIndex < 0) { throw new InvalidOperationException(); } code.GetLocal(varType); code.PushInt(elemTypeIndex); code.SetProperty(Const.Type.ElementType); } if (type.IsEnum) { var utype = type.ValueType; SetUnderlyingType(code, utype); var init = DefineEnumInfoInitializer(type); code.GetLocal(varType); code.GetStaticFunction(init); code.SetProperty(Const.Type.EnumInfoInit); } else if (type.IsNullableInstance()) { var utype = type.GenericArguments[0]; if (utype.IsEnum) { utype = utype.ValueType; } SetUnderlyingType(code, utype); } InitTypeFuncs(code, type, instance); if (GlobalSettings.ReflectionSupport) { InitCustomAttributes(code, instance, type, varType); InitMethods(code, instance, type, varType); InitConstructors(code, instance, type, varType); InitProperties(code, instance, type, varType); } InitFields(code, instance, type); var ifaces = GetInterfaces(type); if (ifaces != null) { code.GetLocal(varType); code.NewNativeArray( varTempArray, ifaces, iface => code.PushTypeId(iface)); code.SetProperty(Const.Type.Interfaces); } }