Author: martin
Date: 2005-04-14 01:01:06 -0400 (Thu, 14 Apr 2005)
New Revision: 42980
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/class.cs
trunk/mcs/gmcs/decl.cs
trunk/mcs/gmcs/delegate.cs
trunk/mcs/gmcs/ecore.cs
trunk/mcs/gmcs/expression.cs
trunk/mcs/gmcs/generic.cs
Log:
2005-04-14 Martin Baulig <[EMAIL PROTECTED]>
* generic.cs (ConstructedType): Moved all the type lookup and
nested class logic into SimpleName.
(ConstructedType.ResolveConstructedType): Our underlying type is
already fully resolved; all the type lookup stuff is in
SimpleName.
* ecore.cs (SimpleName.ResolveAsTypeStep): Resolve nested
constructed types here instead of in ConstructedType.
* decl.cs (MemberName.GetTypeExpression): Always create a
SimpleName, not a ConstructedType.
(DeclSpace.ResolveNestedType): Removed; this is now in SimpleName.
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-14 05:01:06 UTC (rev 42980)
@@ -1,3 +1,18 @@
+2005-04-14 Martin Baulig <[EMAIL PROTECTED]>
+
+ * generic.cs (ConstructedType): Moved all the type lookup and
+ nested class logic into SimpleName.
+ (ConstructedType.ResolveConstructedType): Our underlying type is
+ already fully resolved; all the type lookup stuff is in
+ SimpleName.
+
+ * ecore.cs (SimpleName.ResolveAsTypeStep): Resolve nested
+ constructed types here instead of in ConstructedType.
+
+ * decl.cs (MemberName.GetTypeExpression): Always create a
+ SimpleName, not a ConstructedType.
+ (DeclSpace.ResolveNestedType): Removed; this is now in SimpleName.
+
2005-03-02 Martin Baulig <[EMAIL PROTECTED]>
* class.cs (TypeContainer.DoDefineMembers): We also need a default
Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/class.cs 2005-04-14 05:01:06 UTC (rev 42980)
@@ -1237,7 +1237,7 @@
TypeManager.AddUserType (Name, TypeBuilder, this);
- TypeExpr current_type = null;
+ Expression current_type = null;
if (IsGeneric) {
string[] param_names = new string
[TypeParameters.Length];
@@ -1261,7 +1261,7 @@
for (int i = offset; i < gen_params.Length; i++)
CurrentTypeParameters [i -
offset].DefineConstraints ();
- current_type = new ConstructedType (Name,
TypeParameters, Location);
+ current_type = new SimpleName (Name,
TypeParameters, Location);
foreach (TypeParameter type_param in
TypeParameters) {
if (!type_param.DefineType (ec)) {
@@ -4937,29 +4937,6 @@
this.parent_method = parent_method;
}
- static string RemoveArity (string name)
- {
- int start = 0;
- StringBuilder sb = new StringBuilder ();
- while (start < name.Length) {
- int pos = name.IndexOf ('`', start);
- if (pos < 0) {
- sb.Append (name.Substring (start));
- break;
- }
-
- sb.Append (name.Substring (start, pos-start));
-
- pos++;
- while ((pos < name.Length) && Char.IsNumber
(name [pos]))
- pos++;
-
- start = pos;
- }
-
- return sb.ToString ();
- }
-
public bool Define (TypeContainer container)
{
MethodInfo implementing = null;
Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/decl.cs 2005-04-14 05:01:06 UTC (rev 42980)
@@ -157,7 +157,7 @@
return new MemberAccess (lexpr, Name,
TypeArguments, loc);
} else {
if (TypeArguments != null)
- return new ConstructedType (Name,
TypeArguments, loc);
+ return new SimpleName (Basename,
TypeArguments, loc);
else
return new SimpleName (Name, loc);
}
@@ -711,32 +711,6 @@
EmitContext type_resolve_ec;
- public FullNamedExpression ResolveNestedType
(FullNamedExpression t, Location loc)
- {
- TypeContainer tc = TypeManager.LookupTypeContainer
(t.Type);
- if ((tc != null) && tc.IsGeneric) {
- if (!IsGeneric) {
- int tnum =
TypeManager.GetNumberOfTypeArguments (t.Type);
- Report.Error (305, loc,
- "Using the generic type
`{0}' " +
- "requires {1} type
arguments",
- TypeManager.GetFullName
(t.Type), tnum);
- return null;
- }
-
- TypeParameter[] args;
- if (this is GenericMethod)
- args = Parent.TypeParameters;
- else
- args = TypeParameters;
-
- TypeExpr ctype = new ConstructedType (t.Type,
args, loc);
- return ctype.ResolveAsTypeTerminal (ec);
- }
-
- return t;
- }
-
// <summary>
// Resolves the expression `e' for a type, and will
recursively define
// types. This should only be used for resolving base types.
@@ -1124,7 +1098,7 @@
return null;
if ((t != null) &&
containing_ds.CheckAccessLevel (t.Type))
- return ResolveNestedType (t,
loc);
+ return t;
current_type = current_type.BaseType;
}
@@ -1235,7 +1209,6 @@
}
e = new TypeExpression (t,
Location.Null);
- e = ResolveNestedType (e,
Location.Null);
Cache [name] = e;
return e;
}
@@ -1251,7 +1224,6 @@
Type t = TypeManager.LookupType
(current_type.FullName + "." + name);
if (t != null){
e = new TypeExpression
(t, Location.Null);
- e = ResolveNestedType
(e, Location.Null);
Cache [name] = e;
return e;
}
Modified: trunk/mcs/gmcs/delegate.cs
===================================================================
--- trunk/mcs/gmcs/delegate.cs 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/delegate.cs 2005-04-14 05:01:06 UTC (rev 42980)
@@ -139,7 +139,7 @@
for (int i = offset; i < gen_params.Length; i++)
CurrentTypeParameters [i -
offset].DefineConstraints ();
- TypeExpr current = new ConstructedType (Name,
TypeParameters, Location);
+ Expression current = new SimpleName (Name,
TypeParameters, Location);
current = current.ResolveAsTypeTerminal (ec);
if (current == null)
return null;
Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/ecore.cs 2005-04-14 05:01:06 UTC (rev 42980)
@@ -2039,6 +2039,44 @@
loc = l;
}
+ public SimpleName (string name, TypeParameter[] type_params,
Location l)
+ {
+ Name = name;
+ loc = l;
+
+ Arguments = new TypeArguments (l);
+ foreach (TypeParameter type_param in type_params)
+ Arguments.Add (new TypeParameterExpr
(type_param, l));
+ }
+
+ public static string RemoveGenericArity (string name)
+ {
+ int start = 0;
+ StringBuilder sb = new StringBuilder ();
+ while (start < name.Length) {
+ int pos = name.IndexOf ('`', start);
+ if (pos < 0) {
+ sb.Append (name.Substring (start));
+ break;
+ }
+
+ sb.Append (name.Substring (start, pos-start));
+
+ pos++;
+ while ((pos < name.Length) && Char.IsNumber
(name [pos]))
+ pos++;
+
+ start = pos;
+ }
+
+ return sb.ToString ();
+ }
+
+ public SimpleName GetMethodGroup ()
+ {
+ return new SimpleName (RemoveGenericArity (Name),
Arguments, loc);
+ }
+
public static void Error_ObjectRefRequired (EmitContext ec,
Location l, string name)
{
if (ec.IsFieldInitializer)
@@ -2087,6 +2125,60 @@
return SimpleNameResolve (ec, null, true, intermediate);
}
+ private bool IsNestedChild (Type t, Type parent)
+ {
+ if (parent == null)
+ return false;
+
+ while (parent != null) {
+ if (parent.IsGenericInstance)
+ parent =
parent.GetGenericTypeDefinition ();
+
+ if (TypeManager.IsNestedChildOf (t, parent))
+ return true;
+
+ parent = parent.BaseType;
+ }
+
+ return false;
+ }
+
+ FullNamedExpression ResolveNested (EmitContext ec, Type t)
+ {
+ if (!t.IsGenericTypeDefinition)
+ return null;
+
+ DeclSpace ds = ec.DeclSpace;
+ while (ds != null) {
+ if (IsNestedChild (t, ds.TypeBuilder))
+ break;
+
+ ds = ds.Parent;
+ }
+
+ if (ds == null)
+ return null;
+
+ Type[] gen_params = t.GetGenericArguments ();
+
+ int arg_count = Arguments != null ? Arguments.Count : 0;
+
+ for (; (ds != null) && ds.IsGeneric; ds = ds.Parent) {
+ if (arg_count + ds.CountTypeParameters ==
gen_params.Length) {
+ TypeArguments new_args = new
TypeArguments (loc);
+ foreach (TypeParameter param in
ds.TypeParameters)
+ new_args.Add (new
TypeParameterExpr (param, loc));
+
+ if (Arguments != null)
+ new_args.Add (Arguments);
+
+ return new ConstructedType (t,
new_args, loc);
+ }
+ }
+
+ return null;
+ }
+
public override FullNamedExpression ResolveAsTypeStep
(EmitContext ec)
{
DeclSpace ds = ec.DeclSpace;
@@ -2103,6 +2195,18 @@
if (Report.Errors != errors)
return null;
+ if ((dt == null) || (dt.Type == null))
+ return dt;
+
+ FullNamedExpression nested = ResolveNested (ec,
dt.Type);
+ if (nested != null)
+ return nested.ResolveAsTypeStep (ec);
+
+ if (Arguments != null) {
+ ConstructedType ct = new ConstructedType (dt,
Arguments, loc);
+ return ct.ResolveAsTypeStep (ec);
+ }
+
return dt;
}
Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/expression.cs 2005-04-14 05:01:06 UTC (rev 42980)
@@ -4201,9 +4201,9 @@
public bool ResolveMethodGroup (EmitContext ec, Location loc)
{
- ConstructedType ctype = Expr as ConstructedType;
- if (ctype != null)
- Expr = ctype.GetSimpleName (ec);
+ SimpleName sn = Expr as SimpleName;
+ if (sn != null)
+ Expr = sn.GetMethodGroup ();
// FIXME: csc doesn't report any error if you try to
use `ref' or
// `out' in a delegate creation expression.
@@ -5268,8 +5268,9 @@
// First, resolve the expression that is used to
// trigger the invocation
//
- if (expr is ConstructedType)
- expr = ((ConstructedType) expr).GetSimpleName
(ec);
+ SimpleName sn = expr as SimpleName;
+ if (sn != null)
+ expr = sn.GetMethodGroup ();
expr = expr.Resolve (ec, ResolveFlags.VariableOrValue |
ResolveFlags.MethodGroup);
if (expr == null)
Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs 2005-04-14 04:29:45 UTC (rev 42979)
+++ trunk/mcs/gmcs/generic.cs 2005-04-14 05:01:06 UTC (rev 42980)
@@ -1047,34 +1047,16 @@
}
public class ConstructedType : TypeExpr {
- string name, full_name;
+ string full_name;
+ FullNamedExpression name;
TypeArguments args;
Type[] gen_params, atypes;
Type gt;
- public ConstructedType (string name, TypeArguments args,
Location l)
- {
- loc = l;
- this.name = MemberName.MakeName (name, args.Count);
- this.args = args;
-
- eclass = ExprClass.Type;
- full_name = name + "<" + args.ToString () + ">";
- }
-
- public ConstructedType (string name, TypeParameter[]
type_params, Location l)
- : this (type_params, l)
- {
- loc = l;
-
- this.name = name;
- full_name = name + "<" + args.ToString () + ">";
- }
-
public ConstructedType (FullNamedExpression fname,
TypeArguments args, Location l)
{
loc = l;
- this.name = fname.FullName;
+ this.name = fname;
this.args = args;
eclass = ExprClass.Type;
@@ -1105,7 +1087,7 @@
{
gt = t.GetGenericTypeDefinition ();
- this.name = gt.FullName;
+ this.name = new TypeExpression (gt, l);
full_name = gt.FullName + "<" + args.ToString () + ">";
}
@@ -1114,7 +1096,7 @@
{
gt = t.GetGenericTypeDefinition ();
- this.name = gt.FullName;
+ this.name = new TypeExpression (gt, l);
full_name = gt.FullName + "<" + args.ToString () + ">";
}
@@ -1308,37 +1290,11 @@
if (gt != null)
return DoResolveType (ec);
- //
- // First, resolve the generic type.
- //
- DeclSpace ds;
- Type nested = ec.DeclSpace.FindNestedType (loc, name,
out ds);
- if (nested != null) {
- gt = nested.GetGenericTypeDefinition ();
-
- TypeArguments new_args = new TypeArguments
(loc);
- if (ds.IsGeneric) {
- foreach (TypeParameter param in
ds.TypeParameters)
- new_args.Add (new
TypeParameterExpr (param, loc));
- }
- new_args.Add (args);
-
- args = new_args;
- return DoResolveType (ec);
- }
-
- Type t;
int num_args;
+ Type t = name.Type;
- SimpleName sn = new SimpleName (name, loc);
- TypeExpr resolved = sn.ResolveAsTypeTerminal (ec);
- if (resolved == null)
- return false;
-
- t = resolved.Type;
if (t == null) {
- Report.Error (246, loc, "Cannot find type
`{0}'<...>",
- Basename);
+ Report.Error (246, loc, "Cannot find type
`{0}'<...>", Name);
return false;
}
@@ -1384,7 +1340,7 @@
public Expression GetSimpleName (EmitContext ec)
{
- return new SimpleName (Basename, args, loc);
+ return this;
}
public override bool CheckAccessLevel (DeclSpace ds)
@@ -1430,16 +1386,6 @@
return base.GetHashCode ();
}
- public string Basename {
- get {
- int pos = name.LastIndexOf ('`');
- if (pos >= 0)
- return name.Substring (0, pos);
- else
- return name;
- }
- }
-
public override string Name {
get {
return full_name;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches