Ejemplo n.º 1
0
        private void CreateEnumerator()
        {
            _enumerator = CodeBuilder.CreateClass("$Enumerator");
            _enumerator.AddAttribute(CodeBuilder.CreateAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)));
            _enumerator.Modifiers  |= _enumerable.Modifiers;
            _enumerator.LexicalInfo = this.LexicalInfo;
            foreach (var param in _genericParams)
            {
                var replacement = _enumerator.AddGenericParameter(param.Name);
                _methodToEnumeratorMapper.Replace((IType)param.Entity, (IType)replacement.Entity);
            }
            var abstractEnumeratorType =
                TypeSystemServices.Map(typeof(GenericGeneratorEnumerator <>)).
                GenericInfo.ConstructType(_methodToEnumeratorMapper.MapType(_generatorItemType));

            _state        = NameResolutionService.ResolveField(abstractEnumeratorType, "_state");
            _yield        = NameResolutionService.ResolveMethod(abstractEnumeratorType, "Yield");
            _yieldDefault = NameResolutionService.ResolveMethod(abstractEnumeratorType, "YieldDefault");
            _enumerator.AddBaseType(abstractEnumeratorType);
            _enumerator.AddBaseType(TypeSystemServices.IEnumeratorType);

            CreateEnumeratorConstructor();
            CreateMoveNext();

            _enumerable.ClassDefinition.Members.Add(_enumerator.ClassDefinition);
        }
Ejemplo n.º 2
0
        private BooClassBuilder SetUpEnumerableClassBuilder(Node sourceNode, Method enclosingMethod, IType generatorItemType)
        {
            BooClassBuilder builder = CodeBuilder.CreateClass(
                Context.GetUniqueName(enclosingMethod.Name),
                TypeMemberModifiers.Internal | TypeMemberModifiers.Final);

            builder.LexicalInfo = new LexicalInfo(sourceNode.LexicalInfo);
            builder.AddBaseType(
                TypeSystemServices.Map(typeof(GenericGenerator <>)).GenericInfo.ConstructType(generatorItemType));

            builder.AddAttribute(CodeBuilder.CreateAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)));
            return(builder);
        }
Ejemplo n.º 3
0
        protected virtual void CreateStateMachine()
        {
            _stateMachineClass = CodeBuilder.CreateClass(StateMachineClassName);
            _stateMachineClass.AddAttribute(CodeBuilder.CreateAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)));
            _stateMachineClass.LexicalInfo = this.LexicalInfo;
            foreach (var param in _genericParams)
            {
                var replacement = _stateMachineClass.AddGenericParameter(param);
                _methodToStateMachineMapper.Replace((IType)param.Entity, (IType)replacement.Entity);
            }

            SetupStateMachine();
            CreateStateMachineConstructor();

            SaveStateMachineClass(_stateMachineClass.ClassDefinition);
            CreateMoveNext();
        }
Ejemplo n.º 4
0
        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");
            _yieldDefault = NameResolutionService.ResolveMethod(abstractEnumeratorType, "YieldDefault");

            _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);
        }
Ejemplo n.º 5
0
		void CreateEnumerator()
		{
			var abstractEnumeratorType =
				TypeSystemServices.Map(typeof(GenericGeneratorEnumerator<>)).
					GenericInfo.ConstructType(new IType[] {_generatorItemType});
			
			_state = NameResolutionService.ResolveField(abstractEnumeratorType, "_state");
			_yield = NameResolutionService.ResolveMethod(abstractEnumeratorType, "Yield");
			_yieldDefault = NameResolutionService.ResolveMethod(abstractEnumeratorType, "YieldDefault");
			
			_enumerator = CodeBuilder.CreateClass("$");
			_enumerator.AddAttribute(CodeBuilder.CreateAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)));
			_enumerator.Modifiers |= _enumerable.Modifiers;
			_enumerator.LexicalInfo = this.LexicalInfo;
			_enumerator.AddBaseType(abstractEnumeratorType);
			_enumerator.AddBaseType(TypeSystemServices.IEnumeratorType);

			CreateEnumeratorConstructor();
			CreateMoveNext();
			
			_enumerable.ClassDefinition.Members.Add(_enumerator.ClassDefinition);
		}