Delay initialization of missing methods needed by symbol writer
[mono.git] / mcs / mcs / method.cs
index 654677138bce487fa078492a512d09186a15891e..683004a1347f004b091883c8fe6aa2e927f97343 100644 (file)
@@ -15,8 +15,6 @@ using System;
 using System.Collections.Generic;
 using System.Reflection;
 using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using System.Security;
 using System.Security.Permissions;
 using System.Text;
@@ -461,8 +459,8 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (a.IsInternalMethodImplAttribute) {
-                               is_external_implementation = true;
+                       if (a.Type == pa.MethodImpl) {
+                               is_external_implementation = a.IsInternalCall ();
                        }
 
                        if (a.Type == pa.DllImport) {
@@ -580,16 +578,16 @@ namespace Mono.CSharp {
                public override void Emit ()
                {
                        if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
-                               Compiler.PredefinedAttributes.CompilerGenerated.EmitAttribute (MethodBuilder);
+                               Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (MethodBuilder);
                        if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
-                               Compiler.PredefinedAttributes.DebuggerHidden.EmitAttribute (MethodBuilder);
+                               Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (MethodBuilder);
 
                        if (ReturnType == InternalType.Dynamic) {
                                return_attributes = new ReturnParameter (this, MethodBuilder, Location);
-                               Compiler.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder);
+                               Module.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder);
                        } else if (ReturnType.HasDynamicElement) {
                                return_attributes = new ReturnParameter (this, MethodBuilder, Location);
-                               Compiler.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder, ReturnType);
+                               Module.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder, ReturnType, Location);
                        }
 
                        if (OptAttributes != null)
@@ -667,7 +665,7 @@ namespace Mono.CSharp {
                                if (OptAttributes == null)
                                        return null;
 
-                               Attribute[] attrs = OptAttributes.SearchMulti (Compiler.PredefinedAttributes.Conditional);
+                               Attribute[] attrs = OptAttributes.SearchMulti (Module.PredefinedAttributes.Conditional);
                                if (attrs == null)
                                        return null;
 
@@ -827,7 +825,7 @@ namespace Mono.CSharp {
                {
                        Report.Error (17, b.Location,
                                "Program `{0}' has more than one entry point defined: `{1}'",
-                               CodeGen.FileName, b.GetSignatureForError ());
+                               b.Module.Builder.ScopeName, b.GetSignatureForError ());
                }
 
                bool IsEntryPoint ()
@@ -1050,7 +1048,7 @@ namespace Mono.CSharp {
                                                Report.Error (1109, Location, "`{0}': Extension methods cannot be defined in a nested class",
                                                        GetSignatureForError ());
 
-                                       PredefinedAttribute pa = Compiler.PredefinedAttributes.Extension;
+                                       PredefinedAttribute pa = Module.PredefinedAttributes.Extension;
                                        if (!pa.IsDefined) {
                                                Report.Error (1110, Location,
                                                        "`{0}': Extension methods cannot be declared without a reference to System.Core.dll assembly. Add the assembly reference or remove `this' modifer from the first parameter",
@@ -1060,7 +1058,7 @@ namespace Mono.CSharp {
                                        ModFlags |= Modifiers.METHOD_EXTENSION;
                                        Parent.PartialContainer.ModFlags |= Modifiers.METHOD_EXTENSION;
                                        Spec.DeclaringType.SetExtensionMethodContainer ();
-                                       CodeGen.Assembly.HasExtensionMethods = true;
+                                       Parent.Module.HasExtensionMethod = true;
                                } else {
                                        Report.Error (1106, Location, "`{0}': Extension methods must be defined in a non-generic static class",
                                                GetSignatureForError ());
@@ -1076,16 +1074,16 @@ namespace Mono.CSharp {
                                RootContext.MainClass == Parent.TypeBuilder.FullName)){
                                if (IsEntryPoint ()) {
 
-                                       if (RootContext.EntryPoint == null) {
+                                       if (Parent.DeclaringAssembly.EntryPoint == null) {
                                                if (Parent.IsGeneric || MemberName.IsGeneric) {
                                                        Report.Warning (402, 4, Location, "`{0}': an entry point cannot be generic or in a generic type",
                                                                GetSignatureForError ());
                                                } else {
                                                        SetIsUsed ();
-                                                       RootContext.EntryPoint = this;
+                                                       Parent.DeclaringAssembly.EntryPoint = this;
                                                }
                                        } else {
-                                               Error_DuplicateEntryPoint (RootContext.EntryPoint);
+                                               Error_DuplicateEntryPoint (Parent.DeclaringAssembly.EntryPoint);
                                                Error_DuplicateEntryPoint (this);
                                        }
                                } else {
@@ -1140,7 +1138,7 @@ namespace Mono.CSharp {
                                base.Emit ();
                                
                                if ((ModFlags & Modifiers.METHOD_EXTENSION) != 0)
-                                       Compiler.PredefinedAttributes.Extension.EmitAttribute (MethodBuilder);
+                                       Module.PredefinedAttributes.Extension.EmitAttribute (MethodBuilder);
                        } catch {
                                Console.WriteLine ("Internal compiler error at {0}: exception caught while emitting {1}",
                                                   Location, MethodBuilder);
@@ -1382,8 +1380,8 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (a.IsInternalMethodImplAttribute) {
-                               is_external_implementation = true;
+                       if (a.Type == pa.MethodImpl) {
+                               is_external_implementation = a.IsInternalCall ();
                        }
 
                        ConstructorBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
@@ -1474,7 +1472,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
-                               Compiler.PredefinedAttributes.DebuggerHidden.EmitAttribute (ConstructorBuilder);
+                               Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (ConstructorBuilder);
 
                        if (OptAttributes != null)
                                OptAttributes.Emit ();
@@ -2119,16 +2117,16 @@ namespace Mono.CSharp {
                        method_data.Emit (parent);
 
                        if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
-                               Compiler.PredefinedAttributes.CompilerGenerated.EmitAttribute (method_data.MethodBuilder);
+                               Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (method_data.MethodBuilder);
                        if (((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0))
-                               Compiler.PredefinedAttributes.DebuggerHidden.EmitAttribute (method_data.MethodBuilder);
+                               Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (method_data.MethodBuilder);
 
                        if (ReturnType == InternalType.Dynamic) {
                                return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location);
-                               Compiler.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder);
+                               Module.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder);
                        } else if (ReturnType.HasDynamicElement) {
                                return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location);
-                               Compiler.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder, ReturnType);
+                               Module.PredefinedAttributes.Dynamic.EmitAttribute (return_attributes.Builder, ReturnType, Location);
                        }
 
                        if (OptAttributes != null)