[svn] r6195: nemerle/trunk/ncc: generation/HierarchyEmitter.n testsuite/positive/macrolib.n testsuite/posi...

malekith svnadmin at nemerle.org
Fri Apr 21 21:40:53 CEST 2006


Log:
Allow expression macros to add custom attributes.

Author: malekith
Date: Fri Apr 21 21:40:51 2006
New Revision: 6195

Modified:
   nemerle/trunk/ncc/generation/HierarchyEmitter.n
   nemerle/trunk/ncc/testsuite/positive/macrolib.n
   nemerle/trunk/ncc/testsuite/positive/macroprog.n

Modified: nemerle/trunk/ncc/generation/HierarchyEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/HierarchyEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/HierarchyEmitter.n	Fri Apr 21 21:40:51 2006
@@ -544,6 +544,8 @@
     {
       IsFinalized = true;
       
+      foreach (m is MemberBuilder in member_list) m.Compile ();
+      
       unless (GetModifiers ().IsEmpty) {
         GetModifiers ().SaveCustomAttributes (this, fun (target, a) {
           def valid = target %&& System.AttributeTargets.Class ||
@@ -556,8 +558,6 @@
         })
       }
 
-      foreach (m is MemberBuilder in member_list) m.Compile ();
-      
       //Message.Debug ("finalizing " + FullName);
       unless (Message.SeenError)
         this.FinalizeType ();

Modified: nemerle/trunk/ncc/testsuite/positive/macrolib.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macrolib.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/macrolib.n	Fri Apr 21 21:40:51 2006
@@ -11,6 +11,8 @@
   Foo () : void;
 }
 
+public class MyAttribute : Attribute  { }
+
 macro generateIFoo ()
 {
   def tb = Nemerle.Macros.ImplicitCTX ().Env.Define (<[ decl:
@@ -370,3 +372,8 @@
   def l = <[ $(1UL : ulong) ]>;
   l
 }
\ No newline at end of file
+
+macro MarkWithMy () {
+  Nemerle.Macros.ImplicitCTX().CurrentType.GetModifiers().AddCustomAttribute (<[ My ]>);
+  <[ () ]>
+}

Modified: nemerle/trunk/ncc/testsuite/positive/macroprog.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macroprog.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/macroprog.n	Fri Apr 21 21:40:51 2006
@@ -189,6 +189,14 @@
   }
 }
 
+class MyFoo
+{
+  bar () : void
+  {
+    MarkWithMy ();
+  }
+}
+
 using Nemerle.Logging;
 
 [assembly: LogCondition (LogEnabled)]
@@ -225,6 +233,8 @@
 
       def x = generateIFoo ();
       (x : IFoo).Foo();
+
+      assert (typeof(MyFoo).GetCustomAttributes (typeof(MyAttribute),false).Length > 0);
     }
 }
 



More information about the svn mailing list