Nothing to see here
[mono.git] / mcs / mcs / class.cs
index 2b651d2b29ed5b2985fbdc195a545831ab533e3a..190d85ad164e2f49e5af802165282816478ebda6 100644 (file)
@@ -443,10 +443,6 @@ namespace Mono.CSharp {
 
                public void AddConstructor (Constructor c)
                {
-                       if (c.Name != MemberName.Name) {
-                               Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
-                       }
-
                        bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
                        if (!AddToContainer (c, is_static ?
                                ConstructorBuilder.ConstructorName : ConstructorBuilder.TypeConstructorName))
@@ -693,19 +689,12 @@ namespace Mono.CSharp {
 
                public void ResolveFieldInitializers (EmitContext ec)
                {
-                       // Field initializers are tricky for partial classes. They have to
-                       // share same costructor (block) but they have they own resolve scope.
-                       DeclSpace orig = ec.DeclContainer;
-
                        if (partial_parts != null) {
                                foreach (TypeContainer part in partial_parts) {
-                                       ec.DeclContainer = part;
                                        part.DoResolveFieldInitializers (ec);
                                }
                        }
-                       ec.DeclContainer = PartialContainer;
                        DoResolveFieldInitializers (ec);
-                       ec.DeclContainer = orig; 
                }
 
                void DoResolveFieldInitializers (EmitContext ec)
@@ -715,33 +704,31 @@ namespace Mono.CSharp {
                                        return;
 
                                bool has_complex_initializer = !RootContext.Optimize;
-                               using (ec.Set (EmitContext.Flags.InFieldInitializer)) {
-                                       int i;
-                                       ExpressionStatement[] init = new ExpressionStatement [initialized_static_fields.Count];
-                                       for (i = 0; i < initialized_static_fields.Count; ++i) {
-                                               FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
-                                               ExpressionStatement s = fi.ResolveStatement (ec);
-                                               if (s == null) {
-                                                       s = EmptyExpressionStatement.Instance;
-                                               } else if (fi.IsComplexInitializer) {
-                                                       has_complex_initializer |= true;
-                                               }
-
-                                               init [i] = s;
+                               int i;
+                               ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
+                               for (i = 0; i < initialized_static_fields.Count; ++i) {
+                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
+                                       ExpressionStatement s = fi.ResolveStatement (ec);
+                                       if (s == null) {
+                                               s = EmptyExpressionStatement.Instance;
+                                       } else if (fi.IsComplexInitializer) {
+                                               has_complex_initializer |= true;
                                        }
 
-                                       for (i = 0; i < initialized_static_fields.Count; ++i) {
-                                               FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
-                                               //
-                                               // Need special check to not optimize code like this
-                                               // static int a = b = 5;
-                                               // static int b = 0;
-                                               //
-                                               if (!has_complex_initializer && fi.IsDefaultInitializer)
-                                                       continue;
+                                       init [i] = s;
+                               }
 
-                                               ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
-                                       }
+                               for (i = 0; i < initialized_static_fields.Count; ++i) {
+                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
+                                       //
+                                       // Need special check to not optimize code like this
+                                       // static int a = b = 5;
+                                       // static int b = 0;
+                                       //
+                                       if (!has_complex_initializer && fi.IsDefaultInitializer)
+                                               continue;
+
+                                       ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
                                }
 
                                return;
@@ -750,21 +737,19 @@ namespace Mono.CSharp {
                        if (initialized_fields == null)
                                return;
 
-                       using (ec.Set (EmitContext.Flags.InFieldInitializer)) {
-                               for (int i = 0; i < initialized_fields.Count; ++i) {
-                                       FieldInitializer fi = (FieldInitializer) initialized_fields [i];
-                                       ExpressionStatement s = fi.ResolveStatement (ec);
-                                       if (s == null)
-                                               continue;
+                       for (int i = 0; i < initialized_fields.Count; ++i) {
+                               FieldInitializer fi = (FieldInitializer) initialized_fields [i];
+                               ExpressionStatement s = fi.ResolveStatement (ec);
+                               if (s == null)
+                                       continue;
 
-                                       //
-                                       // Field is re-initialized to its default value => removed
-                                       //
-                                       if (fi.IsDefaultInitializer && RootContext.Optimize)
-                                               continue;
+                               //
+                               // Field is re-initialized to its default value => removed
+                               //
+                               if (fi.IsDefaultInitializer && RootContext.Optimize)
+                                       continue;
 
-                                       ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
-                               }
+                               ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
                        }
                }
 
@@ -1251,23 +1236,13 @@ namespace Mono.CSharp {
                        }
 
                        current_type = new ConstructedType (TypeBuilder, TypeParameters, Location);
-
-                       foreach (TypeParameter type_param in TypeParameters)
-                               if (!type_param.CheckDependencies ()) {
-                                       error = true;
-                                       return false;
-                               }
-
-                       if (current_type != null) {
-                               current_type = current_type.ResolveAsTypeTerminal (this, false);
-                               if (current_type == null) {
-                                       error = true;
-                                       return false;
-                               }
-
-                               CurrentType = current_type.Type;
+                       current_type = current_type.ResolveAsTypeTerminal (this, false);
+                       if (current_type == null) {
+                               error = true;
+                               return false;
                        }
 
+                       CurrentType = current_type.Type;
                        return true;
                }
 
@@ -1332,22 +1307,14 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public static void Error_KeywordNotAllowed (Location loc)
-               {
-                       Report.Error (1530, loc, "Keyword `new' is not allowed on namespace elements");
-               }
-
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
-               public override bool DefineMembers ()
+               public override bool Define ()
                {
                        if (members_defined)
                                return members_defined_ok;
 
-                       if (!base.DefineMembers ())
-                               return false;
-
                        members_defined_ok = DoDefineMembers ();
                        members_defined = true;
 
@@ -1531,12 +1498,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override bool Define ()
-               {
-                       CheckProtectedModifier ();
-                       return true;
-               }
-
                public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
                {
                        return BaseCache == null ? null : BaseCache.FindMemberWithSameName (name, ignore_methods, null);
@@ -1566,7 +1527,7 @@ namespace Mono.CSharp {
                {
                        ArrayList members = new ArrayList ();
 
-                       DefineMembers ();
+                       Define ();
 
                        if (methods != null) {
                                int len = methods.Count;
@@ -2671,7 +2632,7 @@ namespace Mono.CSharp {
                        }
 
                        Constructor c = new Constructor (this, MemberName.Name, mods,
-                               Parameters.EmptyReadOnlyParameters,
+                               null, Parameters.EmptyReadOnlyParameters,
                                new GeneratedBaseInitializer (Location),
                                Location);
                        
@@ -2681,17 +2642,23 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       if (default_static_constructor == null && PartialContainer.HasStaticFieldInitializer)
-                               DefineDefaultConstructor (true);
+                       CheckProtectedModifier ();
+
+                       base.Define ();
 
                        if (default_static_constructor != null)
                                default_static_constructor.Define ();
 
-                       return base.Define ();
+                       return true;
                }
 
                public override void Emit ()
                {
+                       if (default_static_constructor == null && PartialContainer.HasStaticFieldInitializer) {
+                               DefineDefaultConstructor (true);
+                               default_static_constructor.Define ();
+                       }
+
                        base.Emit ();
 
                        if (declarative_security != null) {
@@ -2810,11 +2777,6 @@ namespace Mono.CSharp {
                                        continue;
                                }
 
-                               if ((m.ModFlags & Modifiers.PROTECTED) != 0) {
-                                       m.CheckProtectedModifier ();
-                                       continue;
-                               }
-
                                if (m is Indexer) {
                                        Report.Error (720, m.Location, "`{0}': cannot declare indexers in a static class", m.GetSignatureForError ());
                                        continue;
@@ -2840,19 +2802,17 @@ namespace Mono.CSharp {
                        base.DefineContainerMembers (list);
                }
 
-               public override TypeBuilder DefineType ()
+               public override bool Define ()
                {
                        if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
                                Report.Error (418, Location, "`{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
-                               return null;
                        }
 
                        if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
                                Report.Error (441, Location, "`{0}': a class cannot be both static and sealed", GetSignatureForError ());
-                               return null;
                        }
 
-                       return base.DefineType ();
+                       return base.Define ();
                }
 
                protected override bool DoDefineMembers ()
@@ -3134,13 +3094,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.AutoLayout |
-                       TypeAttributes.Abstract |
-                       TypeAttributes.Interface;
-
                protected override TypeAttributes TypeAttr {
                        get {
+                               const TypeAttributes DefaultTypeAttributes =
+                                       TypeAttributes.AutoLayout |
+                                       TypeAttributes.Abstract |
+                                       TypeAttributes.Interface;
+
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
@@ -3557,14 +3517,12 @@ namespace Mono.CSharp {
                                Report.SymbolRelatedToPreviousError (t);
                                if (this is Indexer)
                                        Report.Error (55, Location,
-                                               "Inconsistent accessibility: parameter type `" +
-                                               TypeManager.CSharpName (t) + "' is less " +
-                                               "accessible than indexer `" + GetSignatureForError () + "'");
+                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'",
+                                                     TypeManager.CSharpName (t), GetSignatureForError ());
                                else if (this is Operator)
                                        Report.Error (57, Location,
-                                               "Inconsistent accessibility: parameter type `" +
-                                               TypeManager.CSharpName (t) + "' is less " +
-                                               "accessible than operator `" + GetSignatureForError () + "'");
+                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'",
+                                                     TypeManager.CSharpName (t), GetSignatureForError ());
                                else
                                        Report.Error (51, Location,
                                                "Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'",
@@ -3836,8 +3794,14 @@ namespace Mono.CSharp {
                        if (!CheckBase ())
                                return false;
 
-                       if (block != null && block.IsIterator && !(Parent is IteratorStorey))
+                       if (block != null && block.IsIterator && !(Parent is IteratorStorey)) {
+                               //
+                               // Current method is turned into automatically generated
+                               // wrapper which creates an instance of iterator
+                               //
                                Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+                               ModFlags |= Modifiers.DEBUGGER_HIDDEN;
+                       }
 
                        if (IsPartialDefinition) {
                                caching_flags &= ~Flags.Excluded_Undetected;
@@ -4228,7 +4192,7 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       if (RootContext.StdLib && (ReturnType == TypeManager.arg_iterator_type || ReturnType == TypeManager.typed_reference_type)) {
+                       if (RootContext.StdLib && TypeManager.IsSpecialType (ReturnType)) {
                                Error1599 (Location, ReturnType);
                                return false;
                        }
@@ -4553,10 +4517,10 @@ namespace Mono.CSharp {
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (DeclSpace parent, string name, int mod, Parameters args,
+               public Constructor (DeclSpace parent, string name, int mod, Attributes attrs, Parameters args,
                                    ConstructorInitializer init, Location loc)
                        : base (parent, null, null, mod, AllowedModifiers,
-                               new MemberName (name, loc), null, args)
+                               new MemberName (name, loc), attrs, args)
                {
                        Initializer = init;
                }
@@ -5367,7 +5331,7 @@ namespace Mono.CSharp {
 
                protected bool IsTypePermitted ()
                {
-                       if (MemberType == TypeManager.arg_iterator_type || MemberType == TypeManager.typed_reference_type) {
+                       if (TypeManager.IsSpecialType (MemberType)) {
                                Report.Error (610, Location, "Field or property cannot be of type `{0}'", TypeManager.CSharpName (MemberType));
                                return false;
                        }
@@ -5475,12 +5439,6 @@ namespace Mono.CSharp {
                        if (TypeManager.IsGenericParameter (MemberType))
                                return true;
 
-                       if (MemberType == TypeManager.void_type) {
-                               // TODO: wrong location
-                               Expression.Error_VoidInvalidInTheContext (Location);
-                               return false;
-                       }
-
                        if (MemberType.IsSealed && MemberType.IsAbstract) {
                                Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
                                return false;
@@ -5629,7 +5587,7 @@ namespace Mono.CSharp {
                        Expression size_expr, Attributes attrs, Location loc):
                        base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
                {
-                       if (RootContext.Version == LanguageVersion.ISO_1)
+                       if (RootContext.Version < LanguageVersion.ISO_2)
                                Report.FeatureIsNotAvailable (loc, "fixed size buffers");
 
                        this.size_expr = size_expr;
@@ -5932,7 +5890,7 @@ namespace Mono.CSharp {
 
                        if (initializer != null) {
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
-                                       new FieldInitializer (FieldBuilder, initializer));
+                                       new FieldInitializer (FieldBuilder, initializer, this));
                        } else {
                                if (Parent.PartialContainer.Kind == Kind.Struct)
                                        CheckStructLayout (member_type, (ModFlags & Modifiers.STATIC) != 0);
@@ -7196,7 +7154,7 @@ namespace Mono.CSharp {
                                }
 
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
-                                       new FieldInitializer (FieldBuilder, Initializer));
+                                       new FieldInitializer (FieldBuilder, Initializer, this));
                        }
 
                        return true;
@@ -7805,11 +7763,6 @@ namespace Mono.CSharp {
                        else if (OperatorType == OpType.Implicit)
                                Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Explicit), Parameters);
 
-                       if (MemberType == TypeManager.void_type) {
-                               Report.Error (590, Location, "User-defined operators cannot return void");
-                               return false;
-                       }
-
                        Type declaring_type = MethodData.DeclaringType;
                        Type return_type = MemberType;
                        Type first_arg_type = ParameterTypes [0];
@@ -7993,24 +7946,24 @@ namespace Mono.CSharp {
                public OpType GetMatchingOperator ()
                {
                        switch (OperatorType) {
-                               case OpType.Equality:
-                                       return OpType.Inequality;
-                               case OpType.Inequality:
-                                       return OpType.Equality;
-                               case OpType.True:
-                                       return OpType.False;
-                               case OpType.False:
-                                       return OpType.True;
-                               case OpType.GreaterThan:
-                                       return OpType.LessThan;
-                               case OpType.LessThan:
-                                       return OpType.GreaterThan;
-                               case OpType.GreaterThanOrEqual:
-                                       return OpType.LessThanOrEqual;
-                               case OpType.LessThanOrEqual:
-                                       return OpType.GreaterThanOrEqual;
-                               default:
-                                       return OpType.TOP;
+                       case OpType.Equality:
+                               return OpType.Inequality;
+                       case OpType.Inequality:
+                               return OpType.Equality;
+                       case OpType.True:
+                               return OpType.False;
+                       case OpType.False:
+                               return OpType.True;
+                       case OpType.GreaterThan:
+                               return OpType.LessThan;
+                       case OpType.LessThan:
+                               return OpType.GreaterThan;
+                       case OpType.GreaterThanOrEqual:
+                               return OpType.LessThanOrEqual;
+                       case OpType.LessThanOrEqual:
+                               return OpType.GreaterThanOrEqual;
+                       default:
+                               return OpType.TOP;
                        }
                }