Author: ankit
Date: 2006-02-19 08:59:36 -0500 (Sun, 19 Feb 2006)
New Revision: 57045

Added:
   trunk/mcs/ilasm/tests/invalid-field.il
   trunk/mcs/ilasm/tests/invalid-method.il
Modified:
   trunk/mcs/ilasm/codegen/ChangeLog
   trunk/mcs/ilasm/codegen/CodeGen.cs
   trunk/mcs/ilasm/codegen/EventDef.cs
   trunk/mcs/ilasm/codegen/FieldRef.cs
   trunk/mcs/ilasm/codegen/MethodRef.cs
   trunk/mcs/ilasm/codegen/PropertyDef.cs
   trunk/mcs/ilasm/codegen/TypeDef.cs
   trunk/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:
        * 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.    


Modified: trunk/mcs/ilasm/codegen/ChangeLog
===================================================================
--- trunk/mcs/ilasm/codegen/ChangeLog   2006-02-19 10:40:06 UTC (rev 57044)
+++ trunk/mcs/ilasm/codegen/ChangeLog   2006-02-19 13:59:36 UTC (rev 57045)
@@ -1,5 +1,25 @@
 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. 

Modified: trunk/mcs/ilasm/codegen/CodeGen.cs
===================================================================
--- trunk/mcs/ilasm/codegen/CodeGen.cs  2006-02-19 10:40:06 UTC (rev 57044)
+++ trunk/mcs/ilasm/codegen/CodeGen.cs  2006-02-19 13:59:36 UTC (rev 57045)
@@ -499,7 +499,7 @@
                                         throw new Exception ("No EntryPoint 
found.");
 
                                 if (ThisModule == null)
-                                        this_module = new Module (output_file);
+                                        this_module = new Module 
(Path.GetFileName (output_file));
 
                                 out_stream = new FileStream (output_file, 
FileMode.Create, FileAccess.Write);
                                 pefile = new PEFile (assembly_name, 
ThisModule.Name, is_dll, is_assembly, null, out_stream);

Modified: trunk/mcs/ilasm/codegen/EventDef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/EventDef.cs 2006-02-19 10:40:06 UTC (rev 57044)
+++ trunk/mcs/ilasm/codegen/EventDef.cs 2006-02-19 13:59:36 UTC (rev 57045)
@@ -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: trunk/mcs/ilasm/codegen/FieldRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/FieldRef.cs 2006-02-19 10:40:06 UTC (rev 57044)
+++ trunk/mcs/ilasm/codegen/FieldRef.cs 2006-02-19 13:59:36 UTC (rev 57045)
@@ -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: trunk/mcs/ilasm/codegen/MethodRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/MethodRef.cs        2006-02-19 10:40:06 UTC (rev 
57044)
+++ trunk/mcs/ilasm/codegen/MethodRef.cs        2006-02-19 13:59:36 UTC (rev 
57045)
@@ -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: trunk/mcs/ilasm/codegen/PropertyDef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/PropertyDef.cs      2006-02-19 10:40:06 UTC (rev 
57044)
+++ trunk/mcs/ilasm/codegen/PropertyDef.cs      2006-02-19 13:59:36 UTC (rev 
57045)
@@ -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: trunk/mcs/ilasm/codegen/TypeDef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/TypeDef.cs  2006-02-19 10:40:06 UTC (rev 57044)
+++ trunk/mcs/ilasm/codegen/TypeDef.cs  2006-02-19 13:59:36 UTC (rev 57045)
@@ -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: trunk/mcs/ilasm/tests/ChangeLog
===================================================================
--- trunk/mcs/ilasm/tests/ChangeLog     2006-02-19 10:40:06 UTC (rev 57044)
+++ trunk/mcs/ilasm/tests/ChangeLog     2006-02-19 13:59:36 UTC (rev 57045)
@@ -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: trunk/mcs/ilasm/tests/invalid-field.il
===================================================================
--- trunk/mcs/ilasm/tests/invalid-field.il      2006-02-19 10:40:06 UTC (rev 
57044)
+++ trunk/mcs/ilasm/tests/invalid-field.il      2006-02-19 13:59:36 UTC (rev 
57045)
@@ -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: trunk/mcs/ilasm/tests/invalid-method.il
===================================================================
--- trunk/mcs/ilasm/tests/invalid-method.il     2006-02-19 10:40:06 UTC (rev 
57044)
+++ trunk/mcs/ilasm/tests/invalid-method.il     2006-02-19 13:59:36 UTC (rev 
57045)
@@ -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

Reply via email to