Browse Source

Use (Namespace,Name) pair instead of FullName.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
dc8d4cadcb
  1. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  2. 6
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  3. 11
      ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
  4. 2
      ICSharpCode.NRefactory/CSharp/Resolver/Conversions.cs
  5. 2
      ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs
  6. 4
      ICSharpCode.NRefactory/TypeSystem/ArrayType.cs
  7. 93
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  8. 10
      ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs
  9. 24
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractMember.cs
  10. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/CompositeTypeResolveContext.cs
  11. 7
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultField.cs
  12. 12
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMethod.cs
  13. 12
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs
  14. 15
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  15. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
  16. 36
      ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs
  17. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/ProxyTypeResolveContext.cs
  18. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs
  19. 29
      ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs
  20. 4
      ICSharpCode.NRefactory/TypeSystem/NullableType.cs
  21. 83
      ICSharpCode.NRefactory/TypeSystem/ReflectionHelper.cs

2
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition GetClass(Type type)
{
return testCasePC.GetClass(type.FullName, type.GetGenericArguments().Length, StringComparer.Ordinal);
return testCasePC.GetClass(type);
}
[Test]

6
ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs

@ -373,7 +373,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -373,7 +373,7 @@ namespace ICSharpCode.NRefactory.CSharp
dtor.BodyRegion = MakeRegion(destructorDeclaration.Body);
dtor.Accessibility = Accessibility.Protected;
dtor.IsOverride = true;
dtor.ReturnType = voidReference;
dtor.ReturnType = ReflectionHelper.VoidReference;
ConvertAttributes(dtor.Attributes, destructorDeclaration.Attributes);
@ -498,8 +498,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -498,8 +498,6 @@ namespace ICSharpCode.NRefactory.CSharp
#endregion
#region Types
static readonly GetClassTypeReference voidReference = new GetClassTypeReference("System.Void", 0);
ITypeReference ConvertType(DomNode node, bool isInUsingDeclaration = false)
{
return ConvertType(node, currentTypeDefinition, currentMethod, usingScope, isInUsingDeclaration);
@ -555,7 +553,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -555,7 +553,7 @@ namespace ICSharpCode.NRefactory.CSharp
case "decimal":
return TypeCode.Decimal.ToTypeReference();
case "void":
return voidReference;
return ReflectionHelper.VoidReference;
default:
return SharedTypes.UnknownType;
}

11
ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs

@ -1573,9 +1573,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1573,9 +1573,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
// look in current namespace definitions
for (UsingScope n = this.UsingScope; n != null; n = n.Parent) {
string fullName = NamespaceDeclaration.BuildQualifiedName(n.NamespaceName, identifier);
// first look for a namespace
if (k == 0) {
string fullName = NamespaceDeclaration.BuildQualifiedName(n.NamespaceName, identifier);
if (context.GetNamespace(fullName, StringComparer.Ordinal) != null) {
if (n.HasAlias(identifier))
return new AmbiguousTypeResolveResult(SharedTypes.UnknownType);
@ -1583,7 +1583,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1583,7 +1583,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
// then look for a type
ITypeDefinition def = context.GetClass(fullName, k, StringComparer.Ordinal);
ITypeDefinition def = context.GetClass(n.NamespaceName, identifier, k, StringComparer.Ordinal);
if (def != null) {
IType result = def;
if (k != 0) {
@ -1617,8 +1617,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1617,8 +1617,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
foreach (var u in n.Usings) {
NamespaceResolveResult ns = u.ResolveNamespace(context);
if (ns != null) {
fullName = NamespaceDeclaration.BuildQualifiedName(ns.NamespaceName, identifier);
def = context.GetClass(fullName, k, StringComparer.Ordinal);
def = context.GetClass(ns.NamespaceName, identifier, k, StringComparer.Ordinal);
if (firstResult == null) {
if (k == 0)
firstResult = def;
@ -1674,12 +1673,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1674,12 +1673,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
NamespaceResolveResult nrr = target as NamespaceResolveResult;
if (nrr != null) {
string fullName = NamespaceDeclaration.BuildQualifiedName(nrr.NamespaceName, identifier);
if (typeArguments.Count == 0) {
string fullName = NamespaceDeclaration.BuildQualifiedName(nrr.NamespaceName, identifier);
if (context.GetNamespace(fullName, StringComparer.Ordinal) != null)
return new NamespaceResolveResult(fullName);
}
ITypeDefinition def = context.GetClass(fullName, typeArguments.Count, StringComparer.Ordinal);
ITypeDefinition def = context.GetClass(nrr.NamespaceName, identifier, typeArguments.Count, StringComparer.Ordinal);
if (def != null)
return new TypeResolveResult(def);
return ErrorResult;

2
ICSharpCode.NRefactory/CSharp/Resolver/Conversions.cs

@ -194,7 +194,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -194,7 +194,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|| ImplicitReferenceConversion(fromArray.ElementType, toPT.TypeArguments[0]);
}
// conversion from any array to System.Array and the interfaces it implements:
ITypeDefinition systemArray = context.GetClass("System.Array", 0, StringComparer.Ordinal);
ITypeDefinition systemArray = context.GetClass("System", "Array", 0, StringComparer.Ordinal);
return systemArray != null && (systemArray.Equals(toType) || ImplicitReferenceConversion(systemArray, toType));
}

2
ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs

@ -718,7 +718,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -718,7 +718,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return resolver.ResolveThisReference();
}
static readonly GetClassTypeReference systemType = new GetClassTypeReference("System.Type", 0);
static readonly GetClassTypeReference systemType = new GetClassTypeReference("System", "Type", 0);
public override ResolveResult VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data)
{

4
ICSharpCode.NRefactory/TypeSystem/ArrayType.cs

@ -46,8 +46,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -46,8 +46,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
return a != null && elementType.Equals(a.elementType) && a.dimensions == dimensions;
}
static readonly GetClassTypeReference systemArray = new GetClassTypeReference("System.Array", 0);
static readonly GetClassTypeReference listInterface = new GetClassTypeReference("System.Collections.Generic.IList", 1);
static readonly GetClassTypeReference systemArray = new GetClassTypeReference("System", "Array", 0);
static readonly GetClassTypeReference listInterface = new GetClassTypeReference("System.Collections.Generic", "IList", 1);
public override IEnumerable<IType> GetBaseTypes(ITypeResolveContext context)
{

93
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -260,45 +260,33 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -260,45 +260,33 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
return SharedTypes.UnknownType;
}
} else if (type.IsNested) {
ITypeReference typeRef = CreateType(type.DeclaringType, entity, typeAttributes, ref typeIndex);
int partTypeParameterCount;
string namepart = ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out partTypeParameterCount);
return new NestedTypeReference(typeRef, namepart, partTypeParameterCount);
} else {
string name = type.FullName;
string ns = type.Namespace ?? string.Empty;
string name = type.Name;
if (name == null)
throw new InvalidOperationException("type.FullName returned null. Type: " + type.ToString());
throw new InvalidOperationException("type.Name returned null. Type: " + type.ToString());
if (name.IndexOf('/') > 0) {
string[] nameparts = name.Split('/');
ITypeReference typeRef = GetSimpleType(nameparts[0]);
for (int i = 1; i < nameparts.Length; i++) {
int partTypeParameterCount;
string namepart = ReflectionHelper.SplitTypeParameterCountFromReflectionName(nameparts[i], out partTypeParameterCount);
typeRef = new NestedTypeReference(typeRef, namepart, partTypeParameterCount);
}
return typeRef;
} else if (name == "System.Object" && HasDynamicAttribute(typeAttributes, typeIndex)) {
if (name == "Object" && ns == "System" && HasDynamicAttribute(typeAttributes, typeIndex)) {
return SharedTypes.Dynamic;
} else {
return GetSimpleType(name);
int typeParameterCount;
name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(name, out typeParameterCount);
var earlyBindContext = this.EarlyBindContext;
if (earlyBindContext != null) {
IType c = earlyBindContext.GetClass(ns, name, typeParameterCount, StringComparer.Ordinal);
if (c != null)
return c;
}
return new GetClassTypeReference(ns, name, typeParameterCount);
}
}
}
/// <summary>
/// Gets a type reference for a reflection name.
/// This method does not handle nested types -- it can be only used with top-level types.
/// </summary>
ITypeReference GetSimpleType(string reflectionName)
{
int typeParameterCount;
string name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(reflectionName, out typeParameterCount);
var earlyBindContext = this.EarlyBindContext;
if (earlyBindContext != null) {
IType c = earlyBindContext.GetClass(name, typeParameterCount, StringComparer.Ordinal);
if (c != null)
return c;
}
return new GetClassTypeReference(name, typeParameterCount);
}
static readonly string DynamicAttributeFullName = typeof(DynamicAttribute).FullName;
static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex)
@ -526,6 +514,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -526,6 +514,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
this.typeDefinition = null;
Freeze(); // freeze after initialization
ApplyInterningProvider(loader.InterningProvider);
}
void InitNestedTypes(CecilLoader loader)
@ -650,23 +639,18 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -650,23 +639,18 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
if (typeDefinition.HasProperties) {
string defaultMemberName = null;
var defaultMemberAttribute = typeDefinition.CustomAttributes.FirstOrDefault(
a => a.AttributeType.FullName == typeof(System.Reflection.DefaultMemberAttribute).FullName);
if (defaultMemberAttribute != null && defaultMemberAttribute.ConstructorArguments.Count == 1) {
defaultMemberName = defaultMemberAttribute.ConstructorArguments[0].Value as string;
}
foreach (PropertyDefinition property in typeDefinition.Properties) {
bool getterVisible = property.GetMethod != null && loader.IsVisible(property.GetMethod.Attributes);
bool setterVisible = property.SetMethod != null && loader.IsVisible(property.SetMethod.Attributes);
if (getterVisible || setterVisible) {
this.Properties.Add(loader.ReadProperty(property, this));
}
}
var defaultMemberAttribute = typeDefinition.CustomAttributes.FirstOrDefault(
a => a.AttributeType.FullName == typeof(System.Reflection.DefaultMemberAttribute).FullName);
if (defaultMemberAttribute != null && defaultMemberAttribute.ConstructorArguments.Count == 1) {
string defaultMemberName = defaultMemberAttribute.ConstructorArguments[0].Value as string;
if (defaultMemberName != null) {
foreach (DefaultProperty p in this.Properties) {
if (p.Name == defaultMemberName) {
p.EntityType = EntityType.Indexer;
}
}
EntityType type = property.Name == defaultMemberName ? EntityType.Indexer : EntityType.Property;
this.Properties.Add(loader.ReadProperty(property, this, type));
}
}
}
@ -682,7 +666,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -682,7 +666,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Read Method
IMethod ReadMethod(MethodDefinition method, ITypeDefinition parentType, EntityType methodType)
public IMethod ReadMethod(MethodDefinition method, ITypeDefinition parentType, EntityType methodType = EntityType.Method)
{
DefaultMethod m = new DefaultMethod(parentType, method.Name);
m.EntityType = methodType;
@ -719,8 +703,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -719,8 +703,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
if (this.InterningProvider != null)
m = this.InterningProvider.Intern(m);
FinishReadMember(m);
return m;
}
@ -841,8 +824,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -841,8 +824,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
f.IsVolatile = true;
}
if (this.InterningProvider != null)
f = this.InterningProvider.Intern(f);
FinishReadMember(f);
return f;
}
@ -890,13 +872,14 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -890,13 +872,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Read Property
public IProperty ReadProperty(PropertyDefinition property, ITypeDefinition parentType)
public IProperty ReadProperty(PropertyDefinition property, ITypeDefinition parentType, EntityType propertyType = EntityType.Property)
{
if (property == null)
throw new ArgumentNullException("property");
if (parentType == null)
throw new ArgumentNullException("parentType");
DefaultProperty p = new DefaultProperty(parentType, property.Name);
p.EntityType = propertyType;
TranslateModifiers(property.GetMethod ?? property.SetMethod, p);
p.ReturnType = ReadTypeReference(property.PropertyType, typeAttributes: property, entity: p);
@ -910,8 +893,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -910,8 +893,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
AddAttributes(property, p);
if (this.InterningProvider != null)
p = this.InterningProvider.Intern(p);
FinishReadMember(p);
return p;
}
@ -951,10 +933,15 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -951,10 +933,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
AddAttributes(ev, e);
if (this.InterningProvider != null)
e = this.InterningProvider.Intern(e);
FinishReadMember(e);
return e;
}
#endregion
void FinishReadMember(AbstractMember member)
{
member.Freeze();
member.ApplyInterningProvider(this.InterningProvider);
}
}
}

10
ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs

@ -18,12 +18,13 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -18,12 +18,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Retrieves a class.
/// </summary>
/// <param name="fullTypeName">Full name of the class</param>
/// <param name="nameSpace">Namespace that contains the class</param>
/// <param name="name">Name of the class</param>
/// <param name="typeParameterCount">Number of type parameters</param>
/// <param name="nameComparer">Language-specific rules for how class names are compared</param>
/// <returns>The type definition for the class; or null if no such class exists.</returns>
/// <remarks>This method never returns inner classes; it can be used only with top-level classes.</remarks>
ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer);
ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer);
/// <summary>
/// Retrieves all top-level classes.
@ -93,9 +94,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -93,9 +94,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
[ContractClassFor(typeof(ITypeResolveContext))]
abstract class ITypeResolveContextContract : ITypeResolveContext
{
ITypeDefinition ITypeResolveContext.GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
ITypeDefinition ITypeResolveContext.GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
{
Contract.Requires(fullTypeName != null);
Contract.Requires(nameSpace != null);
Contract.Requires(name != null);
Contract.Requires(typeParameterCount >= 0);
Contract.Requires(nameComparer != null);
return null;

24
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractMember.cs

@ -10,7 +10,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -10,7 +10,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Base class for <see cref="IMember"/> implementations.
/// </summary>
public abstract class AbstractMember : AbstractFreezable, IMember, ISupportsInterning
public abstract class AbstractMember : AbstractFreezable, IMember
{
// possible optimizations to reduce the memory usage of AbstractMember:
// - put 'bool isFrozen' into flags
@ -260,22 +260,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -260,22 +260,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
return "[" + EntityType + " " + ReflectionName + ":" + ReturnType + "]";
}
public virtual void PrepareForInterning(IInterningProvider provider)
public virtual void ApplyInterningProvider(IInterningProvider provider)
{
returnType = provider.Intern(returnType);
attributes = provider.InternList(attributes);
interfaceImplementations = provider.InternList(interfaceImplementations);
name = provider.Intern(name);
}
int ISupportsInterning.GetHashCodeForInterning()
{
return GetHashCode();
}
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
{
return this == other;
if (provider != null) {
returnType = provider.Intern(returnType);
attributes = provider.InternList(attributes);
interfaceImplementations = provider.InternList(interfaceImplementations);
name = provider.Intern(name);
}
}
}
}

4
ICSharpCode.NRefactory/TypeSystem/Implementation/CompositeTypeResolveContext.cs

@ -52,10 +52,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -52,10 +52,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
/// <inheritdoc/>
public ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
public ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
{
foreach (ITypeResolveContext context in children) {
ITypeDefinition d = context.GetClass(fullTypeName, typeParameterCount, nameComparer);
ITypeDefinition d = context.GetClass(nameSpace, name, typeParameterCount, nameComparer);
if (d != null)
return d;
}

7
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultField.cs

@ -34,10 +34,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -34,10 +34,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.IsVolatile = f.IsVolatile;
}
public override void PrepareForInterning(IInterningProvider provider)
public override void ApplyInterningProvider(IInterningProvider provider)
{
base.PrepareForInterning(provider);
constantValue = provider.Intern(constantValue);
base.ApplyInterningProvider(provider);
if (provider != null)
constantValue = provider.Intern(constantValue);
}
public bool IsConst {

12
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMethod.cs

@ -42,12 +42,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -42,12 +42,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.IsExtensionMethod = method.IsExtensionMethod;
}
public override void PrepareForInterning(IInterningProvider provider)
public override void ApplyInterningProvider(IInterningProvider provider)
{
base.PrepareForInterning(provider);
returnTypeAttributes = provider.InternList(returnTypeAttributes);
typeParameters = provider.InternList(typeParameters);
parameters = provider.InternList(parameters);
base.ApplyInterningProvider(provider);
if (provider != null) {
returnTypeAttributes = provider.InternList(returnTypeAttributes);
typeParameters = provider.InternList(typeParameters);
parameters = provider.InternList(parameters);
}
}
public IList<IAttribute> ReturnTypeAttributes {

12
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs

@ -34,12 +34,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -34,12 +34,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.parameters = CopyList(p.Parameters);
}
public override void PrepareForInterning(IInterningProvider provider)
public override void ApplyInterningProvider(IInterningProvider provider)
{
base.PrepareForInterning(provider);
getter = provider.Intern(getter);
setter = provider.Intern(setter);
parameters = provider.InternList(parameters);
base.ApplyInterningProvider(provider);
if (provider != null) {
getter = provider.Intern(getter);
setter = provider.Intern(setter);
parameters = provider.InternList(parameters);
}
}
public bool IsIndexer {

15
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

@ -16,8 +16,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -16,8 +16,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
readonly IProjectContent projectContent;
readonly ITypeDefinition declaringTypeDefinition;
readonly string ns;
readonly string name;
string ns;
string name;
IList<ITypeReference> baseTypes;
IList<ITypeParameter> typeParameters;
@ -103,6 +103,17 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -103,6 +103,17 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public void ApplyInterningProvider(IInterningProvider provider)
{
if (provider != null) {
ns = provider.Intern(ns);
name = provider.Intern(name);
baseTypes = provider.InternList(baseTypes);
typeParameters = provider.InternList(typeParameters);
attributes = provider.InternList(attributes);
}
}
public IList<ITypeParameter> TypeParameters {
get {
if (typeParameters == null)

4
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs

@ -244,7 +244,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -244,7 +244,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public IEnumerable<IMethod> GetMethods(ITypeResolveContext context, Predicate<IMethod> filter = null)
{
// TODO: get methods from constraints
IType objectType = context.GetClass("System.Object", 0, StringComparer.Ordinal);
IType objectType = context.GetClass("System", "Object", 0, StringComparer.Ordinal);
IEnumerable<IMethod> objectMethods;
if (objectType != null)
objectMethods = objectType.GetMethods(context, filter);
@ -277,7 +277,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -277,7 +277,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public IEnumerable<IType> GetBaseTypes(ITypeResolveContext context)
{
IType defaultBaseType = context.GetClass(HasValueTypeConstraint ? "System.ValueType" : "System.Object", 0, StringComparer.Ordinal);
IType defaultBaseType = context.GetClass("System", HasValueTypeConstraint ? "ValueType" : "Object", 0, StringComparer.Ordinal);
if (defaultBaseType != null)
yield return defaultBaseType;

36
ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@ -11,15 +12,33 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -11,15 +12,33 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// </summary>
public sealed class GetClassTypeReference : ITypeReference, ISupportsInterning
{
string fullTypeName;
string nameSpace, name;
int typeParameterCount;
//volatile CachedResult v_cachedResult;
public GetClassTypeReference(string nameSpace, string name, int typeParameterCount)
{
if (nameSpace == null)
throw new ArgumentNullException("nameSpace");
if (name == null)
throw new ArgumentNullException("name");
this.nameSpace = nameSpace;
this.name = name;
this.typeParameterCount = typeParameterCount;
}
public GetClassTypeReference(string fullTypeName, int typeParameterCount)
{
if (fullTypeName == null)
throw new ArgumentNullException("fullTypeName");
this.fullTypeName = fullTypeName;
int pos = fullTypeName.LastIndexOf('.');
if (pos < 0) {
nameSpace = string.Empty;
name = fullTypeName;
} else {
nameSpace = fullTypeName.Substring(0, pos);
name = fullTypeName.Substring(pos + 1);
}
this.typeParameterCount = typeParameterCount;
}
@ -64,31 +83,32 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -64,31 +83,32 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
IType DoResolve(ITypeResolveContext context)
{
*/
return context.GetClass(fullTypeName, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
return context.GetClass(nameSpace, name, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
}
public override string ToString()
{
if (typeParameterCount == 0)
return fullTypeName;
return NamespaceDeclaration.BuildQualifiedName(nameSpace, name);
else
return fullTypeName + "`" + typeParameterCount;
return NamespaceDeclaration.BuildQualifiedName(nameSpace, name) + "`" + typeParameterCount;
}
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
{
fullTypeName = provider.Intern(fullTypeName);
nameSpace = provider.Intern(nameSpace);
name = provider.Intern(name);
}
int ISupportsInterning.GetHashCodeForInterning()
{
return fullTypeName.GetHashCode() ^ typeParameterCount;
return nameSpace.GetHashCode() ^ name.GetHashCode() ^ typeParameterCount;
}
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
{
GetClassTypeReference o = other as GetClassTypeReference;
return o != null && fullTypeName == o.fullTypeName && typeParameterCount == o.typeParameterCount;
return o != null && name == o.name && nameSpace == o.nameSpace && typeParameterCount == o.typeParameterCount;
}
}
}

4
ICSharpCode.NRefactory/TypeSystem/Implementation/ProxyTypeResolveContext.cs

@ -25,9 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,9 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
/// <inheritdoc/>
public virtual ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
public virtual ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
{
return target.GetClass(fullTypeName, typeParameterCount, nameComparer);
return target.GetClass(nameSpace, name, typeParameterCount, nameComparer);
}
/// <inheritdoc/>

4
ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs

@ -112,11 +112,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -112,11 +112,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
#endregion
#region IProjectContent implementation
public ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
public ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
{
readerWriterLock.EnterReadLock();
try {
return types.GetClass(fullTypeName, typeParameterCount, nameComparer);
return types.GetClass(nameSpace, name, typeParameterCount, nameComparer);
} finally {
readerWriterLock.ExitReadLock();
}

29
ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs

@ -21,12 +21,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -21,12 +21,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
#region FullNameAndTypeParameterCount
struct FullNameAndTypeParameterCount
{
public readonly string FullName;
public readonly string Namespace;
public readonly string Name;
public readonly int TypeParameterCount;
public FullNameAndTypeParameterCount(string fullName, int typeParameterCount)
public FullNameAndTypeParameterCount(string nameSpace, string name, int typeParameterCount)
{
this.FullName = fullName;
this.Namespace = nameSpace;
this.Name = name;
this.TypeParameterCount = typeParameterCount;
}
}
@ -44,12 +46,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -44,12 +46,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public bool Equals(FullNameAndTypeParameterCount x, FullNameAndTypeParameterCount y)
{
return x.TypeParameterCount == y.TypeParameterCount && NameComparer.Equals(x.FullName, y.FullName);
return x.TypeParameterCount == y.TypeParameterCount
&& NameComparer.Equals(x.Name, y.Name)
&& NameComparer.Equals(x.Namespace, y.Namespace);
}
public int GetHashCode(FullNameAndTypeParameterCount obj)
{
return NameComparer.GetHashCode(obj.FullName);
return NameComparer.GetHashCode(obj.Name) ^ NameComparer.GetHashCode(obj.Namespace) ^ obj.TypeParameterCount;
}
}
#endregion
@ -157,13 +161,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -157,13 +161,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
#region ITypeResolveContext implementation
/// <inheritdoc/>
public ITypeDefinition GetClass(string fullTypeName, int typeParameterCount, StringComparer nameComparer)
public ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
{
if (fullTypeName == null)
throw new ArgumentNullException("fullTypeName");
if (nameSpace == null)
throw new ArgumentNullException("nameSpace");
if (name == null)
throw new ArgumentNullException("name");
if (nameComparer == null)
throw new ArgumentNullException("nameComparer");
var key = new FullNameAndTypeParameterCount(fullTypeName, typeParameterCount);
var key = new FullNameAndTypeParameterCount(nameSpace, name, typeParameterCount);
ITypeDefinition result;
if (GetTypeDictionary(nameComparer).TryGetValue(key, out result))
return result;
@ -235,7 +242,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -235,7 +242,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
var key = new FullNameAndTypeParameterCount(typeDefinition.FullName, typeDefinition.TypeParameterCount);
var key = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
bool wasRemoved = false;
foreach (var dict in _typeDicts) {
ITypeDefinition defInDict;
@ -267,7 +274,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -267,7 +274,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
if (typeDefinition == null)
throw new ArgumentNullException("typeDefinition");
var key = new FullNameAndTypeParameterCount(typeDefinition.FullName, typeDefinition.TypeParameterCount);
var key = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
bool isNew = !_typeDicts[0].ContainsKey(key);
foreach (var dict in _typeDicts) {
dict[key] = typeDefinition;

4
ICSharpCode.NRefactory/TypeSystem/NullableType.cs

@ -47,14 +47,14 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -47,14 +47,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (context == null)
throw new ArgumentNullException("context");
ITypeDefinition nullable = context.GetClass("System.Nullable", 1, StringComparer.Ordinal);
ITypeDefinition nullable = context.GetClass("System", "Nullable", 1, StringComparer.Ordinal);
if (nullable != null)
return new ParameterizedType(nullable, new [] { elementType });
else
return SharedTypes.UnknownType;
}
static readonly ITypeReference NullableReference = new GetClassTypeReference("System.Nullable", 1);
static readonly ITypeReference NullableReference = new GetClassTypeReference("System", "Nullable", 1);
/// <summary>
/// Creates a nullable type reference.

83
ICSharpCode.NRefactory/TypeSystem/ReflectionHelper.cs

@ -53,8 +53,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -53,8 +53,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
return null;
} else {
int typeParameterCount;
string name = SplitTypeParameterCountFromReflectionName(type.FullName, out typeParameterCount);
return context.GetClass(name, typeParameterCount, StringComparer.Ordinal);
string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
return context.GetClass(type.Namespace, name, typeParameterCount, StringComparer.Ordinal);
}
}
#endregion
@ -113,8 +113,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -113,8 +113,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
return new NestedTypeReference(baseTypeRef, name, typeParameterCount);
} else {
int typeParameterCount;
string name = SplitTypeParameterCountFromReflectionName(type.FullName, out typeParameterCount);
return new GetClassTypeReference(name, typeParameterCount);
string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
return new GetClassTypeReference(type.Namespace, name, typeParameterCount);
}
}
#endregion
@ -155,26 +155,31 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -155,26 +155,31 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region TypeCode.ToTypeReference()
/// <summary>
/// Gets a type reference pointing to the <c>void</c> type.
/// </summary>
public static readonly ITypeReference VoidReference = new GetClassTypeReference("System", "Void", 0);
static readonly ITypeReference[] primitiveTypeReferences = {
SharedTypes.UnknownType, // TypeCode.Empty
new GetClassTypeReference("System.Object", 0),
new GetClassTypeReference("System.DBNull", 0),
new GetClassTypeReference("System.Boolean", 0),
new GetClassTypeReference("System.Char", 0),
new GetClassTypeReference("System.SByte", 0),
new GetClassTypeReference("System.Byte", 0),
new GetClassTypeReference("System.Int16", 0),
new GetClassTypeReference("System.UInt16", 0),
new GetClassTypeReference("System.Int32", 0),
new GetClassTypeReference("System.UInt32", 0),
new GetClassTypeReference("System.Int64", 0),
new GetClassTypeReference("System.UInt64", 0),
new GetClassTypeReference("System.Single", 0),
new GetClassTypeReference("System.Double", 0),
new GetClassTypeReference("System.Decimal", 0),
new GetClassTypeReference("System.DateTime", 0),
new GetClassTypeReference("System", "Object", 0),
new GetClassTypeReference("System", "DBNull", 0),
new GetClassTypeReference("System", "Boolean", 0),
new GetClassTypeReference("System", "Char", 0),
new GetClassTypeReference("System", "SByte", 0),
new GetClassTypeReference("System", "Byte", 0),
new GetClassTypeReference("System", "Int16", 0),
new GetClassTypeReference("System", "UInt16", 0),
new GetClassTypeReference("System", "Int32", 0),
new GetClassTypeReference("System", "UInt32", 0),
new GetClassTypeReference("System", "Int64", 0),
new GetClassTypeReference("System", "UInt64", 0),
new GetClassTypeReference("System", "Single", 0),
new GetClassTypeReference("System", "Double", 0),
new GetClassTypeReference("System", "Decimal", 0),
new GetClassTypeReference("System", "DateTime", 0),
SharedTypes.UnknownType, // (TypeCode)17 has no enum value?
new GetClassTypeReference("System.String", 0)
new GetClassTypeReference("System", "String", 0)
};
/// <summary>
@ -190,23 +195,23 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -190,23 +195,23 @@ namespace ICSharpCode.NRefactory.TypeSystem
#region GetTypeCode
static readonly Dictionary<string, TypeCode> typeNameToCodeDict = new Dictionary<string, TypeCode> {
{ "System.Object", TypeCode.Object },
{ "System.DBNull", TypeCode.DBNull },
{ "System.Boolean", TypeCode.Boolean },
{ "System.Char", TypeCode.Char },
{ "System.SByte", TypeCode.SByte },
{ "System.Byte", TypeCode.Byte },
{ "System.Int16", TypeCode.Int16 },
{ "System.UInt16", TypeCode.UInt16 },
{ "System.Int32", TypeCode.Int32 },
{ "System.UInt32", TypeCode.UInt32 },
{ "System.Int64", TypeCode.Int64 },
{ "System.UInt64", TypeCode.UInt64 },
{ "System.Single", TypeCode.Single },
{ "System.Double", TypeCode.Double },
{ "System.Decimal", TypeCode.Decimal },
{ "System.DateTime", TypeCode.DateTime },
{ "System.String", TypeCode.String }
{ "Object", TypeCode.Object },
{ "DBNull", TypeCode.DBNull },
{ "Boolean", TypeCode.Boolean },
{ "Char", TypeCode.Char },
{ "SByte", TypeCode.SByte },
{ "Byte", TypeCode.Byte },
{ "Int16", TypeCode.Int16 },
{ "UInt16", TypeCode.UInt16 },
{ "Int32", TypeCode.Int32 },
{ "UInt32", TypeCode.UInt32 },
{ "Int64", TypeCode.Int64 },
{ "UInt64", TypeCode.UInt64 },
{ "Single", TypeCode.Single },
{ "Double", TypeCode.Double },
{ "Decimal", TypeCode.Decimal },
{ "DateTime", TypeCode.DateTime },
{ "String", TypeCode.String }
};
/// <summary>
@ -216,7 +221,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -216,7 +221,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
ITypeDefinition def = type as ITypeDefinition;
TypeCode typeCode;
if (def != null && def.TypeParameterCount == 0 && typeNameToCodeDict.TryGetValue(def.FullName, out typeCode))
if (def != null && def.TypeParameterCount == 0 && def.Namespace == "System" && typeNameToCodeDict.TryGetValue(def.Name, out typeCode))
return typeCode;
else
return TypeCode.Empty;

Loading…
Cancel
Save