[svn] r6170: nemerle/trunk: macros/DesignPatterns.n macros/core.n snippets/designpatt/proxy-p.n

nazgul svnadmin at nemerle.org
Mon Apr 3 18:05:07 CEST 2006


Log:
Make DesignPatterns.ProxyPublicMembers skip constructors and use the same inclusion parametrization as Record macro

Author: nazgul
Date: Mon Apr  3 18:05:05 2006
New Revision: 6170

Modified:
   nemerle/trunk/macros/DesignPatterns.n
   nemerle/trunk/macros/core.n
   nemerle/trunk/snippets/designpatt/proxy-p.n

Modified: nemerle/trunk/macros/DesignPatterns.n
==============================================================================
--- nemerle/trunk/macros/DesignPatterns.n	(original)
+++ nemerle/trunk/macros/DesignPatterns.n	Mon Apr  3 18:05:05 2006
@@ -32,8 +32,10 @@
 {
   [Nemerle.MacroUsage (Nemerle.MacroPhase.WithTypedMembers,
                        Nemerle.MacroTargets.Field)]
-  macro ProxyPublicMembers (t : TypeBuilder, f : FieldBuilder)
+  macro ProxyPublicMembers (t : TypeBuilder, f : FieldBuilder, params options : list [PExpr])
   {
+    def inclusion_regexs = MacrosHelper.AnalyseNameInclusionPatterns (options);
+    
     def classty = match (f.GetMemType()) {
       | Class (typeinfo, _) => typeinfo
       | _ => Message.FatalError ("expected simple class type")
@@ -44,6 +46,7 @@
       // create Name object for name of created object
       def member_name = t.ParsedName.NewName (mem.Name);
       
+      when (!mem.Name.Equals (".ctor") && MacrosHelper.NameMatchesPatterns (mem.Name, inclusion_regexs))
       match (mem) {
         | meth is IMethod
           // we must avoid property method here, a little bit hacking solution

Modified: nemerle/trunk/macros/core.n
==============================================================================
--- nemerle/trunk/macros/core.n	(original)
+++ nemerle/trunk/macros/core.n	Mon Apr  3 18:05:05 2006
@@ -555,7 +555,7 @@
     def instance_flags = BindingFlags.Instance %| BindingFlags.Public %| 
       BindingFlags.NonPublic %| BindingFlags.DeclaredOnly;
 
-    def inclusion_regexs = MacrosHelper.AnalyseRecordFieldsPatterns (options);
+    def inclusion_regexs = MacrosHelper.AnalyseNameInclusionPatterns (options);
       
     def make_ctor (is_value_type, base_ctor : IMethod) {
       def (ctor_parms, base_call) =
@@ -575,7 +575,7 @@
       def flds = par.GetFields (instance_flags);
 
       def collect (mem : IField, acc) {
-        if (MacrosHelper.FieldNameMatchesPatterns (mem.Name, inclusion_regexs)) {
+        if (MacrosHelper.NameMatchesPatterns (mem.Name, inclusion_regexs)) {
           def n = Macros.UseSiteSymbol (mem.Name);
           def fp = <[ parameter: $(n : name) : $(mem.GetMemType () : typed) ]>;
           def ex = <[ this.$(n : name) = $(n : name) ]>;
@@ -626,7 +626,7 @@
 
   
   module MacrosHelper {
-    public AnalyseRecordFieldsPatterns (options : list [PT.PExpr]) : Regex * Regex
+    public AnalyseNameInclusionPatterns (options : list [PT.PExpr]) : Regex * Regex
     {
       mutable inclusion = null;
       mutable exclusion = null;
@@ -644,12 +644,12 @@
           exclusion = Regex (regexp)
           
         | e =>
-          Message.Error (e.Location, $"unsupported argument `$e' in Record macro, please specify 'Include/Exclude = [name1,name2]/pattern")
+          Message.Error (e.Location, $"unsupported argument `$e' in macro, please specify 'Include/Exclude = [name1,name2]/pattern")
       }
       (inclusion, exclusion)
     }
     
-    public FieldNameMatchesPatterns (name : string, patterns : Regex * Regex) : bool
+    public NameMatchesPatterns (name : string, patterns : Regex * Regex) : bool
     {
       def (inclusion, exclusion) = patterns;
       (inclusion == null || inclusion.Match (name).Success) && 

Modified: nemerle/trunk/snippets/designpatt/proxy-p.n
==============================================================================
--- nemerle/trunk/snippets/designpatt/proxy-p.n	(original)
+++ nemerle/trunk/snippets/designpatt/proxy-p.n	Mon Apr  3 18:05:05 2006
@@ -64,10 +64,23 @@
   public Gene ['b] (x : 'b) : 'b { x }
 }
 
+class Constructed {
+   foo : int;
+  
+   public Foo : int {
+     get { foo }
+   } 
+   
+   public this () { foo = 4; }
+}
+
 [Record]
 class BubbaExtend ['a] {
   [Nemerle.DesignPatterns.ProxyPublicMembers ()]
   my_bubba : Bubba ['a];
+  
+  [Nemerle.DesignPatterns.ProxyPublicMembers ()]
+  my_constructed : Constructed;
 }
 
 /// <summary>
@@ -87,10 +100,11 @@
     Console.WriteLine( "4 / 2 = {0}", p.Div( 4.0, 2.0 ) );
 
     // ProxyPublicMembers macro test
-    def x = BubbaExtend (Bubba.Foo("a"));
+    def x = BubbaExtend (Bubba.Foo("a"), Constructed());
     _ = x.Length;
     _ = x.Fire (1);
     _ = x.Gene (1);
+    _ = x.Foo;
   }
 }
 



More information about the svn mailing list