Beispiel #1
0
        /// <summary>
        /// Defines given type in generated ABC file
        /// </summary>
        /// <param name="type">the type to define</param>
        /// <returns>tag associated with given type</returns>
        public object Build(IType type)
        {
            if (type == null)
            {
                return(null);
            }

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

            var tag = ImportType(type);

            bool isImported = false;

            if (tag == null)
            {
                if (type.Data != null)
                {
                    throw new InvalidOperationException();
                }
                tag = BuildCore(type);
            }
            else
            {
                isImported = true;
            }

            if (tag != null)
            {
                _generator.SetData(type, tag);

                RegisterType(type);

                if (!isImported)
                {
                    BuildMembers(type);
                }
            }

            return(type.Data);
        }
Beispiel #2
0
        public void Build(IField field)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            if (MustExclude(field))
            {
                return;
            }

            if (Abc.IsDefined(field))
            {
                return;
            }

            var declType = field.DeclaringType;
            var tag      = _generator.TypeBuilder.Build(declType);

            var instance = tag as AbcInstance;

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

            if (instance.IsForeign)
            {
                return;
            }

            if (Abc.IsDefined(field))
            {
                return;
            }

            var type = _generator.TypeBuilder.BuildMemberType(field.Type);

            if (Abc.IsDefined(field))
            {
                return;
            }

#if DEBUG
            DebugService.LogInfo("ABC DefineField started for field {0}.{1}", field.DeclaringType.FullName, field.Name);
#endif

            var      name     = DefineName(field);
            bool     isStatic = field.IsStatic;
            AbcTrait trait    = null;

            //Try to find trait, may be it has already been defined
            if (field.Data != null)
            {
                var kind = field.IsConstant ? AbcTraitKind.Const : AbcTraitKind.Slot;
                trait = isStatic ? instance.Class.Traits.Find(name, kind) : instance.Traits.Find(name, kind);
            }

            if (trait == null)
            {
                trait = AbcTrait.CreateSlot(type, name);
                _generator.SetData(field, trait);
                instance.AddTrait(trait, isStatic);

                if (IsImportableConstant(field))
                {
                    trait.Kind      = AbcTraitKind.Const;
                    trait.HasValue  = true;
                    trait.SlotValue = Abc.ImportValue(field.Value);
                }

                _generator.EmbeddedAssets.Build(field, trait);
            }
            else
            {
                _generator.SetData(field, trait);
            }

            trait.Type  = field.Type;
            trait.Field = field;

#if DEBUG
            DebugService.LogInfo("ABC DefineField succeeded for field {0}", field.FullName);
#endif
        }