AddBaseType() public méthode

public AddBaseType ( IType type ) : void
type IType
Résultat void
Exemple #1
0
        public ClassDefinition GetCompilerGeneratedExtensionsClass()
        {
            if (null == _compilerGeneratedExtensionsClass)
            {
                BooClassBuilder builder = CodeBuilder.CreateClass("CompilerGeneratedExtensions");
                builder.Modifiers = TypeMemberModifiers.Final | TypeMemberModifiers.Transient | TypeMemberModifiers.Public;
                builder.AddBaseType(ObjectType);

                BooMethodBuilder ctor = builder.AddConstructor();
                ctor.Modifiers = TypeMemberModifiers.Private;
                ctor.Body.Add(
                    CodeBuilder.CreateSuperConstructorInvocation(ObjectType));

                ClassDefinition cd     = builder.ClassDefinition;
                Module          module = GetCompilerGeneratedExtensionsModule();
                module.Members.Add(cd);
                ((ModuleEntity)module.Entity).InitializeModuleClass(cd);

                _compilerGeneratedExtensionsClass = cd;
            }
            return(_compilerGeneratedExtensionsClass);
        }
        void CreateEnumerator()
        {
            IType abstractEnumeratorType =
                TypeSystemServices.Map(typeof(Boo.Lang.GenericGeneratorEnumerator<>)).
                GenericInfo.ConstructType(new IType[] {_generatorItemType});

            _state = NameResolutionService.ResolveField(abstractEnumeratorType, "_state");
            _yield = NameResolutionService.ResolveMethod(abstractEnumeratorType, "Yield");

            _enumerator = CodeBuilder.CreateClass("$");
            _enumerator.AddAttribute(CodeBuilder.CreateAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)));
            _enumerator.Modifiers |= TypeMemberModifiers.Final;
            _enumerator.LexicalInfo = this.LexicalInfo;
            _enumerator.AddBaseType(abstractEnumeratorType);
            _enumerator.AddBaseType(TypeSystemServices.IEnumeratorType);

            CreateEnumeratorConstructor();
            CreateMoveNext();

            _enumerable.ClassDefinition.Members.Add(_enumerator.ClassDefinition);
            //new Boo.Lang.Compiler.Ast.Visitors.BooPrinterVisitor(System.Console.Out).Visit(_enumerator.ClassDefinition);
        }
        void CreateAnonymousGeneratorType()
        {
            _enumerable = (BooClassBuilder)_generator["GeneratorClassBuilder"];

            // Set up some important types
            _sourceItemType = TypeSystemServices.ObjectType;
            _sourceEnumeratorType = TypeSystemServices.IEnumeratorType;
            _sourceEnumerableType = TypeSystemServices.IEnumerableType;

            _resultItemType = (IType)_generator["GeneratorItemType"];
            _resultEnumeratorType = TypeSystemServices.IEnumeratorGenericType.GenericInfo.ConstructType(_resultItemType);

            _enumerator = _collector.CreateSkeletonClass("Enumerator",_generator.LexicalInfo);

            // use a generic enumerator for the source type if possible
            _sourceItemType = TypeSystemServices.GetGenericEnumerableItemType(_generator.Iterator.ExpressionType);
            if (_sourceItemType != null && _sourceItemType != TypeSystemServices.ObjectType)
            {
                _sourceEnumerableType = TypeSystemServices.IEnumerableGenericType.GenericInfo.ConstructType(_sourceItemType);
                _sourceEnumeratorType = TypeSystemServices.IEnumeratorGenericType.GenericInfo.ConstructType(_sourceItemType);
            }
            else
            {
                _sourceItemType = TypeSystemServices.ObjectType;
            }

            // Add base types
            _enumerator.AddBaseType(_resultEnumeratorType);
            _enumerator.AddBaseType(TypeSystemServices.Map(typeof(ICloneable)));
            _enumerator.AddBaseType(TypeSystemServices.Map(typeof(IDisposable)));

            // Add fields
            _enumeratorField = _enumerator.AddField("$$enumerator", _sourceEnumeratorType);
            _current = _enumerator.AddField("$$current", _resultItemType);

            // Add methods
            CreateReset();
            CreateCurrent();
            CreateMoveNext();
            CreateClone();
            CreateDispose();

            EnumeratorConstructorMustCallReset();

            _collector.AdjustReferences();

            _collector.DeclareFieldsAndConstructor(_enumerable);

            CreateGetEnumerator();
            _enumerable.ClassDefinition.Members.Add(_enumerator.ClassDefinition);
        }