[svn] r7264: nemerle/trunk/ncc: generation/HierarchyEmitter.n generation/ImplementsWrapperMaker.n generati...

nazgul svnadmin at nemerle.org
Fri Jan 12 23:19:34 CET 2007


Log:
A little APi clean up

Author: nazgul
Date: Fri Jan 12 23:19:31 2007
New Revision: 7264

Modified:
   nemerle/trunk/ncc/generation/HierarchyEmitter.n
   nemerle/trunk/ncc/generation/ImplementsWrapperMaker.n
   nemerle/trunk/ncc/generation/Typer3.n
   nemerle/trunk/ncc/hierarchy/ClassMembers.n

Modified: nemerle/trunk/ncc/generation/HierarchyEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/HierarchyEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/HierarchyEmitter.n	Fri Jan 12 23:19:31 2007
@@ -668,7 +668,7 @@
         def type_builder = declaring_type.GetTypeBuilder ();      
         assert (type_builder != null);
 
-        def mb = method_builder;
+        def mb = GetMethodInfo ();
         Util.cassert (mb != null, $"method builder is null for $this");
 
         /* update the entry point settings, if necessary */
@@ -878,19 +878,19 @@
         if (fun_header.typarms.IsEmpty) {
           def parm_types_array = param_types ();
 
-          method_builder = Manager.AttributeCompiler.CheckPInvoking (this, tb, attrs, parm_types_array);
+          method_base = Manager.AttributeCompiler.CheckPInvoking (this, tb, attrs, parm_types_array);
 
-          if (method_builder == null)
-            method_builder = tb.DefineMethod (Name, attrs);
+          if (method_base == null)
+            method_base = tb.DefineMethod (Name, attrs);
           else
             pinvoke = true;
         }
         else {
-          method_builder = tb.DefineMethod (Name, attrs);
+          method_base = tb.DefineMethod (Name, attrs);
           
           def names = fun_header.typarms.MapToArray (_.Name);
 
-          def generic_parms = method_builder.DefineGenericParameters (names);
+          def generic_parms = GetMethodInfo().DefineGenericParameters (names);
           fun_header.typarms.IterI (0, (idx, x) => x.SetGenericBuilder (generic_parms [idx]));
           foreach (gp in fun_header.typarms)
             gp.UpdateConstraints ();
@@ -902,7 +902,7 @@
           $"Can't define method '$Name' (attrs: $attrs) in type '$tb'.\nError: $(e.Message)", e);
       }
 
-      method_builder.SetSignature (
+      GetMethodInfo ().SetSignature (
         fun_header.ret_type.SystemType,
         fun_header.GetRetTypeRequiredModifiers (),
         fun_header.GetRetTypeOptionalModifiers (),
@@ -913,7 +913,7 @@
       /* add the runtime modifiers for delegate methods */
       when (DeclaringType.IsDelegate) {
         assert (!pinvoke);
-        method_builder.SetImplementationFlags (
+        GetMethodInfo ().SetImplementationFlags (
           MethodImplAttributes.Runtime | MethodImplAttributes.Managed
         )
       }
@@ -927,7 +927,7 @@
         match (parms) {
           | [] => ()
           | (p : Fun_parm) :: ps =>
-            p.builder = method_builder.DefineParameter (pos, parameter_attributes (p), p.name);
+            p.builder = GetMethodInfo ().DefineParameter (pos, parameter_attributes (p), p.name);
 
             match (p.default_value) {
               | Some (TExpr.Literal (lit)) => p.builder.SetConstant (lit.AsObject (InternalType));
@@ -948,7 +948,7 @@
       // Message.Debug ($"-- AddConstructorBuilder: $this");
 
       /* create the constructor builder */
-      ctor_builder =
+      method_base =
         tb.DefineConstructor (
           make_method_attributes (Attributes) |
           MethodAttributes.RTSpecialName |
@@ -960,7 +960,7 @@
 
       /* add the runtime modifiers for delegate constructors */
       when (DeclaringType.IsDelegate) {
-        ctor_builder.SetImplementationFlags (
+        GetConstructorInfo ().SetImplementationFlags (
           MethodImplAttributes.Runtime | MethodImplAttributes.Managed
         )
       }
@@ -969,7 +969,7 @@
         match (parms) {
           | [] => ()
           | (p : Fun_parm) :: ps =>
-            p.builder = ctor_builder.DefineParameter (pos, parameter_attributes (p), p.name);
+            p.builder = GetConstructorInfo ().DefineParameter (pos, parameter_attributes (p), p.name);
 
             match (p.default_value) {
               | Some (TExpr.Literal (lit)) => p.builder.SetConstant (lit.AsObject (InternalType));
@@ -991,7 +991,7 @@
           if (fun_kind is FunKind.Constructor) 
             fun (target, attribute) {
               if (target %&& System.AttributeTargets.Method) {
-                ctor_builder.SetCustomAttribute (attribute);
+                GetConstructorInfo ().SetCustomAttribute (attribute);
                 null
               }
               else "constructor " + ToString ()
@@ -999,7 +999,7 @@
           else
             fun (target, a) {
               if (target %&& System.AttributeTargets.Method) {
-                method_builder.SetCustomAttribute (a);
+                GetMethodInfo ().SetCustomAttribute (a);
                 null
               }
               else "method " + ToString ()
@@ -1121,8 +1121,8 @@
         if (getter == null)
           (null, null)
         else
-          ( (getter :> MethodBuilder).fun_header.GetRetTypeRequiredModifiers (),
-            (getter :> MethodBuilder).fun_header.GetRetTypeOptionalModifiers () )
+          ( (getter :> MethodBuilder).Header.GetRetTypeRequiredModifiers (),
+            (getter :> MethodBuilder).Header.GetRetTypeOptionalModifiers () )
       }
 
       def (param_type_req_mods, param_type_opt_mods) = {
@@ -1133,8 +1133,8 @@
         else
         {
           def chop (a) { if (a == null) null else a.ChopLastN (1) }
-          ( chop (setter.fun_header.GetParamTypeRequiredModifiers ()),
-            chop (setter.fun_header.GetParamTypeOptionalModifiers ()) )
+          ( chop (setter.Header.GetParamTypeRequiredModifiers ()),
+            chop (setter.Header.GetParamTypeOptionalModifiers ()) )
         }
       }
 

Modified: nemerle/trunk/ncc/generation/ImplementsWrapperMaker.n
==============================================================================
--- nemerle/trunk/ncc/generation/ImplementsWrapperMaker.n	(original)
+++ nemerle/trunk/ncc/generation/ImplementsWrapperMaker.n	Fri Jan 12 23:19:31 2007
@@ -117,7 +117,6 @@
         meth.Attributes = NemerleAttributes.Public | NemerleAttributes.Override;
       }
 
-      meth.disable_type_attr = true;
       Manager.MarkAsUsed (meth);
 
       def current_fun = meth.GetHeader ();

Modified: nemerle/trunk/ncc/generation/Typer3.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer3.n	(original)
+++ nemerle/trunk/ncc/generation/Typer3.n	Fri Jan 12 23:19:31 2007
@@ -254,7 +254,7 @@
 
 
     /** Just a shorthand for TExpr.LocalRef.  */
-    static PlainRef (decl : LocalValue) : TExpr
+    internal static PlainRef (decl : LocalValue) : TExpr
     {
       assert (decl != null);
       TExpr.LocalRef (decl.Type, decl)
@@ -417,7 +417,7 @@
     }
 
 
-    static FixType (t : TyVar, subst : Subst) : MType
+    internal static FixType (t : TyVar, subst : Subst) : MType
     {
       if (subst == null)
         t.DeepFix ()
@@ -826,7 +826,7 @@
           RewriteTryFinally (clo_type, fh);
           fh.used_closures = fh.GetParents ();
           fh.is_in_closure_of = fh.id;
-          PrepareForEmission (meth, fh, subst);
+          meth.PrepareForEmission (fh, subst);
           def child = Typer3 (this, meth);
           child.current_subst = subst;
           child.Run ();
@@ -1098,7 +1098,7 @@
     }
 
 
-    static ClosureParmCount (fn : Fun_header) : int
+    internal static ClosureParmCount (fn : Fun_header) : int
     {
       Util.cassert (fn.used_closures != null || fn.decl == null, 
                     $ "closures not computed for $(fn.name)");
@@ -1106,58 +1106,6 @@
       else fn.used_closures.Length
     }
 
-
-    static PrepareForEmission (meth : MethodBuilder, fn : Fun_header, subst : Subst) : void
-    {
-      def new_header = meth.fun_header;
-      meth.fun_header = fn;
-
-      def clo_count = ClosureParmCount (fn);
-      def new_parms = new_header.parms.ChopFirstN (clo_count);
-
-      foreach (parm in new_header.parms.FirstN (clo_count)) {
-        parm.decl = LocalValue (fn, parm.name, parm.ty, 
-                                LocalValue.Kind.Plain (),
-                                is_mutable = false);
-        parm.decl.Register ();
-        parm.decl.UseFrom (fn);
-      }
-      
-      if (new_parms.Length > 1 && fn.parms.Length == 1) {
-        match (fn.body) {
-          | FunBody.Typed (body) =>
-            def vals = new_parms.Map (fun (parm : Fun_parm) {
-              def local = LocalValue (fn, parm.name, parm.ty, 
-                                      LocalValue.Kind.Plain (), is_mutable = false);
-              local.Register ();
-              local.UseFrom (fn);
-              parm.decl = local;
-              local
-            });
-            def parm = fn.parms.Head;
-            def expr =
-              TExpr.DefValIn (body.Type,
-                              parm.decl, 
-                              TExpr.Tuple (parm.ty, vals.Map (PlainRef)),
-                              body);
-            fn.body = FunBody.Typed (expr);
-            fn.parms = new_header.parms;
-          | _ => assert (false)
-        }
-      } else {
-        List.Iter2 (fn.parms, new_parms, fun (orig, copy : Fun_parm) {
-          copy.decl = orig.decl;
-          // FIXME: is it still needed?
-          copy.ty = FixType (copy.ty, subst);
-          copy.decl.SetType (FixType (copy.decl.Type, subst));
-        });
-        fn.parms = new_header.parms;
-      }
-
-      fn.ret_type = new_header.ret_type;
-    }
-
-
     EmitStaticLocalFunction (fn : Fun_header, children : Queue [Typer3]) : void
     {
       def (new_tp, subst) = CopyFunTyparms ();
@@ -1209,7 +1157,7 @@
       def meth = CurrentType.DefineAndReturn (decl) :> MethodBuilder;
 
       fn.static_method = meth;
-      PrepareForEmission (meth, fn, subst);
+      meth.PrepareForEmission (fn, subst);
       fn.typarms_to_pass =
         accumulated_typarms.Map (fun (x) { MType.TyVarRef (x) });
 
@@ -1291,7 +1239,7 @@
       
       def the_method = SingleMemberLookup (builder, apply_name) :> MethodBuilder;
 
-      PrepareForEmission (the_method, fn, subst);
+      the_method.PrepareForEmission (fn, subst);
 
       def child = Typer3 (this, the_method);
       child.closure_fields = clo_fields;
@@ -1869,4 +1817,56 @@
     #endregion
 
   }
+  
+  public partial class MethodBuilder {
+    internal PrepareForEmission (fn : Fun_header, subst : Subst) : void
+    {
+      def new_header = fun_header;
+      fun_header = fn;
+
+      def clo_count = Typer3.ClosureParmCount (fn);
+      def new_parms = new_header.parms.ChopFirstN (clo_count);
+
+      foreach (parm in new_header.parms.FirstN (clo_count)) {
+        parm.decl = LocalValue (fn, parm.name, parm.ty, 
+                                LocalValue.Kind.Plain (),
+                                is_mutable = false);
+        parm.decl.Register ();
+        parm.decl.UseFrom (fn);
+      }
+      
+      if (new_parms.Length > 1 && fn.parms.Length == 1) {
+        match (fn.body) {
+          | FunBody.Typed (body) =>
+            def vals = new_parms.Map (fun (parm : Fun_parm) {
+              def local = LocalValue (fn, parm.name, parm.ty, 
+                                      LocalValue.Kind.Plain (), is_mutable = false);
+              local.Register ();
+              local.UseFrom (fn);
+              parm.decl = local;
+              local
+            });
+            def parm = fn.parms.Head;
+            def expr =
+              TExpr.DefValIn (body.Type,
+                              parm.decl, 
+                              TExpr.Tuple (parm.ty, vals.Map (Typer3.PlainRef)),
+                              body);
+            fn.body = FunBody.Typed (expr);
+            fn.parms = new_header.parms;
+          | _ => assert (false)
+        }
+      } else {
+        List.Iter2 (fn.parms, new_parms, fun (orig, copy : Fun_parm) {
+          copy.decl = orig.decl;
+          // FIXME: is it still needed?
+          copy.ty = Typer3.FixType (copy.ty, subst);
+          copy.decl.SetType (Typer3.FixType (copy.decl.Type, subst));
+        });
+        fn.parms = new_header.parms;
+      }
+
+      fn.ret_type = new_header.ret_type;
+    }
+  }
 }

Modified: nemerle/trunk/ncc/hierarchy/ClassMembers.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ClassMembers.n	(original)
+++ nemerle/trunk/ncc/hierarchy/ClassMembers.n	Fri Jan 12 23:19:31 2007
@@ -79,10 +79,12 @@
 
   protected mutable m_has_been_used : bool;
 
-  internal mutable disable_type_attr : bool;
+  //internal mutable disable_type_attr : bool;
 
-  public mutable required_modifiers : list[System.Type] = [];
-  public mutable optional_modifiers : list[System.Type] = [];
+  [Accessor (flags = WantSetter)]
+  protected mutable required_modifiers : list[System.Type] = [];
+  [Accessor (flags = WantSetter)]
+  protected mutable optional_modifiers : list[System.Type] = [];
   public Env : GlobalEnv;
   
   protected this (par : TypeBuilder, ast : PT.ClassMember)
@@ -755,11 +757,12 @@
 public partial class MethodBuilder : MemberBuilder, IMethod
 {
   mutable fun_kind : FunKind;
-  // FIXME: make these private
-  public mutable fun_header : Fun_header;
   
-  public mutable method_builder : SRE.MethodBuilder;
-  public mutable ctor_builder : SRE.ConstructorBuilder;
+  [Accessor (Header)]
+  mutable fun_header : Fun_header;
+
+  /// system reflection emit method/constructor builder is stored here
+  mutable method_base : SR.MethodBase;
 
   internal mutable overridden_method : IMethod;
   
@@ -782,13 +785,8 @@
 
   public GetMethodBase () : SR.MethodBase
   {
-    def res =
-      if (method_builder == null)
-        ctor_builder
-      else
-        method_builder;
-    assert (res != null);
-    res
+    assert (method_base != null);
+    method_base
   }
 
   public override GetHandle () : SR.MemberInfo
@@ -803,14 +801,14 @@
   
   public GetConstructorInfo () : SRE.ConstructorBuilder 
   {
-    assert (ctor_builder != null);
-    ctor_builder
+    assert (method_base != null && method_base.IsConstructor);
+    method_base :> SRE.ConstructorBuilder 
   }
   
   public GetMethodInfo () : SRE.MethodBuilder
   {
-    assert (method_builder != null, declaring_type.FullName + "." + Name);
-    method_builder
+    assert (method_base != null && !method_base.IsConstructor, declaring_type.FullName + "." + Name);
+    method_base :> SRE.MethodBuilder
   }
 
   public override HasBeenUsed : bool



More information about the svn mailing list