2004-07-13 Anirban Bhattacharjee <banirban@novell.com>
authorAnirban Bhattacharjee <anirban@mono-cvs.ximian.com>
Tue, 13 Jul 2004 09:27:11 +0000 (09:27 -0000)
committerAnirban Bhattacharjee <anirban@mono-cvs.ximian.com>
Tue, 13 Jul 2004 09:27:11 +0000 (09:27 -0000)
        * driver.cs: Added support for AddModule compiler option
        * typemanager.cs: AddModule function will now store list of Modules instaed of ModuleBuilders. This change has been made to get LoadModule function working of driver.cs.

svn path=/trunk/mcs/; revision=31066

mcs/mbas/ChangeLog
mcs/mbas/driver.cs
mcs/mbas/typemanager.cs

index a6a5106d93bb77834886c0ff8bebcf2b743023ff..20d3635442891fd88284ea95d79084424ce920d8 100644 (file)
@@ -1,3 +1,7 @@
+2004-07-13 Anirban Bhattacharjee <banirban@novell.com>
+       * driver.cs: Added support for AddModule compiler option
+       * typemanager.cs: AddModule function will now store list of Modules instaed of ModuleBuilders. This change has been made to get LoadModule function working of driver.cs.
+
 2004-07-13 Anirban Bhattacharjee <banirban@novell.com>
        * driver.cs: Compilation to module is supported now
 
index a93b32239ac6c21aee8cc32d5ed7f84eb63fc102..7f4f1163e03015c47eb56e76af6b653795343795 100644 (file)
@@ -133,7 +133,7 @@ namespace Mono.Languages
                //------------------------------------------------------------------
                public ArrayList AddedModules = new ArrayList();
 
-               [Option("[NOT IMPLEMENTED YET]References metadata from specified {module}", "addmodule")]
+               [Option("References metadata from specified {module}", "addmodule")]
                public string AddedModule { set { AddedModules.Add(value); } }
 
                [Option("[NOT IMPLEMENTED YET]Include all files in the current directory and subdirectories according to the {wildcard}", "recurse")]
@@ -396,6 +396,56 @@ namespace Mono.Languages
                        return 0;
                }
 
+               public void LoadModule (MethodInfo adder_method, string module)
+               {
+                       System.Reflection.Module m;
+                       string total_log = "";
+
+                       try {
+                               try {
+                                       m = (System.Reflection.Module)adder_method.Invoke (CodeGen.AssemblyBuilder, new object [] { module });
+                               }
+                               catch (TargetInvocationException ex) {
+                                       throw ex.InnerException;
+                               }
+                               TypeManager.AddModule (m);
+
+                       } 
+                       catch (FileNotFoundException) {
+                               foreach (string dir in libpath) {
+                                       string full_path = Path.Combine (dir, module);
+                                       if (!module.EndsWith (".netmodule"))
+                                               full_path += ".netmodule";
+
+                                       try {
+                                               try {
+                                                       m = (System.Reflection.Module) adder_method.Invoke (CodeGen.AssemblyBuilder, new object [] { full_path });
+                                               }
+                                               catch (TargetInvocationException ex) {
+                                                       throw ex.InnerException;
+                                               }
+                                               TypeManager.AddModule (m);
+                                               return;
+                                       }
+                                       catch (FileNotFoundException ff) {
+                                               total_log += ff.FusionLog;
+                                               continue;
+                                       }
+                               }
+                               Report.Error (6, "Cannot find module `" + module + "'" );
+                               Console.WriteLine ("Log: \n" + total_log);
+                       }
+                       catch (BadImageFormatException f) {
+                               Report.Error(6, "Cannot load module (bad file format)" + f.FusionLog);
+                       }
+                       catch (FileLoadException f)     {
+                               Report.Error(6, "Cannot load module " + f.FusionLog);
+                       }
+                       catch (ArgumentNullException) {
+                               Report.Error(6, "Cannot load module (null argument)");
+                       }
+               }
+
                void Error(string message)
                {
                        Console.WriteLine(message);
@@ -613,8 +663,7 @@ namespace Mono.Languages
 
                bool ParseAll() // Phase 1
                {
-                       if (first_source == null)
-                       {
+                       if (first_source == null) {
                                Report.Error(2008, "No files to compile were specified");
                                return false;
                        }
@@ -674,7 +723,17 @@ namespace Mono.Languages
                                TypeManager.AddModule (CodeGen.ModuleBuilder);
                        }
 
-                       
+                       if (AddedModules.Count > 0) {
+                               MethodInfo adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance|BindingFlags.NonPublic);
+                               if (adder_method == null) {
+                                       Report.Error (0, new Location (-1, -1), "Cannot use /addmodule on this runtime: Try the Mono runtime instead.");
+                                       Environment.Exit (1);
+                               }
+
+                               foreach (string module in AddedModules)
+                                       LoadModule (adder_method, module);
+                       }
+
 
                        //
                        // Before emitting, we need to get the core
index eb4352f1317ad84fffd74e1d7b03e4191af5569d..9d34c5882953cdecaaed91f2c7abbb95975d71fd 100644 (file)
@@ -160,7 +160,13 @@ public class TypeManager {
        //  Keeps a list of module builders. We used this to do lookups
        //  on the modulebuilder using GetType -- needed for arrays
        // </remarks>
-       static ModuleBuilder [] modules;
+       
+       // This is changed from list of ModuleBuilders 
+       // to list of Modules for getting addmodule 
+       // compiler option working
+       // Anirban - 13.07.2004
+
+       static System.Reflection.Module [] modules;
 
        // <remarks>
        //   This is the type_cache from the assemblies to avoid
@@ -454,10 +460,10 @@ public class TypeManager {
        /// <summary>
        ///  Registers a module builder to lookup types from
        /// </summary>
-       public static void AddModule (ModuleBuilder mb)
+       public static void AddModule (System.Reflection.Module mb)
        {
                int top = modules != null ? modules.Length : 0;
-               ModuleBuilder [] n = new ModuleBuilder [top + 1];
+               System.Reflection.Module [] n = new System.Reflection.Module [top + 1];
 
                if (modules != null)
                        modules.CopyTo (n, 0);
@@ -465,7 +471,6 @@ public class TypeManager {
                modules = n;
        }
 
-
        private class StandardModule {
                public readonly string Namespace;
                public readonly string Name;
@@ -552,7 +557,7 @@ public class TypeManager {
                                        return t;
                        }
 
-                       foreach (ModuleBuilder mb in modules) {
+                       foreach (System.Reflection.Module mb in modules) {
                                t = mb.GetType (name, false, true);
                                if (t != null){
                                        return t;
@@ -652,7 +657,7 @@ public class TypeManager {
                        }
                }
 
-               foreach (ModuleBuilder mb in modules) {
+               foreach (System.Reflection.Module mb in modules) {
                        foreach (Type t in mb.GetTypes ()) {
                                string ns = t.Namespace;