Author: martin
Date: 2005-04-17 23:26:31 -0400 (Sun, 17 Apr 2005)
New Revision: 43181
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/decl.cs
trunk/mcs/gmcs/expression.cs
trunk/mcs/gmcs/namespace.cs
trunk/mcs/gmcs/rootcontext.cs
trunk/mcs/gmcs/tree.cs
trunk/mcs/gmcs/typemanager.cs
Log:
**** Merged r41877 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-18 03:26:31 UTC (rev 43181)
@@ -1,3 +1,32 @@
+2005-03-16 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Remove TypeManager.LookupType and TypeManager.LookupTypeDirect.
+ Refactor to avoid traversing the list of assemblies, and to avoid
+ string concatenation.
+ * typemanager.cs (guid_attr_type): Remove.
+ (negative_hits, pointers, references): Remove hashes.
+ (type_hash): New.
+ (GetConstructedType): New. Uses type_hash to handle constructed
+ types (arrays, references, pointers).
+ (GetReferenceType, GetPointerType): Use it.
+ (GetNestedType): New. Uses type_hash to handle nested types of
+ reflected types.
+ (LookupType, LookupTypeDirect): Remove.
+ (CoreLookupType): Inline parts of old LookupTypeDirect code. Use
+ 'types' hash and LookupTypeReflection directly.
+ (params_string, params_object): Use GetConstructedType.
+ * namespace.cs (Namespace.cached_types): New. Cache of reflected
+ top-level types.
+ (Namespace.Lookup): Use cached_types.
+ (NamespaceEntry.LookupNamespaceOrType): Inline the functionality
+ provided by old TypeManager.LookupType.
+ * rootcontext.cs (MakeFQN): Remove.
+ * decl.cs (DeclSpace.MakeFQN): Likewise.
+ (DeclSpace.LookupType): Use TypeManager.GetNestedType.
+ * expression.cs (ComposedCast.DoResolveAsTypeStep): Use
+ TypeManager.GetConstructedType.
+ * tree.cs (decl_ns_hash, LookupByNamespace): Remove.
+
2005-04-16 Zoltan Varga <[EMAIL PROTECTED]>
* cs-parser.jay: Fix build.
Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/decl.cs 2005-04-18 03:26:31 UTC (rev 43181)
@@ -708,13 +708,6 @@
}
}
- public static string MakeFQN (string nsn, string name)
- {
- if (nsn == "")
- return name;
- return String.Concat (nsn, ".", name);
- }
-
EmitContext type_resolve_ec;
protected EmitContext TypeResolveEmitContext {
get {
@@ -977,7 +970,7 @@
decl =
TypeManager.LookupDeclSpace (current_type);
t = decl.FindNestedType (name);
} else {
- t = TypeManager.LookupTypeDirect
(current_type.FullName + "+" + name);
+ t = TypeManager.GetNestedType
(current_type, name);
}
if (t != null && CheckAccessLevel (t))
Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/expression.cs 2005-04-18 03:26:31 UTC (rev 43181)
@@ -9000,65 +9000,15 @@
return nullable.ResolveAsTypeTerminal (ec);
}
- int pos = 0;
- while ((pos < dim.Length) && (dim [pos] == '[')) {
- pos++;
+ if (dim != "")
+ type = TypeManager.GetConstructedType (ltype,
dim);
+ else
+ type = ltype;
- if (dim [pos] == ']') {
- ltype = ltype.MakeArrayType ();
- pos++;
-
- if (pos < dim.Length)
- continue;
-
- type = ltype;
- eclass = ExprClass.Type;
- return this;
- }
-
- int rank = 0;
- while (dim [pos] == ',') {
- pos++; rank++;
- }
-
- if ((dim [pos] != ']') || (pos != dim.Length-1))
- return null;
-
- type = ltype.MakeArrayType (rank + 1);
- eclass = ExprClass.Type;
- return this;
+ if (type == null) {
+ throw new InternalErrorException ("Couldn't
create computed type " + ltype + dim);
}
- if (dim != "") {
- //
- // ltype.Fullname is already fully qualified,
so we can skip
- // a lot of probes, and go directly to
TypeManager.LookupType
- //
- string fname = ltype.FullName != null ?
ltype.FullName : ltype.Name;
- string cname = fname + dim;
- type = TypeManager.LookupTypeDirect (cname);
- if (type == null){
- //
- // For arrays of enumerations we are
having a problem
- // with the direct lookup. Need to
investigate.
- //
- // For now, fall back to the full
lookup in that case.
- //
- FullNamedExpression e =
ec.DeclSpace.LookupType (
- cname, loc, /*ignore_cs0104=*/
false);
- if (e == null) {
- Report.Error (246, loc, "Cannot
find type `" + cname + "'");
- return null;
- }
- if (e is TypeExpr)
- type = ((TypeExpr)
e).ResolveType (ec);
- if (type == null)
- return null;
- }
- } else {
- type = ltype;
- }
-
if (!ec.InUnsafe && type.IsPointer){
UnsafeError (loc);
return null;
Modified: trunk/mcs/gmcs/namespace.cs
===================================================================
--- trunk/mcs/gmcs/namespace.cs 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/namespace.cs 2005-04-18 03:26:31 UTC (rev 43181)
@@ -26,6 +26,7 @@
ArrayList entries;
Hashtable namespaces;
Hashtable defined_names;
+ Hashtable cached_types;
public static Namespace Root;
@@ -66,6 +67,7 @@
entries = new ArrayList ();
namespaces = new Hashtable ();
defined_names = new Hashtable ();
+ cached_types = new Hashtable ();
all_namespaces.Add (this);
if (namespaces_map.Contains (fullname))
@@ -121,40 +123,40 @@
public FullNamedExpression Lookup (DeclSpace ds, string name,
Location loc)
{
- IAlias o = (IAlias) defined_names [name];
-
- Type t;
- DeclSpace tdecl = o as DeclSpace;
- if (tdecl != null) {
- //
- // Note that this is not:
- //
- // t = tdecl.DefineType ()
- //
- // This is to make it somewhat more useful when
a DefineType
- // fails due to problems in nested types (more
useful in the sense
- // of fewer misleading error messages)
- //
- tdecl.DefineType ();
- t = tdecl.TypeBuilder;
-
- if (t == null)
- return null;
-
- if ((ds == null) || ds.CheckAccessLevel (t))
- return new TypeExpression (t,
Location.Null);
- }
-
Namespace ns = GetNamespace (name, false);
if (ns != null)
return ns;
- // We are sure that 'name' is a simple name (no dots).
- t = TypeManager.LookupTypeDirect (DeclSpace.MakeFQN
(fullname, name));
- if ((t == null) || ((ds != null) &&
!ds.CheckAccessLevel (t)))
+ TypeExpr te;
+ if (cached_types.Contains (name)) {
+ te = (TypeExpr) cached_types [name];
+ } else {
+ Type t;
+ DeclSpace tdecl = defined_names [name] as
DeclSpace;
+ if (tdecl != null) {
+ //
+ // Note that this is not:
+ //
+ // t = tdecl.DefineType ()
+ //
+ // This is to make it somewhat more
useful when a DefineType
+ // fails due to problems in nested
types (more useful in the sense
+ // of fewer misleading error messages)
+ //
+ tdecl.DefineType ();
+ t = tdecl.TypeBuilder;
+ } else {
+ string lookup = this == Namespace.Root
? name : FullName + "." + name;
+ t = TypeManager.LookupTypeReflection
(lookup);
+ }
+ te = t == null ? null : new TypeExpression (t,
Location.Null);
+ cached_types [name] = te;
+ }
+
+ if (te != null && ds != null && !ds.CheckAccessLevel
(te.Type))
return null;
- return new TypeExpression (t, Location.Null);
+ return te;
}
public void AddNamespaceEntry (NamespaceEntry entry)
@@ -453,6 +455,8 @@
return entry == null ? null : entry.Resolve ();
}
+ static readonly char [] dot_array = { '.' };
+
public FullNamedExpression LookupNamespaceOrType (DeclSpace ds,
string name, Location loc, bool ignore_cs0104)
{
FullNamedExpression resolved = null;
@@ -473,15 +477,29 @@
if (resolved == null || rest == null)
return resolved;
- Namespace ns = resolved as Namespace;
- if (ns != null)
- return ns.Lookup (ds, rest, loc);
+ // Now handle the rest of the the name.
+ string [] elements = rest.Split (dot_array);
+ int count = elements.Length;
+ int i = 0;
+ while (i < count && resolved != null && resolved is
Namespace) {
+ Namespace ns = resolved as Namespace;
+ resolved = ns.Lookup (ds, elements [i++], loc);
+ }
- Type nested = TypeManager.LookupType (resolved.FullName
+ "." + rest);
- if ((nested == null) || ((ds != null) &&
!ds.CheckAccessLevel (nested)))
- return null;
+ if (resolved == null || resolved is Namespace)
+ return resolved;
- return new TypeExpression (nested, Location.Null);
+ Type t = ((TypeExpr) resolved).Type;
+
+ while (t != null) {
+ if (ds != null && !ds.CheckAccessLevel (t))
+ break;
+ if (i == count)
+ return new TypeExpression (t,
Location.Null);
+ t = TypeManager.GetNestedType (t, elements
[i++]);
+ }
+
+ return null;
}
private FullNamedExpression Lookup (DeclSpace ds, string name,
Location loc, bool ignore_cs0104)
Modified: trunk/mcs/gmcs/rootcontext.cs
===================================================================
--- trunk/mcs/gmcs/rootcontext.cs 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/rootcontext.cs 2005-04-18 03:26:31 UTC (rev 43181)
@@ -145,13 +145,6 @@
//
static public bool Unsafe;
- static string MakeFQN (string nsn, string name)
- {
- if (nsn == "")
- return name;
- return String.Concat (nsn, ".", name);
- }
-
// <remarks>
// This function is used to resolve the hierarchy tree.
// It processes interfaces, structs and classes in that order.
Modified: trunk/mcs/gmcs/tree.cs
===================================================================
--- trunk/mcs/gmcs/tree.cs 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/tree.cs 2005-04-18 03:26:31 UTC (rev 43181)
@@ -45,8 +45,6 @@
decls = new Hashtable ();
}
- DoubleHash decl_ns_name = new DoubleHash ();
-
public void RecordDecl (string name, DeclSpace ds)
{
DeclSpace other = (DeclSpace) decls [name];
@@ -74,23 +72,8 @@
ds.RecordDecl ();
- int p = name.LastIndexOf ('.');
- if (p == -1)
- decl_ns_name.Insert ("", name, ds);
- else {
- decl_ns_name.Insert (name.Substring (0, p),
name.Substring (p+1), ds);
- }
-
decls.Add (name, ds);
}
-
- public DeclSpace LookupByNamespace (string ns, string name)
- {
- object res;
-
- decl_ns_name.Lookup (ns, name, out res);
- return (DeclSpace) res;
- }
//
// FIXME: Why are we using Types?
Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs 2005-04-18 02:38:44 UTC (rev 43180)
+++ trunk/mcs/gmcs/typemanager.cs 2005-04-18 03:26:31 UTC (rev 43181)
@@ -80,7 +80,6 @@
static public Type methodimpl_attr_type;
static public Type marshal_as_attr_type;
static public Type param_array_type;
- static public Type guid_attr_type;
static public Type void_ptr_type;
static public Type indexer_name_type;
static public Type exception_type;
@@ -270,10 +269,8 @@
// </remarks>
public static Hashtable all_imported_types;
- static Hashtable negative_hits;
static Hashtable fieldbuilders_to_fields;
static Hashtable fields;
- static Hashtable references;
struct Signature {
public string name;
@@ -297,15 +294,15 @@
builder_to_method = null;
fields = null;
- references = null;
- negative_hits = null;
builder_to_constant = null;
fieldbuilders_to_fields = null;
events = null;
priv_fields_events = null;
properties = null;
- CleanUpGenerics ();
+ type_hash = null;
+
+ CleanUpGenerics ();
TypeHandle.CleanUp ();
}
@@ -409,10 +406,9 @@
NoTypes = new Type [0];
NoTypeExprs = new TypeExpr [0];
- negative_hits = new Hashtable ();
fieldbuilders_to_fields = new Hashtable ();
fields = new Hashtable ();
- references = new Hashtable ();
+ type_hash = new DoubleHash ();
}
public static void HandleDuplicate (string name, Type t)
@@ -452,8 +448,6 @@
HandleDuplicate (name, t);
}
- negative_hits.Remove (t);
-
user_types.Add (t);
}
@@ -624,8 +618,20 @@
return modules;
}
}
-
+
//
+ // We use this hash for multiple kinds of constructed types:
+ //
+ // (T, "&") Given T, get T &
+ // (T, "*") Given T, get T *
+ // (T, "[]") Given T and a array dimension, get T []
+ // (T, X) Given a type T and a simple name X, get the type T+X
+ //
+ // Accessibility tests, if necessary, should be done by the user
+ //
+ static DoubleHash type_hash = new DoubleHash ();
+
+ //
// Gets the reference to T version of the Type (T&)
//
public static Type GetReferenceType (Type t)
@@ -633,36 +639,83 @@
return t.MakeByRefType ();
}
- static Hashtable pointers = new Hashtable ();
-
//
// Gets the pointer to T version of the Type (T*)
//
public static Type GetPointerType (Type t)
{
- string tname = t.FullName + "*";
-
- Type ret = t.Assembly.GetType (tname);
-
- //
- // If the type comes from the assembly we are building
- // We need the Hashtable, because .NET 1.1 will return
different instance types
- // every time we call ModuleBuilder.GetType.
- //
- if (ret == null){
- if (pointers [t] == null)
- pointers [t] = CodeGen.Module.Builder.GetType
(tname);
-
- ret = (Type) pointers [t];
+ return GetConstructedType (t, "*");
+ }
+
+ public static Type GetConstructedType (Type t, string dim)
+ {
+ object ret = null;
+ if (type_hash.Lookup (t, dim, out ret))
+ return (Type) ret;
+
+ ret = t.Module.GetType (t.ToString () + dim);
+ if (ret != null) {
+ type_hash.Insert (t, dim, ret);
+ return (Type) ret;
}
- return ret;
+ if (dim == "&") {
+ ret = GetReferenceType (t);
+ type_hash.Insert (t, dim, ret);
+ return (Type) ret;
+ }
+
+ if (t.IsGenericParameter || t.IsGenericInstance) {
+ int pos = 0;
+ Type result = t;
+ while ((pos < dim.Length) && (dim [pos] == '[')) {
+ pos++;
+
+ if (dim [pos] == ']') {
+ result = result.MakeArrayType ();
+ pos++;
+
+ if (pos < dim.Length)
+ continue;
+
+ type_hash.Insert (t, dim, result);
+ return result;
+ }
+
+ int rank = 0;
+ while (dim [pos] == ',') {
+ pos++; rank++;
+ }
+
+ if ((dim [pos] != ']') || (pos != dim.Length-1))
+ break;
+
+ result = result.MakeArrayType (rank + 1);
+ type_hash.Insert (t, dim, result);
+ return result;
+ }
+ }
+
+ type_hash.Insert (t, dim, null);
+ return null;
}
+
+ public static Type GetNestedType (Type t, string name)
+ {
+ object ret = null;
+ Report.Debug (64, "GET NESTED TYPE", t, t.FullName, t.Name,
name);
+ if (!type_hash.Lookup (t, name, out ret)) {
+ string lookup = t.FullName + "+" + name;
+ ret = t.Module.GetType (lookup);
+ type_hash.Insert (t, name, ret);
+ }
+ return (Type) ret;
+ }
//
// Low-level lookup, cache-less
//
- static Type LookupTypeReflection (string name)
+ public static Type LookupTypeReflection (string name)
{
Type t;
@@ -702,88 +755,7 @@
return null;
}
- //
- // This function is used when you want to avoid the lookups, and want
to go
- // directly to the source. This will use the cache.
- //
- // Notice that bypassing the cache is bad, because on Microsoft.NET
runtime
- // GetType ("DynamicType[]") != GetType ("DynamicType[]"), and there is
no
- // way to test things other than doing a fullname compare
- //
- public static Type LookupTypeDirect (string name)
- {
- Type t = (Type) types [name];
- if (t != null)
- return t;
-
- t = LookupTypeReflection (name);
- if (t == null)
- return null;
-
- types [name] = t;
- return t;
- }
-
- static readonly char [] dot_array = { '.' };
-
/// <summary>
- /// Returns the Type associated with @name, takes care of the fact
that
- /// reflection expects nested types to be separated from the main type
- /// with a "+" instead of a "."
- /// </summary>
- public static Type LookupType (string name)
- {
- Type t;
-
- //
- // First lookup in user defined and cached values
- //
-
- t = LookupTypeDirect (name);
- if (t != null)
- return t;
-
- string [] elements = name.Split (dot_array);
- int count = elements.Length;
-
- if (count == 1)
- return null;
-
- string top_level_type = elements [0];
- int n = 1;
- for (;;) {
- t = LookupTypeDirect (top_level_type);
-
- if (count == n)
- return t;
-
- if (t != null)
- break;
-
- top_level_type = top_level_type + "." + elements [n++];
- }
-
- //
- // We know that System.Object does not have children, and since
its the base of
- // all the objects, it always gets probed for inner classes.
- //
- if (top_level_type == "System.Object")
- return null;
-
- string nested_type = top_level_type + "+" + String.Join ("+",
elements, n, count - n);
- //Console.WriteLine ("Looking up: " + newt + " " + name);
-
- t = LookupTypeDirect (nested_type);
-
- // Cache the dotted version of the name too.
- if (t == null)
- negative_hits [name] = null;
- else
- types [name] = t;
- return t;
- }
-
- /// <summary>
/// Computes the namespaces that we import from the assemblies we
reference.
/// </summary>
public static void ComputeNamespaces ()
@@ -1033,11 +1005,16 @@
/// </summary>
static Type CoreLookupType (string name)
{
- Type t = LookupTypeDirect (name);
+ Type t = null;
+ if (types.Contains (name))
+ t = (Type) types [name];
+ else
+ t = LookupTypeReflection (name);
if (t == null)
Report.Error (518, "The predefined type `" + name + "'
is not defined or imported");
+ types [name] = t;
return t;
}
@@ -1182,12 +1159,6 @@
mbr_type = CoreLookupType
("System.MarshalByRefObject");
decimal_constant_attribute_type = CoreLookupType
("System.Runtime.CompilerServices.DecimalConstantAttribute");
- //
- // Sigh. Remove this before the release. Wonder what versions
of Mono
- // people are running.
- //
- guid_attr_type = LookupType
("System.Runtime.InteropServices.GuidAttribute");
-
unverifiable_code_type= CoreLookupType
("System.Security.UnverifiableCodeAttribute");
void_ptr_type = CoreLookupType ("System.Void*");
@@ -1325,7 +1296,7 @@
Type [] string_string_string_string = { string_type,
string_type, string_type, string_type };
string_concat_string_string_string_string = GetMethod (
string_type, "Concat", string_string_string_string);
- Type[] params_string = { TypeManager.LookupTypeDirect
("System.String[]") };
+ Type[] params_string = { GetConstructedType (string_type, "[]")
};
string_concat_string_dot_dot_dot = GetMethod (
string_type, "Concat", params_string);
@@ -1335,7 +1306,7 @@
Type [] object_object_object = { object_type, object_type,
object_type };
string_concat_object_object_object = GetMethod (
string_type, "Concat", object_object_object);
- Type[] params_object = { TypeManager.LookupTypeDirect
("System.Object[]") };
+ Type[] params_object = { GetConstructedType (object_type, "[]")
};
string_concat_object_dot_dot_dot = GetMethod (
string_type, "Concat", params_object);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches