Browse Source

Move member interning logic into AbstractMember.

newNRvisualizers
Daniel Grunwald 15 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 @@ @@ -2,9 +2,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using NUnit.Framework;
@ -101,10 +101,12 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -101,10 +101,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
T newItem = Intern(oldItem);
if (oldItem != newItem) {
if (list.IsReadOnly)
list = new List<T>(list);
list = new T[list.Count];
list[i] = newItem;
}
}
if (!list.IsReadOnly)
list = new ReadOnlyCollection<T>(list);
IEnumerable<object> output;
if (listDict.TryGetValue(list, out output))
list = (IList<T>)output;
@ -120,28 +122,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -120,28 +122,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
Run(n);
}
Intern(c.Name);
foreach (IProperty p in c.Properties) {
Intern(p.Name);
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);
foreach (IMember m in c.Members) {
Intern(m);
}
}

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Base class for <see cref="IMember"/> implementations.
/// </summary>
public abstract class AbstractMember : AbstractFreezable, IMember
public abstract class AbstractMember : AbstractFreezable, IMember, ISupportsInterning
{
ITypeDefinition declaringTypeDefinition;
ITypeReference returnType = SharedTypes.UnknownType;
@ -244,5 +244,23 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -244,5 +244,23 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
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 @@ -8,7 +8,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation for IExplicitInterfaceImplementation.
/// </summary>
public sealed class DefaultExplicitInterfaceImplementation : Immutable, IExplicitInterfaceImplementation
public sealed class DefaultExplicitInterfaceImplementation : Immutable, IExplicitInterfaceImplementation, ISupportsInterning
{
public ITypeReference InterfaceType { get; private set; }
public string MemberName { get; private set; }
@ -27,5 +27,22 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -27,5 +27,22 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
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 @@ -34,6 +34,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.IsVolatile = f.IsVolatile;
}
public override void PrepareForInterning(IInterningProvider provider)
{
base.PrepareForInterning(provider);
constantValue = provider.Intern(constantValue);
}
public bool IsConst {
get { return constantValue != null; }
}

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

@ -42,6 +42,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -42,6 +42,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
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 {
get {
if (returnTypeAttributes == null)

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

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

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="ITypeParameter"/>.
/// </summary>
public class DefaultTypeParameter : AbstractType, ITypeParameter
public class DefaultTypeParameter : AbstractType, ITypeParameter, ISupportsInterning
{
IEntity parent;
@ -168,5 +168,21 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -168,5 +168,21 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
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