2004-11-18 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Thu, 18 Nov 2004 05:58:47 +0000 (05:58 -0000)
committerMartin Baulig <martin@novell.com>
Thu, 18 Nov 2004 05:58:47 +0000 (05:58 -0000)
* generic.cs (Constraints.Resolve): Take an `EmitContext' instead
of a `DeclSpace'.  If one of our constraints is a `ConstructedType',
call ResolveConstructedType() on it to resolve it without checking
constraints.
(Constraints.ResolveTypes): Check them here.
(ConstructedType.DoResolveAsTypeStep): Fully resolve ourselves,
but don't check constraints.
(ConstructedType.ResolveAsTypeTerminal): Override this and also
check constraints here.
(ConstructedType.ResolveConstructedType): New public method.  This
is called from DoResolveAsTypeStep() and Constraints.Resolve() to
resolve ourselves without checking constraints.

* ecore.cs (Expression.ResolveAsTypeTerminal): Make this virtual.

svn path=/trunk/mcs/; revision=36245

mcs/gmcs/ChangeLog
mcs/gmcs/ecore.cs
mcs/gmcs/generic.cs

index 8f44ae7df2860d0618ce15de008f983e321b623d..9d5f4bc575ec3d7d08e92c65ce9e33c8e06b5453 100755 (executable)
@@ -1,3 +1,20 @@
+2004-11-18  Martin Baulig  <martin@ximian.com>
+
+       * generic.cs (Constraints.Resolve): Take an `EmitContext' instead
+       of a `DeclSpace'.  If one of our constraints is a `ConstructedType',
+       call ResolveConstructedType() on it to resolve it without checking
+       constraints.
+       (Constraints.ResolveTypes): Check them here.
+       (ConstructedType.DoResolveAsTypeStep): Fully resolve ourselves,
+       but don't check constraints.
+       (ConstructedType.ResolveAsTypeTerminal): Override this and also
+       check constraints here.
+       (ConstructedType.ResolveConstructedType): New public method.  This
+       is called from DoResolveAsTypeStep() and Constraints.Resolve() to
+       resolve ourselves without checking constraints.
+
+       * ecore.cs (Expression.ResolveAsTypeTerminal): Make this virtual.
+
 2004-11-18  Martin Baulig  <martin@ximian.com>
 
        * decl.cs
index 65ff6a732a60174cea055c0c5e6fd3d7881d80c0..de6c2452a2ec26da550a438ba266a930ca9be534 100755 (executable)
@@ -270,7 +270,7 @@ namespace Mono.CSharp {
                // value will be returned if the expression is not a type
                // reference
                //
-               public TypeExpr ResolveAsTypeTerminal (EmitContext ec)
+               public virtual TypeExpr ResolveAsTypeTerminal (EmitContext ec)
                {
                        int errors = Report.Errors;
 
index 95aa1808111ab5bfb8175db5f5a4ffdf993be02d..775c008ca1eae748e3ea7a474576f8621ed5f681 100644 (file)
@@ -153,8 +153,10 @@ namespace Mono.CSharp {
                Type[] iface_constraint_types;
                Type effective_base_type;
 
-               public bool Resolve (DeclSpace ds)
+               public bool Resolve (EmitContext ec)
                {
+                       DeclSpace ds = ec.DeclSpace;
+
                        iface_constraints = new ArrayList ();
                        type_param_constraints = new ArrayList ();
 
@@ -195,7 +197,15 @@ namespace Mono.CSharp {
                                        continue;
                                }
 
-                               TypeExpr expr = ds.ResolveTypeExpr ((Expression) obj, loc);
+                               TypeExpr expr;
+                               if (obj is ConstructedType) {
+                                       ConstructedType cexpr = (ConstructedType) obj;
+                                       if (!cexpr.ResolveConstructedType (ec))
+                                               return false;
+                                       expr = cexpr;
+                               } else
+                                       expr = ((Expression) obj).ResolveAsTypeTerminal (ec);
+
                                if (expr == null)
                                        return false;
 
@@ -260,6 +270,15 @@ namespace Mono.CSharp {
 
                public bool ResolveTypes (EmitContext ec)
                {
+                       foreach (object obj in constraints) {
+                               ConstructedType cexpr = obj as ConstructedType;
+                               if (cexpr == null)
+                                       continue;
+
+                               if (!cexpr.CheckConstraints (ec))
+                                       return false;
+                       }
+
                        foreach (TypeParameterExpr expr in type_param_constraints) {
                                Hashtable seen = new Hashtable ();
                                if (!CheckTypeParameterConstraints (expr.TypeParameter, seen))
@@ -515,7 +534,7 @@ namespace Mono.CSharp {
                public bool Resolve (DeclSpace ds)
                {
                        if (constraints != null)
-                               return constraints.Resolve (ds);
+                               return constraints.Resolve (ds.EmitContext);
 
                        return true;
                }
@@ -1164,9 +1183,38 @@ namespace Mono.CSharp {
                }
 
                public override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+               {
+                       if (!ResolveConstructedType (ec))
+                               return null;
+
+                       return this;
+               }
+
+               public bool CheckConstraints (EmitContext ec)
+               {
+                       for (int i = 0; i < gen_params.Length; i++) {
+                               if (!CheckConstraints (ec, i))
+                                       return false;
+                       }
+
+                       return true;
+               }
+
+               public override TypeExpr ResolveAsTypeTerminal (EmitContext ec)
+               {
+                       if (base.ResolveAsTypeTerminal (ec) == null)
+                               return null;
+
+                       if (!CheckConstraints (ec))
+                               return null;
+
+                       return this;
+               }
+
+               public bool ResolveConstructedType (EmitContext ec)
                {
                        if (type != null)
-                               return this;
+                               return true;
                        if (gt != null)
                                return DoResolveType (ec);
 
@@ -1195,13 +1243,13 @@ namespace Mono.CSharp {
                        SimpleName sn = new SimpleName (name, loc);
                        TypeExpr resolved = sn.ResolveAsTypeTerminal (ec);
                        if (resolved == null)
-                               return null;
+                               return false;
 
                        t = resolved.Type;
                        if (t == null) {
                                Report.Error (246, loc, "Cannot find type `{0}'<...>",
                                              Basename);
-                               return null;
+                               return false;
                        }
 
                        num_args = TypeManager.GetNumberOfTypeArguments (t);
@@ -1210,20 +1258,20 @@ namespace Mono.CSharp {
                                              "The non-generic type `{0}' cannot " +
                                              "be used with type arguments.",
                                              TypeManager.CSharpName (t));
-                               return null;
+                               return false;
                        }
 
                        gt = t.GetGenericTypeDefinition ();
                        return DoResolveType (ec);
                }
 
-               TypeExpr DoResolveType (EmitContext ec)
+               bool DoResolveType (EmitContext ec)
                {
                        //
                        // Resolve the arguments.
                        //
                        if (args.Resolve (ec) == false)
-                               return null;
+                               return false;
 
                        gen_params = gt.GetGenericArguments ();
                        atypes = args.Arguments;
@@ -1234,19 +1282,14 @@ namespace Mono.CSharp {
                                              "requires {1} type arguments",
                                              TypeManager.GetFullName (gt),
                                              gen_params.Length);
-                               return null;
-                       }
-
-                       for (int i = 0; i < gen_params.Length; i++) {
-                               if (!CheckConstraints (ec, i))
-                                       return null;
+                               return false;
                        }
 
                        //
                        // Now bind the parameters.
                        //
                        type = gt.BindGenericParameters (atypes);
-                       return this;
+                       return true;
                }
 
                public Expression GetSimpleName (EmitContext ec)