Browse Source

Make ITypeParameter inherit from IType.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
5e329ed343
  1. 2
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  2. 38
      ICSharpCode.NRefactory/TypeSystem/CecilProjectContent.cs
  3. 50
      ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
  4. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractFreezable.cs
  5. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs
  6. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractTypeReference.cs
  7. 9
      ICSharpCode.NRefactory/TypeSystem/Implementation/BitVector16.cs
  8. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultExplicitInterfaceImplementation.cs
  9. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs
  10. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  11. 31
      ICSharpCode.NRefactory/TypeSystem/Implementation/DynamicType.cs
  12. 9
      ICSharpCode.NRefactory/TypeSystem/Implementation/GetClassTypeReference.cs
  13. 9
      ICSharpCode.NRefactory/TypeSystem/Implementation/NestedTypeReference.cs
  14. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/NullType.cs
  15. 9
      ICSharpCode.NRefactory/TypeSystem/Implementation/ProxyTypeResolveContext.cs
  16. 37
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleConstantValue.cs
  17. 9
      ICSharpCode.NRefactory/TypeSystem/Implementation/TypeWithElementType.cs
  18. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/UnknownType.cs
  19. 7
      ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs

2
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -151,12 +151,14 @@ @@ -151,12 +151,14 @@
<Compile Include="TypeSystem\Implementation\BitVector16.cs" />
<Compile Include="TypeSystem\Implementation\DefaultExplicitInterfaceImplementation.cs" />
<Compile Include="TypeSystem\Implementation\DefaultParameter.cs" />
<Compile Include="TypeSystem\Implementation\DynamicType.cs" />
<Compile Include="TypeSystem\Implementation\GetClassTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\NestedTypeReference.cs" />
<Compile Include="TypeSystem\Implementation\PointerType.cs" />
<Compile Include="TypeSystem\Implementation\ProxyTypeResolveContext.cs" />
<Compile Include="TypeSystem\Implementation\DefaultTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\NullType.cs" />
<Compile Include="TypeSystem\Implementation\SimpleConstantValue.cs" />
<Compile Include="TypeSystem\Implementation\TypeWithElementType.cs" />
<Compile Include="TypeSystem\Implementation\UnknownType.cs" />
<Compile Include="TypeSystem\INamedElement.cs" />

38
ICSharpCode.NRefactory/TypeSystem/CecilProjectContent.cs

@ -166,8 +166,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -166,8 +166,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
return new ConstructedReturnType(baseType, para);*/
throw new NotImplementedException();
} else if (type is GenericParameter) {
throw new NotImplementedException();
/*GenericParameter typeGP = type as GenericParameter;
GenericParameter typeGP = type as GenericParameter;
if (typeGP.Owner is MethodDefinition) {
IMethod method = entity as IMethod;
if (method != null) {
@ -184,7 +183,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -184,7 +183,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
return SharedTypes.UnknownType;
}*/
}
} else {
string name = type.FullName;
if (name == null)
@ -331,33 +330,12 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -331,33 +330,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
#region Read Constant Value
static IConstantValue ReadConstantValue(CustomAttributeArgument arg, ITypeResolveContext earlyBindContext)
{
return new CecilConstantValue(arg.Type, arg.Value, earlyBindContext);
}
sealed class CecilConstantValue : Immutable, IConstantValue
{
readonly ITypeReference type;
readonly object value;
public CecilConstantValue(TypeReference type, object value, ITypeResolveContext earlyBindContext)
{
this.type = ReadTypeReference(type, earlyBindContext: earlyBindContext);
TypeReference valueType = value as TypeReference;
if (valueType != null)
this.value = ReadTypeReference(valueType, earlyBindContext: earlyBindContext);
else
this.value = value;
}
public IType GetValueType(ITypeResolveContext context)
{
return type.Resolve(context);
}
public object GetValue(ITypeResolveContext context)
{
return value;
}
ITypeReference type = ReadTypeReference(arg.Type, earlyBindContext: earlyBindContext);
object value = arg.Value;
TypeReference valueType = value as TypeReference;
if (valueType != null)
value = ReadTypeReference(valueType, earlyBindContext: earlyBindContext);
return new SimpleConstantValue(type, value);
}
#endregion

50
ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.TypeSystem
{
@ -11,13 +12,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -11,13 +12,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Type parameter of a generic class/method.
/// </summary>
[ContractClass(typeof(ITypeParameterContract))]
public interface ITypeParameter : IFreezable
public interface ITypeParameter : IType, IFreezable
{
/// <summary>
/// The name of the type parameter (for example "T")
/// </summary>
string Name { get; }
/// <summary>
/// Gets the index of the type parameter in the type parameter list of the owning method/class.
/// </summary>
@ -30,14 +26,13 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,14 +26,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// The method this type parameter is defined for.
/// This property is null when the type parameter is for a class.
/// This property returns null if the type parameter belong to a class.
/// </summary>
IMethod ParentMethod { get; }
/// <summary>
/// The class this type parameter is defined for.
/// When the type parameter is defined for a method, this is the class containing
/// that method.
/// This property returns null if the type parameter belong to a method.
/// </summary>
ITypeDefinition ParentClass { get; }
@ -61,6 +56,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -61,6 +56,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
bool HasValueTypeConstraint { get; }
/// <summary>
/// Gets the variance of this type parameter.
/// </summary>
VarianceModifier Variance { get; }
/// <summary>
/// Gets the type that was used to bind this type parameter.
/// This property returns null for generic methods/classes, it
@ -74,17 +74,28 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -74,17 +74,28 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeParameter UnboundTypeParameter { get; }
}
/// <summary>
/// Represents the variance of a type parameter.
/// </summary>
public enum VarianceModifier
{
/// <summary>
/// The type parameter is not variant.
/// </summary>
Invariant,
/// <summary>
/// The type parameter is covariant (used in output position).
/// </summary>
Covariant,
/// <summary>
/// The type parameter is contravariant (used in input position).
/// </summary>
Contravariant
};
[ContractClassFor(typeof(ITypeParameter))]
abstract class ITypeParameterContract : IFreezableContract, ITypeParameter
abstract class ITypeParameterContract : ITypeContract, ITypeParameter
{
string ITypeParameter.Name {
get {
Contract.Ensures(Contract.Result<string>() != null);
return null;
}
}
int ITypeParameter.Index {
get {
Contract.Ensures(Contract.Result<int>() >= 0);
@ -107,7 +118,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -107,7 +118,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
ITypeDefinition ITypeParameter.ParentClass {
get {
Contract.Ensures(Contract.Result<ITypeDefinition>() != null);
return null;
}
}
@ -142,5 +152,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -142,5 +152,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
return null;
}
}
VarianceModifier ITypeParameter.Variance {
get { return VarianceModifier.Invariant; }
}
}
}

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;

9
ICSharpCode.NRefactory/TypeSystem/Implementation/BitVector16.cs

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;

31
ICSharpCode.NRefactory/TypeSystem/Implementation/DynamicType.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Type representing the C# 'dynamic' type.
/// </summary>
sealed class DynamicType : AbstractType
{
public override string Name {
get { return "dynamic"; }
}
public override bool? IsReferenceType {
get { return true; }
}
public override bool Equals(IType other)
{
return other is DynamicType;
}
public override int GetHashCode()
{
return 31986112;
}
}
}

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

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation

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

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;

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

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation

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

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// A simple constant value that is independent of the resolve context.
/// </summary>
public sealed class SimpleConstantValue : Immutable, IConstantValue
{
readonly ITypeReference type;
readonly object value;
public SimpleConstantValue(ITypeReference type, object value)
{
if (type == null)
throw new ArgumentNullException("type");
this.type = type;
this.value = value;
}
public IType GetValueType(ITypeResolveContext context)
{
return type.Resolve(context);
}
public object GetValue(ITypeResolveContext context)
{
if (value is ITypeReference)
return ((ITypeReference)value).Resolve(context);
else
return value;
}
}
}

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

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation

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

@ -1,9 +1,5 @@ @@ -1,9 +1,5 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;

7
ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs

@ -23,8 +23,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -23,8 +23,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "It's immutable")]
public readonly static IType Null = new NullType();
// TODO: implement DynamicType
public readonly static IType Dynamic = new UnknownType();
/// <summary>
/// Type representing the C# 'dynamic' type.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "It's immutable")]
public readonly static IType Dynamic = new DynamicType();
/*
* I'd like to define static instances for common types like

Loading…
Cancel
Save