+ this.compiler = compiler;
+
+ paths = new List<string> ();
+ paths.AddRange (compiler.Settings.ReferencesLookupPaths);
+ paths.Add (Directory.GetCurrentDirectory ());
+ }
+
+ public abstract bool HasObjectType (T assembly);
+ protected abstract string[] GetDefaultReferences ();
+ public abstract T LoadAssemblyFile (string fileName, bool isImplicitReference);
+ public abstract void LoadReferences (ModuleContainer module);
+
+ protected void Error_FileNotFound (string fileName)
+ {
+ compiler.Report.Error (6, "Metadata file `{0}' could not be found", fileName);
+ }
+
+ protected void Error_FileCorrupted (string fileName)
+ {
+ compiler.Report.Error (9, "Metadata file `{0}' does not contain valid metadata", fileName);
+ }
+
+ protected void Error_AssemblyIsModule (string fileName)
+ {
+ compiler.Report.Error (1509,
+ "Referenced assembly file `{0}' is a module. Consider using `-addmodule' option to add the module",
+ fileName);
+ }
+
+ protected void Error_ModuleIsAssembly (string fileName)
+ {
+ compiler.Report.Error (1542,
+ "Added module file `{0}' is an assembly. Consider using `-r' option to reference the file",
+ fileName);
+ }
+
+ protected void LoadReferencesCore (ModuleContainer module, out T corlib_assembly, out List<Tuple<RootNamespace, T>> loaded)
+ {
+ compiler.TimeReporter.Start (TimeReporter.TimerType.ReferencesLoading);
+
+ loaded = new List<Tuple<RootNamespace, T>> ();
+
+ //
+ // Load mscorlib.dll as the first
+ //
+ if (module.Compiler.Settings.StdLib) {
+ corlib_assembly = LoadAssemblyFile ("mscorlib.dll", true);
+ } else {
+ corlib_assembly = default (T);
+ }
+
+ T a;
+ foreach (string r in module.Compiler.Settings.AssemblyReferences) {
+ a = LoadAssemblyFile (r, false);
+ if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly))
+ continue;
+
+ var key = Tuple.Create (module.GlobalRootNamespace, a);
+ 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);
+ }
+
+ foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) {
+ a = LoadAssemblyFile (entry.Item2, false);
+ if (a == null)
+ continue;
+
+ var key = Tuple.Create (module.CreateRootNamespace (entry.Item1), a);
+ if (loaded.Contains (key))
+ continue;
+
+ loaded.Add (key);
+ }
+
+ if (compiler.Settings.LoadDefaultReferences) {
+ foreach (string r in GetDefaultReferences ()) {
+ a = LoadAssemblyFile (r, true);
+ if (a == null)
+ continue;
+
+ var key = Tuple.Create (module.GlobalRootNamespace, a);
+ if (loaded.Contains (key))
+ continue;
+
+ loaded.Add (key);
+ }
+ }
+
+ compiler.TimeReporter.Stop (TimeReporter.TimerType.ReferencesLoading);