From: Martin Baulig Date: Thu, 18 Nov 2004 05:58:47 +0000 (-0000) Subject: 2004-11-18 Martin Baulig X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=e6f4c7973096202b36fa4e3083a5de6562b1205a;p=mono.git 2004-11-18 Martin Baulig * 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 --- diff --git a/mcs/gmcs/ChangeLog b/mcs/gmcs/ChangeLog index 8f44ae7df28..9d5f4bc575e 100755 --- a/mcs/gmcs/ChangeLog +++ b/mcs/gmcs/ChangeLog @@ -1,3 +1,20 @@ +2004-11-18 Martin Baulig + + * 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 * decl.cs diff --git a/mcs/gmcs/ecore.cs b/mcs/gmcs/ecore.cs index 65ff6a732a6..de6c2452a2e 100755 --- a/mcs/gmcs/ecore.cs +++ b/mcs/gmcs/ecore.cs @@ -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; diff --git a/mcs/gmcs/generic.cs b/mcs/gmcs/generic.cs index 95aa1808111..775c008ca1e 100644 --- a/mcs/gmcs/generic.cs +++ b/mcs/gmcs/generic.cs @@ -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)