|
|
|
@ -14,13 +14,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class DefaultTypeParameter : AbstractFreezable, ITypeParameter, ISupportsInterning |
|
|
|
public class DefaultTypeParameter : AbstractFreezable, ITypeParameter, ISupportsInterning |
|
|
|
{ |
|
|
|
{ |
|
|
|
IEntity parent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string name; |
|
|
|
string name; |
|
|
|
int index; |
|
|
|
int index; |
|
|
|
IList<ITypeReference> constraints; |
|
|
|
IList<ITypeReference> constraints; |
|
|
|
IList<IAttribute> attributes; |
|
|
|
IList<IAttribute> attributes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DomRegion region; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Small fields: byte+byte+short
|
|
|
|
VarianceModifier variance; |
|
|
|
VarianceModifier variance; |
|
|
|
|
|
|
|
EntityType ownerType; |
|
|
|
BitVector16 flags; |
|
|
|
BitVector16 flags; |
|
|
|
|
|
|
|
|
|
|
|
const ushort FlagReferenceTypeConstraint = 0x0001; |
|
|
|
const ushort FlagReferenceTypeConstraint = 0x0001; |
|
|
|
@ -34,28 +37,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
base.FreezeInternal(); |
|
|
|
base.FreezeInternal(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DefaultTypeParameter(IMethod parentMethod, int index, string name) |
|
|
|
public DefaultTypeParameter(EntityType ownerType, int index, string name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (parentMethod == null) |
|
|
|
if (!(ownerType == EntityType.TypeDefinition || ownerType == EntityType.Method)) |
|
|
|
throw new ArgumentNullException("parentMethod"); |
|
|
|
throw new ArgumentException("owner must be a type or a method", "ownerType"); |
|
|
|
if (index < 0) |
|
|
|
if (index < 0) |
|
|
|
throw new ArgumentOutOfRangeException("index", index, "Value must not be negative"); |
|
|
|
throw new ArgumentOutOfRangeException("index", index, "Value must not be negative"); |
|
|
|
if (name == null) |
|
|
|
if (name == null) |
|
|
|
throw new ArgumentNullException("name"); |
|
|
|
throw new ArgumentNullException("name"); |
|
|
|
this.parent = parentMethod; |
|
|
|
this.ownerType = ownerType; |
|
|
|
this.index = index; |
|
|
|
|
|
|
|
this.name = name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DefaultTypeParameter(ITypeDefinition parentClass, int index, string name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (parentClass == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("parentClass"); |
|
|
|
|
|
|
|
if (index < 0) |
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException("index", index, "Value must not be negative"); |
|
|
|
|
|
|
|
if (name == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("name"); |
|
|
|
|
|
|
|
this.parent = parentClass; |
|
|
|
|
|
|
|
this.index = index; |
|
|
|
this.index = index; |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -74,7 +64,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
|
|
|
|
|
|
|
|
public string ReflectionName { |
|
|
|
public string ReflectionName { |
|
|
|
get { |
|
|
|
get { |
|
|
|
if (parent is IMethod) |
|
|
|
if (ownerType == EntityType.Method) |
|
|
|
return "``" + index.ToString(); |
|
|
|
return "``" + index.ToString(); |
|
|
|
else |
|
|
|
else |
|
|
|
return "`" + index.ToString(); |
|
|
|
return "`" + index.ToString(); |
|
|
|
@ -114,11 +104,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode() |
|
|
|
public override int GetHashCode() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int hashCode = parent.GetHashCode(); |
|
|
|
|
|
|
|
unchecked { |
|
|
|
unchecked { |
|
|
|
hashCode += 1000000033 * index.GetHashCode(); |
|
|
|
return (int)ownerType * 178256151 + index; |
|
|
|
} |
|
|
|
} |
|
|
|
return hashCode; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj) |
|
|
|
public override bool Equals(object obj) |
|
|
|
@ -131,8 +119,13 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
DefaultTypeParameter p = other as DefaultTypeParameter; |
|
|
|
DefaultTypeParameter p = other as DefaultTypeParameter; |
|
|
|
if (p == null) |
|
|
|
if (p == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
return parent.Equals(p.parent) |
|
|
|
return ownerType == p.ownerType && index == p.index; |
|
|
|
&& index == p.index; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EntityType OwnerType { |
|
|
|
|
|
|
|
get { |
|
|
|
|
|
|
|
return ownerType; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int Index { |
|
|
|
public int Index { |
|
|
|
@ -147,18 +140,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IEntity Parent { |
|
|
|
|
|
|
|
get { return parent; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IMethod ParentMethod { |
|
|
|
|
|
|
|
get { return parent as IMethod; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ITypeDefinition ParentClass { |
|
|
|
|
|
|
|
get { return parent as ITypeDefinition; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IList<ITypeReference> Constraints { |
|
|
|
public IList<ITypeReference> Constraints { |
|
|
|
get { |
|
|
|
get { |
|
|
|
if (constraints == null) |
|
|
|
if (constraints == null) |
|
|
|
@ -199,6 +180,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DomRegion Region { |
|
|
|
|
|
|
|
get { return region; } |
|
|
|
|
|
|
|
set { |
|
|
|
|
|
|
|
CheckBeforeMutation(); |
|
|
|
|
|
|
|
region = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual IType BoundTo { |
|
|
|
public virtual IType BoundTo { |
|
|
|
get { return null; } |
|
|
|
get { return null; } |
|
|
|
} |
|
|
|
} |
|
|
|
@ -217,10 +206,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static readonly SimpleProjectContent dummyProjectContent = new SimpleProjectContent(); |
|
|
|
|
|
|
|
|
|
|
|
DefaultTypeDefinition GetDummyClassForTypeParameter() |
|
|
|
DefaultTypeDefinition GetDummyClassForTypeParameter() |
|
|
|
{ |
|
|
|
{ |
|
|
|
DefaultTypeDefinition c = new DefaultTypeDefinition(ParentClass ?? ParentMethod.DeclaringTypeDefinition, this.Name); |
|
|
|
DefaultTypeDefinition c = new DefaultTypeDefinition(dummyProjectContent, string.Empty, this.Name); |
|
|
|
c.Region = new DomRegion(parent.Region.FileName, parent.Region.BeginLine, parent.Region.BeginColumn); |
|
|
|
c.Region = this.Region; |
|
|
|
if (HasValueTypeConstraint) { |
|
|
|
if (HasValueTypeConstraint) { |
|
|
|
c.ClassType = ClassType.Struct; |
|
|
|
c.ClassType = ClassType.Struct; |
|
|
|
} else if (HasDefaultConstructorConstraint) { |
|
|
|
} else if (HasDefaultConstructorConstraint) { |
|
|
|
@ -294,12 +285,29 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
|
|
|
|
|
|
|
|
|
|
|
int ISupportsInterning.GetHashCodeForInterning() |
|
|
|
int ISupportsInterning.GetHashCodeForInterning() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return GetHashCode(); |
|
|
|
unchecked { |
|
|
|
|
|
|
|
int hashCode = GetHashCode(); |
|
|
|
|
|
|
|
if (name != null) |
|
|
|
|
|
|
|
hashCode += name.GetHashCode(); |
|
|
|
|
|
|
|
if (attributes != null) |
|
|
|
|
|
|
|
hashCode += attributes.GetHashCode(); |
|
|
|
|
|
|
|
if (constraints != null) |
|
|
|
|
|
|
|
hashCode += constraints.GetHashCode(); |
|
|
|
|
|
|
|
hashCode += 771 * flags.Data + 900103 * (int)variance; |
|
|
|
|
|
|
|
return hashCode; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other) |
|
|
|
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return this == other; |
|
|
|
DefaultTypeParameter o = other as DefaultTypeParameter; |
|
|
|
|
|
|
|
return o != null |
|
|
|
|
|
|
|
&& this.attributes == o.attributes |
|
|
|
|
|
|
|
&& this.constraints == o.constraints |
|
|
|
|
|
|
|
&& this.flags == o.flags |
|
|
|
|
|
|
|
&& this.ownerType == o.ownerType |
|
|
|
|
|
|
|
&& this.index == o.index |
|
|
|
|
|
|
|
&& this.variance == o.variance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
public override string ToString() |
|
|
|
|