mirror of https://github.com/icsharpcode/ILSpy.git
28 changed files with 400 additions and 221 deletions
@ -1,192 +0,0 @@
@@ -1,192 +0,0 @@
|
||||
// Copyright (c) 2010-2013 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.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.Decompiler.TypeSystem.Implementation; |
||||
using ICSharpCode.Decompiler.Util; |
||||
|
||||
namespace ICSharpCode.Decompiler.TypeSystem |
||||
{ |
||||
/// <summary>
|
||||
/// Anonymous type.
|
||||
/// </summary>
|
||||
public class AnonymousType : AbstractType |
||||
{ |
||||
ICompilation compilation; |
||||
|
||||
public AnonymousType(ICompilation compilation) |
||||
{ |
||||
if (compilation == null) |
||||
throw new ArgumentNullException("compilation"); |
||||
this.compilation = compilation; |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/* |
||||
sealed class AnonymousTypeProperty : DefaultResolvedProperty |
||||
{ |
||||
readonly AnonymousType declaringType; |
||||
|
||||
public AnonymousTypeProperty(IUnresolvedProperty unresolved, ITypeResolveContext parentContext, AnonymousType declaringType) |
||||
: base(unresolved, parentContext) |
||||
{ |
||||
this.declaringType = declaringType; |
||||
} |
||||
|
||||
public override IType DeclaringType { |
||||
get { return declaringType; } |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
AnonymousTypeProperty p = obj as AnonymousTypeProperty; |
||||
return p != null && this.Name == p.Name && declaringType.Equals(p.declaringType); |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return declaringType.GetHashCode() ^ unchecked(27 * this.Name.GetHashCode()); |
||||
} |
||||
|
||||
protected override IMethod CreateResolvedAccessor(IUnresolvedMethod unresolvedAccessor) |
||||
{ |
||||
return new AnonymousTypeAccessor(unresolvedAccessor, context, this); |
||||
} |
||||
} |
||||
|
||||
sealed class AnonymousTypeAccessor : DefaultResolvedMethod |
||||
{ |
||||
readonly AnonymousTypeProperty owner; |
||||
|
||||
public AnonymousTypeAccessor(IUnresolvedMethod unresolved, ITypeResolveContext parentContext, AnonymousTypeProperty owner) |
||||
: base(unresolved, parentContext, isExtensionMethod: false) |
||||
{ |
||||
this.owner = owner; |
||||
} |
||||
|
||||
public override IMember AccessorOwner { |
||||
get { return owner; } |
||||
} |
||||
|
||||
public override IType DeclaringType { |
||||
get { return owner.DeclaringType; } |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
AnonymousTypeAccessor p = obj as AnonymousTypeAccessor; |
||||
return p != null && this.Name == p.Name && owner.DeclaringType.Equals(p.owner.DeclaringType); |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return owner.DeclaringType.GetHashCode() ^ unchecked(27 * this.Name.GetHashCode()); |
||||
} |
||||
} |
||||
*/ |
||||
|
||||
public override string Name { |
||||
get { return "Anonymous Type"; } |
||||
} |
||||
|
||||
public override TypeKind Kind { |
||||
get { return TypeKind.Anonymous; } |
||||
} |
||||
|
||||
public override IEnumerable<IType> DirectBaseTypes { |
||||
get { |
||||
yield return compilation.FindType(KnownTypeCode.Object); |
||||
} |
||||
} |
||||
|
||||
public override bool? IsReferenceType { |
||||
get { return true; } |
||||
} |
||||
|
||||
/* |
||||
public IReadOnlyList<IProperty> Properties { |
||||
get { return resolvedProperties; } |
||||
} |
||||
|
||||
public override IEnumerable<IMethod> GetMethods(Predicate<IMethod> filter = null, GetMemberOptions options = GetMemberOptions.None) |
||||
{ |
||||
if ((options & GetMemberOptions.IgnoreInheritedMembers) == GetMemberOptions.IgnoreInheritedMembers) |
||||
return EmptyList<IMethod>.Instance; |
||||
else |
||||
return compilation.FindType(KnownTypeCode.Object).GetMethods(filter, options); |
||||
} |
||||
|
||||
public override IEnumerable<IMethod> GetMethods(IReadOnlyList<IType> typeArguments, Predicate<IMethod> filter = null, GetMemberOptions options = GetMemberOptions.None) |
||||
{ |
||||
if ((options & GetMemberOptions.IgnoreInheritedMembers) == GetMemberOptions.IgnoreInheritedMembers) |
||||
return EmptyList<IMethod>.Instance; |
||||
else |
||||
return compilation.FindType(KnownTypeCode.Object).GetMethods(typeArguments, filter, options); |
||||
} |
||||
|
||||
public override IEnumerable<IProperty> GetProperties(Predicate<IProperty> filter = null, GetMemberOptions options = GetMemberOptions.None) |
||||
{ |
||||
for (int i = 0; i < unresolvedProperties.Length; i++) { |
||||
if (filter == null || filter(resolvedProperties[i])) |
||||
yield return resolvedProperties[i]; |
||||
} |
||||
} |
||||
|
||||
public override IEnumerable<IMethod> GetAccessors(Predicate<IMethod> filter, GetMemberOptions options) |
||||
{ |
||||
for (int i = 0; i < unresolvedProperties.Length; i++) { |
||||
if (unresolvedProperties[i].CanGet) { |
||||
if (filter == null || filter(resolvedProperties[i].Getter)) |
||||
yield return resolvedProperties[i].Getter; |
||||
} |
||||
if (unresolvedProperties[i].CanSet) { |
||||
if (filter == null || filter(resolvedProperties[i].Setter)) |
||||
yield return resolvedProperties[i].Setter; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
unchecked { |
||||
int hashCode = resolvedProperties.Count; |
||||
foreach (var p in resolvedProperties) { |
||||
hashCode *= 31; |
||||
hashCode += p.Name.GetHashCode() ^ p.ReturnType.GetHashCode(); |
||||
} |
||||
return hashCode; |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(IType other) |
||||
{ |
||||
AnonymousType o = other as AnonymousType; |
||||
if (o == null || resolvedProperties.Count != o.resolvedProperties.Count) |
||||
return false; |
||||
for (int i = 0; i < resolvedProperties.Count; i++) { |
||||
IProperty p1 = resolvedProperties[i]; |
||||
IProperty p2 = o.resolvedProperties[i]; |
||||
if (p1.Name != p2.Name || !p1.ReturnType.Equals(p2.ReturnType)) |
||||
return false; |
||||
} |
||||
return true; |
||||
}*/ |
||||
} |
||||
} |
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Decompiler.TypeSystem.Implementation |
||||
{ |
||||
public abstract class DecoratedType : IType |
||||
{ |
||||
protected readonly IType baseType; |
||||
|
||||
protected DecoratedType(IType baseType) |
||||
{ |
||||
this.baseType = baseType; |
||||
} |
||||
|
||||
TypeKind IType.Kind => baseType.Kind; |
||||
|
||||
bool? IType.IsReferenceType => baseType.IsReferenceType; |
||||
|
||||
bool IType.IsByRefLike => baseType.IsByRefLike; |
||||
|
||||
Nullability IType.Nullability => baseType.Nullability; |
||||
public abstract IType ChangeNullability(Nullability nullability); |
||||
|
||||
IType IType.DeclaringType => baseType.DeclaringType; |
||||
|
||||
int IType.TypeParameterCount => baseType.TypeParameterCount; |
||||
|
||||
IReadOnlyList<ITypeParameter> IType.TypeParameters => baseType.TypeParameters; |
||||
|
||||
IReadOnlyList<IType> IType.TypeArguments => baseType.TypeArguments; |
||||
|
||||
IEnumerable<IType> IType.DirectBaseTypes => baseType.DirectBaseTypes; |
||||
|
||||
string INamedElement.FullName => baseType.FullName; |
||||
|
||||
string INamedElement.Name => baseType.Name; |
||||
|
||||
string INamedElement.ReflectionName => baseType.ReflectionName; |
||||
|
||||
string INamedElement.Namespace => baseType.Namespace; |
||||
|
||||
public abstract IType AcceptVisitor(TypeVisitor visitor); |
||||
|
||||
public abstract bool Equals(IType other); |
||||
|
||||
IEnumerable<IMethod> IType.GetAccessors(Predicate<IMethod> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetAccessors(filter, options); |
||||
} |
||||
|
||||
IEnumerable<IMethod> IType.GetConstructors(Predicate<IMethod> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetConstructors(filter, options); |
||||
} |
||||
|
||||
ITypeDefinition IType.GetDefinition() |
||||
{ |
||||
return baseType.GetDefinition(); |
||||
} |
||||
|
||||
IEnumerable<IEvent> IType.GetEvents(Predicate<IEvent> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetEvents(filter, options); |
||||
} |
||||
|
||||
IEnumerable<IField> IType.GetFields(Predicate<IField> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetFields(filter, options); |
||||
} |
||||
|
||||
IEnumerable<IMember> IType.GetMembers(Predicate<IMember> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetMembers(filter, options); |
||||
} |
||||
|
||||
IEnumerable<IMethod> IType.GetMethods(Predicate<IMethod> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetMethods(filter, options); |
||||
} |
||||
|
||||
IEnumerable<IMethod> IType.GetMethods(IReadOnlyList<IType> typeArguments, Predicate<IMethod> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetMethods(typeArguments, filter, options); |
||||
} |
||||
|
||||
IEnumerable<IType> IType.GetNestedTypes(Predicate<ITypeDefinition> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetNestedTypes(filter, options); |
||||
} |
||||
|
||||
IEnumerable<IType> IType.GetNestedTypes(IReadOnlyList<IType> typeArguments, Predicate<ITypeDefinition> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetNestedTypes(typeArguments, filter, options); |
||||
} |
||||
|
||||
IEnumerable<IProperty> IType.GetProperties(Predicate<IProperty> filter, GetMemberOptions options) |
||||
{ |
||||
return baseType.GetProperties(filter, options); |
||||
} |
||||
|
||||
TypeParameterSubstitution IType.GetSubstitution() |
||||
{ |
||||
return baseType.GetSubstitution(); |
||||
} |
||||
|
||||
public abstract IType VisitChildren(TypeVisitor visitor); |
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Decompiler.TypeSystem.Implementation |
||||
{ |
||||
public sealed class NullabilityAnnotatedType : DecoratedType, IType |
||||
{ |
||||
readonly Nullability nullability; |
||||
|
||||
internal NullabilityAnnotatedType(IType type, Nullability nullability) |
||||
: base(type) |
||||
{ |
||||
Debug.Assert(nullability != Nullability.Oblivious); |
||||
Debug.Assert(!(type is ParameterizedType || type is NullabilityAnnotatedType)); |
||||
this.nullability = nullability; |
||||
} |
||||
|
||||
public Nullability Nullability => nullability; |
||||
|
||||
public IType ElementType => baseType; |
||||
|
||||
public override IType AcceptVisitor(TypeVisitor visitor) |
||||
{ |
||||
return visitor.VisitNullabilityAnnotatedType(this); |
||||
} |
||||
|
||||
public override bool Equals(IType other) |
||||
{ |
||||
return other is NullabilityAnnotatedType nat |
||||
&& nat.nullability == nullability |
||||
&& nat.baseType.Equals(baseType); |
||||
} |
||||
|
||||
public override IType ChangeNullability(Nullability nullability) |
||||
{ |
||||
if (nullability == this.nullability) |
||||
return this; |
||||
else |
||||
return baseType.ChangeNullability(nullability); |
||||
} |
||||
|
||||
public override IType VisitChildren(TypeVisitor visitor) |
||||
{ |
||||
IType newBase = baseType.AcceptVisitor(visitor); |
||||
if (newBase != baseType) |
||||
return new NullabilityAnnotatedType(newBase, nullability); |
||||
else |
||||
return this; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return baseType.ToString() + (nullability == Nullability.Nullable ? "?" : "!"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Decompiler.TypeSystem |
||||
{ |
||||
public enum Nullability : byte |
||||
{ |
||||
Oblivious = 0, |
||||
NotNullable = 1, |
||||
Nullable = 2 |
||||
} |
||||
} |
Loading…
Reference in new issue