//
// Copyright 2001, 2002, 2003 Ximian, Inc.
// Copyright 2004-2011 Novell, Inc.
-// Copyright 2011 Xamarin Inc
+// Copyright 2011-2013 Xamarin Inc
//
public interface IAssemblyDefinition
{
string FullName { get; }
- bool HasExtensionMethod { get; }
bool IsCLSCompliant { get; }
bool IsMissing { get; }
string Name { get; }
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;
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;
}
}
- public bool HasExtensionMethod {
- get {
- return module.HasExtensionMethod;
- }
- }
-
public bool HasCLSCompliantAttribute {
get {
return cls_attribute != null;
}
}
+ public bool IsSatelliteAssembly { get; private set; }
+
public string Name {
get {
return name;
builder_extra.SetCulture (value, a.Location);
}
+ IsSatelliteAssembly = true;
return;
}
} 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;
}
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;
}
} 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);
}
// 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) {
}
}
- 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 ();
new MemberAccess (system_security_permissions, "SecurityPermissionAttribute"),
new Arguments[] { pos, named }, loc, false);
g.AttachTo (module, module);
- var ctor = g.Resolve ();
- if (ctor != null) {
- g.ExtractSecurityPermissionSet (ctor, ref declarative_security);
+
+ // Disable no-location warnings (e.g. obsolete) for compiler generated attribute
+ Compiler.Report.DisableReporting ();
+ try {
+ var ctor = g.Resolve ();
+ if (ctor != null) {
+ g.ExtractSecurityPermissionSet (ctor, ref declarative_security);
+ }
+ } finally {
+ Compiler.Report.EnableReporting ();
}
}
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) {
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;
//
// A placeholder class for assembly attributes when emitting module
//
- class AssemblyAttributesPlaceholder : CompilerGeneratedClass
+ class AssemblyAttributesPlaceholder : CompilerGeneratedContainer
{
static readonly string TypeNamePrefix = "<$AssemblyAttributes${0}>";
public static readonly string AssemblyFieldName = "attributes";
Field assembly;
public AssemblyAttributesPlaceholder (ModuleContainer parent, string outputName)
- : base (parent, new MemberName (GetGeneratedName (outputName)), Modifiers.STATIC)
+ : base (parent, new MemberName (GetGeneratedName (outputName)), Modifiers.STATIC | Modifiers.INTERNAL)
{
assembly = new Field (this, new TypeExpression (parent.Compiler.BuiltinTypes.Object, Location), Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName (AssemblyFieldName), null);
}
}
- 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;
paths = new List<string> ();
- paths.AddRange (compiler.Settings.ReferencesLookupPaths);
paths.Add (Directory.GetCurrentDirectory ());
+ paths.AddRange (compiler.Settings.ReferencesLookupPaths);
}
public abstract bool HasObjectType (T assembly);
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)