Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / mcs / assembly.cs
index d86430193a8bceb18110dda6a9f87d681e75c404..6c99245480b93f6766af3adb8b86f5beddb78c0c 100644 (file)
@@ -7,7 +7,7 @@
 //
 // Copyright 2001, 2002, 2003 Ximian, Inc.
 // Copyright 2004-2011 Novell, Inc.
-// Copyright 2011 Xamarin Inc
+// Copyright 2011-2013 Xamarin Inc
 //
 
 
@@ -54,6 +54,7 @@ namespace Mono.CSharp
                bool is_cls_compliant;
                bool wrap_non_exception_throws;
                bool wrap_non_exception_throws_custom;
+               bool has_user_debuggable;
 
                protected ModuleContainer module;
                readonly string name;
@@ -74,6 +75,9 @@ namespace Mono.CSharp
                Dictionary<ITypeDefinition, Attribute> emitted_forwarders;
                AssemblyAttributesPlaceholder module_target_attrs;
 
+               // Win32 version info values
+               string vi_product, vi_product_version, vi_company, vi_copyright, vi_trademark;
+
                protected AssemblyDefinition (ModuleContainer module, string name)
                {
                        this.module = module;
@@ -154,6 +158,8 @@ namespace Mono.CSharp
                        }
                }
 
+               public bool IsSatelliteAssembly { get; private set; }
+
                public string Name {
                        get {
                                return name;
@@ -214,6 +220,7 @@ namespace Mono.CSharp
                                        builder_extra.SetCulture (value, a.Location);
                                }
 
+                               IsSatelliteAssembly = true;
                                return;
                        }
 
@@ -285,7 +292,7 @@ namespace Mono.CSharp
                                } else if (emitted_forwarders.ContainsKey (t.MemberDefinition)) {
                                        Report.SymbolRelatedToPreviousError (emitted_forwarders[t.MemberDefinition].Location, null);
                                        Report.Error (739, a.Location, "A duplicate type forward of type `{0}'",
-                                               TypeManager.CSharpName (t));
+                                               t.GetSignatureForError ());
                                        return;
                                }
 
@@ -294,13 +301,13 @@ namespace Mono.CSharp
                                if (t.MemberDefinition.DeclaringAssembly == this) {
                                        Report.SymbolRelatedToPreviousError (t);
                                        Report.Error (729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly",
-                                               TypeManager.CSharpName (t));
+                                               t.GetSignatureForError ());
                                        return;
                                }
 
                                if (t.IsNested) {
                                        Report.Error (730, a.Location, "Cannot forward type `{0}' because it is a nested type",
-                                               TypeManager.CSharpName (t));
+                                               t.GetSignatureForError ());
                                        return;
                                }
 
@@ -344,15 +351,26 @@ namespace Mono.CSharp
                        } else if (a.Type == pa.RuntimeCompatibility) {
                                wrap_non_exception_throws_custom = true;
                        } else if (a.Type == pa.AssemblyFileVersion) {
-                               string value = a.GetString ();
-                               if (string.IsNullOrEmpty (value) || IsValidAssemblyVersion (value, false) == null) {
+                               vi_product_version = a.GetString ();
+                               if (string.IsNullOrEmpty (vi_product_version) || IsValidAssemblyVersion (vi_product_version, false) == null) {
                                        Report.Warning (1607, 1, a.Location, "The version number `{0}' specified for `{1}' is invalid",
-                                               value, a.Name);
+                                               vi_product_version, a.Name);
                                        return;
                                }
+                       } else if (a.Type == pa.AssemblyProduct) {
+                               vi_product = a.GetString ();
+                       } else if (a.Type == pa.AssemblyCompany) {
+                               vi_company = a.GetString ();
+                       } else if (a.Type == pa.AssemblyDescription) {
+                               // TODO: Needs extra api
+                       } else if (a.Type == pa.AssemblyCopyright) {
+                               vi_copyright = a.GetString ();
+                       } else if (a.Type == pa.AssemblyTrademark) {
+                               vi_trademark = a.GetString ();
+                       } else if (a.Type == pa.Debuggable) {
+                               has_user_debuggable = true;
                        }
 
-
                        SetCustomAttribute (ctor, cdata);
                }
 
@@ -367,7 +385,7 @@ namespace Mono.CSharp
                        // no working SRE API
                        foreach (var entry in Importer.Assemblies) {
                                var a = entry as ImportedAssemblyDefinition;
-                               if (a == null)
+                               if (a == null || a.IsMissing)
                                        continue;
 
                                if (public_key != null && !a.HasStrongName) {
@@ -457,26 +475,39 @@ namespace Mono.CSharp
                                }
                        }
 
-                       if (!wrap_non_exception_throws_custom) {
-                               PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility;
-                               if (pa.IsDefined && pa.ResolveBuilder ()) {
-                                       var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get ();
-                                       if (prop != null) {
-                                               AttributeEncoder encoder = new AttributeEncoder ();
-                                               encoder.EncodeNamedPropertyArgument (prop, new BoolLiteral (Compiler.BuiltinTypes, true, Location.Null));
-                                               SetCustomAttribute (pa.Constructor, encoder.ToArray ());
+                       if (!IsSatelliteAssembly) {
+                               if (!has_user_debuggable && Compiler.Settings.GenerateDebugInfo) {
+                                       var pa = module.PredefinedAttributes.Debuggable;
+                                       if (pa.IsDefined) {
+                                               var modes = System.Diagnostics.DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints;
+                                               if (!Compiler.Settings.Optimize)
+                                                       modes |= System.Diagnostics.DebuggableAttribute.DebuggingModes.DisableOptimizations;
+
+                                               pa.EmitAttribute (Builder, modes);
                                        }
                                }
-                       }
 
-                       if (declarative_security != null) {
-#if STATIC
-                               foreach (var entry in declarative_security) {
-                                       Builder.__AddDeclarativeSecurity (entry);
+                               if (!wrap_non_exception_throws_custom) {
+                                       PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility;
+                                       if (pa.IsDefined && pa.ResolveBuilder ()) {
+                                               var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get ();
+                                               if (prop != null) {
+                                                       AttributeEncoder encoder = new AttributeEncoder ();
+                                                       encoder.EncodeNamedPropertyArgument (prop, new BoolLiteral (Compiler.BuiltinTypes, true, Location.Null));
+                                                       SetCustomAttribute (pa.Constructor, encoder.ToArray ());
+                                               }
+                                       }
                                }
+
+                               if (declarative_security != null) {
+#if STATIC
+                                       foreach (var entry in declarative_security) {
+                                               Builder.__AddDeclarativeSecurity (entry);
+                                       }
 #else
-                               throw new NotSupportedException ("Assembly-level security");
+                                       throw new NotSupportedException ("Assembly-level security");
 #endif
+                               }
                        }
 
                        CheckReferencesPublicToken ();
@@ -744,7 +775,7 @@ namespace Mono.CSharp
                        if (Compiler.Settings.Win32ResourceFile != null) {
                                Builder.DefineUnmanagedResource (Compiler.Settings.Win32ResourceFile);
                        } else {
-                               Builder.DefineVersionInfoResource ();
+                               Builder.DefineVersionInfoResource (vi_product, vi_product_version, vi_company, vi_copyright, vi_trademark);
                        }
 
                        if (Compiler.Settings.Win32IconFile != null) {
@@ -902,7 +933,7 @@ namespace Mono.CSharp
                                                return;
                                        }
 
-                                       var mtype = texpr.Type.MemberDefinition as ClassOrStruct;
+                                       var mtype = texpr.MemberDefinition as ClassOrStruct;
                                        if (mtype == null) {
                                                Report.Error (1556, "`{0}' specified for Main method must be a valid class or struct", main_class);
                                                return;
@@ -1093,13 +1124,13 @@ namespace Mono.CSharp
                }
        }
 
-       abstract class AssemblyReferencesLoader<T>
+       abstract class AssemblyReferencesLoader<T> where T : class
        {
                protected readonly CompilerContext compiler;
 
                protected readonly List<string> paths;
 
-               public AssemblyReferencesLoader (CompilerContext compiler)
+               protected AssemblyReferencesLoader (CompilerContext compiler)
                {
                        this.compiler = compiler;
 
@@ -1162,15 +1193,27 @@ namespace Mono.CSharp
                                if (loaded.Contains (key))
                                        continue;
 
-                               // A corlib assembly is the first assembly which contains System.Object
-                               if (corlib_assembly == null && HasObjectType (a)) {
-                                       corlib_assembly = a;
-                                       continue;
-                               }
-
                                loaded.Add (key);
                        }
 
+                       if (corlib_assembly == null) {
+                               //
+                               // Requires second pass because HasObjectType can trigger assembly load event
+                               //
+                               for (int i = 0; i < loaded.Count; ++i) {
+                                       var assembly = loaded [i];
+
+                                       //
+                                       // corlib assembly is the first referenced assembly which contains System.Object
+                                       //
+                                       if (HasObjectType (assembly.Item2)) {
+                                               corlib_assembly = assembly.Item2;
+                                               loaded.RemoveAt (i);
+                                               break;
+                                       }
+                               }
+                       }
+
                        foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) {
                                a = LoadAssemblyFile (entry.Item2, false);
                                if (a == null)