コード例 #1
0
ファイル: iterators.cs プロジェクト: jordanbtucker/mono
        protected override bool DoDefineMembers()
        {
            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)
            {
                FullNamedExpression explicit_iface = new TypeExpression(Compiler.BuiltinTypes.IEnumerable, Location);
                var name = new MemberName("GetEnumerator", null, explicit_iface, Location);

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

                    explicit_iface = new GenericTypeExpr(Module.PredefinedTypes.IEnumerableGeneric.Resolve(), generic_args, Location);
                    name           = new MemberName("GetEnumerator", null, explicit_iface, 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));
                }
            }

            return(base.DoDefineMembers());
        }
コード例 #2
0
            public static GetEnumeratorMethod Create(IteratorStorey host, FullNamedExpression returnType, MemberName name, Statement statement)
            {
                var m    = new GetEnumeratorMethod(host, returnType, name);
                var stmt = statement ?? new GetEnumeratorStatement(host, m);

                m.block.AddStatement(stmt);
                return(m);
            }
コード例 #3
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
            }
        }
コード例 #4
0
ファイル: iterators.cs プロジェクト: speier/shake
        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
ファイル: iterators.cs プロジェクト: nuxleus/mono
        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
        protected override bool DoDefineMembers()
        {
            current_field   = AddCompilerGeneratedField("$current", iterator_type_expr);
            disposing_field = AddCompilerGeneratedField("$disposing", new TypeExpression(Compiler.BuiltinTypes.Bool, Location));

            if (Iterator.IsEnumerable && 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
                //
                hoisted_params_copy = new List <HoistedParameter> (hoisted_params.Count);
                foreach (HoistedParameter hp in hoisted_params)
                {
                    //
                    // Don't create field copy for unmodified captured parameters
                    //
                    HoistedParameter hp_copy;
                    if (hp.IsAssigned)
                    {
                        hp_copy = new HoistedParameter(hp, "<$>" + hp.Field.Name);
                    }
                    else
                    {
                        hp_copy = null;
                    }

                    hoisted_params_copy.Add(hp_copy);
                }
            }

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

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

            if (Iterator.IsEnumerable)
            {
                FullNamedExpression explicit_iface = new TypeExpression(Compiler.BuiltinTypes.IEnumerable, Location);
                var name = new MemberName("GetEnumerator", null, explicit_iface, Location.Null);

                if (generic_enumerator_type != null)
                {
                    explicit_iface = new TypeExpression(generic_enumerable_type, Location);
                    var    gname           = new MemberName("GetEnumerator", null, explicit_iface, Location.Null);
                    Method gget_enumerator = GetEnumeratorMethod.Create(this, new TypeExpression(generic_enumerator_type, Location), gname);

                    //
                    // Just call generic GetEnumerator implementation
                    //
                    var    stmt           = new Return(new Invocation(new DynamicMethodGroupExpr(gget_enumerator, Location), null), Location);
                    Method get_enumerator = GetEnumeratorMethod.Create(this, new TypeExpression(Compiler.BuiltinTypes.IEnumerator, Location), name, stmt);

                    Members.Add(get_enumerator);
                    Members.Add(gget_enumerator);
                }
                else
                {
                    Members.Add(GetEnumeratorMethod.Create(this, new TypeExpression(Compiler.BuiltinTypes.IEnumerator, Location), name));
                }
            }

            return(base.DoDefineMembers());
        }