Пример #1
0
        public void DefineIteratorMembers()
        {
            pc_field      = AddCompilerGeneratedField("$PC", TypeManager.system_int32_expr);
            current_field = AddCompilerGeneratedField("$current", iterator_type_expr);

            if (hoisted_params != null)
            {
                //
                // Iterators are independent, each GetEnumerator call has to
                // create same enumerator therefore we have to keep original values
                // around for re-initialization
                //
                // TODO: Do it for assigned/modified parameters only
                //
                hoisted_params_copy = new ArrayList(hoisted_params.Count);
                foreach (HoistedParameter hp in hoisted_params)
                {
                    hoisted_params_copy.Add(new HoistedParameter(hp, "<$>" + hp.Field.Name));
                }
            }

#if GMCS_SOURCE
            Define_Current(true);
#endif
            Define_Current(false);
            new DisposeMethod(this);
            Define_Reset();

            if (Iterator.IsEnumerable)
            {
                MemberName name = new MemberName(
                    new MemberName("System.Collections.IEnumerable", Location), "GetEnumerator", Location);

#if GMCS_SOURCE
                Method get_enumerator = new IteratorMethod(this, enumerator_type, 0, name);

                name = new MemberName(
                    new MemberName("System.Collections.Generic.IEnumerable", generic_args, Location), "GetEnumerator", Location);
                Method gget_enumerator = new GetEnumeratorMethod(this, generic_enumerator_type, name);

                //
                // Just call generic GetEnumerator implementation
                //
                get_enumerator.Block.AddStatement(
                    new Return(new Invocation(new DynamicMethodGroupExpr(gget_enumerator, Location), new ArrayList(0)), Location));

                AddMethod(get_enumerator);
                AddMethod(gget_enumerator);
#else
                AddMethod(new GetEnumeratorMethod(this, enumerator_type, name));
#endif
            }
        }
Пример #2
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            IteratorHost = (IteratorStorey)block.TopBlock.AnonymousMethodStorey;

            BlockContext ctx = new BlockContext(ec, block, ReturnType);

            ctx.CurrentAnonymousMethod = this;

            ctx.StartFlowBranching(this, ec.CurrentBranching);
            Block.Resolve(ctx);
            ctx.EndFlowBranching();

            var move_next = new IteratorMethod(IteratorHost, new TypeExpression(ec.BuiltinTypes.Bool, loc),
                                               Modifiers.PUBLIC, new MemberName("MoveNext", Location));

            move_next.Block.AddStatement(new MoveNextMethodStatement(this));
            IteratorHost.AddMethod(move_next);

            eclass = ExprClass.Value;
            return(this);
        }
Пример #3
0
 public GetEnumeratorStatement(IteratorStorey host, IteratorMethod host_method)
 {
     this.host = host;
     this.host_method = host_method;
     loc = host_method.Location;
 }
Пример #4
0
        void DefineIteratorMembers()
        {
            pc_field = AddCompilerGeneratedField ("$PC", TypeManager.system_int32_expr);
            current_field = AddCompilerGeneratedField ("$current", iterator_type_expr);

            if (hoisted_params != null) {
                //
                // Iterators are independent, each GetEnumerator call has to
                // create same enumerator therefore we have to keep original values
                // around for re-initialization
                //
                // TODO: Do it for assigned/modified parameters only
                //
                hoisted_params_copy = new List<HoistedParameter> (hoisted_params.Count);
                foreach (HoistedParameter hp in hoisted_params) {
                    hoisted_params_copy.Add (new HoistedParameter (hp, "<$>" + hp.Field.Name));
                }
            }

            if (generic_enumerator_type != null)
                Define_Current (true);

            Define_Current (false);
            new DisposeMethod (this);
            Define_Reset ();

            if (Iterator.IsEnumerable) {
                MemberName name = new MemberName (QualifiedAliasMember.GlobalAlias, "System", null, Location);
                name = new MemberName (name, "Collections", Location);
                name = new MemberName (name, "IEnumerable", Location);
                name = new MemberName (name, "GetEnumerator", Location);

                if (generic_enumerator_type != null) {
                    Method get_enumerator = new IteratorMethod (this, enumerator_type, 0, name);

                    name = new MemberName (name.Left.Left, "Generic", Location);
                    name = new MemberName (name, "IEnumerable", generic_args, Location);
                    name = new MemberName (name, "GetEnumerator", Location);
                    Method gget_enumerator = new GetEnumeratorMethod (this, generic_enumerator_type, name);

                    //
                    // Just call generic GetEnumerator implementation
                    //
                    get_enumerator.Block.AddStatement (
                        new Return (new Invocation (new DynamicMethodGroupExpr (gget_enumerator, Location), null), Location));

                    AddMethod (get_enumerator);
                    AddMethod (gget_enumerator);
                } else {
                    AddMethod (new GetEnumeratorMethod (this, enumerator_type, name));
                }
            }
        }
Пример #5
0
        void DefineIteratorMembers()
        {
            pc_field        = AddCompilerGeneratedField("$PC", new TypeExpression(Compiler.BuiltinTypes.Int, Location));
            current_field   = AddCompilerGeneratedField("$current", iterator_type_expr);
            disposing_field = AddCompilerGeneratedField("$disposing", new TypeExpression(Compiler.BuiltinTypes.Bool, Location));

            if (hoisted_params != null)
            {
                //
                // Iterators are independent, each GetEnumerator call has to
                // create same enumerator therefore we have to keep original values
                // around for re-initialization
                //
                // TODO: Do it for assigned/modified parameters only
                //
                hoisted_params_copy = new List <HoistedParameter> (hoisted_params.Count);
                foreach (HoistedParameter hp in hoisted_params)
                {
                    hoisted_params_copy.Add(new HoistedParameter(hp, "<$>" + hp.Field.Name));
                }
            }

            if (generic_enumerator_type != null)
            {
                Define_Current(true);
            }

            Define_Current(false);
            new DisposeMethod(this);
            Define_Reset();

            if (Iterator.IsEnumerable)
            {
                MemberName name = new MemberName(QualifiedAliasMember.GlobalAlias, "System", null, Location);
                name = new MemberName(name, "Collections", Location);
                name = new MemberName(name, "IEnumerable", Location);
                name = new MemberName(name, "GetEnumerator", Location);

                if (generic_enumerator_type != null)
                {
                    Method get_enumerator = new IteratorMethod(this, enumerator_type, 0, name);

                    name = new MemberName(name.Left.Left, "Generic", Location);
                    name = new MemberName(name, "IEnumerable", generic_args, Location);
                    name = new MemberName(name, "GetEnumerator", Location);
                    Method gget_enumerator = new GetEnumeratorMethod(this, generic_enumerator_type, name);

                    //
                    // Just call generic GetEnumerator implementation
                    //
                    get_enumerator.Block.AddStatement(
                        new Return(new Invocation(new DynamicMethodGroupExpr(gget_enumerator, Location), null), Location));

                    AddMethod(get_enumerator);
                    AddMethod(gget_enumerator);
                }
                else
                {
                    AddMethod(new GetEnumeratorMethod(this, enumerator_type, name));
                }
            }
        }
Пример #6
0
 public GetEnumeratorStatement(IteratorStorey host, IteratorMethod host_method)
 {
     this.host        = host;
     this.host_method = host_method;
     loc = host_method.Location;
 }
Пример #7
0
		protected override Expression DoResolve (ResolveContext ec)
		{
			IteratorHost = (IteratorStorey) block.TopBlock.AnonymousMethodStorey;

			BlockContext ctx = new BlockContext (ec, block, ReturnType);
			ctx.CurrentAnonymousMethod = this;

			ctx.StartFlowBranching (this, ec.CurrentBranching);
			Block.Resolve (ctx);
			ctx.EndFlowBranching ();

			var move_next = new IteratorMethod (IteratorHost, new TypeExpression (TypeManager.bool_type, loc),
				Modifiers.PUBLIC, new MemberName ("MoveNext", Location));
			move_next.Block.AddStatement (new MoveNextMethodStatement (this));
			IteratorHost.AddMethod (move_next);

			eclass = ExprClass.Value;
			return this;
		}