Author: ankit
Date: 2006-02-19 09:52:30 -0500 (Sun, 19 Feb 2006)
New Revision: 57047
Added:
branches/mono-1-1-13/mcs/ilasm/tests/invalid-field.il
branches/mono-1-1-13/mcs/ilasm/tests/invalid-method.il
Modified:
branches/mono-1-1-13/mcs/class/PEAPI/ChangeLog
branches/mono-1-1-13/mcs/class/PEAPI/Metadata.cs
branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog
branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs
branches/mono-1-1-13/mcs/ilasm/codegen/EventDef.cs
branches/mono-1-1-13/mcs/ilasm/codegen/ExternTable.cs
branches/mono-1-1-13/mcs/ilasm/codegen/FieldRef.cs
branches/mono-1-1-13/mcs/ilasm/codegen/MethodRef.cs
branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs
branches/mono-1-1-13/mcs/ilasm/codegen/PropertyDef.cs
branches/mono-1-1-13/mcs/ilasm/codegen/TypeDef.cs
branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog
Log:
In ilasm/tests:
* invalid-method.il: New. Reference to undefined method.
* invalid-field.il: New. Reference to undefined field.
In ilasm/codegen:
* ExternTable.cs (ExternTable.GetModuleTypeRef): 'module_table' can be
null.
* CodeGen.cs (CodeGen.Write): Use only filename as the name of the
module.
* TypeDef.cs (TypeDef.ResolveAsMethodRef): New.
(TypeDef.ResolveMethod): Change signature to take ret_type, params
etc instead of a signature string. Also, if the method does not exist,
then use ResolveAsMethodRef to return a MethodRef for it.
(TypeDef.ResolveVarargMethod): Likewise.
(TypeDef.ResolveField): Likewise.
* MethodRef.cs (MethodRef.Resolve): Update use of TypeDef.Resolve*
methods.
* FieldRef.cs (FieldRef.Resolve): Update use of TypeDef.ResolveField.
* PropertyDef.cs (PropertyDef.AsMethodDef): Throws an exception is the
method is not a MethodDef.
(PropertyDef.Define): Use AsMethodDef to ensure that get/set/other are
MethodDefs.
* EventDef.cs (EventDef.AsMethodDef): Same as PropertyDef.
(EventDef.Define): Likewise.
* CodeGen.cs (CodeGen.ThisModule): New.
(CodeGen.Write): Set module name if not set by '.module' directive.
* Module.cs: Inherit from ExternRef.
In class/PEAPI:
* Metadata.cs (Module): Implment IExternRef to allow reference to types
in 'this' module.
Modified: branches/mono-1-1-13/mcs/class/PEAPI/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/class/PEAPI/ChangeLog 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/class/PEAPI/ChangeLog 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -1,3 +1,8 @@
+2006-02-19 Ankit Jain <[EMAIL PROTECTED]>
+
+ * Metadata.cs (Module): Implment IExternRef to allow reference to types
+ in 'this' module.
+
2006-02-15 Raja R Harinath <[EMAIL PROTECTED]>
* Metadata.cs (BoundArray.CompressSignedNum): Document the
Modified: branches/mono-1-1-13/mcs/class/PEAPI/Metadata.cs
===================================================================
--- branches/mono-1-1-13/mcs/class/PEAPI/Metadata.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/class/PEAPI/Metadata.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -2510,7 +2510,7 @@
/// <summary>
/// Descriptor for THIS module
/// </summary>
- public class Module : ResolutionScope {
+ public class Module : ResolutionScope, IExternRef {
Guid mvid;
uint mvidIx = 0;
@@ -2526,6 +2526,21 @@
get { return mvid; }
}
+ public ClassRef AddClass(string nsName, string name)
+ {
+ ClassRef aClass = new ClassRef (nsName, name, metaData);
+ metaData.AddToTable (MDTable.TypeRef, aClass);
+ aClass.SetParent (this);
+ return aClass;
+ }
+
+ public ClassRef AddValueClass(string nsName, string name)
+ {
+ ClassRef aClass = AddClass (nsName, name);
+ aClass.MakeValueClass (ValueClass.ValueType);
+ return aClass;
+ }
+
internal sealed override uint Size(MetaData md)
{
return 2 + md.StringsIndexSize() + 3 *
md.GUIDIndexSize();
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -1,3 +1,34 @@
+2006-02-19 Ankit Jain <[EMAIL PROTECTED]>
+
+ * ExternTable.cs (ExternTable.GetModuleTypeRef): 'module_table' can be
+ null.
+
+2006-02-19 Ankit Jain <[EMAIL PROTECTED]>
+
+ * CodeGen.cs (CodeGen.Write): Use only filename as the name of the
+ module.
+ * TypeDef.cs (TypeDef.ResolveAsMethodRef): New.
+ (TypeDef.ResolveMethod): Change signature to take ret_type, params
+ etc instead of a signature string. Also, if the method does not exist,
+ then use ResolveAsMethodRef to return a MethodRef for it.
+ (TypeDef.ResolveVarargMethod): Likewise.
+ (TypeDef.ResolveField): Likewise.
+ * MethodRef.cs (MethodRef.Resolve): Update use of TypeDef.Resolve*
+ methods.
+ * FieldRef.cs (FieldRef.Resolve): Update use of TypeDef.ResolveField.
+ * PropertyDef.cs (PropertyDef.AsMethodDef): Throws an exception is the
+ method is not a MethodDef.
+ (PropertyDef.Define): Use AsMethodDef to ensure that get/set/other are
+ MethodDefs.
+ * EventDef.cs (EventDef.AsMethodDef): Same as PropertyDef.
+ (EventDef.Define): Likewise.
+
+2006-02-19 Ankit Jain <[EMAIL PROTECTED]>
+
+ * CodeGen.cs (CodeGen.ThisModule): New.
+ (CodeGen.Write): Set module name if not set by '.module' directive.
+ * Module.cs: Inherit from ExternRef.
+
2006-02-10 Ankit Jain <[EMAIL PROTECTED]>
* CodeGen.cs (CodeGen.ResolveMethod): Throw exception if global method
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -278,6 +278,10 @@
return (name == assembly_name);
}
+ public Module ThisModule {
+ get { return this_module; }
+ }
+
public bool IsThisModule (string name)
{
return (this_module != null && name ==
this_module.Name);
@@ -494,10 +498,15 @@
if (!is_dll && !HasEntryPoint)
throw new Exception ("No EntryPoint
found.");
+ if (ThisModule == null)
+ this_module = new Module
(Path.GetFileName (output_file));
+
out_stream = new FileStream (output_file,
FileMode.Create, FileAccess.Write);
- pefile = new PEFile (assembly_name,
(this_module != null ? this_module.Name : ""), is_dll, is_assembly, null,
out_stream);
+ pefile = new PEFile (assembly_name,
ThisModule.Name, is_dll, is_assembly, null, out_stream);
PEAPI.Assembly asmb = pefile.GetThisAssembly
();
+ ThisModule.PeapiModule = pefile.GetThisModule
();
+
if (file_ref != null)
file_ref.Resolve (this);
@@ -526,8 +535,7 @@
cattr.AddTo (this, asmb);
}
- if (this_module != null)
- this_module.Resolve (this,
pefile.GetThisModule ());
+ ThisModule.Resolve (this, pefile.GetThisModule
());
if (assembly_declsec != null)
assembly_declsec.AddTo (this, asmb);
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/EventDef.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/EventDef.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/EventDef.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -66,6 +66,14 @@
return event_def;
}
+ private PEAPI.MethodDef AsMethodDef (PEAPI.Method method,
string type)
+ {
+ PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
+ if (methoddef == null)
+ throw new Exception (type + " method of event
" + name + " not found");
+ return methoddef;
+ }
+
public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
{
if (!is_resolved)
@@ -73,22 +81,22 @@
if (addon != null) {
addon.Resolve (code_gen);
- event_def.AddAddon ((PEAPI.MethodDef)
addon.PeapiMethod);
+ event_def.AddAddon (AsMethodDef
(addon.PeapiMethod, "addon"));
}
if (fire != null) {
fire.Resolve (code_gen);
- event_def.AddFire ((PEAPI.MethodDef)
fire.PeapiMethod);
+ event_def.AddFire (AsMethodDef
(fire.PeapiMethod, "fire"));
}
if (other != null) {
other.Resolve (code_gen);
- event_def.AddOther ((PEAPI.MethodDef)
other.PeapiMethod);
+ event_def.AddOther (AsMethodDef
(other.PeapiMethod, "other"));
}
if (removeon != null) {
removeon.Resolve (code_gen);
- event_def.AddRemoveOn ((PEAPI.MethodDef)
removeon.PeapiMethod);
+ event_def.AddRemoveOn (AsMethodDef
(removeon.PeapiMethod, "removeon"));
}
}
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/ExternTable.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/ExternTable.cs 2006-02-19
14:49:12 UTC (rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/ExternTable.cs 2006-02-19
14:52:30 UTC (rev 57047)
@@ -336,8 +336,9 @@
public ExternTypeRef GetModuleTypeRef (string mod_name, string
full_name, bool is_valuetype)
{
- ExternModule mod;
- mod = module_table [mod_name] as ExternModule;
+ ExternModule mod = null;
+ if (module_table != null)
+ mod = module_table [mod_name] as ExternModule;
if (mod == null)
throw new Exception (String.Format ("Module
{0} not defined.", mod_name));
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/FieldRef.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/FieldRef.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/FieldRef.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -41,7 +41,7 @@
return;
TypeDef owner_def =
code_gen.TypeManager[owner.FullName];
- peapi_field = owner_def.ResolveField (name,
ret_type.FullName, code_gen);
+ peapi_field = owner_def.ResolveField (name, ret_type,
code_gen);
is_resolved = true;
}
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/MethodRef.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/MethodRef.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/MethodRef.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -39,13 +39,10 @@
else
write_name = name;
- string sig;
-
if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
- sig = MethodDef.CreateSignature (ret_type,
name, param, gen_param_count);
- peapi_method = owner_def.ResolveMethod (sig,
code_gen);
+ peapi_method = owner_def.ResolveMethod
(ret_type, call_conv, name,
+ param, gen_param_count, code_gen);
} else {
- sig = MethodDef.CreateVarargSignature
(ret_type, name, param);
ArrayList opt_list = new ArrayList ();
bool in_opt = false;
foreach (BaseTypeRef type in param) {
@@ -56,8 +53,10 @@
opt_list.Add (type.PeapiType);
}
}
- peapi_method = owner_def.ResolveVarargMethod
(sig, code_gen,
- (PEAPI.Type[])
opt_list.ToArray (typeof (PEAPI.Type)));
+ peapi_method = owner_def.ResolveVarargMethod (
+ ret_type, call_conv, name,
param, gen_param_count,
+ (PEAPI.Type[])
opt_list.ToArray (typeof (PEAPI.Type)),
+ code_gen);
}
is_resolved = true;
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -12,30 +12,42 @@
namespace Mono.ILASM {
- public class Module : ICustomAttrTarget {
- string name;
- ArrayList customattr_list;
+ public class Module : ExternRef {
+ PEAPI.Module module;
+
public Module (string name)
+ : base (name)
{
- this.name = name;
- customattr_list = null;
}
- public string Name {
- get { return name; }
+ public PEAPI.Module PeapiModule {
+ get { return module; }
+ set { module = value; }
}
- public void AddCustomAttribute (CustomAttr customattr)
+ public override string FullName {
+ get {
+ //'name' field should not contain the [ ]
+ //as its used for resolving
+ return String.Format ("[{0}]", name);
+ }
+ }
+
+ public override PEAPI.IExternRef GetExternRef ()
{
- if (customattr_list == null)
- customattr_list = new ArrayList ();
+ return module;
+ }
- customattr_list.Add (customattr);
+ public override void Resolve (CodeGen code_gen)
+ {
+ throw new Exception ("This should not get called");
}
public void Resolve (CodeGen code_gen, PEAPI.Module module)
{
+ this.module = module;
+
if (customattr_list == null)
return;
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/PropertyDef.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/PropertyDef.cs 2006-02-19
14:49:12 UTC (rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/PropertyDef.cs 2006-02-19
14:52:30 UTC (rev 57047)
@@ -78,6 +78,14 @@
return prop_def;
}
+
+ private PEAPI.MethodDef AsMethodDef (PEAPI.Method method,
string type)
+ {
+ PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
+ if (methoddef == null)
+ throw new Exception (type + " method of
property " + name + " not found");
+ return methoddef;
+ }
public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
{
@@ -86,17 +94,17 @@
if (_get != null) {
_get.Resolve (code_gen);
- prop_def.AddGetter ((PEAPI.MethodDef)
_get.PeapiMethod);
+ prop_def.AddGetter (AsMethodDef
(_get.PeapiMethod, "get"));
}
if (_set != null) {
_set.Resolve (code_gen);
- prop_def.AddSetter ((PEAPI.MethodDef)
_set.PeapiMethod);
+ prop_def.AddSetter (AsMethodDef
(_set.PeapiMethod, "set"));
}
if (other != null) {
other.Resolve (code_gen);
- prop_def.AddOther ((PEAPI.MethodDef)
other.PeapiMethod);
+ prop_def.AddOther (AsMethodDef
(other.PeapiMethod, "other"));
}
if (init_value != null)
Modified: branches/mono-1-1-13/mcs/ilasm/codegen/TypeDef.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/TypeDef.cs 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/TypeDef.cs 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -463,37 +463,52 @@
}
}
- public PEAPI.MethodDef ResolveMethod (string signature,
CodeGen code_gen)
+ public PEAPI.Method ResolveMethod (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ string name, BaseTypeRef [] param, int
gen_param_count, CodeGen code_gen)
{
+ string signature = MethodDef.CreateSignature
(ret_type, name, param, gen_param_count);
MethodDef methoddef = (MethodDef)
method_table[signature];
- if (methoddef == null) {
- code_gen.Report.Error ("Unable to resolve
method: " + signature);
- Environment.Exit (1);
- }
-
- return methoddef.Resolve (code_gen, classdef);
+ if (methoddef != null)
+ return methoddef.Resolve (code_gen, classdef);
+ return ResolveAsMethodRef (ret_type, call_conv, name,
param, gen_param_count, code_gen);
}
- public PEAPI.Method ResolveVarargMethod (string signature,
- CodeGen code_gen, PEAPI.Type[] opt)
+ public PEAPI.Method ResolveVarargMethod (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ string name, BaseTypeRef [] param, int
gen_param_count, PEAPI.Type [] opt, CodeGen code_gen)
{
+ string signature = MethodDef.CreateVarargSignature
(ret_type, name, param);
MethodDef methoddef = (MethodDef)
method_table[signature];
- if (methoddef == null) {
- code_gen.Report.Error ("Unable to resolve
method: " + signature);
- Environment.Exit (1);
+ if (methoddef != null) {
+ methoddef.Resolve (code_gen, classdef);
+ return methoddef.GetVarargSig (opt);
}
+
+ return ResolveAsMethodRef (ret_type, call_conv, name,
param, gen_param_count, code_gen);
+ }
- methoddef.Resolve (code_gen, classdef);
- return methoddef.GetVarargSig (opt);
+ private PEAPI.Method ResolveAsMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ string name, BaseTypeRef [] param, int
gen_param_count, CodeGen code_gen)
+ {
+ ExternTypeRef type_ref =
code_gen.ThisModule.GetTypeRef (FullName, false);
+ ExternMethodRef methodref = (ExternMethodRef)
type_ref.GetMethodRef (ret_type, call_conv, name, param, gen_param_count);
+ methodref.Resolve (code_gen);
+
+ return methodref.PeapiMethod;
}
- public PEAPI.Field ResolveField (string name, string
type_name, CodeGen code_gen)
+ public PEAPI.Field ResolveField (string name, BaseTypeRef
ret_type, CodeGen code_gen)
{
- FieldDef fielddef = (FieldDef) field_table[new
DictionaryEntry (name, type_name)];
+ FieldDef fielddef = (FieldDef) field_table[new
DictionaryEntry (name, ret_type.FullName)];
+ if (fielddef !=null)
+ return fielddef.Resolve (code_gen, classdef);
- return fielddef.Resolve (code_gen, classdef);
+ ExternTypeRef type_ref =
code_gen.ThisModule.GetTypeRef (FullName, false);
+ IFieldRef fieldref = type_ref.GetFieldRef (ret_type,
name);
+ fieldref.Resolve (code_gen);
+
+ return fieldref.PeapiField;
}
private string MakeFullName ()
Modified: branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog 2006-02-19 14:49:12 UTC
(rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog 2006-02-19 14:52:30 UTC
(rev 57047)
@@ -1,3 +1,8 @@
+2006-02-19 Ankit Jain <[EMAIL PROTECTED]>
+
+ * invalid-method.il: New. Reference to undefined method.
+ * invalid-field.il: New. Reference to undefined field.
+
2006-01-31 Ankit Jain <[EMAIL PROTECTED]>
* test-assembly2.il: New. Test for referencing undeclared external
assembly.
Added: branches/mono-1-1-13/mcs/ilasm/tests/invalid-field.il
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/tests/invalid-field.il 2006-02-19
14:49:12 UTC (rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/tests/invalid-field.il 2006-02-19
14:52:30 UTC (rev 57047)
@@ -0,0 +1,34 @@
+// Test for ref to an non-existant field
+
+.assembly extern mscorlib
+{
+ .ver 1:0:5000:0
+}
+.assembly 'invalid-field'
+{
+}
+
+ .class private auto ansi beforefieldinit test
+ extends [mscorlib]System.Object
+ {
+ .method public hidebysig specialname rtspecialname
+ instance default void .ctor () cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void object::.ctor()
+ IL_0006: ret
+ }
+
+ .method public hidebysig
+ instance default void foo () cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: ldc.i4.5
+ IL_0002: stfld int32 test::invalid
+ IL_0007: ret
+ }
+
+ }
+
Added: branches/mono-1-1-13/mcs/ilasm/tests/invalid-method.il
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/tests/invalid-method.il 2006-02-19
14:49:12 UTC (rev 57046)
+++ branches/mono-1-1-13/mcs/ilasm/tests/invalid-method.il 2006-02-19
14:52:30 UTC (rev 57047)
@@ -0,0 +1,33 @@
+// Test for ref to an non-existant method
+
+.assembly extern mscorlib
+{
+ .ver 1:0:5000:0
+}
+.assembly 'invalid-method'
+{
+}
+
+ .class private auto ansi beforefieldinit test
+ extends [mscorlib]System.Object
+ {
+
+ .method public hidebysig specialname rtspecialname
+ instance default void .ctor () cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void object::.ctor()
+ IL_0006: ret
+ }
+
+ .method public hidebysig
+ instance default void foo () cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void class test::bar()
+ IL_0006: ret
+ }
+
+ }
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches