53 changed files with 1145 additions and 318 deletions
@ -0,0 +1,106 @@ |
|||||||
|
// 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.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.NRefactory.Utils; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Anonymous type.
|
||||||
|
/// </summary>
|
||||||
|
public class AnonymousType : AbstractType |
||||||
|
{ |
||||||
|
ICompilation compilation; |
||||||
|
IUnresolvedProperty[] unresolvedProperties; |
||||||
|
IList<IProperty> resolvedProperties; |
||||||
|
|
||||||
|
public AnonymousType(ICompilation compilation, IList<IUnresolvedProperty> properties) |
||||||
|
{ |
||||||
|
if (compilation == null) |
||||||
|
throw new ArgumentNullException("compilation"); |
||||||
|
if (properties == null) |
||||||
|
throw new ArgumentNullException("properties"); |
||||||
|
this.compilation = compilation; |
||||||
|
this.unresolvedProperties = properties.ToArray(); |
||||||
|
var context = new SimpleTypeResolveContext(compilation.MainAssembly); |
||||||
|
this.resolvedProperties = new ProjectedList<ITypeResolveContext, IUnresolvedProperty, IProperty>(context, unresolvedProperties, (c, p) => (IProperty)p.CreateResolved(c)); |
||||||
|
} |
||||||
|
|
||||||
|
public override ITypeReference ToTypeReference() |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public override string Name { |
||||||
|
get { return "Anonymous Type"; } |
||||||
|
} |
||||||
|
|
||||||
|
public override TypeKind Kind { |
||||||
|
get { return TypeKind.Anonymous; } |
||||||
|
} |
||||||
|
|
||||||
|
public override bool? IsReferenceType { |
||||||
|
get { return true; } |
||||||
|
} |
||||||
|
|
||||||
|
public IList<IProperty> Properties { |
||||||
|
get { return resolvedProperties; } |
||||||
|
} |
||||||
|
|
||||||
|
public override IEnumerable<IMethod> GetMethods(Predicate<IUnresolvedMethod> 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(IList<IType> typeArguments, Predicate<IUnresolvedMethod> 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<IUnresolvedProperty> filter = null, GetMemberOptions options = GetMemberOptions.None) |
||||||
|
{ |
||||||
|
for (int i = 0; i < unresolvedProperties.Length; i++) { |
||||||
|
if (filter == null || filter(unresolvedProperties[i])) |
||||||
|
yield return resolvedProperties[i]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
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,92 @@ |
|||||||
|
// 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.Collections.Generic; |
||||||
|
using ICSharpCode.NRefactory.Utils; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
||||||
|
{ |
||||||
|
public class DefaultResolvedEvent : AbstractResolvedMember, IEvent |
||||||
|
{ |
||||||
|
protected new readonly IUnresolvedEvent unresolved; |
||||||
|
IAccessor addAccessor; |
||||||
|
IAccessor removeAccessor; |
||||||
|
IAccessor invokeAccessor; |
||||||
|
|
||||||
|
public DefaultResolvedEvent(IUnresolvedEvent unresolved, ITypeResolveContext parentContext) |
||||||
|
: base(unresolved, parentContext) |
||||||
|
{ |
||||||
|
this.unresolved = unresolved; |
||||||
|
} |
||||||
|
|
||||||
|
public bool CanAdd { |
||||||
|
get { return unresolved.CanAdd; } |
||||||
|
} |
||||||
|
|
||||||
|
public bool CanRemove { |
||||||
|
get { return unresolved.CanRemove; } |
||||||
|
} |
||||||
|
|
||||||
|
public bool CanInvoke { |
||||||
|
get { return unresolved.CanInvoke; } |
||||||
|
} |
||||||
|
|
||||||
|
public IAccessor AddAccessor { |
||||||
|
get { |
||||||
|
if (!unresolved.CanAdd) |
||||||
|
return null; |
||||||
|
IAccessor result = this.addAccessor; |
||||||
|
if (result != null) { |
||||||
|
LazyInit.ReadBarrier(); |
||||||
|
return result; |
||||||
|
} else { |
||||||
|
return LazyInit.GetOrSet(ref this.addAccessor, unresolved.AddAccessor.CreateResolvedAccessor(context)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public IAccessor RemoveAccessor { |
||||||
|
get { |
||||||
|
if (!unresolved.CanRemove) |
||||||
|
return null; |
||||||
|
IAccessor result = this.removeAccessor; |
||||||
|
if (result != null) { |
||||||
|
LazyInit.ReadBarrier(); |
||||||
|
return result; |
||||||
|
} else { |
||||||
|
return LazyInit.GetOrSet(ref this.removeAccessor, unresolved.RemoveAccessor.CreateResolvedAccessor(context)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public IAccessor InvokeAccessor { |
||||||
|
get { |
||||||
|
if (!unresolved.CanInvoke) |
||||||
|
return null; |
||||||
|
IAccessor result = this.invokeAccessor; |
||||||
|
if (result != null) { |
||||||
|
LazyInit.ReadBarrier(); |
||||||
|
return result; |
||||||
|
} else { |
||||||
|
return LazyInit.GetOrSet(ref this.invokeAccessor, unresolved.InvokeAccessor.CreateResolvedAccessor(context)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,134 @@ |
|||||||
|
// 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.Collections.Generic; |
||||||
|
using System.Threading; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
||||||
|
{ |
||||||
|
public sealed class DummyTypeParameter : AbstractType, ITypeParameter |
||||||
|
{ |
||||||
|
static ITypeParameter[] methodTypeParameters = { new DummyTypeParameter(EntityType.Method, 0) }; |
||||||
|
static ITypeParameter[] classTypeParameters = { new DummyTypeParameter(EntityType.TypeDefinition, 0) }; |
||||||
|
|
||||||
|
public static ITypeParameter GetMethodTypeParameter(int index) |
||||||
|
{ |
||||||
|
return GetTypeParameter(ref methodTypeParameters, EntityType.Method, index); |
||||||
|
} |
||||||
|
|
||||||
|
public static ITypeParameter GetClassTypeParameter(int index) |
||||||
|
{ |
||||||
|
return GetTypeParameter(ref classTypeParameters, EntityType.TypeDefinition, index); |
||||||
|
} |
||||||
|
|
||||||
|
static ITypeParameter GetTypeParameter(ref ITypeParameter[] typeParameters, EntityType entityType, int index) |
||||||
|
{ |
||||||
|
ITypeParameter[] tps = typeParameters; |
||||||
|
while (index >= tps.Length) { |
||||||
|
// We don't have a normal type parameter for this index, so we need to extend our array.
|
||||||
|
// Because the array can be used concurrently from multiple threads, we have to use
|
||||||
|
// Interlocked.CompareExchange.
|
||||||
|
ITypeParameter[] newTps = new ITypeParameter[index + 1]; |
||||||
|
tps.CopyTo(newTps, 0); |
||||||
|
for (int i = tps.Length; i < newTps.Length; i++) { |
||||||
|
newTps[i] = new DummyTypeParameter(entityType, i); |
||||||
|
} |
||||||
|
ITypeParameter[] oldTps = Interlocked.CompareExchange(ref typeParameters, newTps, tps); |
||||||
|
if (oldTps == tps) { |
||||||
|
// exchange successful
|
||||||
|
tps = newTps; |
||||||
|
} else { |
||||||
|
// exchange not successful
|
||||||
|
tps = oldTps; |
||||||
|
} |
||||||
|
} |
||||||
|
return tps[index]; |
||||||
|
} |
||||||
|
|
||||||
|
readonly EntityType ownerType; |
||||||
|
readonly int index; |
||||||
|
|
||||||
|
private DummyTypeParameter(EntityType ownerType, int index) |
||||||
|
{ |
||||||
|
this.ownerType = ownerType; |
||||||
|
this.index = index; |
||||||
|
} |
||||||
|
|
||||||
|
public override string Name { |
||||||
|
get { return "!" + index; } |
||||||
|
} |
||||||
|
|
||||||
|
public override bool? IsReferenceType { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
|
||||||
|
public override TypeKind Kind { |
||||||
|
get { return TypeKind.TypeParameter; } |
||||||
|
} |
||||||
|
|
||||||
|
public override ITypeReference ToTypeReference() |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public int Index { |
||||||
|
get { return index; } |
||||||
|
} |
||||||
|
|
||||||
|
IList<IAttribute> ITypeParameter.Attributes { |
||||||
|
get { return EmptyList<IAttribute>.Instance; } |
||||||
|
} |
||||||
|
|
||||||
|
EntityType ITypeParameter.OwnerType { |
||||||
|
get { return ownerType; } |
||||||
|
} |
||||||
|
|
||||||
|
VarianceModifier ITypeParameter.Variance { |
||||||
|
get { return VarianceModifier.Invariant; } |
||||||
|
} |
||||||
|
|
||||||
|
DomRegion ITypeParameter.Region { |
||||||
|
get { return DomRegion.Empty; } |
||||||
|
} |
||||||
|
|
||||||
|
IEntity ITypeParameter.Owner { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
|
||||||
|
IType ITypeParameter.EffectiveBaseClass { |
||||||
|
get { return SpecialType.UnknownType; } |
||||||
|
} |
||||||
|
|
||||||
|
IList<IType> ITypeParameter.EffectiveInterfaceSet { |
||||||
|
get { return EmptyList<IType>.Instance; } |
||||||
|
} |
||||||
|
|
||||||
|
bool ITypeParameter.HasDefaultConstructorConstraint { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
|
||||||
|
bool ITypeParameter.HasReferenceTypeConstraint { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
|
||||||
|
bool ITypeParameter.HasValueTypeConstraint { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue