Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs/gmcs
diff options
context:
space:
mode:
authorRaja R Harinath <harinath@hurrynot.org>2005-12-09 14:23:51 +0300
committerRaja R Harinath <harinath@hurrynot.org>2005-12-09 14:23:51 +0300
commit95e471b90ffeeed89c1327c89582bdcb8bb2dd52 (patch)
tree4f983e5633ee0f5fd5cfe2b763f495bf0500f5e0 /mcs/gmcs
parentf1ba199971d51e83c372257ce63bccf7e24feade (diff)
* generic.cs (DropGenericTypeArguments): New. Captures the common
pattern: if (t.IsGenericInstance) t = t.GetGenericTypeDefinition (); * attribute.cs, class.cs, decl.cs, ecore.cs: Use it. * generic.cs, report.cs, typemanager.cs: Likewise. svn path=/trunk/mcs/; revision=54157
Diffstat (limited to 'mcs/gmcs')
-rw-r--r--mcs/gmcs/ChangeLog7
-rw-r--r--mcs/gmcs/attribute.cs3
-rw-r--r--mcs/gmcs/class.cs10
-rw-r--r--mcs/gmcs/decl.cs7
-rw-r--r--mcs/gmcs/ecore.cs4
-rw-r--r--mcs/gmcs/generic.cs28
-rw-r--r--mcs/gmcs/report.cs3
-rw-r--r--mcs/gmcs/typemanager.cs17
8 files changed, 32 insertions, 47 deletions
diff --git a/mcs/gmcs/ChangeLog b/mcs/gmcs/ChangeLog
index 438b048f2d2..0fdc08c702f 100644
--- a/mcs/gmcs/ChangeLog
+++ b/mcs/gmcs/ChangeLog
@@ -1,3 +1,10 @@
+2005-12-09 Raja R Harinath <rharinath@novell.com>
+
+ * generic.cs (DropGenericTypeArguments): New. Captures the common
+ pattern: if (t.IsGenericInstance) t = t.GetGenericTypeDefinition ();
+ * attribute.cs, class.cs, decl.cs, ecore.cs: Use it.
+ * generic.cs, report.cs, typemanager.cs: Likewise.
+
2005-12-08 Martin Baulig <martin@ximian.com>
* generic.cs (TypeArguments.Resolve): Added CS1547 check.
diff --git a/mcs/gmcs/attribute.cs b/mcs/gmcs/attribute.cs
index bbf2c848487..18935a16340 100644
--- a/mcs/gmcs/attribute.cs
+++ b/mcs/gmcs/attribute.cs
@@ -1663,8 +1663,7 @@ namespace Mono.CSharp {
static bool AnalyzeTypeCompliance (Type type)
{
- if (type.IsGenericInstance)
- type = type.GetGenericTypeDefinition ();
+ type = TypeManager.DropGenericTypeArguments (type);
DeclSpace ds = TypeManager.LookupDeclSpace (type);
if (ds != null)
return ds.IsClsComplianceRequired (ds);
diff --git a/mcs/gmcs/class.cs b/mcs/gmcs/class.cs
index 97a549d8dc2..4c5386e0524 100644
--- a/mcs/gmcs/class.cs
+++ b/mcs/gmcs/class.cs
@@ -1467,9 +1467,7 @@ namespace Mono.CSharp {
Type parent = ptype;
if (parent != null) {
- if (parent.IsGenericInstance)
- parent = parent.GetGenericTypeDefinition ();
-
+ parent = TypeManager.DropGenericTypeArguments (parent);
TypeContainer ptc = TypeManager.LookupTypeContainer (parent);
if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
return false;
@@ -1477,11 +1475,7 @@ namespace Mono.CSharp {
if (iface_exprs != null) {
foreach (TypeExpr iface in iface_exprs) {
- Type itype = iface.Type;
-
- if (itype.IsGenericInstance)
- itype = itype.GetGenericTypeDefinition ();
-
+ Type itype = TypeManager.DropGenericTypeArguments (iface.Type);
TypeContainer ptc = TypeManager.LookupTypeContainer (itype);
if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
return false;
diff --git a/mcs/gmcs/decl.cs b/mcs/gmcs/decl.cs
index 4381e640f0c..590c35fe272 100644
--- a/mcs/gmcs/decl.cs
+++ b/mcs/gmcs/decl.cs
@@ -889,9 +889,7 @@ namespace Mono.CSharp {
else
tb = TypeBuilder;
- if (check_type.IsGenericInstance)
- check_type = check_type.GetGenericTypeDefinition ();
-
+ check_type = TypeManager.DropGenericTypeArguments (check_type);
if (check_type == tb)
return true;
@@ -1098,8 +1096,7 @@ namespace Mono.CSharp {
for (Type current_type = TypeBuilder;
current_type != null && current_type != TypeManager.object_type;
current_type = current_type.BaseType) {
- if (current_type.IsGenericInstance)
- current_type = current_type.GetGenericTypeDefinition ();
+ current_type = TypeManager.DropGenericTypeArguments (current_type);
if (current_type is TypeBuilder) {
DeclSpace decl = this;
if (current_type != TypeBuilder)
diff --git a/mcs/gmcs/ecore.cs b/mcs/gmcs/ecore.cs
index 8036635ab77..fdbea06e164 100644
--- a/mcs/gmcs/ecore.cs
+++ b/mcs/gmcs/ecore.cs
@@ -1931,9 +1931,7 @@ namespace Mono.CSharp {
return false;
while (parent != null) {
- if (parent.IsGenericInstance)
- parent = parent.GetGenericTypeDefinition ();
-
+ parent = TypeManager.DropGenericTypeArguments (parent);
if (TypeManager.IsNestedChildOf (t, parent))
return true;
diff --git a/mcs/gmcs/generic.cs b/mcs/gmcs/generic.cs
index 0e095e56702..e938019b20b 100644
--- a/mcs/gmcs/generic.cs
+++ b/mcs/gmcs/generic.cs
@@ -1967,9 +1967,7 @@ namespace Mono.CSharp {
public static TypeContainer LookupGenericTypeContainer (Type t)
{
- while (t.IsGenericInstance)
- t = t.GetGenericTypeDefinition ();
-
+ t = DropGenericTypeArguments (t);
return LookupTypeContainer (t);
}
@@ -2033,6 +2031,16 @@ namespace Mono.CSharp {
return t.GetGenericArguments ();
}
+ public static Type DropGenericTypeArguments (Type t)
+ {
+ if (!t.IsGenericType)
+ return t;
+ // Micro-optimization: a generic typebuilder is always a generic type definition
+ if (t is TypeBuilder)
+ return t;
+ return t.GetGenericTypeDefinition ();
+ }
+
//
// Whether `array' is an array of T and `enumerator' is `IEnumerable<T>'.
// For instance "string[]" -> "IEnumerable<string>".
@@ -2260,14 +2268,12 @@ namespace Mono.CSharp {
int tcount = GetNumberOfTypeArguments (type);
int pcount = GetNumberOfTypeArguments (parent);
- if (type.IsGenericInstance)
- type = type.GetGenericTypeDefinition ();
- if (parent.IsGenericInstance)
- parent = parent.GetGenericTypeDefinition ();
-
if (tcount != pcount)
return false;
+ type = DropGenericTypeArguments (type);
+ parent = DropGenericTypeArguments (parent);
+
return type.Equals (parent);
}
@@ -2582,11 +2588,7 @@ namespace Mono.CSharp {
public static bool IsNullableType (Type t)
{
- if (!t.IsGenericInstance)
- return false;
-
- Type gt = t.GetGenericTypeDefinition ();
- return gt == generic_nullable_type;
+ return generic_nullable_type == DropGenericTypeArguments (t);
}
}
diff --git a/mcs/gmcs/report.cs b/mcs/gmcs/report.cs
index 20f85213557..da3e423fad2 100644
--- a/mcs/gmcs/report.cs
+++ b/mcs/gmcs/report.cs
@@ -335,8 +335,7 @@ namespace Mono.CSharp {
static public void SymbolRelatedToPreviousError (Type type)
{
- if (type.IsGenericInstance)
- type = type.GetGenericTypeDefinition ();
+ type = TypeManager.DropGenericTypeArguments (type);
if (type.IsGenericParameter) {
TypeParameter tp = TypeManager.LookupTypeParameter (type);
diff --git a/mcs/gmcs/typemanager.cs b/mcs/gmcs/typemanager.cs
index 42e5869b58d..b5d3c0e7f41 100644
--- a/mcs/gmcs/typemanager.cs
+++ b/mcs/gmcs/typemanager.cs
@@ -1428,9 +1428,7 @@ public partial class TypeManager {
public static bool IsDelegateType (Type t)
{
- if (t.IsGenericInstance)
- t = t.GetGenericTypeDefinition ();
-
+ t = DropGenericTypeArguments (t);
if (t.IsSubclassOf (TypeManager.delegate_type))
return true;
else
@@ -1600,14 +1598,7 @@ public partial class TypeManager {
return true;
}
- if (type.IsGenericInstance && parent.IsGenericInstance) {
- if (type.GetGenericTypeDefinition () != parent.GetGenericTypeDefinition ())
- return false;
-
- return true;
- }
-
- return false;
+ return DropGenericTypeArguments (type) == DropGenericTypeArguments (parent);
}
public static bool IsFamilyAccessible (Type type, Type parent)
@@ -2341,9 +2332,7 @@ public partial class TypeManager {
/// </remarks>
public static string IndexerPropertyName (Type t)
{
- if (t.IsGenericInstance)
- t = t.GetGenericTypeDefinition ();
-
+ t = DropGenericTypeArguments (t);
if (t is TypeBuilder) {
TypeContainer tc = t.IsInterface ? LookupInterface (t) : LookupTypeContainer (t);
return tc == null ? TypeContainer.DefaultIndexerName : tc.IndexerName;