Author: ankit
Date: 2006-01-19 10:26:09 -0500 (Thu, 19 Jan 2006)
New Revision: 55787

Added:
   branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs
   branches/mono-1-1-13/mcs/ilasm/tests/test-module-cattr.il
Modified:
   branches/mono-1-1-13/mcs/ilasm/ChangeLog
   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/ilasm.exe.sources
   branches/mono-1-1-13/mcs/ilasm/parser/ChangeLog
   branches/mono-1-1-13/mcs/ilasm/parser/ILParser.jay
   branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog
   branches/mono-1-1-13/mcs/ilasm/tests/test-array-2.il
Log:
Backport r55786

In ilasm/tests:
        * test-module-cattr.il: New. Test for custom attributes on .module
        * test-array-2.i: Add the missing closing brace.

In ilasm/codegen:
        * Module.cs (Module): New. Class for representing this module.
        * CodeGen.cs (CodeGen): Update to use the new Module class.
        (CodeGen.Write): Resolve this_module.

In ilasm:
        * ilasm.exe.sources: Add Module.cs to the build.

In ilasm/parser:
        * ILParser.jay (decl | customattr_decl): Add custom attributes.
        (assembly_all | ..): Set CurrentCustomAttrTarget to null.


Modified: branches/mono-1-1-13/mcs/ilasm/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/ChangeLog    2006-01-19 15:21:01 UTC (rev 
55786)
+++ branches/mono-1-1-13/mcs/ilasm/ChangeLog    2006-01-19 15:26:09 UTC (rev 
55787)
@@ -1,3 +1,7 @@
+2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * ilasm.exe.sources: Add Module.cs to the build.
+
 2006-01-13  Ankit Jain  <[EMAIL PROTECTED]>
 
        * ilasm.exe.sources: Replace IMethodRef.cs with BaseMethodRef.cs

Modified: branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog    2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/ChangeLog    2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -1,5 +1,11 @@
 2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
 
+       * Module.cs (Module): New. Class for representing this module.
+       * CodeGen.cs (CodeGen): Update to use the new Module class.
+       (CodeGen.Write): Resolve this_module.
+
+2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
+
        * GenericParameters.cs (GenericParameter): Implement ICustomAttrTarget.
        (GenericParameter.Resolve): New overload, reduce code duplication.
        (GenericParameters.GetGenericParam): New. Returns a GenericParameter.

Modified: branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs   2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/CodeGen.cs   2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -72,7 +72,7 @@
                 private bool is_assembly;
                 private bool entry_point;
 
-                private string module_name;
+                private Module this_module;
 
                 public CodeGen (string output_file, bool is_dll, bool 
is_assembly,
                                bool debugging_info, Report report)
@@ -101,6 +101,7 @@
                         image_base = -1;
                         stack_reserve = -1;
                         entry_point = false;
+                        this_module = null;
                 }
 
                private string CreateDebugFile (string output_file)
@@ -263,7 +264,8 @@
 
                 public void SetModuleName (string module_name)
                 {
-                        this.module_name = module_name;
+                        this_module = new Module (module_name);
+                        CurrentCustomAttrTarget = this_module;
                 }
 
                 public void SetFileRef (FileRef file_ref)
@@ -278,7 +280,7 @@
 
                 public bool IsThisModule (string name)
                 {
-                        return (name == module_name);
+                        return (this_module != null && name == 
this_module.Name);
                 }
 
                public void BeginSourceFile (string name)
@@ -493,7 +495,7 @@
                                         throw new Exception ("No EntryPoint 
found.");
 
                                 out_stream = new FileStream (output_file, 
FileMode.Create, FileAccess.Write);
-                                pefile = new PEFile (assembly_name, 
module_name, is_dll, is_assembly, null, out_stream);
+                                pefile = new PEFile (assembly_name, 
(this_module != null ? this_module.Name : ""), is_dll, is_assembly, null, 
out_stream);
                                 PEAPI.Assembly asmb = pefile.GetThisAssembly 
();
 
                                 if (file_ref != null)
@@ -523,7 +525,10 @@
                                         foreach (CustomAttr cattr in 
assembly_custom_attributes)
                                                 cattr.AddTo (this, asmb);
                                 }
-                                
+
+                                if (this_module != null)
+                                        this_module.Resolve (this, 
pefile.GetThisModule ());
+
                                 if (assembly_declsec != null)
                                         assembly_declsec.AddTo (this, asmb);   
     
 

Added: branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs    2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/codegen/Module.cs    2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -0,0 +1,46 @@
+//
+// Mono.ILASM.Module
+//
+// Author(s):
+//  Ankit Jain  <[EMAIL PROTECTED]>
+//
+// Copyright 2006 Novell, Inc (http://www.novell.com)
+//
+
+using System;
+using System.Collections;
+
+namespace Mono.ILASM {
+
+        public class Module : ICustomAttrTarget {
+                string name;
+                ArrayList customattr_list;
+
+                public Module (string name)
+                {
+                        this.name = name;
+                        customattr_list = null;
+                }
+
+                public string Name {
+                        get { return name; }
+                }
+
+                public void AddCustomAttribute (CustomAttr customattr)
+                {
+                        if (customattr_list == null)
+                                customattr_list = new ArrayList ();
+
+                        customattr_list.Add (customattr);
+                }
+
+                public void Resolve (CodeGen code_gen, PEAPI.Module module)
+                {
+                        if (customattr_list == null)
+                                return;
+
+                        foreach (CustomAttr customattr in customattr_list)
+                                customattr.AddTo (code_gen, module);
+                }
+        }
+}

Modified: branches/mono-1-1-13/mcs/ilasm/ilasm.exe.sources
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/ilasm.exe.sources    2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/ilasm.exe.sources    2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -2,6 +2,7 @@
 Report.cs
 AssemblyInfo.cs
 codegen/CodeGen.cs
+codegen/Module.cs
 codegen/DebuggingInfo.cs
 codegen/ExternTable.cs
 codegen/InstrTable.cs

Modified: branches/mono-1-1-13/mcs/ilasm/parser/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/parser/ChangeLog     2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/parser/ChangeLog     2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -1,5 +1,10 @@
 2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
 
+       * ILParser.jay (decl | customattr_decl): Add custom attributes.
+       (assembly_all | ..): Set CurrentCustomAttrTarget to null.
+
+2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
+
        * ILParser.jay (K_TYPE): New.
        (param_type_decl): New. Rule for '.param type ..', for specifying 
custom attibutes
        for type parameters.

Modified: branches/mono-1-1-13/mcs/ilasm/parser/ILParser.jay
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/parser/ILParser.jay  2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/parser/ILParser.jay  2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -489,6 +489,10 @@
                        | module_head
                        | sec_decl
                        | customattr_decl
+                         {
+                               if (codegen.CurrentCustomAttrTarget != null)
+                                       
codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
+                         }
                        | D_SUBSYSTEM int32
                           {
                                 codegen.SetSubSystem ((int) $2);
@@ -2922,6 +2926,9 @@
                        ;
 
 assembly_all           : assembly_head OPEN_BRACE assembly_decls CLOSE_BRACE
+                         {
+                               codegen.CurrentCustomAttrTarget = null;
+                         }
                        ;
 
 assembly_head          : D_ASSEMBLY asm_attr slashed_name

Modified: branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog      2006-01-19 15:21:01 UTC 
(rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/tests/ChangeLog      2006-01-19 15:26:09 UTC 
(rev 55787)
@@ -1,5 +1,10 @@
 2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
 
+       * test-module-cattr.il: New. Test for custom attributes on .module
+       * test-array-2.i: Add the missing closing brace.
+
+2006-01-19  Ankit Jain  <[EMAIL PROTECTED]>
+
        * err-gen-cattr-1.il: New.
        * err-gen-cattr-2.il: New.
        * err-gen-cattr-3.il: New.

Modified: branches/mono-1-1-13/mcs/ilasm/tests/test-array-2.il
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/tests/test-array-2.il        2006-01-19 
15:21:01 UTC (rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/tests/test-array-2.il        2006-01-19 
15:26:09 UTC (rev 55787)
@@ -4,6 +4,7 @@
 .assembly extern mscorlib
 {
   .ver 1:0:5000:0
+}
 .assembly 'test-array'
 {
   .ver  0:0:0:0

Added: branches/mono-1-1-13/mcs/ilasm/tests/test-module-cattr.il
===================================================================
--- branches/mono-1-1-13/mcs/ilasm/tests/test-module-cattr.il   2006-01-19 
15:21:01 UTC (rev 55786)
+++ branches/mono-1-1-13/mcs/ilasm/tests/test-module-cattr.il   2006-01-19 
15:26:09 UTC (rev 55787)
@@ -0,0 +1,60 @@
+// Test for custom attributes on this .module
+
+.assembly extern mscorlib
+{
+  .ver 1:0:5000:0
+}
+.assembly extern System
+{
+  .ver 1:0:5000:0
+}
+.assembly 'test-module-cattr'
+{
+  .ver  0:0:0:0
+}
+.module 'test-module-cattr.exe'
+
+.custom instance void class 
[System]System.ComponentModel.DescriptionAttribute::.ctor(string) =  (01 00 0A 
53 6F 6D 65 4D 6F 64 75 6C 65 00 00 ) // ...SomeModule..
+
+
+  .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 static  hidebysig 
+           default void Main ()  cil managed 
+    {
+       .entrypoint
+       .maxstack 7
+       .locals init (
+               class [mscorlib]System.Reflection.Module        V_0)
+       IL_0000:  ldtoken test
+       IL_0005:  call class [mscorlib]System.Type class 
[mscorlib]System.Type::GetTypeFromHandle(valuetype 
[mscorlib]System.RuntimeTypeHandle)
+       IL_000a:  callvirt instance class [mscorlib]System.Reflection.Module 
class [mscorlib]System.Type::get_Module()
+       IL_000f:  stloc.0 
+       IL_0010:  ldloc.0 
+       IL_0011:  call class [mscorlib]System.Attribute[] class 
[mscorlib]System.Attribute::GetCustomAttributes(class 
[mscorlib]System.Reflection.Module)
+       IL_0016:  ldlen 
+       IL_0017:  conv.i4 
+       IL_0018:  ldc.i4.1 
+       IL_0019:  bne.un IL_002d
+
+       IL_001e:  ldstr "OK"
+       IL_0023:  call void class [mscorlib]System.Console::WriteLine(string)
+       IL_0028:  br IL_0037
+
+       IL_002d:  ldstr "Error"
+       IL_0032:  call void class [mscorlib]System.Console::WriteLine(string)
+       IL_0037:  ret 
+    }
+
+  }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to