Author: raja
Date: 2006-11-08 10:19:54 -0500 (Wed, 08 Nov 2006)
New Revision: 67538
Modified:
trunk/mcs/errors/cs0006.cs
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/codegen.cs
trunk/mcs/mcs/driver.cs
Log:
Address parts of #58244 -- most of what's left is in the runtime
* driver.cs (LoadAssembly): Simplify slightly. Add CS0009 and
CS1509 error checks, and handle them for all assembly loads, not
just the first invocation.
(LoadModule): Likewise. Move handling of 'adder_method' ...
* codegen.cs (AssemblyClass.AddModule): ... here.
Modified: trunk/mcs/errors/cs0006.cs
===================================================================
--- trunk/mcs/errors/cs0006.cs 2006-11-08 15:15:42 UTC (rev 67537)
+++ trunk/mcs/errors/cs0006.cs 2006-11-08 15:19:54 UTC (rev 67538)
@@ -1,7 +1,7 @@
-// CS0006: Cannot find assembly file `a:b'
+// CS0006: cannot find metadata file `a:b'
// Line: 0
// Compiler options: -r:a:b
class C
{
-}
\ No newline at end of file
+}
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2006-11-08 15:15:42 UTC (rev 67537)
+++ trunk/mcs/mcs/ChangeLog 2006-11-08 15:19:54 UTC (rev 67538)
@@ -1,3 +1,12 @@
+2006-11-08 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Address parts of #58244 -- most of what's left is in the runtime
+ * driver.cs (LoadAssembly): Simplify slightly. Add CS0009 and
+ CS1509 error checks, and handle them for all assembly loads, not
+ just the first invocation.
+ (LoadModule): Likewise. Move handling of 'adder_method' ...
+ * codegen.cs (AssemblyClass.AddModule): ... here.
+
2006-11-02 Marek Safar <[EMAIL PROTECTED]>
* statement.cs.cs (CollectionForeach.TryType): Issue a error when
Modified: trunk/mcs/mcs/codegen.cs
===================================================================
--- trunk/mcs/mcs/codegen.cs 2006-11-08 15:15:42 UTC (rev 67537)
+++ trunk/mcs/mcs/codegen.cs 2006-11-08 15:19:54 UTC (rev 67538)
@@ -1364,6 +1364,30 @@
return attribute_targets;
}
}
+
+ // Wrapper for AssemblyBuilder.AddModule
+ static MethodInfo adder_method;
+ static public MethodInfo AddModule_Method {
+ get {
+ if (adder_method == null)
+ adder_method = typeof
(AssemblyBuilder).GetMethod ("AddModule",
BindingFlags.Instance|BindingFlags.NonPublic);
+ return adder_method;
+ }
+ }
+ public Module AddModule (string module)
+ {
+ MethodInfo m = AddModule_Method;
+ if (m == null) {
+ Report.RuntimeMissingSupport (Location.Null,
"/addmodule");
+ Environment.Exit (1);
+ }
+
+ try {
+ return (Module) m.Invoke (Builder, new object
[] { module });
+ } catch (TargetInvocationException ex) {
+ throw ex.InnerException;
+ }
+ }
}
public class ModuleClass : CommonAssemblyModulClass {
Modified: trunk/mcs/mcs/driver.cs
===================================================================
--- trunk/mcs/mcs/driver.cs 2006-11-08 15:15:42 UTC (rev 67537)
+++ trunk/mcs/mcs/driver.cs 2006-11-08 15:19:54 UTC (rev 67538)
@@ -314,103 +314,124 @@
LoadAssembly (assembly, null, soft);
}
+ static void Error6 (string name, string log)
+ {
+ if (log != null && log.Length > 0)
+ Report.ExtraInformation (Location.Null,
"Log:\n" + log + "\n(log related to previous ");
+ Report.Error (6, "cannot find metadata file `{0}'",
name);
+ }
+
+ static void Error9 (string type, string filename, string log)
+ {
+ if (log != null && log.Length > 0)
+ Report.ExtraInformation (Location.Null,
"Log:\n" + log + "\n(log related to previous ");
+ Report.Error (9, "file `{0}' has invalid `{1}'
metadata", filename, type);
+ }
+
+ static void BadAssembly (string filename, string log)
+ {
+ MethodInfo adder_method =
AssemblyClass.AddModule_Method;
+
+ if (adder_method != null) {
+ AssemblyName an = new AssemblyName ();
+ an.Name = ".temp";
+ AssemblyBuilder ab =
AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
+ if (adder_method.Invoke (ab, new object [] {
filename }) != null) {
+ Report.Error (1509, "referenced file
`{0}' is not an assembly; try using the '-addmodule' option", filename);
+ return;
+ }
+ }
+ Error9 ("assembly", filename, log);
+ }
+
static public void LoadAssembly (string assembly, string alias,
bool soft)
{
- Assembly a;
+ Assembly a = null;
string total_log = "";
try {
- char[] path_chars = { '/', '\\' };
+ try {
+ char[] path_chars = { '/', '\\' };
- if (assembly.IndexOfAny (path_chars) != -1) {
- a = Assembly.LoadFrom (assembly);
- } else {
- string ass = assembly;
- if (ass.EndsWith (".dll") ||
ass.EndsWith (".exe"))
- ass = assembly.Substring (0,
assembly.Length - 4);
- a = Assembly.Load (ass);
+ if (assembly.IndexOfAny (path_chars) !=
-1) {
+ a = Assembly.LoadFrom
(assembly);
+ } else {
+ string ass = assembly;
+ if (ass.EndsWith (".dll") ||
ass.EndsWith (".exe"))
+ ass =
assembly.Substring (0, assembly.Length - 4);
+ a = Assembly.Load (ass);
+ }
+ } catch (FileNotFoundException) {
+ bool err = !soft;
+ foreach (string dir in link_paths) {
+ string full_path = Path.Combine
(dir, assembly);
+ if (!assembly.EndsWith (".dll")
&& !assembly.EndsWith (".exe"))
+ full_path += ".dll";
+
+ try {
+ a = Assembly.LoadFrom
(full_path);
+ err = false;
+ break;
+ } catch (FileNotFoundException
ff) {
+ total_log +=
ff.FusionLog;
+ }
+ }
+ if (err) {
+ Error6 (assembly, total_log);
+ return;
+ }
}
+
// Extern aliased refs require special handling
if (alias == null)
RootNamespace.Global.AddAssemblyReference (a);
else
RootNamespace.DefineRootNamespace
(alias, a);
- } catch (FileNotFoundException){
- foreach (string dir in link_paths){
- string full_path = Path.Combine (dir,
assembly);
- if (!assembly.EndsWith (".dll") &&
!assembly.EndsWith (".exe"))
- full_path += ".dll";
-
- try {
- a = Assembly.LoadFrom
(full_path);
- if (alias == null)
-
RootNamespace.Global.AddAssemblyReference (a);
- else
-
RootNamespace.DefineRootNamespace (alias, a);
- return;
- } catch (FileNotFoundException ff) {
- total_log += ff.FusionLog;
- continue;
- }
- }
- if (!soft) {
- Report.Error (6, "Cannot find assembly
file `{0}'", assembly);
- Report.Stderr.WriteLine ("Log: \n" +
total_log);
- }
} catch (BadImageFormatException f) {
- Report.Error(6, "Cannot load assembly (bad file
format)" + f.FusionLog);
- } catch (FileLoadException f){
- Report.SymbolRelatedToPreviousError
(Location.Null, f.FusionLog);
- Report.Error(6, "Cannot load assembly file
`{0}'", f.FileName);
- } catch (ArgumentNullException){
- Report.Error(6, "Cannot load assembly (null
argument)");
+ // .NET 2.0 throws this if we try to load a
module without an assembly manifest ...
+ BadAssembly (f.FileName, f.FusionLog);
+ } catch (FileLoadException f) {
+ // ... while .NET 1.1 throws this
+ BadAssembly (f.FileName, f.FusionLog);
}
}
- static public void LoadModule (MethodInfo adder_method, string
module)
+ static public void LoadModule (string module)
{
- Module m;
+ Module m = null;
string total_log = "";
try {
try {
- m = (Module)adder_method.Invoke
(CodeGen.Assembly.Builder, new object [] { module });
- }
- catch (TargetInvocationException ex) {
- throw ex.InnerException;
- }
- RootNamespace.Global.AddModuleReference (m);
+ m = CodeGen.Assembly.AddModule (module);
+ } catch (FileNotFoundException) {
+ bool err = true;
+ foreach (string dir in link_paths) {
+ string full_path = Path.Combine
(dir, module);
+ if (!module.EndsWith
(".netmodule"))
+ full_path +=
".netmodule";
- }
- catch (FileNotFoundException){
- foreach (string dir in link_paths){
- string full_path = Path.Combine (dir,
module);
- if (!module.EndsWith (".netmodule"))
- full_path += ".netmodule";
-
- try {
try {
- m =
(Module)adder_method.Invoke (CodeGen.Assembly.Builder, new object [] {
full_path });
+ m =
CodeGen.Assembly.AddModule (full_path);
+ err = false;
+ break;
+ } catch (FileNotFoundException
ff) {
+ total_log +=
ff.FusionLog;
}
- catch
(TargetInvocationException ex) {
- throw ex.InnerException;
- }
-
RootNamespace.Global.AddModuleReference (m);
+ }
+ if (err) {
+ Error6 (module, total_log);
return;
- } catch (FileNotFoundException ff) {
- total_log += ff.FusionLog;
- continue;
}
}
- Report.Error (6, "Cannot find module `" +
module + "'" );
- Console.WriteLine ("Log: \n" + total_log);
+
+ RootNamespace.Global.AddModuleReference (m);
+
} 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)");
+ Error9 ("module", f.FileName, f.FusionLog);
+ } catch (FileLoadException f) {
+ Error9 ("module", f.FileName, f.FusionLog);
}
}
@@ -1626,14 +1647,8 @@
RootNamespace.Global.AddModuleReference
(CodeGen.Module.Builder);
if (modules.Count > 0) {
- MethodInfo adder_method = typeof
(AssemblyBuilder).GetMethod ("AddModule",
BindingFlags.Instance|BindingFlags.NonPublic);
- if (adder_method == null) {
- Report.RuntimeMissingSupport
(Location.Null, "/addmodule");
- Environment.Exit (1);
- }
-
foreach (string module in modules)
- LoadModule (adder_method, module);
+ LoadModule (module);
}
//
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches