Example #1
0
        private AbcInstance DefineEnumSuperType(IType type)
        {
            if (!type.IsEnum)
            {
                throw new InvalidOperationException("type is not enum");
            }
            var vtype = type.ValueType;
            var st    = vtype.SystemType();

            if (st == null)
            {
                throw new InvalidOperationException(string.Format("invalid enum type {0}", type.FullName));
            }
            int index = GetEnumIndex(st);

            var instance = _enumSuperTypes[index];

            if (instance != null)
            {
                return(instance);
            }

            var super = BuildInstance(type.BaseType);

            instance = _enumSuperTypes[index];
            if (instance != null)
            {
                return(instance);
            }

            instance = new AbcInstance(true)
            {
                Name         = Abc.DefineName(QName.PfxPackage(GetEnumName(st))),
                BaseTypeName = super.Name,
                BaseInstance = super,
                Initializer  = Initializers.BuildDefaultInitializer(Abc, null)
            };
            Abc.AddInstance(instance);

            instance.Class.Initializer = Abc.DefineEmptyMethod();

            _enumSuperTypes[index] = instance;

            string name = Const.Boxing.Value;

            instance.CreateSlot(Abc.DefineName(QName.Global(name)), BuildMemberType(vtype));

            //SetFlags(instance, type);

            return(instance);
        }
Example #2
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);
        }