public string GetTypeName ()
{
- string suffix = "";
if (Left != null)
return Left.GetTypeName () + "." +
MakeName (Name, TypeArguments);
//
public NamespaceEntry NamespaceEntry;
- public Hashtable Cache = new Hashtable ();
+ private Hashtable Cache = new Hashtable ();
public string Basename;
in_transit = value;
}
}
-
- /// <summary>
- /// Looks up the alias for the name
- /// </summary>
- public IAlias LookupAlias (string name)
- {
- if (NamespaceEntry != null)
- return NamespaceEntry.LookupAlias (name);
- else
- return null;
- }
//
// root_types contains all the types. All TopLevel types
EmitContext type_resolve_ec;
- public Type ResolveNestedType (Type t, Location loc)
+ public FullNamedExpression ResolveNestedType (FullNamedExpression t, Location loc)
{
- TypeContainer tc = TypeManager.LookupTypeContainer (t);
+ TypeContainer tc = TypeManager.LookupTypeContainer (t.Type);
if ((tc != null) && tc.IsGeneric) {
if (!IsGeneric) {
- int tnum = TypeManager.GetNumberOfTypeArguments (t);
+ int tnum = TypeManager.GetNumberOfTypeArguments (t.Type);
Report.Error (305, loc,
"Using the generic type `{0}' " +
"requires {1} type arguments",
- TypeManager.GetFullName (t), tnum);
+ TypeManager.GetFullName (t.Type), tnum);
return null;
}
else
args = TypeParameters;
- TypeExpr ctype = new ConstructedType (t, args, loc);
- ctype = ctype.ResolveAsTypeTerminal (ec);
- if (ctype == null)
- return null;
-
- t = ctype.Type;
+ TypeExpr ctype = new ConstructedType (t.Type, args, loc);
+ return ctype.ResolveAsTypeTerminal (ec);
}
return t;
return tc.DefineType ();
}
- Type LookupInterfaceOrClass (string ns, string name, out bool error)
+ FullNamedExpression LookupInterfaceOrClass (string ns, string name, out bool error)
{
DeclSpace parent;
+ FullNamedExpression result;
Type t;
object r;
error = false;
if (dh.Lookup (ns, name, out r))
- return (Type) r;
+ return (FullNamedExpression) r;
else {
if (ns != ""){
if (Namespace.IsNamespace (ns)){
}
if (t != null) {
- dh.Insert (ns, name, t);
- return t;
+ result = new TypeExpression (t, Location.Null);
+ dh.Insert (ns, name, result);
+ return result;
+ }
+
+ if (ns != "" && Namespace.IsNamespace (ns)) {
+ result = Namespace.LookupNamespace (ns, false).Lookup (this, name, Location.Null);
+ if (result != null) {
+ dh.Insert (ns, name, result);
+ return result;
+ }
+ }
+
+ if (ns == "" && Namespace.IsNamespace (name)) {
+ result = Namespace.LookupNamespace (name, false);
+ dh.Insert (ns, name, result);
+ return result;
}
//
ns = MakeFQN (ns, name.Substring (0, p));
name = name.Substring (p+1);
}
-
+
+ if (ns.IndexOf ('+') != -1)
+ ns = ns.Replace ('+', '.');
+
parent = RootContext.Tree.LookupByNamespace (ns, name);
if (parent == null) {
dh.Insert (ns, name, null);
return null;
}
- dh.Insert (ns, name, t);
- return t;
+ result = new TypeExpression (t, Location.Null);
+ dh.Insert (ns, name, result);
+ return result;
}
public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
public Type FindNestedType (Location loc, string name,
out DeclSpace containing_ds)
{
- Type t;
+ FullNamedExpression t;
bool error;
containing_ds = this;
if (error)
return null;
- if ((t != null) && containing_ds.CheckAccessLevel (t))
- return t;
+ if ((t != null) && containing_ds.CheckAccessLevel (t.Type))
+ return t.Type;
current_type = current_type.BaseType;
}
/// during the tree resolution process and potentially define
/// recursively the type
/// </remarks>
- public Type FindType (Location loc, string name)
+ public FullNamedExpression FindType (Location loc, string name)
{
- Type t;
+ FullNamedExpression t;
bool error;
//
// For the case the type we are looking for is nested within this one
// or is in any base class
//
+
DeclSpace containing_ds = this;
while (containing_ds != null){
if (error)
return null;
- if ((t != null) && containing_ds.CheckAccessLevel (t))
+ if ((t != null) && containing_ds.CheckAccessLevel (t.Type))
return ResolveNestedType (t, loc);
current_type = current_type.BaseType;
if (name.IndexOf ('.') > 0)
continue;
- IAlias alias_value = ns.LookupAlias (name);
- if (alias_value != null) {
- t = LookupInterfaceOrClass ("", alias_value.Name, out error);
- if (error)
- return null;
-
- if (t != null)
- return t;
- }
+ t = ns.LookupAlias (name);
+ if (t != null)
+ return t;
//
// Now check the using clause list
//
- Type match = null;
+ FullNamedExpression match = null;
foreach (Namespace using_ns in ns.GetUsingTable ()) {
match = LookupInterfaceOrClass (using_ns.Name, name, out error);
if (error)
return null;
- if (match != null) {
- if (t != null){
- if (CheckAccessLevel (match)) {
- Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
- return null;
- }
+ if ((match != null) && (match is TypeExpr)) {
+ Type matched = ((TypeExpr) match).Type;
+ if (!CheckAccessLevel (matched))
continue;
+ if (t != null){
+ Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
+ return null;
}
-
t = match;
}
}
return null;
}
+ //
+ // Public function used to locate types, this can only
+ // be used after the ResolveTree function has been invoked.
+ //
+ // Returns: Type or null if they type can not be found.
+ //
+ // Come to think of it, this should be a DeclSpace
+ //
+ public FullNamedExpression LookupType (string name, bool silent, Location loc)
+ {
+ FullNamedExpression e;
+
+ if (Cache.Contains (name)) {
+ e = (FullNamedExpression) Cache [name];
+ } else {
+ //
+ // For the case the type we are looking for is nested within this one
+ // or is in any base class
+ //
+ DeclSpace containing_ds = this;
+ while (containing_ds != null){
+
+ // if the member cache has been created, lets use it.
+ // the member cache is MUCH faster.
+ if (containing_ds.MemberCache != null) {
+ Type t = containing_ds.MemberCache.FindNestedType (name);
+ if (t == null) {
+ containing_ds = containing_ds.Parent;
+ continue;
+ }
+
+ e = new TypeExpression (t, Location.Null);
+ e = ResolveNestedType (e, Location.Null);
+ Cache [name] = e;
+ return e;
+ }
+
+ // no member cache. Do it the hard way -- reflection
+ Type current_type = containing_ds.TypeBuilder;
+
+ while (current_type != null &&
+ current_type != TypeManager.object_type) {
+ //
+ // nested class
+ //
+ 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;
+ }
+
+ current_type = current_type.BaseType;
+ }
+
+ containing_ds = containing_ds.Parent;
+ }
+
+ e = NamespaceEntry.LookupNamespaceOrType (this, name, loc);
+ if (!silent || e != null)
+ Cache [name] = e;
+ }
+
+ if (e == null && !silent)
+ Report.Error (246, loc, "Cannot find type `"+name+"'");
+
+ return e;
+ }
+
/// <remarks>
/// This function is broken and not what you're looking for. It should only
/// be used while the type is still being created since it doesn't use the cache
return copy;
}
+ // find the nested type @name in @this.
+ public Type FindNestedType (string name)
+ {
+ ArrayList applicable = (ArrayList) member_hash [name];
+ if (applicable == null)
+ return null;
+
+ for (int i = applicable.Count-1; i >= 0; i--) {
+ CacheEntry entry = (CacheEntry) applicable [i];
+ if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
+ return (Type) entry.Member;
+ }
+
+ return null;
+ }
+
//
// This finds the method or property for us to override. invocationType is the type where
// the override is going to be declared, name is the name of the method/property, and