Browse Source

Allow CecilProjectContent to be serialized. Add FastSerializer to NRefactory.Utils.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
769c0ae2e0
  1. 11
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
  2. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  3. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs
  4. 42
      ICSharpCode.NRefactory.Tests/TypeSystem/SerializedCecilLoaderTests.cs
  5. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  6. 6
      ICSharpCode.NRefactory/Documentation/XmlDocumentationProvider.cs
  7. 2
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  8. 2
      ICSharpCode.NRefactory/TypeSystem/ArrayType.cs
  9. 2
      ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs
  10. 6
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  11. 1
      ICSharpCode.NRefactory/TypeSystem/IAnnotatable.cs
  12. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractFreezable.cs
  13. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractMember.cs
  14. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs
  15. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultAccessor.cs
  16. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultAttribute.cs
  17. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultEvent.cs
  18. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultField.cs
  19. 6
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultMethod.cs
  20. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs
  21. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs
  22. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  23. 10
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
  24. 3
      ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs
  25. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/NestedTypeReference.cs
  26. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/ProxyTypeResolveContext.cs
  27. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleConstantValue.cs
  28. 10
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleInterningProvider.cs
  29. 35
      ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs
  30. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/TypeWithElementType.cs
  31. 1
      ICSharpCode.NRefactory/TypeSystem/Implementation/VoidTypeDefinition.cs
  32. 1
      ICSharpCode.NRefactory/TypeSystem/IntersectionType.cs
  33. 2
      ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs
  34. 2
      ICSharpCode.NRefactory/TypeSystem/PointerType.cs
  35. 1
      ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs
  36. 117
      ICSharpCode.NRefactory/Utils/7BitEncodedInts.cs
  37. 1
      ICSharpCode.NRefactory/Utils/BitVector16.cs
  38. 1
      ICSharpCode.NRefactory/Utils/EmptyList.cs
  39. 1148
      ICSharpCode.NRefactory/Utils/FastSerializer.cs

11
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.IO;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.Utils;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser
@ -27,10 +28,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -27,10 +28,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
[TestFixture]
public class TypeSystemConvertVisitorTests : TypeSystemTests
{
ITypeResolveContext ctx = CecilLoaderTests.Mscorlib;
[TestFixtureSetUp]
public void FixtureSetUp()
{
testCasePC = ParseTestCase();
}
internal static IProjectContent ParseTestCase()
{
const string fileName = "TypeSystemTests.TestCase.cs";
@ -40,10 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -40,10 +44,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
cu = parser.Parse(s);
}
testCasePC = new SimpleProjectContent();
var testCasePC = new SimpleProjectContent();
ParsedFile parsedFile = new TypeSystemConvertVisitor(testCasePC, fileName).Convert(cu);
parsedFile.Freeze();
testCasePC.UpdateProjectContent(null, parsedFile);
return testCasePC;
}
}
}

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -148,6 +148,7 @@ @@ -148,6 +148,7 @@
<Compile Include="TypeSystem\GetAllBaseTypesTest.cs" />
<Compile Include="TypeSystem\GetMembersTests.cs" />
<Compile Include="TypeSystem\ReflectionHelperTests.cs" />
<Compile Include="TypeSystem\SerializedCecilLoaderTests.cs" />
<Compile Include="TypeSystem\StructureTests.cs" />
<Compile Include="TypeSystem\TestInterningProvider.cs" />
<Compile Include="TypeSystem\TypeSystemTests.cs" />

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

@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IProperty def = c.Properties.Single(p => p.Name == "Default");
ParameterizedType pt = (ParameterizedType)def.ReturnType.Resolve(ctx);
Assert.AreEqual("System.Collections.Generic.Comparer", pt.FullName);
Assert.AreSame(c.TypeParameters[0], pt.TypeArguments[0]);
Assert.AreEqual(c.TypeParameters[0], pt.TypeArguments[0]);
}
[Test]

42
ICSharpCode.NRefactory.Tests/TypeSystem/SerializedCecilLoaderTests.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.NRefactory.Utils;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.TypeSystem
{
[TestFixture]
public class SerializedCecilLoaderTests : TypeSystemTests
{
[TestFixtureSetUp]
public void FixtureSetUp()
{
CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true };
IProjectContent pc = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location);
FastSerializer serializer = new FastSerializer();
using (MemoryStream ms = new MemoryStream()) {
serializer.Serialize(ms, pc);
ms.Position = 0;
testCasePC = (IProjectContent)serializer.Deserialize(ms);
}
}
}
}

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

@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void DynamicType()
{
ITypeDefinition testClass = testCasePC.GetTypeDefinition(typeof(DynamicTest));
Assert.AreSame(SharedTypes.Dynamic, testClass.Properties.Single().ReturnType.Resolve(ctx));
Assert.AreEqual(SharedTypes.Dynamic, testClass.Properties.Single().ReturnType.Resolve(ctx));
Assert.AreEqual(0, testClass.Properties.Single().Attributes.Count);
}

6
ICSharpCode.NRefactory/Documentation/XmlDocumentationProvider.cs

@ -33,6 +33,7 @@ namespace ICSharpCode.NRefactory.Documentation @@ -33,6 +33,7 @@ namespace ICSharpCode.NRefactory.Documentation
/// This class first creates an in-memory index of the .xml file, and then uses that to read only the requested members.
/// This way, we avoid keeping all the documentation in memory.
/// </remarks>
[Serializable]
public class XmlDocumentationProvider : IDocumentationProvider
{
#region Cache
@ -66,6 +67,7 @@ namespace ICSharpCode.NRefactory.Documentation @@ -66,6 +67,7 @@ namespace ICSharpCode.NRefactory.Documentation
}
#endregion
[Serializable]
struct IndexEntry : IComparable<IndexEntry>
{
/// <summary>
@ -90,7 +92,9 @@ namespace ICSharpCode.NRefactory.Documentation @@ -90,7 +92,9 @@ namespace ICSharpCode.NRefactory.Documentation
}
}
[NonSerialized]
readonly XmlDocumentationCache cache = new XmlDocumentationCache();
readonly string fileName;
DateTime lastWriteDate;
IndexEntry[] index; // SORTED array of index entries
@ -265,6 +269,8 @@ namespace ICSharpCode.NRefactory.Documentation @@ -265,6 +269,8 @@ namespace ICSharpCode.NRefactory.Documentation
#endregion
#region Save index / Restore from index
// TODO: consider removing this code, we're just using serialization instead
// FILE FORMAT FOR BINARY DOCUMENTATION
// long magic = 0x4244636f446c6d58 (identifies file type = 'XmlDocDB')
const long magic = 0x4244636f446c6d58;

2
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -336,6 +336,7 @@ @@ -336,6 +336,7 @@
<Compile Include="CSharp\Parser\mcs\support.cs" />
<Compile Include="CSharp\Parser\mcs\complete.cs" />
<Compile Include="CSharp\Parser\mcs\literal.cs" />
<Compile Include="Utils\7BitEncodedInts.cs" />
<Compile Include="Utils\BitVector16.cs" />
<Compile Include="Utils\BusyManager.cs" />
<Compile Include="Utils\CacheManager.cs" />
@ -343,6 +344,7 @@ @@ -343,6 +344,7 @@
<Compile Include="Utils\DotNet35Compat.cs" />
<Compile Include="Utils\EmptyList.cs" />
<Compile Include="Utils\ExtensionMethods.cs" />
<Compile Include="Utils\FastSerializer.cs" />
<Compile Include="Utils\GraphVizGraph.cs" />
<Compile Include="Utils\Platform.cs" />
<Compile Include="Utils\TreeTraversal.cs" />

2
ICSharpCode.NRefactory/TypeSystem/ArrayType.cs

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents an array type.
/// </summary>
[Serializable]
public sealed class ArrayType : TypeWithElementType
{
readonly int dimensions;
@ -135,6 +136,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -135,6 +136,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
[Serializable]
public sealed class ArrayTypeReference : ITypeReference, ISupportsInterning
{
ITypeReference elementType;

2
ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs

@ -21,6 +21,7 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation; @@ -21,6 +21,7 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.TypeSystem
{
[Serializable]
public sealed class ByReferenceType : TypeWithElementType
{
public ByReferenceType(IType elementType) : base(elementType)
@ -68,6 +69,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -68,6 +69,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
[Serializable]
public class ByReferenceTypeReference : ITypeReference
{
readonly ITypeReference elementType;

6
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -84,6 +84,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -84,6 +84,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
if (createCecilReferences)
typeSystemTranslationTable = new Dictionary<object, object> ();
// Enable interning by default.
this.InterningProvider = new SimpleInterningProvider();
}
#region Load From AssemblyDefinition
@ -164,6 +167,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -164,6 +167,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region IProjectContent implementation
[Serializable]
sealed class CecilProjectContent : ProxyTypeResolveContext, IProjectContent, ISynchronizedTypeResolveContext, IDocumentationProvider
{
readonly string assemblyName;
@ -840,8 +844,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -840,8 +844,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion
#region Read Type Definition
[Serializable]
sealed class CecilTypeDefinition : DefaultTypeDefinition
{
[NonSerialized]
internal TypeDefinition typeDefinition;
public CecilTypeDefinition(IProjectContent pc, TypeDefinition typeDefinition)

1
ICSharpCode.NRefactory/TypeSystem/IAnnotatable.cs

@ -78,6 +78,7 @@ namespace ICSharpCode.NRefactory @@ -78,6 +78,7 @@ namespace ICSharpCode.NRefactory
void RemoveAnnotations(Type type);
}
[Serializable]
public abstract class AbstractAnnotatable : IAnnotatable
{
// Annotations: points either null (no annotations), to the single annotation,

2
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractFreezable.cs

@ -27,6 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -27,6 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// Base class for immutable objects. Provides implementation for IFreezable that reports the
/// object as always-frozen.
/// </summary>
[Serializable]
public abstract class Immutable : IFreezable
{
bool IFreezable.IsFrozen {
@ -38,6 +39,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -38,6 +39,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
[Serializable]
public abstract class AbstractFreezable : IFreezable
{
bool isFrozen;

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

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Base class for <see cref="IMember"/> implementations.
/// </summary>
[Serializable]
public abstract class AbstractMember : AbstractFreezable, IMember
{
// possible optimizations to reduce the memory usage of AbstractMember:

1
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation for IType interface.
/// </summary>
[Serializable]
public abstract class AbstractType : IType
{
public virtual string FullName {

1
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultAccessor.cs

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="IAccessor"/>.
/// </summary>
[Serializable]
public sealed class DefaultAccessor : AbstractFreezable, IAccessor, ISupportsInterning
{
static readonly DefaultAccessor[] defaultAccessors = CreateDefaultAccessors();

1
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultAttribute.cs

@ -27,6 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -27,6 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="IAttribute"/>.
/// </summary>
[Serializable]
public sealed class DefaultAttribute : AbstractFreezable, IAttribute, ISupportsInterning
{
ITypeReference attributeType;

1
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultEvent.cs

@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="IEvent"/>.
/// </summary>
[Serializable]
public class DefaultEvent : AbstractMember, IEvent
{
IAccessor addAccessor, removeAccessor, invokeAccessor;

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

@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="IField"/>.
/// </summary>
[Serializable]
public class DefaultField : AbstractMember, IField
{
IConstantValue constantValue;

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

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="IMethod" /> interface.
/// </summary>
[Serializable]
public class DefaultMethod : AbstractMember, IMethod
{
IList<IAttribute> returnTypeAttributes;
@ -123,7 +124,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -123,7 +124,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
var p = this.Parameters;
for (int i = 0; i < p.Count; i++) {
if (i > 0) b.Append(", ");
b.Append(p[i].ToString());
if (p[i] == null)
b.Append("null");
else
b.Append(p[i].ToString());
}
b.Append("):");
b.Append(ReturnType.ToString());

1
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation for IParameter.
/// </summary>
[Serializable]
public sealed class DefaultParameter : AbstractFreezable, IParameter, ISupportsInterning
{
string name = string.Empty;

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

@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="IProperty"/>.
/// </summary>
[Serializable]
public class DefaultProperty : AbstractMember, IProperty
{
IAccessor getter, setter;

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

@ -25,6 +25,7 @@ using ICSharpCode.NRefactory.Utils; @@ -25,6 +25,7 @@ using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
[Serializable]
public class DefaultTypeDefinition : AbstractFreezable, ITypeDefinition
{
readonly IProjectContent projectContent;

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

@ -27,6 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -27,6 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Default implementation of <see cref="ITypeParameter"/>.
/// </summary>
[Serializable]
public sealed class DefaultTypeParameter : AbstractFreezable, ITypeParameter, ISupportsInterning
{
string name;
@ -348,8 +349,13 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -348,8 +349,13 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
{
constraints = provider.InternList(constraints);
attributes = provider.InternList(attributes);
// protect against cyclic constraints
using (var busyLock = BusyManager.Enter(this)) {
if (busyLock.Success) {
constraints = provider.InternList(constraints);
attributes = provider.InternList(attributes);
}
}
}
int ISupportsInterning.GetHashCodeForInterning()

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

@ -25,11 +25,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,11 +25,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Type Reference used when the fully qualified type name is known.
/// </summary>
[Serializable]
public sealed class GetClassTypeReference : ITypeReference, ISupportsInterning
{
string nameSpace, name;
int typeParameterCount;
//volatile CachedResult v_cachedResult;
// [NonSerialized] volatile CachedResult v_cachedResult;
public GetClassTypeReference(string nameSpace, string name, int typeParameterCount)
{

1
ICSharpCode.NRefactory/TypeSystem/Implementation/NestedTypeReference.cs

@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Type reference used to reference nested types.
/// </summary>
[Serializable]
public sealed class NestedTypeReference : ITypeReference, ISupportsInterning
{
ITypeReference declaringTypeRef;

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

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// Proxy that forwards calls to another TypeResolveContext.
/// Useful as base class for decorators.
/// </summary>
[Serializable]
public class ProxyTypeResolveContext : AbstractAnnotatable, ITypeResolveContext
{
protected readonly ITypeResolveContext target;

1
ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleConstantValue.cs

@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// A simple constant value that is independent of the resolve context.
/// </summary>
[Serializable]
public sealed class SimpleConstantValue : Immutable, IConstantValue, ISupportsInterning
{
ITypeReference type;

10
ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleInterningProvider.cs

@ -104,6 +104,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -104,6 +104,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
Dictionary<ISupportsInterning, ISupportsInterning> supportsInternDict = new Dictionary<ISupportsInterning, ISupportsInterning>(new InterningComparer());
Dictionary<IEnumerable, IEnumerable> listDict = new Dictionary<IEnumerable, IEnumerable>(new ListComparer());
int stackDepth = 0;
public T Intern<T>(T obj) where T : class
{
if (obj == null)
@ -127,6 +129,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -127,6 +129,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
else
byValueDict.Add(obj, obj);
}
stackDepth--;
return obj;
}
@ -138,8 +141,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -138,8 +141,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
T oldItem = list[i];
T newItem = Intern(oldItem);
if (oldItem != newItem) {
if (list.IsReadOnly)
list = new T[list.Count];
if (list.IsReadOnly) {
T[] array = new T[list.Count];
list.CopyTo(array, 0);
list = array;
}
list[i] = newItem;
}
}

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

@ -19,8 +19,8 @@ @@ -19,8 +19,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
@ -31,7 +31,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -31,7 +31,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <remarks>
/// Concurrent read accesses are thread-safe, but a write access concurrent to any other access is not safe.
/// </remarks>
public sealed class TypeStorage : ITypeResolveContext
[Serializable]
public sealed class TypeStorage : ITypeResolveContext, ISerializable, IDeserializationCallback
{
#region FullNameAndTypeParameterCount
struct FullNameAndTypeParameterCount
@ -362,5 +363,35 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -362,5 +363,35 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
#endregion
#region Serialization
/// <summary>
/// Creates a new TypeStorage instance.
/// </summary>
public TypeStorage()
{
}
SerializationInfo serializationInfo;
protected TypeStorage(SerializationInfo info, StreamingContext context)
{
this.serializationInfo = info;
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Types", this.GetTypes().ToArray());
}
void IDeserializationCallback.OnDeserialization(object sender)
{
if (serializationInfo == null)
return;
foreach (var typeDef in (ITypeDefinition[])serializationInfo.GetValue("Types", typeof(ITypeDefinition[]))) {
UpdateType(typeDef);
}
}
#endregion
}
}

1
ICSharpCode.NRefactory/TypeSystem/Implementation/TypeWithElementType.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
[Serializable]
public abstract class TypeWithElementType : AbstractType
{
protected readonly IType elementType;

1
ICSharpCode.NRefactory/TypeSystem/Implementation/VoidTypeDefinition.cs

@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
/// <summary>
/// Special type definition for 'void'.
/// </summary>
[Serializable]
public class VoidTypeDefinition : DefaultTypeDefinition
{
public VoidTypeDefinition(IProjectContent projectContent)

1
ICSharpCode.NRefactory/TypeSystem/IntersectionType.cs

@ -30,6 +30,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,6 +30,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents the intersection of several types.
/// </summary>
[Serializable]
public class IntersectionType : AbstractType
{
readonly ReadOnlyCollection<IType> types;

2
ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs

@ -36,6 +36,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -36,6 +36,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// type parameters in the signatures of the members are replaced with
/// the type arguments.
/// </remarks>
[Serializable]
public sealed class ParameterizedType : Immutable, IType
{
readonly ITypeDefinition genericType;
@ -327,6 +328,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -327,6 +328,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// ParameterizedTypeReference is a reference to generic class that specifies the type parameters.
/// Example: List&lt;string&gt;
/// </summary>
[Serializable]
public sealed class ParameterizedTypeReference : ITypeReference, ISupportsInterning
{
public static ITypeReference Create(ITypeReference genericType, IEnumerable<ITypeReference> typeArguments)

2
ICSharpCode.NRefactory/TypeSystem/PointerType.cs

@ -22,6 +22,7 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation; @@ -22,6 +22,7 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.TypeSystem
{
[Serializable]
public sealed class PointerType : TypeWithElementType
{
public PointerType(IType elementType) : base(elementType)
@ -69,6 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -69,6 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
[Serializable]
public class PointerTypeReference : ITypeReference
{
readonly ITypeReference elementType;

1
ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs

@ -70,6 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -70,6 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
* would have to return true even though these are two distinct definitions.
*/
[Serializable]
sealed class SharedTypeImpl : AbstractType
{
readonly TypeKind kind;

117
ICSharpCode.NRefactory/Utils/7BitEncodedInts.cs

@ -0,0 +1,117 @@ @@ -0,0 +1,117 @@
// Copyright (c) 2011 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
namespace ICSharpCode.NRefactory.Utils
{
/// <summary>
/// A binary reader that can read the output of BinaryWriterWith7BitEncodedInts.
/// </summary>
public sealed class BinaryReaderWith7BitEncodedInts : BinaryReader
{
public BinaryReaderWith7BitEncodedInts(Stream stream) : base(stream)
{
}
public override short ReadInt16()
{
return unchecked((short)(ushort)base.Read7BitEncodedInt());
}
public override ushort ReadUInt16()
{
return unchecked((ushort)base.Read7BitEncodedInt());
}
public override int ReadInt32()
{
return base.Read7BitEncodedInt();
}
public override uint ReadUInt32()
{
return unchecked((uint)base.Read7BitEncodedInt());
}
public override long ReadInt64()
{
return unchecked((long)this.ReadUInt64());
}
public override ulong ReadUInt64()
{
ulong num = 0;
int shift = 0;
while (shift < 64) {
byte b = this.ReadByte();
num |= (ulong)(b & 127) << shift;
shift += 7;
if ((b & 128) == 0) {
return num;
}
}
throw new FormatException("Invalid 7-bit int64");
}
}
/// <summary>
/// A binary writer that encodes all integers as 7-bit-encoded-ints.
/// </summary>
public sealed class BinaryWriterWith7BitEncodedInts : BinaryWriter
{
public BinaryWriterWith7BitEncodedInts(Stream stream) : base(stream)
{
}
public override void Write(short value)
{
base.Write7BitEncodedInt(unchecked((ushort)value));
}
public override void Write(ushort value)
{
base.Write7BitEncodedInt(value);
}
public override void Write(int value)
{
base.Write7BitEncodedInt(value);
}
public override void Write(uint value)
{
base.Write7BitEncodedInt(unchecked((int)value));
}
public override void Write(long value)
{
this.Write(unchecked((ulong)value));
}
public override void Write(ulong value)
{
while (value >= 128) {
this.Write(unchecked((byte)(value | 128u)));
value >>= 7;
}
this.Write(unchecked((byte)value));
}
}
}

1
ICSharpCode.NRefactory/Utils/BitVector16.cs

@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.Utils @@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.Utils
/// <summary>
/// Holds 16 boolean values.
/// </summary>
[Serializable]
public struct BitVector16 : IEquatable<BitVector16>
{
ushort data;

1
ICSharpCode.NRefactory/Utils/EmptyList.cs

@ -23,6 +23,7 @@ using System.Collections.ObjectModel; @@ -23,6 +23,7 @@ using System.Collections.ObjectModel;
namespace ICSharpCode.NRefactory
{
[Serializable]
sealed class EmptyList<T> : IList<T>, IEnumerator<T>
{
public static readonly IList<T> Instance = new EmptyList<T>();

1148
ICSharpCode.NRefactory/Utils/FastSerializer.cs

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save