[svn] r6496: nemerle/trunk/ncc: external/InternalTypes.n external/LibrariesLoader.n generation/HierarchyEm...

nazgul svnadmin at nemerle.org
Tue Aug 8 23:43:47 CEST 2006


Log:
Change implementation of fix for 731. Also do not support optional attribute when declared in custom attributes - we force the correct way of defining default value for optional parameters

Author: nazgul
Date: Tue Aug  8 23:42:58 2006
New Revision: 6496

Modified:
   nemerle/trunk/ncc/external/InternalTypes.n
   nemerle/trunk/ncc/external/LibrariesLoader.n
   nemerle/trunk/ncc/generation/HierarchyEmitter.n
   nemerle/trunk/ncc/typing/TypedTree.n
   nemerle/trunk/ncc/typing/Typer-CallTyper.n

Modified: nemerle/trunk/ncc/external/InternalTypes.n
==============================================================================
--- nemerle/trunk/ncc/external/InternalTypes.n	(original)
+++ nemerle/trunk/ncc/external/InternalTypes.n	Tue Aug  8 23:42:58 2006
@@ -446,6 +446,7 @@
   public mutable ValueType : MType.Class;
   public mutable MatchFailureException : MType.Class;
   public mutable IObjectReference : MType.Class;  
+  public mutable Reflection_Missing : MType.Class;
 
   public mutable Delegate_Combine : IMethod;
   public mutable Delegate_Remove : IMethod;
@@ -587,6 +588,7 @@
     DllImport_tc = lookup ("System.Runtime.InteropServices.DllImportAttribute");
     Serializable_tc = lookup ("System.SerializableAttribute");    
     IObjectReference = MType.Class (lookup ("System.Runtime.Serialization.IObjectReference"), []);
+    Reflection_Missing = MType.Class (lookup ("System.Reflection.Missing"), []);
     
     ParamArrayAttribute_tc = lookup ("System.ParamArrayAttribute");
     FlagsAttribute_tc = lookup ("System.FlagsAttribute");

Modified: nemerle/trunk/ncc/external/LibrariesLoader.n
==============================================================================
--- nemerle/trunk/ncc/external/LibrariesLoader.n	(original)
+++ nemerle/trunk/ncc/external/LibrariesLoader.n	Tue Aug  8 23:42:58 2006
@@ -1882,10 +1882,17 @@
             modifiers = Modifiers.Empty // FIXME?
           );
           def deflt = p.DefaultValue;
-          when (p.IsOptional)
-            fp.is_optional = true;
-          when (deflt != System.DBNull.Value && deflt != System.Reflection.Missing.Value)
-            fp.default_value = Some (Literal.FromObject (deflt));
+          when (deflt != System.DBNull.Value) {
+            fp.default_value = 
+              if (deflt != System.Reflection.Missing.Value) {
+                def lit = Literal.FromObject (deflt);
+                Some (TExpr.Literal (ty, lit));
+              }
+              else {
+                assert (InternalType.Object.Equals (ty));
+                Some (TExpr.StaticRef (ty, InternalType.Reflection_Missing, InternalType.Reflection_Missing.tycon.LookupMember ("Value").Head, []))
+              }
+          }
           fp
         };
         def ret_type =

Modified: nemerle/trunk/ncc/generation/HierarchyEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/HierarchyEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/HierarchyEmitter.n	Tue Aug  8 23:42:58 2006
@@ -932,7 +932,8 @@
             p.builder = method_builder.DefineParameter (pos, parameter_attributes (p), p.name);
 
             match (p.default_value) {
-              | Some (lit) => p.builder.SetConstant (lit.AsObject ());
+              | Some (TExpr.Literal (lit)) => p.builder.SetConstant (lit.AsObject ());
+              | Some (e) => Util.ice ($"complex expr $e");
               | None => {}
             }
             name_parms (pos + 1, ps)
@@ -973,8 +974,9 @@
             p.builder = ctor_builder.DefineParameter (pos, parameter_attributes (p), p.name);
 
             match (p.default_value) {
-              | Some (lit) => p.builder.SetConstant (lit.AsObject ());
-              | None => {}
+              | Some (TExpr.Literal (lit)) => p.builder.SetConstant (lit.AsObject ());
+              | Some (e) => Util.ice ($"complex expr $e");
+              | None => ()
             }
             name_parms (pos + 1, ps)
         }

Modified: nemerle/trunk/ncc/typing/TypedTree.n
==============================================================================
--- nemerle/trunk/ncc/typing/TypedTree.n	(original)
+++ nemerle/trunk/ncc/typing/TypedTree.n	Tue Aug  8 23:42:58 2006
@@ -52,10 +52,7 @@
     public mutable required_modifiers : list[System.Type] = [];
     public mutable optional_modifiers : list[System.Type] = [];
 
-    public mutable is_optional : bool = false;
-    public mutable default_value : option [Literal] = None ();
-    // for local functions only
-    mutable local_default_value : option [TExpr] = None ();
+    public mutable default_value : option [TExpr] = None ();
 
     public mutable decl : LocalValue;
     public mutable builder : System.Reflection.Emit.ParameterBuilder;
@@ -99,27 +96,18 @@
       get { name }
     }
 
-    public IsOptional : bool
-    {
-      get {
-        is_optional || default_value.IsSome || local_default_value.IsSome
-      }
-    }
-
     public HasDefaultValue : bool
     {
       get {
-        default_value.IsSome || local_default_value.IsSome
+        default_value.IsSome
       }
     }
 
     public DefaultValueAsTExpr () : TExpr
     {
-      match (local_default_value) {
+      match (default_value) {
         | Some (e) => e
-        | None =>
-          def lit = Option.UnSome (default_value);
-          TExpr.Literal (Typer.TypeOfLiteral (lit), lit)
+        | None => Util.ice ("there is no default value for: " + ToString ())
       }
     }
 
@@ -129,18 +117,12 @@
       foreach (<[ System.ComponentModel.DefaultValueAttribute ($e) ]>
                in modifiers.custom_attrs)
       {
-        when (local_default_value.IsSome)
+        when (default_value.IsSome)
           Message.Error (e.loc, 
                          $ "default value specified twice for parameter "
                            "`$name'");
-        local_default_value = Some (par.TypeExpr (e, Typer.AtLeast (ty)));
-        is_optional = true;
+        default_value = Some (par.TypeExpr (e, Typer.AtLeast (ty)));
       }
-
-      // store optional flag
-      when (modifiers.custom_attrs.Exists (x => x is <[ System.Runtime.InteropServices.OptionalAttribute ]>) ||
-            modifiers.custom_attrs.Exists (x => x is <[ System.Runtime.InteropServices.OptionalAttribute () ]>))
-        is_optional = true;
     }
     
     internal GetDefaultValueFromModifiers (par : TypeBuilder) : void
@@ -192,8 +174,7 @@
                 }
               else lit;
               
-            default_value = Some (lit);
-            is_optional = true;
+            default_value = Some (TExpr.Literal (Typer.TypeOfLiteral (lit), lit));
             
           | _ =>
             Message.Error (e.loc,
@@ -208,11 +189,6 @@
           | <[ System.ComponentModel.DefaultValueAttribute ($_) ]> => false
           | _ => true
         });
-
-      // store optional flag
-      when (modifiers.custom_attrs.Exists (x => x is <[ System.Runtime.InteropServices.OptionalAttribute ]>) ||
-            modifiers.custom_attrs.Exists (x => x is <[ System.Runtime.InteropServices.OptionalAttribute () ]>))
-        is_optional = true;
     }
 
 

Modified: nemerle/trunk/ncc/typing/Typer-CallTyper.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-CallTyper.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-CallTyper.n	Tue Aug  8 23:42:58 2006
@@ -354,7 +354,7 @@
           ! is_var_args &&
           header != null && 
           header.parms.Length > call_parms.Length &&
-          header.parms.Exists (fun (fp) { fp.IsOptional });
+          header.parms.Exists (fun (fp) { fp.HasDefaultValue });
 
         when (has_named || need_default)
           if (header == null)
@@ -485,7 +485,7 @@
                   seen_named_parms.Contains (fp.name) || 
                   seen_unnamed_parms.Contains (fp.name);
                 if (seen) false
-                else if (fp.IsOptional) {
+                else if (fp.HasDefaultValue) {
                   used_default_parms = true;
                   use_defaults_for [fp.name] = fp;
                   false
@@ -548,15 +548,7 @@
               reorder_parms (rest_of_names,
                              Option.UnSome (seen_named_parms.Get (name)) :: acc)
             else if (use_defaults_for.Contains (name)) {
-              def expr =
-                if (fp.HasDefaultValue) {
-                  fp.DefaultValueAsTExpr ();
-                } else {
-                  if (fp.ty.Fix ().Equals (InternalType.Object))
-                    typer.TypeExpr (<[ System.Reflection.Missing.Value ]>)
-                  else
-                    TExpr.DefaultValue (FreshTyVar ())
-                }
+              def expr = fp.DefaultValueAsTExpr ();
               reorder_parms (rest_of_names, Parm (expr) :: acc)
             } else
               Util.ice ("reorder_named_parms: reorder")



More information about the svn mailing list