Report less cascading errors
[mono.git] / mcs / mcs / field.cs
index 29d44a446d4e26c5bb085e5eb6ed4bd35c47bbb7..f5603b4fae4ebecd7daa335c60ed08f4bf131d4f 100644 (file)
@@ -42,6 +42,11 @@ namespace Mono.CSharp
                public Expression Initializer { get; private set; }
 
                #endregion
+
+               public virtual FullNamedExpression GetFieldTypeExpression (FieldBase field)
+               {
+                       return new TypeExpression (field.MemberType, Name.Location); 
+               }
        }
 
        //
@@ -233,12 +238,14 @@ namespace Mono.CSharp
                {
                        if (member_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
                                Module.PredefinedAttributes.Dynamic.EmitAttribute (FieldBuilder);
-                       } else if (!(Parent is CompilerGeneratedClass) && member_type.HasDynamicElement) {
+                       } else if (!Parent.IsCompilerGenerated && member_type.HasDynamicElement) {
                                Module.PredefinedAttributes.Dynamic.EmitAttribute (FieldBuilder, member_type, Location);
                        }
 
                        if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
                                Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (FieldBuilder);
+                       if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
+                               Module.PredefinedAttributes.DebuggerBrowsable.EmitAttribute (FieldBuilder, System.Diagnostics.DebuggerBrowsableState.Never);
 
                        if (OptAttributes != null) {
                                OptAttributes.Emit ();
@@ -351,9 +358,9 @@ namespace Mono.CSharp
                        return fs;
                }
 
-               public override List<TypeSpec> ResolveMissingDependencies ()
+               public override List<MissingTypeSpecReference> ResolveMissingDependencies (MemberSpec caller)
                {
-                       return memberType.ResolveMissingDependencies ();
+                       return memberType.ResolveMissingDependencies (this);
                }
        }
 
@@ -406,9 +413,8 @@ namespace Mono.CSharp
                                        "`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double",
                                        GetSignatureForError ());
                        } else if (declarators != null) {
-                               var t = new TypeExpression (MemberType, TypeExpression.Location);
                                foreach (var d in declarators) {
-                                       var f = new FixedField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
+                                       var f = new FixedField (Parent, d.GetFieldTypeExpression (this), ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
                                        f.initializer = d.Initializer;
                                        ((ConstInitializer) f.initializer).Name = d.Name.Value;
                                        f.Define ();
@@ -427,7 +433,7 @@ namespace Mono.CSharp
                        FieldBuilder = Parent.TypeBuilder.DefineField (Name, fixed_buffer_type, ModifiersExtensions.FieldAttr (ModFlags));
 
                        var element_spec = new FieldSpec (null, this, MemberType, ffield, ModFlags);
-                       spec = new FixedFieldSpec (Parent.Definition, this, FieldBuilder, element_spec, ModFlags);
+                       spec = new FixedFieldSpec (Module, Parent.Definition, this, FieldBuilder, element_spec, ModFlags);
 
                        Parent.MemberCache.AddMember (spec);
                        return true;
@@ -480,7 +486,7 @@ namespace Mono.CSharp
 
                        if (buffer_size > int.MaxValue / type_size) {
                                Report.Error (1664, Location, "Fixed size buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit",
-                                       GetSignatureForError (), buffer_size.ToString (), TypeManager.CSharpName (MemberType));
+                                       GetSignatureForError (), buffer_size.ToString (), MemberType.GetSignatureForError ());
                                return;
                        }
 
@@ -532,8 +538,8 @@ namespace Mono.CSharp
        {
                readonly FieldSpec element;
 
-               public FixedFieldSpec (TypeSpec declaringType, IMemberDefinition definition, FieldInfo info, FieldSpec element, Modifiers modifiers)
-                       : base (declaringType, definition, element.MemberType, info, modifiers)
+               public FixedFieldSpec (ModuleContainer module, TypeSpec declaringType, IMemberDefinition definition, FieldInfo info, FieldSpec element, Modifiers modifiers)
+                       : base (declaringType, definition, PointerContainer.MakeType (module, element.MemberType), info, modifiers)
                {
                        this.element = element;
 
@@ -546,10 +552,10 @@ namespace Mono.CSharp
                                return element;
                        }
                }
-
+               
                public TypeSpec ElementType {
                        get {
-                               return MemberType;
+                               return element.MemberType;
                        }
                }
        }
@@ -634,14 +640,12 @@ namespace Mono.CSharp
                        }
 
                        if (initializer != null) {
-                               Parent.RegisterFieldForInitialization (this,
-                                       new FieldInitializer (spec, initializer, this));
+                               Parent.RegisterFieldForInitialization (this, new FieldInitializer (this, initializer, TypeExpression.Location));
                        }
 
                        if (declarators != null) {
-                               var t = new TypeExpression (MemberType, TypeExpression.Location);
                                foreach (var d in declarators) {
-                                       var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
+                                       var f = new Field (Parent, d.GetFieldTypeExpression (this), ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
                                        if (d.Initializer != null)
                                                f.initializer = d.Initializer;
 
@@ -663,7 +667,7 @@ namespace Mono.CSharp
                        if ((ModFlags & Modifiers.VOLATILE) != 0) {
                                if (!CanBeVolatile ()) {
                                        Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'",
-                                               GetSignatureForError (), TypeManager.CSharpName (MemberType));
+                                               GetSignatureForError (), MemberType.GetSignatureForError ());
                                }
 
                                if ((ModFlags & Modifiers.READONLY) != 0) {