This was only for debugging.
[mono.git] / mcs / gmcs / codegen.cs
index 6c5a3816181121762a9edb64e17a525ccbd04a5e..71f4a9dafdb20f79a84c694bf9496fee576f1104 100755 (executable)
@@ -96,6 +96,22 @@ namespace Mono.CSharp {
                {
                        FileName = output;
                        AssemblyName an = Assembly.GetAssemblyName (name, output);
+
+                       if (an.KeyPair != null) {
+                               // If we are going to strong name our assembly make
+                               // sure all its refs are strong named
+                               foreach (Assembly a in TypeManager.GetAssemblies ()) {
+                                       AssemblyName ref_name = a.GetName ();
+                                       byte [] b = ref_name.GetPublicKeyToken ();
+                                       if (b == null || b.Length == 0) {
+                                               Report.Warning (1577, "Assembly generation failed " +
+                                                               "-- Referenced assembly '" +
+                                                               ref_name.Name +
+                                                               "' does not have a strong name.");
+                                               //Environment.Exit (1);
+                                       }
+                               }
+                       }
                        
                        current_domain = AppDomain.CurrentDomain;
 
@@ -765,19 +781,21 @@ namespace Mono.CSharp {
 
 
        public abstract class CommonAssemblyModulClass: Attributable {
+               static string[] attribute_targets = new string [] { "assembly", "module" };
 
                protected CommonAssemblyModulClass ():
                        base (null)
                {
                }
 
-               public void AddAttribute (AttributeSection attr)
+               public void AddAttributes (ArrayList attrs)
                {
                        if (OptAttributes == null) {
-                               OptAttributes = new Attributes (attr);
+                               OptAttributes = new Attributes (attrs);
                                return;
                        }
-                       OptAttributes.AddAttributeSection (attr);
+                       OptAttributes.AddAttributes (attrs);
+                       OptAttributes.CheckTargets (ValidAttributeTargets);
                }
 
                public virtual void Emit (TypeContainer tc) 
@@ -801,6 +819,12 @@ namespace Mono.CSharp {
                        }
                        return a;
                }
+
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
        }
 
        public class AssemblyClass: CommonAssemblyModulClass {
@@ -840,17 +864,19 @@ namespace Mono.CSharp {
                        is_cls_compliant = a.GetClsCompliantAttributeValue (null);
                }
 
-               //TODO: this code is buggy because compare Attribute name without resolve is wrong
                public AssemblyName GetAssemblyName (string name, string output) 
                {
                        if (OptAttributes != null) {
-                               foreach (AttributeSection asect in OptAttributes.AttributeSections) {
-                                       if (asect.Target != "assembly")
+                               foreach (Attribute a in OptAttributes.Attrs) {
+                                       if (a.Target != "assembly")
                                                continue;
-                                       // strongname attributes don't support AllowMultiple
-                                       Attribute a = (Attribute) asect.Attributes [0];
+                                       // TODO: This code is buggy: comparing Attribute name without resolving it is wrong.
+                                       //       However, this is invoked by CodeGen.Init, at which time none of the namespaces
+                                       //       are loaded yet.
                                        switch (a.Name) {
                                                case "AssemblyKeyFile":
+                                               case "AssemblyKeyFileAttribute":
+                                               case "System.Reflection.AssemblyKeyFileAttribute":
                                                        if (RootContext.StrongNameKeyFile != null) {
                                                                Report.Warning (1616, "Compiler option -keyfile overrides " +
                                                                        "AssemblyKeyFileAttribute");
@@ -862,6 +888,8 @@ namespace Mono.CSharp {
                                                        }
                                                        break;
                                                case "AssemblyKeyName":
+                                               case "AssemblyKeyNameAttribute":
+                                               case "System.Reflection.AssemblyKeyNameAttribute":
                                                        if (RootContext.StrongNameKeyContainer != null) {
                                                                Report.Warning (1616, "Compiler option -keycontainer overrides " +
                                                                        "AssemblyKeyNameAttribute");
@@ -873,6 +901,8 @@ namespace Mono.CSharp {
                                                        }
                                                        break;
                                                case "AssemblyDelaySign":
+                                               case "AssemblyDelaySignAttribute":
+                                               case "System.Reflection.AssemblyDelaySignAttribute":
                                                        RootContext.StrongNameDelaySign = a.GetBoolean ();
                                                        break;
                                        }
@@ -973,7 +1003,6 @@ namespace Mono.CSharp {
        public class ModuleClass: CommonAssemblyModulClass {
                // TODO: make it private and move all builder based methods here
                public ModuleBuilder Builder;
-            
                bool m_module_is_unsafe;
 
                public ModuleClass (bool is_unsafe)