Browse Source

Move member interning logic into AbstractMember.

newNRvisualizers
Daniel Grunwald 16 years ago
parent
commit
d2f8d6e34a
  1. 30
      ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs
  2. 20
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractMember.cs
  3. 19
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultExplicitInterfaceImplementation.cs
  4. 6
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultField.cs
  5. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMethod.cs
  6. 6
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs
  7. 18
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs

30
ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs

@ -2,9 +2,9 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
using NUnit.Framework; using NUnit.Framework;
@ -101,10 +101,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
T newItem = Intern(oldItem); T newItem = Intern(oldItem);
if (oldItem != newItem) { if (oldItem != newItem) {
if (list.IsReadOnly) if (list.IsReadOnly)
list = new List<T>(list); list = new T[list.Count];
list[i] = newItem; list[i] = newItem;
} }
} }
if (!list.IsReadOnly)
list = new ReadOnlyCollection<T>(list);
IEnumerable<object> output; IEnumerable<object> output;
if (listDict.TryGetValue(list, out output)) if (listDict.TryGetValue(list, out output))
list = (IList<T>)output; list = (IList<T>)output;
@ -120,28 +122,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
Run(n); Run(n);
} }
Intern(c.Name); Intern(c.Name);
foreach (IProperty p in c.Properties) { foreach (IMember m in c.Members) {
Intern(p.Name); Intern(m);
Intern(p.ReturnType);
InternList(p.Parameters);
InternList(p.Attributes);
}
foreach (IMethod m in c.Methods) {
Intern(m.Name);
Intern(m.ReturnType);
InternList(m.Parameters);
InternList(m.Attributes);
}
foreach (IField f in c.Fields) {
Intern(f.Name);
Intern(f.ReturnType);
Intern(f.ConstantValue);
InternList(f.Attributes);
}
foreach (IEvent e in c.Events) {
Intern(e.Name);
Intern(e.ReturnType);
InternList(e.Attributes);
} }
} }

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary> /// <summary>
/// Base class for <see cref="IMember"/> implementations. /// Base class for <see cref="IMember"/> implementations.
/// </summary> /// </summary>
public abstract class AbstractMember : AbstractFreezable, IMember public abstract class AbstractMember : AbstractFreezable, IMember, ISupportsInterning
{ {
ITypeDefinition declaringTypeDefinition; ITypeDefinition declaringTypeDefinition;
ITypeReference returnType = SharedTypes.UnknownType; ITypeReference returnType = SharedTypes.UnknownType;
@ -244,5 +244,23 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{ {
return "[" + EntityType + " " + DotNetName + ":" + ReturnType + "]"; return "[" + EntityType + " " + DotNetName + ":" + ReturnType + "]";
} }
public virtual void PrepareForInterning(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;
}
} }
} }

19
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultExplicitInterfaceImplementation.cs

@ -8,7 +8,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary> /// <summary>
/// Default implementation for IExplicitInterfaceImplementation. /// Default implementation for IExplicitInterfaceImplementation.
/// </summary> /// </summary>
public sealed class DefaultExplicitInterfaceImplementation : Immutable, IExplicitInterfaceImplementation public sealed class DefaultExplicitInterfaceImplementation : Immutable, IExplicitInterfaceImplementation, ISupportsInterning
{ {
public ITypeReference InterfaceType { get; private set; } public ITypeReference InterfaceType { get; private set; }
public string MemberName { get; private set; } public string MemberName { get; private set; }
@ -27,5 +27,22 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{ {
return InterfaceType + "." + MemberName; return InterfaceType + "." + MemberName;
} }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
{
InterfaceType = provider.Intern(InterfaceType);
MemberName = provider.Intern(MemberName);
}
int ISupportsInterning.GetHashCodeForInterning()
{
return InterfaceType.GetHashCode() ^ MemberName.GetHashCode();
}
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
{
DefaultExplicitInterfaceImplementation o = other as DefaultExplicitInterfaceImplementation;
return InterfaceType == o.InterfaceType && MemberName == o.MemberName;
}
} }
} }

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

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

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

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

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

@ -40,6 +40,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.CanSet = p.CanSet; this.CanSet = p.CanSet;
} }
public override void PrepareForInterning(IInterningProvider provider)
{
base.PrepareForInterning(provider);
parameters = provider.InternList(parameters);
}
public bool IsIndexer { public bool IsIndexer {
get { return flags[FlagIsIndexer]; } get { return flags[FlagIsIndexer]; }
set { set {

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary> /// <summary>
/// Default implementation of <see cref="ITypeParameter"/>. /// Default implementation of <see cref="ITypeParameter"/>.
/// </summary> /// </summary>
public class DefaultTypeParameter : AbstractType, ITypeParameter public class DefaultTypeParameter : AbstractType, ITypeParameter, ISupportsInterning
{ {
IEntity parent; IEntity parent;
@ -168,5 +168,21 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{ {
return visitor.VisitTypeParameter(this); return visitor.VisitTypeParameter(this);
} }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
{
constraints = provider.InternList(constraints);
attributes = provider.InternList(attributes);
}
int ISupportsInterning.GetHashCodeForInterning()
{
return GetHashCode();
}
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
{
return this == other;
}
} }
} }

Loading…
Cancel
Save