2007-12-06 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mcs / iterators.cs
index d331162d47fc68841480e051a57686a8507c078f..678ca672fbbe781db1f3c822e1cba454006801b9 100644 (file)
@@ -47,26 +47,11 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       Type ignored_type;
-                       bool ignored_is_enumerable;
-
-                       if (ec.IsConstructor){
-                               Report.Error (1624, loc, "Can not use iterators inside constructors");
-                               return false;
-                       }
-                       
-                       if (!Iterator.CheckType (ec.ReturnType, out ignored_type, out ignored_is_enumerable)){
-                               Report.Error (1624, loc,
-                                             "Can not use iterator block because `{0}' is not an iterator interface type",
-                                             TypeManager.CSharpName (ec.ReturnType));
-                               return false;
-                       }
-                       
                        //
                        // We can't use `ec.InUnsafe' here because it's allowed to have an iterator
                        // inside an unsafe class.  See test-martin-29.cs for an example.
                        //
-                       if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.IsIterator == false) {
+                       if (!ec.CurrentAnonymousMethod.IsIterator) {
                                Report.Error (1621, loc,
                                              "The yield statement cannot be used inside " +
                                              "anonymous method blocks");
@@ -822,6 +807,10 @@ namespace Mono.CSharp {
                        point.Define (ig);
                }
 
+               public override string ContainerType {
+                       get { return "iterator"; }
+               }
+
                public override bool IsIterator {
                        get { return true; }
                }
@@ -839,7 +828,7 @@ namespace Mono.CSharp {
                //
                private Iterator (IMethodData m_container, DeclSpace host, GenericMethod generic,
                                 int modifiers, Type iterator_type, bool is_enumerable)
-                       : base (null, host, generic, m_container.ParameterInfo,
+                       : base (host, generic, m_container.ParameterInfo,
                                new ToplevelBlock (m_container.ParameterInfo, m_container.Location),
                                m_container.Block, TypeManager.bool_type, modifiers,
                                m_container.Location)
@@ -883,7 +872,7 @@ namespace Mono.CSharp {
                        return OriginalMethod.GetSignatureForError ();
                }
 
-               public override bool Resolve (EmitContext ec)
+               public override bool Define (EmitContext ec)
                {
                        Report.Debug (64, "RESOLVE ITERATOR", this, Container, Block);
 
@@ -916,7 +905,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (!base.Resolve (ec))
+                       if (!base.Define (ec))
                                return false;
 
                        Report.Debug (64, "RESOLVE ITERATOR #1", this, method, method.Parent,
@@ -949,6 +938,11 @@ namespace Mono.CSharp {
                                Parameters.EmptyReadOnlyParameters);
                }
 
+               public override Expression Resolve (EmitContext ec)
+               {
+                       throw new NotSupportedException ();
+               }
+
                protected class MoveNextStatement : Statement {
                        Iterator iterator;
 
@@ -1027,7 +1021,7 @@ namespace Mono.CSharp {
                                             iterator_type, is_enumerable);
                }
 
-               internal static bool CheckType (Type ret, out Type original_iterator_type, out bool is_enumerable)
+               static bool CheckType (Type ret, out Type original_iterator_type, out bool is_enumerable)
                {
                        original_iterator_type = null;
                        is_enumerable = false;