Пример #1
0
        private AbcMethod DefineEnumInfoInitializer(IType type)
        {
            var enumInstance = type.AbcInstance();

            if (enumInstance == null)
            {
                throw new InvalidOperationException();
            }

            var EnumInfo = _generator.Corlib.GetInstance(CorlibTypeId.EnumInfo);

            var name = _generator.Abc.DefineName(QName.PfxPublic("init_enum_info_" + type.GetSigName()));

            return(enumInstance.DefineMethod(
                       Sig.@static(name, EnumInfo),
                       code =>
            {
                const int varEnumInfo = 1;
                const int varArr = 2;
                code.CreateInstance(EnumInfo);
                code.SetLocal(varEnumInfo);

                if (type.HasAttribute("System.FlagsAttribute"))
                {
                    code.GetLocal(varEnumInfo);
                    code.PushBool(true);
                    code.SetProperty(Const.EnumInfo.Flags);
                }

                var fields = type.GetEnumFields();
                var utype = type.ValueType;

                code.GetLocal(varEnumInfo);

                code.NewArray(varArr, SystemTypes.Object, fields,
                              f =>
                {
                    var val = f.Value;
                    if (val == null)
                    {
                        throw new InvalidOperationException();
                    }
                    val = ToIntegralType(utype, val);
                    code.Box(type, () => code.LoadConstant(val));
                });

                code.SetProperty(Const.EnumInfo.Values);

                code.GetLocal(varEnumInfo);
                code.NewArray(varArr, SystemTypes.String, fields,
                              field => code.PushString(field.Name));
                code.SetProperty(Const.EnumInfo.Names);

                code.GetLocal(varEnumInfo);
                code.ReturnValue();
            }));
        }
Пример #2
0
        public static bool IsAvmObject(this IType type)
        {
            if (type == null)
            {
                return(false);
            }
            var instance = type.AbcInstance();

            return(instance != null && instance.IsObject);
        }
Пример #3
0
        public void Call(AbcCode code, IType type)
        {
            var instance = type.AbcInstance();

            if (instance == null)
            {
                return;
            }
            Call(code, instance);
        }
Пример #4
0
        private void LoadStaticInstance(AbcCode code, IType type)
        {
            EnsureType(type);

            var instance = type.AbcInstance();

            if (instance != null)
            {
                LoadStaticInstance(code, type, instance);
                return;
            }

            throw new InvalidOperationException();
        }
Пример #5
0
        public static bool Is(this IType type, AvmTypeCode typeCode)
        {
            if (type == null)
            {
                return(false);
            }
            var instance = type.AbcInstance();

            if (instance == null)
            {
                return(false);
            }
            if (!instance.IsNative)
            {
                return(false);
            }
            return(instance.FullName == typeCode.FullName());
        }
Пример #6
0
        private void RegisterType(IType type)
        {
            string name = type.FullName;

            if (!_typeCache.ContainsKey(name))
            {
                _typeCache.Add(name, type);
            }

            var instance = type.AbcInstance();

            if (instance != null)
            {
                string name2 = instance.FullName;
                if (name2 != name)
                {
                    _typeCache.Add(name2, type);
                }
            }
        }
Пример #7
0
        private void BuildMembers(IType type)
        {
            var instance = type.AbcInstance();

            if (instance == null)
            {
                return;
            }
            if (instance.IsForeign)
            {
                return;
            }
            if (type.IsArray)
            {
                return;
            }

            //NOTE:
            //For array types we define only System.Array.
            //Therefore in order to correctly define memebers
            //we should use System.Array instead of SomeType[].
            if (!ReferenceEquals(instance.Type, type))
            {
                type = instance.Type;
            }

            if (!type.IsInterface)
            {
                _generator.FlexAppBuilder.DefineMembers(instance);
                DefineFields(type);
            }

            Initializers.EnshureInitializers(instance);

            //DefineCompiledMethods(type);
            DefineExposedMethods(type);
        }
Пример #8
0
        private object BuildUserType(IType type)
        {
            if (LinkVectorInstance(type))
            {
                return(type.Data);
            }

            //NOTE: can be used only in typeof operations
            if (type.IsGeneric())
            {
                return(null);
            }

            if (type.HasGenericParams())
            {
                throw new InvalidOperationException();
            }

            AbcMultiname superName;
            AbcInstance  superType;

            DefineSuperType(type, out superName, out superType);

            //NOTE: Fix for enums.
            if (Abc.IsDefined(type))
            {
                return(type.Data);
            }

#if DEBUG
            DebugService.LogInfo("DefineUserType started for {0}", type.FullName);
#endif
            var ifaceNames = BuildInterfaces(type);

            if (Abc.IsDefined(type))
            {
                return(type.AbcInstance());
            }

            var name = DefineInstanceName(type);

            var instance = new AbcInstance(true)
            {
                Type         = type,
                Name         = name,
                BaseTypeName = superName,
                BaseInstance = superType
            };

            _generator.SetData(type, instance);
            SetFlags(instance, type);
            AddInterfaces(instance, type, ifaceNames);

            Abc.AddInstance(instance);

            if (_generator.IsRootSprite(type))
            {
                _generator.RootSprite.Instance = instance;
            }

            DebugInfoBuilder.Build(_generator, type, instance);

#if DEBUG
            DebugService.LogInfo("DefineUserType succeeded for {0}", type.FullName);
#endif

            return(instance);
        }
Пример #9
0
 private static bool IsLinked(IType type)
 {
     return(type.Data is NativeType ||
            type.AbcInstance() != null);
 }