+2004-04-05 Martin Baulig <martin@ximian.com>
+
+ * decl.cs (MemberCore): For generic classes, interfaces and
+ structs, `Name' now includes the number of type parameters
+ ("Stack!1.Node!1").
+ (DeclSpace.FindType): Removed the `num_type_args' argument; we now
+ encode the number of type arguments in the type name.
+
+ * expression.cs (Expression.MemberLookup): Removed the
+ `num_type_args' argument; we now encode the number of type
+ arguments in the type name.
+
+ * ecore.cs (SimpleName): Encode the number of type arguments in
+ the type name itself.
+
+ * generic.cs (ConstructedType): Likewise.
+
+ * tree.cs (Tree.RecordDecl): Take a `string' instead of a
+ `MemberName'; we now include the number of type parameters in the
+ type name.
+
+ * typemanager.cs (TypeManager.CheckGeneric): Removed.
+ (TypeManager.MemberLookup): Removed the
+ `num_type_args' argument; we now encode the number of type
+ arguments in the type name.
+
2004-04-03 Martin Baulig <martin@ximian.com>
* decl.cs (MemberCore.ctor): Take a MemberName instead of a sting.
}
TypeBuilder = builder.DefineNestedType (
- Basename, type_attributes, ptype, null);
+ MemberName.Basename, type_attributes, ptype, null);
}
TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
t = ec.ContainerType;
parent_constructor_group = Expression.MemberLookup (
- ec, t, null, t, ".ctor", 0,
+ ec, t, null, t, ".ctor",
MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc);
if (ec.ContainerType.BaseType != null) {
Expression member_lookup = Expression.MemberLookup (
ec, ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
- "Finalize", 0, MemberTypes.Method, Expression.AllBindingFlags, Location);
+ "Finalize", MemberTypes.Method, Expression.AllBindingFlags, Location);
if (member_lookup != null){
MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
new_struct = new Struct (current_namespace, current_container, full_struct_name,
(int) $2, (Attributes) $1, lexer.Location);
current_container = new_struct;
- RootContext.Tree.RecordDecl (full_struct_name, new_struct);
+ RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
lexer.ConstraintsParsing = true;
}
opt_class_base
}
current_interface = new_interface;
current_container = new_interface;
- RootContext.Tree.RecordDecl (full_interface_name, new_interface);
+ RootContext.Tree.RecordDecl (
+ full_interface_name.GetName (true), new_interface);
lexer.ConstraintsParsing = true;
}
opt_class_base
ev.identifier, loc);
}
- CheckDef (current_container.AddEnum (e), (string) full_name, enum_location);
- RootContext.Tree.RecordDecl (full_name, e);
+ string name = full_name.GetName (false);
+ CheckDef (current_container.AddEnum (e), name, enum_location);
+ RootContext.Tree.RecordDecl (name, e);
}
;
new_class = new Class (current_namespace, current_container, name, (int) $2,
(Attributes) $1, lexer.Location);
current_container = new_class;
- RootContext.Tree.RecordDecl (name, new_class);
+ RootContext.Tree.RecordDecl (name.GetName (true), new_class);
lexer.ConstraintsParsing = true;
}
return full_name;
}
- public string GetTypeName ()
+ public string GetTypeName (bool full)
{
- string full_name;
+ string suffix = "";
+ if (full && (TypeArguments != null))
+ suffix = "!" + TypeArguments.Count;
if (Left != null)
- return Left.GetFullName () + "." + Name;
+ return Left.GetTypeName (full) + "." + Name + suffix;
else
- return Name;
+ return Name + suffix;
}
public Expression GetTypeExpression (Location loc)
public static readonly MemberName Null = new MemberName ("");
- public string GetMemberName ()
+ public string Basename {
+ get {
+ if (TypeParameters != null)
+ return Name + "!" + TypeParameters.Length;
+ else
+ return Name;
+ }
+ }
+
+ public string GetName (bool is_generic)
{
- string full_name;
+ string name = is_generic ? Basename : Name;
if (TypeName != null)
- return TypeName.GetFullName () + "." + Name;
+ return TypeName.GetTypeName (is_generic) + "." + name;
else
- return Name;
+ return name;
}
- public static explicit operator string (MemberName name)
- {
- if (name.TypeName != null)
- return name.TypeName + "." + name.Name;
- else
- return name.Name;
+ public int CountTypeParameters {
+ get {
+ if (TypeParameters != null)
+ return 0;
+ else
+ return TypeParameters.Length;
+ }
}
protected string PrintTypeParams ()
public MemberCore (MemberName name, Attributes attrs, Location loc)
{
- Name = (string) name;
+ Name = name.GetName (!(this is GenericMethod) && !(this is Method));
MemberName = name;
Location = loc;
attributes = attrs;
public void RecordDecl ()
{
if ((NamespaceEntry != null) && (parent == RootContext.Tree.Types))
- NamespaceEntry.DefineName (Basename, this);
+ NamespaceEntry.DefineName (MemberName.Basename, this);
}
/// <summary>
return null;
if (e is SimpleName){
- SimpleName s = new SimpleName (((SimpleName) e).Name, -1, loc);
+ SimpleName s = new SimpleName (((SimpleName) e).Name, loc);
d = s.ResolveAsTypeTerminal (type_resolve_ec);
if ((d == null) || (d.Type == null)) {
/// during the tree resolution process and potentially define
/// recursively the type
/// </remarks>
- public Type FindType (Location loc, string name, int num_type_args)
+ public Type FindType (Location loc, string name)
{
Type t;
bool error;
if (error)
return null;
- if ((t != null) &&
- containing_ds.CheckAccessLevel (t) &&
- TypeManager.CheckGeneric (t, num_type_args))
+ if ((t != null) && containing_ds.CheckAccessLevel (t))
return t;
current_type = current_type.BaseType;
if (error)
return null;
- if ((t != null) && TypeManager.CheckGeneric (t, num_type_args))
+ if (t != null)
return t;
}
if (error)
return null;
- if ((t != null) && TypeManager.CheckGeneric (t, num_type_args))
+ if (t != null)
return t;
//
if (error)
return null;
- if ((t != null) && TypeManager.CheckGeneric (t, num_type_args))
+ if (t != null)
return t;
//
if (error)
return null;
- if ((match != null) &&
- TypeManager.CheckGeneric (match, num_type_args)) {
+ if (match != null) {
if (t != null){
if (CheckAccessLevel (match)) {
Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
t = match;
}
}
- if ((t != null) && TypeManager.CheckGeneric (t, num_type_args))
+ if (t != null)
return t;
}
if ((flags & ResolveFlags.SimpleName) == 0) {
MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
- 0, ec.DeclSpace.Name, loc);
+ ec.DeclSpace.Name, loc);
return null;
}
if (e is SimpleName){
SimpleName s = (SimpleName) e;
MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
- 0, ec.DeclSpace.Name, loc);
+ ec.DeclSpace.Name, loc);
return null;
}
public static Expression MemberLookup (EmitContext ec, Type queried_type, string name,
MemberTypes mt, BindingFlags bf, Location loc)
{
- return MemberLookup (ec, ec.ContainerType, null, queried_type, name, 0, mt, bf, loc);
+ return MemberLookup (ec, ec.ContainerType, null, queried_type, name, mt, bf, loc);
}
//
public static Expression MemberLookup (EmitContext ec, Type container_type,
Type qualifier_type, Type queried_type,
- string name, int num_type_arguments,
- MemberTypes mt, BindingFlags bf,
- Location loc)
+ string name, MemberTypes mt,
+ BindingFlags bf, Location loc)
{
- MemberInfo [] mi = TypeManager.MemberLookup (container_type, qualifier_type,
- queried_type, num_type_arguments,
- mt, bf, name);
+ MemberInfo [] mi = TypeManager.MemberLookup (
+ container_type, qualifier_type,queried_type, mt, bf, name);
if (mi == null)
return null;
BindingFlags.Static |
BindingFlags.Instance;
- public static Expression MemberLookup (EmitContext ec, Type queried_type,
- string name, int num_type_arguments,
- Location loc)
- {
- return MemberLookup (ec, ec.ContainerType, null, queried_type, name,
- num_type_arguments, AllMemberTypes, AllBindingFlags,
- loc);
- }
-
public static Expression MemberLookup (EmitContext ec, Type queried_type,
string name, Location loc)
{
return MemberLookup (ec, ec.ContainerType, null, queried_type, name,
- 0, AllMemberTypes, AllBindingFlags, loc);
+ AllMemberTypes, AllBindingFlags, loc);
}
public static Expression MemberLookup (EmitContext ec, Type qualifier_type,
Type queried_type, string name, Location loc)
{
return MemberLookup (ec, ec.ContainerType, qualifier_type, queried_type,
- name, 0, AllMemberTypes, AllBindingFlags, loc);
+ name, AllMemberTypes, AllBindingFlags, loc);
}
public static Expression MethodLookup (EmitContext ec, Type queried_type,
string name, Location loc)
{
return MemberLookup (ec, ec.ContainerType, null, queried_type, name,
- 0, MemberTypes.Method, AllBindingFlags, loc);
+ MemberTypes.Method, AllBindingFlags, loc);
}
/// <summary>
/// </summary>
public static Expression MemberLookupFinal (EmitContext ec, Type qualifier_type,
Type queried_type, string name,
- int num_type_arguments, Location loc)
+ Location loc)
{
return MemberLookupFinal (ec, qualifier_type, queried_type, name,
- num_type_arguments, AllMemberTypes,
- AllBindingFlags, loc);
+ AllMemberTypes, AllBindingFlags, loc);
}
public static Expression MemberLookupFinal (EmitContext ec, Type qualifier_type,
Type queried_type, string name,
- int num_type_arguments, MemberTypes mt,
- BindingFlags bf, Location loc)
+ MemberTypes mt, BindingFlags bf,
+ Location loc)
{
Expression e;
int errors = Report.Errors;
e = MemberLookup (ec, ec.ContainerType, qualifier_type, queried_type,
- name, num_type_arguments, mt, bf, loc);
+ name, mt, bf, loc);
if (e != null)
return e;
return null;
MemberLookupFailed (ec, qualifier_type, queried_type, name,
- num_type_arguments, null, loc);
+ null, loc);
return null;
}
public static void MemberLookupFailed (EmitContext ec, Type qualifier_type,
Type queried_type, string name,
- int num_type_arguments, string class_name,
- Location loc)
+ string class_name, Location loc)
{
MemberInfo[] mi = TypeManager.MemberLookup (queried_type, null, queried_type,
- -1, AllMemberTypes, AllBindingFlags |
+ AllMemberTypes, AllBindingFlags |
BindingFlags.NonPublic, name);
if (mi == null) {
}
if (TypeManager.MemberLookup (queried_type, null, queried_type,
- 0, AllMemberTypes, AllBindingFlags |
+ AllMemberTypes, AllBindingFlags |
BindingFlags.NonPublic, name) == null) {
if ((mi.Length == 1) && (mi [0] is Type)) {
Type t = (Type) mi [0];
mi = TypeManager.MemberLookup (
ec.ContainerType, ec.ContainerType, ec.ContainerType,
- 0, AllMemberTypes, AllBindingFlags, name);
+ AllMemberTypes, AllBindingFlags, name);
if (mi != null) {
Report.Error (
/// </remarks>
public class SimpleName : Expression {
public string Name;
- public int NumTypeArguments;
//
// If true, then we are a simple name, not composed with a ".
is_base = true;
}
- public SimpleName (string name, int num_type_arguments, Location l)
- {
- Name = name;
- NumTypeArguments = num_type_arguments;
- loc = l;
- is_base = true;
- }
-
public static void Error_ObjectRefRequired (EmitContext ec, Location l, string name)
{
if (ec.IsFieldInitializer)
if (ec.ResolvingTypeTree){
int errors = Report.Errors;
- Type dt = ds.FindType (loc, Name, NumTypeArguments);
+ Type dt = ds.FindType (loc, Name);
if (Report.Errors != errors)
return null;
if (alias_value != null){
if (alias_value.IsType)
return alias_value.Type;
- if ((t = RootContext.LookupType (ds, alias_value.Name, true, NumTypeArguments, loc)) != null)
+ if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
return t;
}
}
// or a namespace.
//
- if ((t = RootContext.LookupType (ds, Name, true, NumTypeArguments, loc)) != null)
+ if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
return t;
// No match, maybe our parent can compose us
if (lookup_ds.TypeBuilder == null)
break;
- e = MemberLookup (ec, lookup_ds.TypeBuilder,
- Name, NumTypeArguments, loc);
+ e = MemberLookup (ec, lookup_ds.TypeBuilder, Name, loc);
if (e != null)
break;
} while (lookup_ds != null);
if (e == null && ec.ContainerType != null)
- e = MemberLookup (ec, ec.ContainerType,
- Name, NumTypeArguments, loc);
+ e = MemberLookup (ec, ec.ContainerType, Name, loc);
if (e == null) {
//
group = TypeManager.MemberLookup (
invocation_type, invocation_type, PropertyInfo.DeclaringType,
- 0, MemberTypes.Method, flags, accessor_name + "_" + PropertyInfo.Name);
+ MemberTypes.Method, flags, accessor_name + "_" + PropertyInfo.Name);
//
// The first method is the closest to us
return this;
Expression ml;
- ml = MemberLookupFinal (ec, null, type, ".ctor", 0,
+ ml = MemberLookupFinal (ec, null, type, ".ctor",
MemberTypes.Constructor,
AllBindingFlags | BindingFlags.DeclaredOnly, loc);
/// Implements the member access expression
/// </summary>
public class MemberAccess : Expression {
- public readonly string Identifier;
- public readonly int NumTypeArguments;
+ public string Identifier;
protected Expression expr;
public MemberAccess (Expression expr, string id, Location l)
loc = l;
}
- protected MemberAccess (Expression expr, string id, int num_type_args,
- Location l)
- : this (expr, id, l)
- {
- NumTypeArguments = num_type_args;
- }
-
public Expression Expr {
get {
return expr;
return null;
}
- int real_num_type_args = NumTypeArguments +
- TypeManager.GetNumberOfTypeArguments (expr_type);
-
Expression member_lookup;
- member_lookup = MemberLookupFinal (ec, expr_type, expr_type,
- Identifier, real_num_type_args,
- loc);
+ member_lookup = MemberLookupFinal (
+ ec, expr_type, expr_type, Identifier, loc);
if (member_lookup == null)
return null;
if (full_expr.Expr is SimpleName) {
string full_name = String.Concat (((SimpleName) full_expr.Expr).Name, ".", fname);
- Type fully_qualified = ec.DeclSpace.FindType (loc, full_name, 0);
+ Type fully_qualified = ec.DeclSpace.FindType (loc, full_name);
if (fully_qualified != null)
return new TypeExpression (fully_qualified, loc);
}
return null;
}
- int real_num_type_args = NumTypeArguments +
- TypeManager.GetNumberOfTypeArguments (expr_type);
-
Expression member_lookup;
- member_lookup = MemberLookupFinal (ec, expr_type, expr_type,
- Identifier, real_num_type_args,
- loc);
+ member_lookup = MemberLookupFinal (
+ ec, expr_type, expr_type, Identifier, loc);
if (member_lookup == null)
return null;
string p_name = TypeManager.IndexerPropertyName (lookup_type);
MemberInfo [] mi = TypeManager.MemberLookup (
- caller_type, caller_type, lookup_type, 0, MemberTypes.Property,
+ caller_type, caller_type, lookup_type, MemberTypes.Property,
BindingFlags.Public | BindingFlags.Instance |
BindingFlags.DeclaredOnly, p_name);
}
member_lookup = MemberLookup (ec, ec.ContainerType, null, base_type,
- member, 0, AllMemberTypes,
- AllBindingFlags, loc);
+ member, AllMemberTypes, AllBindingFlags,
+ loc);
if (member_lookup == null) {
- MemberLookupFailed (ec, base_type, base_type, member,
- 0, null, loc);
+ MemberLookupFailed (
+ ec, base_type, base_type, member, null, loc);
return null;
}
public ConstructedType (string name, TypeArguments args, Location l)
{
loc = l;
- this.name = name;
+ this.name = name + "!" + args.Count;
this.args = args;
eclass = ExprClass.Type;
Type t;
int num_args;
- SimpleName sn = new SimpleName (name, args.Count, loc);
+ SimpleName sn = new SimpleName (name, loc);
TypeExpr resolved = sn.ResolveAsTypeTerminal (ec);
- if (resolved == null) {
- sn = new SimpleName (name, -1, loc);
- resolved = sn.ResolveAsTypeTerminal (ec);
- if ((resolved == null) || (resolved.Type == null)) {
- Report.Error (246, loc,
- "The type or namespace name `{0}<...>' "+
- "could not be found", name);
- return null;
- }
-
- t = resolved.Type;
- num_args = TypeManager.GetNumberOfTypeArguments (t);
-
- if (num_args == 0) {
- Report.Error (308, loc,
- "The non-generic type `{0}' cannot " +
- "be used with type arguments.",
- TypeManager.CSharpName (t));
- return null;
- }
-
- Report.Error (305, loc,
- "Using the generic type `{0}' " +
- "requires {1} type arguments",
- TypeManager.GetFullName (t), num_args);
+ if ((resolved == null) || (resolved.Type == null)) {
+ Report.Error (246, loc,
+ "The type or namespace name `{0}<...>' "+
+ "could not be found", name);
return null;
}
else
current = new TypeExpression (ec.ContainerType, loc);
- return new GenericMemberAccess (current, name, args, loc);
+ string basename;
+ int pos = name.LastIndexOf ('!');
+ if (pos >= 0)
+ basename = name.Substring (0, pos);
+ else
+ basename = name;
+
+ return new GenericMemberAccess (current, basename, args, loc);
}
public override bool CheckAccessLevel (DeclSpace ds)
TypeArguments args;
bool has_outer_params;
- public GenericMemberAccess (Expression expr, string id, TypeArguments args, Location loc)
- : base (expr, id, args.Count, loc)
+ public GenericMemberAccess (Expression expr, string id, TypeArguments args,
+ Location loc)
+ : base (expr, id, loc)
{
this.args = args;
}
if (expr == null)
return null;
- TypeExpr texpr = expr as TypeExpr;
- if (texpr != null) {
- Type t = texpr.ResolveType (ec);
- if (t == null)
- return null;
-
- ConstructedType ctype = new ConstructedType (t, args, loc);
- return ctype.DoResolve (ec);
- }
-
MethodGroupExpr mg = expr as MethodGroupExpr;
- if (mg == null) {
+ if (mg == null)
return expr;
- Report.Error (-220, loc, "Member `{0}' has type arguments, but did " +
- "not resolve as a method group.", Identifier);
- return null;
- }
if (args.Resolve (ec) == false)
return null;
public override Expression ResolveAsTypeStep (EmitContext ec)
{
- if (!DoResolveBase (ec))
- return null;
+ Identifier = Identifier + "!" + args.Count;
expr = base.ResolveAsTypeStep (ec);
if (expr == null)
// this will fail with `using A = Stack<int>'
//
- string alias = Alias.GetTypeName ();
+ string alias = Alias.GetTypeName (true);
while ((curr_ns != null) && (resolved == null)) {
resolved = curr_ns.Lookup (
null, alias, Alias.CountTypeArguments,
DoubleHash decl_ns_name = new DoubleHash ();
- public void RecordDecl (MemberName member_name, DeclSpace ds)
+ public void RecordDecl (string name, DeclSpace ds)
{
- string name = (string) member_name;
-
if (decls.Contains (name)){
Report.Error (
101, ds.Location,
/// to check base classes and interfaces anymore.
/// </summary>
private static MemberList MemberLookup_FindMembers (Type t, MemberTypes mt, BindingFlags bf,
- string name, int num_type_arguments,
- out bool used_cache)
+ string name, out bool used_cache)
{
//
// We have to take care of arrays specially, because GetType on
} else
return t.GetGenericArguments ();
}
-
- public static bool CheckGeneric (Type t, int num_type_arguments)
- {
- if (num_type_arguments < 0)
- return true;
-
- DeclSpace tc = LookupDeclSpace (t);
-
- if (tc != null) {
- if (!tc.IsGeneric)
- return num_type_arguments == 0;
-
- if (num_type_arguments == 0)
- return false;
-
- if (num_type_arguments != tc.CountTypeParameters)
- return false;
- } else {
- if (!t.HasGenericArguments)
- return num_type_arguments == 0;
-
- if (num_type_arguments == 0)
- return false;
-
- if (num_type_arguments != t.GetGenericArguments ().Length)
- return false;
- }
-
- return true;
- }
//
// Whether a type is unmanaged. This is used by the unsafe code (25.2)
//
static Type closure_invocation_type;
static Type closure_qualifier_type;
- static int closure_num_type_arguments;
//
// The assembly that defines the type is that is calling us
if ((filter_criteria != null) && (m.Name != (string) filter_criteria))
return false;
- if (m is Type)
- return TypeManager.CheckGeneric ((Type) m, closure_num_type_arguments);
-
if (((closure_qualifier_type == null) || (closure_qualifier_type == closure_invocation_type)) &&
(closure_invocation_type != null) && IsEqual (m.DeclaringType, closure_invocation_type))
return true;
// that might return multiple matches.
//
public static MemberInfo [] MemberLookup (Type invocation_type, Type qualifier_type,
- Type queried_type, int num_type_arguments,
- MemberTypes mt, BindingFlags original_bf,
- string name)
+ Type queried_type, MemberTypes mt,
+ BindingFlags original_bf, string name)
{
Timer.StartTimer (TimerType.MemberLookup);
MemberInfo[] retval = RealMemberLookup (invocation_type, qualifier_type,
- queried_type, num_type_arguments,
- mt, original_bf, name);
+ queried_type, mt, original_bf, name);
Timer.StopTimer (TimerType.MemberLookup);
}
static MemberInfo [] RealMemberLookup (Type invocation_type, Type qualifier_type,
- Type queried_type, int num_type_arguments,
- MemberTypes mt, BindingFlags original_bf,
- string name)
+ Type queried_type, MemberTypes mt,
+ BindingFlags original_bf, string name)
{
BindingFlags bf = original_bf;
closure_invocation_assembly = invocation_type != null ? invocation_type.Assembly : null;
closure_qualifier_type = qualifier_type;
- closure_num_type_arguments = num_type_arguments;
-
//
// If we are a nested class, we always have access to our container
// type names
Timer.StopTimer (TimerType.MemberLookup);
- list = MemberLookup_FindMembers (current_type, mt, bf, name,
- num_type_arguments, out used_cache);
+ list = MemberLookup_FindMembers (
+ current_type, mt, bf, name, out used_cache);
Timer.StartTimer (TimerType.MemberLookup);
foreach (TypeExpr itype in ifaces){
MemberInfo [] x;
- x = MemberLookup (null, null, itype.Type, num_type_arguments,
- mt, bf, name);
+ x = MemberLookup (null, null, itype.Type, mt, bf, name);
if (x != null)
return x;
}