2009-08-12 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / iterators.cs
index f3edad4e2c09d36e7cdb536fff7c0694d62876db..ddd316fa14cef277eb578f740bc398dbde7fef4f 100644 (file)
@@ -139,9 +139,9 @@ namespace Mono.CSharp {
        class IteratorStatement : Statement
        {
                Iterator iterator;
-               ExplicitBlock original_block;
+               Block original_block;
 
-               public IteratorStatement (Iterator iterator, ExplicitBlock original_block)
+               public IteratorStatement (Iterator iterator, Block original_block)
                {
                        this.iterator = iterator;
                        this.original_block = original_block;
@@ -183,11 +183,11 @@ namespace Mono.CSharp {
 
                        public IteratorMethod (IteratorStorey host, FullNamedExpression returnType, int mod, MemberName name)
                                : base (host, null, returnType, mod | Modifiers.DEBUGGER_HIDDEN | Modifiers.COMPILER_GENERATED,
-                                 name, Parameters.EmptyReadOnlyParameters, null)
+                                 name, ParametersCompiled.EmptyReadOnlyParameters, null)
                        {
                                this.host = host;
 
-                               Block = new ToplevelBlock (host.Iterator.Container.Toplevel, Parameters.EmptyReadOnlyParameters, Location);
+                               Block = new ToplevelBlock (host.Iterator.Container.Toplevel, ParametersCompiled.EmptyReadOnlyParameters, Location);
                        }
 
                        public override EmitContext CreateEmitContext (DeclSpace tc, ILGenerator ig)
@@ -249,10 +249,10 @@ namespace Mono.CSharp {
                                        }
 
                                        if (init != null) {
-                                               new_storey = new NewInitialize (storey_type_expr, new ArrayList (0),
+                                               new_storey = new NewInitialize (storey_type_expr, null,
                                                        new CollectionOrObjectInitializers (init, loc), loc);
                                        } else {
-                                               new_storey = new New (storey_type_expr, new ArrayList (0), loc);
+                                               new_storey = new New (storey_type_expr, null, loc);
                                        }
 
                                        new_storey = new_storey.Resolve (ec);
@@ -346,7 +346,7 @@ namespace Mono.CSharp {
                        {
                                host.AddMethod (this);
 
-                               Block = new ToplevelBlock (host.Iterator.Container, Parameters.EmptyReadOnlyParameters, Location);
+                               Block = new ToplevelBlock (host.Iterator.Container, ParametersCompiled.EmptyReadOnlyParameters, Location);
                                Block.AddStatement (new DisposeMethodStatement (host.Iterator));
                        }
                }
@@ -400,13 +400,9 @@ namespace Mono.CSharp {
 
                TypeExpr enumerator_type;
                TypeExpr enumerable_type;
-#if GMCS_SOURCE
                TypeArguments generic_args;
                TypeExpr generic_enumerator_type;
                TypeExpr generic_enumerable_type;
-#else
-               const TypeArguments generic_args = null;
-#endif
 
                ArrayList hoisted_params_copy;
                int local_name_idx;
@@ -416,7 +412,6 @@ namespace Mono.CSharp {
                          iterator.OriginalMethod as MemberBase, iterator.GenericMethod, "Iterator")
                {
                        this.Iterator = iterator;
-                       HasHoistedVariables = true;
                }
 
                public Field PC {
@@ -434,10 +429,7 @@ namespace Mono.CSharp {
                protected override TypeExpr [] ResolveBaseTypes (out TypeExpr base_class)
                {
                        iterator_type_expr = new TypeExpression (MutateType (Iterator.OriginalIteratorType), Location);
-
-#if GMCS_SOURCE
                        generic_args = new TypeArguments (iterator_type_expr);
-#endif
 
                        ArrayList list = new ArrayList ();
                        if (Iterator.IsEnumerable) {
@@ -445,12 +437,12 @@ namespace Mono.CSharp {
                                        TypeManager.ienumerable_type, Location);
                                list.Add (enumerable_type);
 
-#if GMCS_SOURCE
-                               generic_enumerable_type = new GenericTypeExpr (
-                                       TypeManager.generic_ienumerable_type,
-                                       generic_args, Location);
-                               list.Add (generic_enumerable_type);
-#endif
+                               if (TypeManager.generic_ienumerable_type != null) {
+                                       generic_enumerable_type = new GenericTypeExpr (
+                                               TypeManager.generic_ienumerable_type,
+                                               generic_args, Location);
+                                       list.Add (generic_enumerable_type);
+                               }
                        }
 
                        enumerator_type = new TypeExpression (
@@ -459,12 +451,12 @@ namespace Mono.CSharp {
 
                        list.Add (new TypeExpression (TypeManager.idisposable_type, Location));
 
-#if GMCS_SOURCE
-                       generic_enumerator_type = new GenericTypeExpr (
-                               TypeManager.generic_ienumerator_type,
-                               generic_args, Location);
-                       list.Add (generic_enumerator_type);
-#endif
+                       if (TypeManager.generic_ienumerator_type != null) {
+                               generic_enumerator_type = new GenericTypeExpr (
+                                       TypeManager.generic_ienumerator_type,
+                                       generic_args, Location);
+                               list.Add (generic_enumerator_type);
+                       }
 
                        type_bases = list;
 
@@ -495,35 +487,38 @@ namespace Mono.CSharp {
                                }
                        }
 
-#if GMCS_SOURCE
-                       Define_Current (true);
-#endif
+                       if (generic_enumerator_type != null)
+                               Define_Current (true);
+
                        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
+                               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));
+                               }
                        }
                }
 
@@ -535,20 +530,21 @@ namespace Mono.CSharp {
 
                void Define_Current (bool is_generic)
                {
-                       MemberName left;
                        TypeExpr type;
 
+                       MemberName name = new MemberName (QualifiedAliasMember.GlobalAlias, "System", null, Location);
+                       name = new MemberName (name, "Collections", Location);
+
                        if (is_generic) {
-                               left = new MemberName (
-                                       "System.Collections.Generic.IEnumerator",
-                                       generic_args, Location);
+                               name = new MemberName (name, "Generic", Location);
+                               name = new MemberName (name, "IEnumerator", generic_args, Location);
                                type = iterator_type_expr;
                        } else {
-                               left = new MemberName ("System.Collections.IEnumerator", Location);
+                               name = new MemberName (name, "IEnumerator");
                                type = TypeManager.system_object_expr;
                        }
 
-                       MemberName name = new MemberName (left, "Current", Location);
+                       name = new MemberName (name, "Current", Location);
 
                        ToplevelBlock get_block = new ToplevelBlock (Location);
                        get_block.AddStatement (new Return (new DynamicFieldExpr (CurrentField, Location), Location));
@@ -566,13 +562,16 @@ namespace Mono.CSharp {
                                this, null, TypeManager.system_void_expr,
                                Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
                                new MemberName ("Reset", Location),
-                               Parameters.EmptyReadOnlyParameters, null);
+                               ParametersCompiled.EmptyReadOnlyParameters, null);
                        AddMethod (reset);
 
                        reset.Block = new ToplevelBlock (Location);
 
-                       TypeExpr ex_type = new TypeLookupExpression ("System.NotSupportedException");
-                       reset.Block.AddStatement (new Throw (new New (ex_type, null, Location), Location));
+                       Type ex_type = TypeManager.CoreLookupType ("System", "NotSupportedException", Kind.Class, true);
+                       if (ex_type == null)
+                               return;
+
+                       reset.Block.AddStatement (new Throw (new New (new TypeExpression (ex_type, Location), null, Location), Location));
                }
        }
 
@@ -618,11 +617,6 @@ namespace Mono.CSharp {
                        Start = 0
                }
 
-               public override void AddStoreyReference (AnonymousMethodStorey storey)
-               {
-                       // do nothing
-               }
-
                public void EmitYieldBreak (ILGenerator ig, bool unwind_protect)
                {
                        ig.Emit (unwind_protect ? OpCodes.Leave : OpCodes.Br, move_next_error);
@@ -820,7 +814,7 @@ namespace Mono.CSharp {
                //
                private Iterator (IMethodData method, TypeContainer host, Type iterator_type, bool is_enumerable)
                        : base (
-                               new ToplevelBlock (method.Block, Parameters.EmptyReadOnlyParameters, method.Block.StartLocation),
+                               new ToplevelBlock (method.Block, ParametersCompiled.EmptyReadOnlyParameters, method.Block.StartLocation),
                                TypeManager.bool_type,
                                method.Location)
                {
@@ -843,7 +837,7 @@ namespace Mono.CSharp {
                                this, Storey, null, TypeManager.system_boolean_expr,
                                Modifiers.PUBLIC, OriginalMethod.GetSignatureForError (),
                                new MemberName ("MoveNext", Location),
-                               Parameters.EmptyReadOnlyParameters);
+                               ParametersCompiled.EmptyReadOnlyParameters);
 
                        if (!Compatible (ec))
                                return null;
@@ -902,7 +896,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       Parameters parameters = method.ParameterInfo;
+                       ParametersCompiled parameters = method.ParameterInfo;
                        for (int i = 0; i < parameters.Count; i++) {
                                Parameter p = parameters [i];
                                Parameter.Modifier mod = p.ModFlags;
@@ -912,7 +906,7 @@ namespace Mono.CSharp {
                                        return;
                                }
 
-                               if ((mod & Parameter.Modifier.ARGLIST) != 0) {
+                               if (p is ArglistParameter) {
                                        Report.Error (1636, method.Location,
                                                "__arglist is not allowed in parameter list of iterators");
                                        return;
@@ -960,13 +954,13 @@ namespace Mono.CSharp {
 
                        Type gt = TypeManager.DropGenericTypeArguments (ret);
                        if (gt == TypeManager.generic_ienumerable_type) {
-                               original_iterator_type = args [0];
+                               original_iterator_type = TypeManager.TypeToCoreType (args [0]);
                                is_enumerable = true;
                                return true;
                        }
                        
                        if (gt == TypeManager.generic_ienumerator_type) {
-                               original_iterator_type = args [0];
+                               original_iterator_type = TypeManager.TypeToCoreType (args [0]);
                                is_enumerable = false;
                                return true;
                        }