Browse Source

Add TypeKind enum.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
18fb49ca7c
  1. 4
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
  2. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs
  3. 9
      ICSharpCode.NRefactory.Tests/TypeSystem/GetMembersTests.cs
  4. 16
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  5. 8
      ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs
  6. 12
      ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  7. 21
      ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs
  8. 18
      ICSharpCode.NRefactory/CSharp/Analysis/MinimalResolveContext.cs
  9. 10
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs
  10. 2
      ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs
  11. 47
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  12. 4
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs
  13. 4
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/RemoveBackingStore.cs
  14. 99
      ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
  15. 5
      ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs
  16. 2
      ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs
  17. 32
      ICSharpCode.NRefactory/CSharp/Resolver/SimpleNameLookupMode.cs
  18. 10
      ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs
  19. 14
      ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs
  20. 3
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  21. 4
      ICSharpCode.NRefactory/TypeSystem/ArrayType.cs
  22. 4
      ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs
  23. 16
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  24. 17
      ICSharpCode.NRefactory/TypeSystem/ClassType.cs
  25. 13
      ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  26. 32
      ICSharpCode.NRefactory/TypeSystem/IType.cs
  27. 2
      ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs
  28. 12
      ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
  29. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs
  30. 5
      ICSharpCode.NRefactory/TypeSystem/Implementation/BaseTypeCollector.cs
  31. 81
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  32. 25
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeParameter.cs
  33. 7
      ICSharpCode.NRefactory/TypeSystem/Implementation/VoidTypeDefinition.cs
  34. 4
      ICSharpCode.NRefactory/TypeSystem/IntersectionType.cs
  35. 69
      ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs
  36. 4
      ICSharpCode.NRefactory/TypeSystem/PointerType.cs
  37. 96
      ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs
  38. 66
      ICSharpCode.NRefactory/TypeSystem/TypeKind.cs

4
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
protected ITypeOrNamespaceReference MakeReference(string namespaceName)
{
string[] nameParts = namespaceName.Split('.');
ITypeOrNamespaceReference r = new SimpleTypeOrNamespaceReference(nameParts[0], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope, true);
ITypeOrNamespaceReference r = new SimpleTypeOrNamespaceReference(nameParts[0], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope, SimpleNameLookupMode.TypeInUsingDeclaration);
for (int i = 1; i < nameParts.Length; i++) {
r = new MemberTypeOrNamespaceReference(r, nameParts[i], new ITypeReference[0], resolver.CurrentTypeDefinition, resolver.UsingScope);
}
@ -82,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -82,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (value == null)
return new ConstantResolveResult(SharedTypes.Null, null);
IType type = ResolveType(value.GetType());
if (type.IsEnum())
if (type.Kind == TypeKind.Enum)
value = Convert.ChangeType(value, Enum.GetUnderlyingType(value.GetType()));
return new ConstantResolveResult(type, value);
}

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

@ -116,7 +116,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -116,7 +116,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
// struct S : IEquatable<S> {}
// don't use a Cecil-loaded struct for this test; we're testing the implicit addition of System.ValueType
DefaultTypeDefinition s = new DefaultTypeDefinition(mscorlib, string.Empty, "S");
s.ClassType = ClassType.Struct;
s.Kind = TypeKind.Struct;
s.BaseTypes.Add(new ParameterizedType(mscorlib.GetTypeDefinition(typeof(IEquatable<>)), new[] { s }));
IType[] expected = {
s,

9
ICSharpCode.NRefactory.Tests/TypeSystem/GetMembersTests.cs

@ -25,15 +25,15 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -25,15 +25,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void MultipleInheritanceTest()
{
DefaultTypeDefinition b1 = new DefaultTypeDefinition(mscorlib, string.Empty, "B1");
b1.ClassType = ClassType.Interface;
b1.Kind = TypeKind.Interface;
b1.Properties.Add(new DefaultProperty(b1, "P1"));
DefaultTypeDefinition b2 = new DefaultTypeDefinition(mscorlib, string.Empty, "B1");
b2.ClassType = ClassType.Interface;
b2.Kind = TypeKind.Interface;
b2.Properties.Add(new DefaultProperty(b1, "P2"));
DefaultTypeDefinition c = new DefaultTypeDefinition(mscorlib, string.Empty, "C");
c.ClassType = ClassType.Interface;
c.Kind = TypeKind.Interface;
c.BaseTypes.Add(b1);
c.BaseTypes.Add(b2);
@ -102,7 +102,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -102,7 +102,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
a.NestedTypes.Add(b);
Assert.AreSame(b, a.GetNestedTypes(mscorlib).Single());
// A<> gets self-parameterized, B<> stays unbound
Assert.AreEqual("A`1+B`1[[`0],[]]", a.GetNestedTypes(mscorlib).Single().ReflectionName);
ParameterizedType pt = new ParameterizedType(a, new [] { KnownTypeReference.String.Resolve(mscorlib) });
Assert.AreEqual("A`1+B`1[[System.String],[]]", pt.GetNestedTypes(mscorlib).Single().ReflectionName);

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

@ -223,7 +223,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -223,7 +223,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void EnumTest()
{
var e = testCasePC.GetTypeDefinition(typeof(MyEnum));
Assert.AreEqual(ClassType.Enum, e.ClassType);
Assert.AreEqual(TypeKind.Enum, e.Kind);
Assert.AreEqual(false, e.IsReferenceType(ctx));
Assert.AreEqual("System.Int16", e.BaseTypes[0].Resolve(ctx).ReflectionName);
Assert.AreEqual(new[] { "System.Enum" }, e.GetBaseTypes(ctx).Select(t => t.ReflectionName).ToArray());
@ -260,6 +260,14 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -260,6 +260,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.AreEqual(0x30, e.Fields[4].ConstantValue.GetValue(ctx));
}
[Test]
public void GetNestedTypesFromGenericClassTest()
{
ITypeDefinition b = ctx.GetTypeDefinition(typeof(Base<>));
// Base.GetNestedTypes() = { Base`1+Nested`1[`0, unbound] }
}
[Test]
public void GetNestedTypesFromBaseClassTest()
{
@ -267,11 +275,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -267,11 +275,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
IType pBase = d.BaseTypes.Single().Resolve(ctx);
Assert.AreEqual(typeof(Base<>).FullName + "[[`1]]", pBase.ReflectionName);
// Base<`1>.GetNestedTypes() = Base<`1>.Nested<>
// Base[`1].GetNestedTypes() = { Base`1+Nested`1[`1, unbound] }
Assert.AreEqual(new[] { typeof(Base<>.Nested<>).FullName + "[[`1],[]]" },
pBase.GetNestedTypes(ctx).Select(n => n.ReflectionName).ToArray());
// Derived<,>.GetNestedTypes() = Base<`1>.Nested<>
// Derived.GetNestedTypes() = { Base`1+Nested`1[`1, unbound] }
Assert.AreEqual(new[] { typeof(Base<>.Nested<>).FullName + "[[`1],[]]" },
d.GetNestedTypes(ctx).Select(n => n.ReflectionName).ToArray());
// This is 'leaking' the type parameter from B as is usual when retrieving any members from an unbound type.
@ -280,7 +288,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -280,7 +288,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
[Test]
public void ParameterizedTypeGetNestedTypesFromBaseClassTest()
{
// Derived<string,int>.GetNestedTypes() = Base<int>.Nested<>
// Derived[string,int].GetNestedTypes() = { Base`1+Nested`1[int, unbound] }
var d = typeof(Derived<string, int>).ToTypeReference().Resolve(ctx);
Assert.AreEqual(new[] { typeof(Base<>.Nested<>).FullName + "[[System.Int32],[]]" },
d.GetNestedTypes(ctx).Select(n => n.ReflectionName).ToArray());

8
ICSharpCode.NRefactory.VB/Ast/GlobalScope/TypeDeclaration.cs

@ -8,6 +8,14 @@ using ICSharpCode.NRefactory.TypeSystem; @@ -8,6 +8,14 @@ using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.VB.Ast
{
public enum ClassType
{
Class,
Struct,
Interface,
Module
}
public class TypeDeclaration : AttributedNode
{
public readonly static Role<AttributedNode> MemberRole = new Role<AttributedNode>("Member");

12
ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -270,20 +270,16 @@ namespace ICSharpCode.NRefactory.VB @@ -270,20 +270,16 @@ namespace ICSharpCode.NRefactory.VB
void WriteClassTypeKeyword(TypeDeclaration typeDeclaration)
{
switch (typeDeclaration.ClassType) {
case ICSharpCode.NRefactory.TypeSystem.ClassType.Class:
case ClassType.Class:
WriteKeyword("Class");
break;
case ICSharpCode.NRefactory.TypeSystem.ClassType.Enum:
break;
case ICSharpCode.NRefactory.TypeSystem.ClassType.Interface:
case ClassType.Interface:
WriteKeyword("Interface");
break;
case ICSharpCode.NRefactory.TypeSystem.ClassType.Struct:
case ClassType.Struct:
WriteKeyword("Structure");
break;
case ICSharpCode.NRefactory.TypeSystem.ClassType.Delegate:
break;
case ICSharpCode.NRefactory.TypeSystem.ClassType.Module:
case ClassType.Module:
WriteKeyword("Module");
break;
default:

21
ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

@ -822,7 +822,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -822,7 +822,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors
{
// TODO add missing features!
if (typeDeclaration.ClassType == ClassType.Enum) {
if (typeDeclaration.ClassType == CSharp.ClassType.Enum) {
var type = new EnumDeclaration();
CopyAnnotations(typeDeclaration, type);
@ -846,7 +846,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -846,7 +846,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors
CSharp.Attribute stdModAttr;
if (typeDeclaration.ClassType == ClassType.Class && HasAttribute(typeDeclaration.Attributes, "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute", out stdModAttr)) {
if (typeDeclaration.ClassType == CSharp.ClassType.Class && HasAttribute(typeDeclaration.Attributes, "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute", out stdModAttr)) {
type.ClassType = ClassType.Module;
// remove AttributeSection if only one attribute is present
var attrSec = (CSharp.AttributeSection)stdModAttr.Parent;
@ -854,8 +854,21 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -854,8 +854,21 @@ namespace ICSharpCode.NRefactory.VB.Visitors
attrSec.Remove();
else
stdModAttr.Remove();
} else
type.ClassType = typeDeclaration.ClassType;
} else {
switch (typeDeclaration.ClassType) {
case CSharp.ClassType.Class:
type.ClassType = ClassType.Class;
break;
case CSharp.ClassType.Struct:
type.ClassType = ClassType.Struct;
break;
case CSharp.ClassType.Interface:
type.ClassType = ClassType.Interface;
break;
default:
throw new InvalidOperationException("Invalid value for ClassType");
}
}
if ((typeDeclaration.Modifiers & CSharp.Modifiers.Static) == CSharp.Modifiers.Static) {
type.ClassType = ClassType.Module;

18
ICSharpCode.NRefactory/CSharp/Analysis/MinimalResolveContext.cs

@ -30,8 +30,13 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -30,8 +30,13 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
private MinimalResolveContext()
{
List<ITypeDefinition> types = new List<ITypeDefinition>();
types.Add(systemObject = new DefaultTypeDefinition(this, "System", "Object"));
types.Add(systemValueType = new DefaultTypeDefinition(this, "System", "ValueType") { BaseTypes = { systemObject } });
types.Add(systemObject = new DefaultTypeDefinition(this, "System", "Object") {
Accessibility = Accessibility.Public
});
types.Add(systemValueType = new DefaultTypeDefinition(this, "System", "ValueType") {
Accessibility = Accessibility.Public,
BaseTypes = { systemObject }
});
types.Add(CreateStruct("System", "Boolean"));
types.Add(CreateStruct("System", "SByte"));
types.Add(CreateStruct("System", "Byte"));
@ -44,7 +49,11 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -44,7 +49,11 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
types.Add(CreateStruct("System", "Single"));
types.Add(CreateStruct("System", "Double"));
types.Add(CreateStruct("System", "Decimal"));
types.Add(new DefaultTypeDefinition(this, "System", "String") { BaseTypes = { systemObject } });
types.Add(new DefaultTypeDefinition(this, "System", "String") {
Accessibility = Accessibility.Public,
BaseTypes = { systemObject }
});
types.Add(new VoidTypeDefinition(this));
foreach (ITypeDefinition type in types)
type.Freeze();
this.types = types.AsReadOnly();
@ -53,7 +62,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -53,7 +62,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
ITypeDefinition CreateStruct(string nameSpace, string name)
{
return new DefaultTypeDefinition(this, nameSpace, name) {
ClassType = ClassType.Struct,
Kind = TypeKind.Struct,
Accessibility = Accessibility.Public,
BaseTypes = { systemValueType }
};
}

10
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// TypeDeclaration.cs
//
// Author:
@ -30,6 +30,14 @@ using ICSharpCode.NRefactory.TypeSystem; @@ -30,6 +30,14 @@ using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public enum ClassType
{
Class,
Struct,
Interface,
Enum
}
/// <summary>
/// class Name&lt;TypeParameters&gt; : BaseTypes where Constraints;
/// </summary>

2
ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AstFormattingVisitor.cs
//
// Author:

47
ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs

@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override IEntity VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
ITypeOrNamespaceReference u = ConvertType(usingDeclaration.Import, true) as ITypeOrNamespaceReference;
ITypeOrNamespaceReference u = ConvertType(usingDeclaration.Import, SimpleNameLookupMode.TypeInUsingDeclaration) as ITypeOrNamespaceReference;
if (u != null)
usingScope.Usings.Add(u);
return null;
@ -105,7 +105,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -105,7 +105,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override IEntity VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, object data)
{
ITypeOrNamespaceReference u = ConvertType(usingDeclaration.Import, true) as ITypeOrNamespaceReference;
ITypeOrNamespaceReference u = ConvertType(usingDeclaration.Import, SimpleNameLookupMode.TypeInUsingDeclaration) as ITypeOrNamespaceReference;
if (u != null)
usingScope.UsingAliases.Add(new KeyValuePair<string, ITypeOrNamespaceReference>(usingDeclaration.Alias, u));
return null;
@ -146,22 +146,31 @@ namespace ICSharpCode.NRefactory.CSharp @@ -146,22 +146,31 @@ namespace ICSharpCode.NRefactory.CSharp
public override IEntity VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
var td = currentTypeDefinition = CreateTypeDefinition(typeDeclaration.Name);
td.ClassType = typeDeclaration.ClassType;
td.Region = MakeRegion(typeDeclaration);
td.BodyRegion = MakeBraceRegion(typeDeclaration);
td.AddDefaultConstructorIfRequired = true;
ConvertAttributes(td.Attributes, typeDeclaration.Attributes);
ApplyModifiers(td, typeDeclaration.Modifiers);
if (td.ClassType == ClassType.Interface)
td.IsAbstract = true; // interfaces are implicitly abstract
else if (td.ClassType == ClassType.Enum || td.ClassType == ClassType.Struct)
td.IsSealed = true; // enums/structs are implicitly sealed
switch (typeDeclaration.ClassType) {
case ClassType.Enum:
td.Kind = TypeKind.Enum;
break;
case ClassType.Interface:
td.Kind = TypeKind.Interface;
td.IsAbstract = true; // interfaces are implicitly abstract
break;
case ClassType.Struct:
td.Kind = TypeKind.Struct;
td.IsSealed = true; // enums/structs are implicitly sealed
break;
}
ConvertAttributes(td.Attributes, typeDeclaration.Attributes);
ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints, EntityType.TypeDefinition);
foreach (AstType baseType in typeDeclaration.BaseTypes) {
td.BaseTypes.Add(ConvertType(baseType));
td.BaseTypes.Add(ConvertType(baseType, SimpleNameLookupMode.BaseTypeReference));
}
foreach (AttributedNode member in typeDeclaration.Members) {
@ -177,7 +186,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -177,7 +186,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override IEntity VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
{
var td = currentTypeDefinition = CreateTypeDefinition(delegateDeclaration.Name);
td.ClassType = ClassType.Delegate;
td.Kind = TypeKind.Delegate;
td.Region = MakeRegion(delegateDeclaration);
td.BaseTypes.Add(multicastDelegateReference);
@ -590,7 +599,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -590,7 +599,7 @@ namespace ICSharpCode.NRefactory.CSharp
static void ApplyModifiers(TypeSystem.Implementation.AbstractMember m, Modifiers modifiers)
{
// members from interfaces are always Public+Abstract.
if (m.DeclaringTypeDefinition.ClassType == ClassType.Interface) {
if (m.DeclaringTypeDefinition.Kind == TypeKind.Interface) {
m.Accessibility = Accessibility.Public;
m.IsAbstract = true;
return;
@ -689,18 +698,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -689,18 +698,18 @@ namespace ICSharpCode.NRefactory.CSharp
#endregion
#region Types
ITypeReference ConvertType(AstType type, bool isInUsingDeclaration = false)
ITypeReference ConvertType(AstType type, SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)
{
return ConvertType(type, currentTypeDefinition, currentMethod, usingScope, isInUsingDeclaration);
return ConvertType(type, currentTypeDefinition, currentMethod, usingScope, lookupMode);
}
internal static ITypeReference ConvertType(AstType type, ITypeDefinition parentTypeDefinition, IMethod parentMethodDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration)
internal static ITypeReference ConvertType(AstType type, ITypeDefinition parentTypeDefinition, IMethod parentMethodDefinition, UsingScope parentUsingScope, SimpleNameLookupMode lookupMode)
{
SimpleType s = type as SimpleType;
if (s != null) {
List<ITypeReference> typeArguments = new List<ITypeReference>();
foreach (var ta in s.TypeArguments) {
typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration));
typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, lookupMode));
}
if (typeArguments.Count == 0 && parentMethodDefinition != null) {
// SimpleTypeOrNamespaceReference doesn't support method type parameters,
@ -714,7 +723,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -714,7 +723,7 @@ namespace ICSharpCode.NRefactory.CSharp
// empty SimpleType is used for typeof(List<>).
return SharedTypes.UnboundTypeArgument;
}
return new SimpleTypeOrNamespaceReference(s.Identifier, typeArguments, parentTypeDefinition, parentUsingScope, isInUsingDeclaration);
return new SimpleTypeOrNamespaceReference(s.Identifier, typeArguments, parentTypeDefinition, parentUsingScope, lookupMode);
}
PrimitiveType p = type as PrimitiveType;
@ -767,19 +776,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -767,19 +776,19 @@ namespace ICSharpCode.NRefactory.CSharp
t = null;
}
} else {
t = ConvertType(m.Target, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration) as ITypeOrNamespaceReference;
t = ConvertType(m.Target, parentTypeDefinition, parentMethodDefinition, parentUsingScope, lookupMode) as ITypeOrNamespaceReference;
}
if (t == null)
return SharedTypes.UnknownType;
List<ITypeReference> typeArguments = new List<ITypeReference>();
foreach (var ta in m.TypeArguments) {
typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration));
typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, lookupMode));
}
return new MemberTypeOrNamespaceReference(t, m.MemberName, typeArguments, parentTypeDefinition, parentUsingScope);
}
ComposedType c = type as ComposedType;
if (c != null) {
ITypeReference t = ConvertType(c.BaseType, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration);
ITypeReference t = ConvertType(c.BaseType, parentTypeDefinition, parentMethodDefinition, parentUsingScope, lookupMode);
if (c.HasNullableSpecifier) {
t = NullableType.Create(t);
}

4
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AddAnotherAccessor.cs
//
// Author:
@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (pdecl == null)
return false;
var type = pdecl.Parent as TypeDeclaration;
if (type != null && type.ClassType == ICSharpCode.NRefactory.TypeSystem.ClassType.Interface)
if (type != null && type.ClassType == ClassType.Interface)
return false;
return pdecl.Setter.IsNull || pdecl.Getter.IsNull;

4
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/RemoveBackingStore.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// RemoveBackingStore.cs
//
// Author:
@ -80,7 +80,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -80,7 +80,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// automatic properties always need getter & setter
if (propertyDeclaration == null || propertyDeclaration.Getter.IsNull || propertyDeclaration.Setter.IsNull || propertyDeclaration.Getter.Body.IsNull || propertyDeclaration.Setter.Body.IsNull)
return null;
if (!context.HasCSharp3Support || propertyDeclaration.HasModifier (ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ICSharpCode.NRefactory.TypeSystem.ClassType.Interface)
if (!context.HasCSharp3Support || propertyDeclaration.HasModifier (ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ClassType.Interface)
return null;
var getterField = ScanGetter (context, propertyDeclaration);
if (getterField == null)

99
ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs

@ -1514,88 +1514,49 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1514,88 +1514,49 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
#endregion
#region ResolveSimpleName
enum SimpleNameLookupMode
{
/// <summary>
/// Normal name lookup in expressions
/// </summary>
Expression,
/// <summary>
/// Name lookup in expression, where the expression is the target of an invocation.
/// Such a lookup will only return methods and delegate-typed fields.
/// </summary>
InvocationTarget,
/// <summary>
/// Normal name lookup in type references.
/// </summary>
Type,
/// <summary>
/// Name lookup in the type reference inside a using declaration.
/// </summary>
TypeInUsingDeclaration,
/// <summary>
/// Name lookup for unbound types "Dictionary&lt;,&gt;". Can only occur within typeof-expressions.
/// </summary>
UnboundType
}
public ResolveResult ResolveSimpleName(string identifier, IList<IType> typeArguments, bool isInvocationTarget = false)
{
// C# 4.0 spec: §7.6.2 Simple Names
if (identifier == null)
throw new ArgumentNullException("identifier");
if (typeArguments == null)
throw new ArgumentNullException("typeArguments");
if (typeArguments.Count == 0) {
foreach (IVariable v in this.LocalVariables) {
if (v.Name == identifier) {
object constantValue = v.IsConst ? v.ConstantValue.GetValue(context) : null;
return new LocalResolveResult(v, v.Type.Resolve(context), constantValue);
}
}
IParameterizedMember parameterizedMember = this.CurrentMember as IParameterizedMember;
if (parameterizedMember != null) {
foreach (IParameter p in parameterizedMember.Parameters) {
if (p.Name == identifier) {
return new LocalResolveResult(p, p.Type.Resolve(context));
}
}
}
}
return LookupSimpleNameOrTypeName(
identifier, typeArguments,
isInvocationTarget ? SimpleNameLookupMode.InvocationTarget : SimpleNameLookupMode.Expression);
}
public ResolveResult LookupSimpleNamespaceOrTypeName(string identifier, IList<IType> typeArguments, bool isUsingDeclaration = false)
public ResolveResult LookupSimpleNameOrTypeName(string identifier, IList<IType> typeArguments, SimpleNameLookupMode lookupMode)
{
// C# 4.0 spec: §3.8 Namespace and type names; §7.6.2 Simple Names
if (identifier == null)
throw new ArgumentNullException("identifier");
if (typeArguments == null)
throw new ArgumentNullException("typeArguments");
return LookupSimpleNameOrTypeName(identifier, typeArguments,
isUsingDeclaration ? SimpleNameLookupMode.TypeInUsingDeclaration : SimpleNameLookupMode.Type);
}
ResolveResult LookupSimpleNameOrTypeName(string identifier, IList<IType> typeArguments, SimpleNameLookupMode lookupMode)
{
// C# 4.0 spec: §3.8 Namespace and type names; §7.6.2 Simple Names
cancellationToken.ThrowIfCancellationRequested();
int k = typeArguments.Count;
bool parameterizeResultType = k > 0;
if (parameterizeResultType) {
if (typeArguments.All(t => t.Equals(SharedTypes.UnboundTypeArgument)))
parameterizeResultType = false;
}
// look in type parameters of current method
if (k == 0) {
if (lookupMode == SimpleNameLookupMode.Expression || lookupMode == SimpleNameLookupMode.InvocationTarget) {
// Look in local variables
foreach (IVariable v in this.LocalVariables) {
if (v.Name == identifier) {
object constantValue = v.IsConst ? v.ConstantValue.GetValue(context) : null;
return new LocalResolveResult(v, v.Type.Resolve(context), constantValue);
}
}
// Look in parameters of current method
IParameterizedMember parameterizedMember = this.CurrentMember as IParameterizedMember;
if (parameterizedMember != null) {
foreach (IParameter p in parameterizedMember.Parameters) {
if (p.Name == identifier) {
return new LocalResolveResult(p, p.Type.Resolve(context));
}
}
}
}
// look in type parameters of current method
IMethod m = this.CurrentMember as IMethod;
if (m != null) {
foreach (ITypeParameter tp in m.TypeParameters) {
@ -1605,6 +1566,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1605,6 +1566,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
bool parameterizeResultType = k > 0;
if (parameterizeResultType) {
if (typeArguments.All(t => t.Equals(SharedTypes.UnboundTypeArgument)))
parameterizeResultType = false;
}
// look in current type definitions
for (ITypeDefinition t = this.CurrentTypeDefinition; t != null; t = t.DeclaringTypeDefinition) {
if (k == 0) {
@ -1617,6 +1584,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1617,6 +1584,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
if (lookupMode == SimpleNameLookupMode.BaseTypeReference && t == this.CurrentTypeDefinition) {
// don't look in current type when resolving a base type reference
continue;
}
MemberLookup lookup = new MemberLookup(context, t, t.ProjectContent);
ResolveResult r;
if (lookupMode == SimpleNameLookupMode.Expression || lookupMode == SimpleNameLookupMode.InvocationTarget) {
@ -2091,8 +2063,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -2091,8 +2063,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
ITypeDefinition t = CurrentTypeDefinition;
if (t != null) {
foreach (IType baseType in t.GetBaseTypes(context)) {
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef != null && baseTypeDef.ClassType != ClassType.Interface) {
if (baseType.Kind != TypeKind.Unknown && baseType.Kind != TypeKind.Interface) {
return new ResolveResult(baseType);
}
}

5
ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs

@ -225,8 +225,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -225,8 +225,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (type is ITypeParameter) {
// this can happen only with type parameters
for (int i = members.Count - 1; i >= 0; i--) {
ITypeDefinition d = members[i].DeclaringTypeDefinition;
if (d.ClassType != ClassType.Interface)
if (members[i].DeclaringTypeDefinition.Kind != TypeKind.Interface)
continue;
IMethod mi = members[i] as IMethod;
for (int j = 0; j < members.Count; j++) {
@ -262,7 +261,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -262,7 +261,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
static bool IsNonInterfaceType(ITypeDefinition def)
{
// return type if def is neither an interface nor System.Object
return def.ClassType != ClassType.Interface && !(def.Name == "Object" && def.Namespace == "System" && def.TypeParameterCount == 0);
return def.Kind != TypeKind.Interface && !(def.Name == "Object" && def.Namespace == "System" && def.TypeParameterCount == 0);
}
static ITypeDefinition GetDeclaringTypeDef(IType type)

2
ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs

@ -1065,7 +1065,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1065,7 +1065,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
ITypeReference MakeTypeReference(AstType type)
{
return TypeSystemConvertVisitor.ConvertType(type, resolver.CurrentTypeDefinition, resolver.CurrentMember as IMethod, resolver.UsingScope, false);
return TypeSystemConvertVisitor.ConvertType(type, resolver.CurrentTypeDefinition, resolver.CurrentMember as IMethod, resolver.UsingScope, SimpleNameLookupMode.Type);
}
static bool IsVar(AstType returnType)

32
ICSharpCode.NRefactory/CSharp/Resolver/SimpleNameLookupMode.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// 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.CSharp.Resolver
{
public enum SimpleNameLookupMode
{
/// <summary>
/// Normal name lookup in expressions
/// </summary>
Expression,
/// <summary>
/// Name lookup in expression, where the expression is the target of an invocation.
/// Such a lookup will only return methods and delegate-typed fields.
/// </summary>
InvocationTarget,
/// <summary>
/// Normal name lookup in type references.
/// </summary>
Type,
/// <summary>
/// Name lookup in the type reference inside a using declaration.
/// </summary>
TypeInUsingDeclaration,
/// <summary>
/// Name lookup for base type references.
/// </summary>
BaseTypeReference
}
}

10
ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs

@ -16,9 +16,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -16,9 +16,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
readonly UsingScope parentUsingScope;
readonly string identifier;
readonly IList<ITypeReference> typeArguments;
readonly bool isInUsingDeclaration;
readonly SimpleNameLookupMode lookupMode;
public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration = false)
public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope, SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)
{
if (identifier == null)
throw new ArgumentNullException("identifier");
@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;
this.parentTypeDefinition = parentTypeDefinition;
this.parentUsingScope = parentUsingScope;
this.isInUsingDeclaration = isInUsingDeclaration;
this.lookupMode = lookupMode;
}
/// <summary>
@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// </summary>
public SimpleTypeOrNamespaceReference AddSuffix(string suffix)
{
return new SimpleTypeOrNamespaceReference(identifier + suffix, typeArguments, parentTypeDefinition, parentUsingScope, isInUsingDeclaration);
return new SimpleTypeOrNamespaceReference(identifier + suffix, typeArguments, parentTypeDefinition, parentUsingScope, lookupMode);
}
public ResolveResult DoResolve(ITypeResolveContext context)
@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
for (int i = 0; i < typeArgs.Length; i++) {
typeArgs[i] = typeArguments[i].Resolve(context);
}
return r.LookupSimpleNamespaceOrTypeName(identifier, typeArgs, isInUsingDeclaration);
return r.LookupSimpleNameOrTypeName(identifier, typeArgs, lookupMode);
}
public NamespaceResolveResult ResolveNamespace(ITypeResolveContext context)

14
ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs

@ -739,14 +739,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -739,14 +739,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
get { return VarianceModifier.Invariant; }
}
IType ITypeParameter.BoundTo {
get { return null; }
}
ITypeParameter ITypeParameter.UnboundTypeParameter {
get { return null; }
}
bool IFreezable.IsFrozen {
get { return true; }
}
@ -758,6 +750,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -758,6 +750,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
DomRegion ITypeParameter.Region {
get { return DomRegion.Empty; }
}
public override TypeKind Kind {
get { return TypeKind.TypeParameter; }
}
}
#endregion
@ -784,7 +780,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -784,7 +780,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
static IType GetFirstTypePreferNonInterfaces(IList<IType> result)
{
return result.FirstOrDefault(c => c.GetDefinition().ClassType != ClassType.Interface)
return result.FirstOrDefault(c => c.Kind != TypeKind.Interface)
?? result.FirstOrDefault() ?? SharedTypes.UnknownType;
}

3
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -105,6 +105,7 @@ @@ -105,6 +105,7 @@
<Compile Include="CSharp\Resolver\CSharpAttribute.cs" />
<Compile Include="CSharp\Resolver\ConstantValues.cs" />
<Compile Include="CSharp\Resolver\MapTypeIntoNewContext.cs" />
<Compile Include="CSharp\Resolver\SimpleNameLookupMode.cs" />
<Compile Include="PatternMatching\BacktrackingInfo.cs" />
<Compile Include="PatternMatching\Choice.cs" />
<Compile Include="PatternMatching\AnyNode.cs" />
@ -210,7 +211,6 @@ @@ -210,7 +211,6 @@
<Compile Include="TypeSystem\ArrayType.cs" />
<Compile Include="TypeSystem\ByReferenceType.cs" />
<Compile Include="TypeSystem\CecilLoader.cs" />
<Compile Include="TypeSystem\ClassType.cs" />
<Compile Include="TypeSystem\DomRegion.cs" />
<Compile Include="TypeSystem\EntityType.cs" />
<Compile Include="TypeSystem\ExtensionMethods.cs" />
@ -276,6 +276,7 @@ @@ -276,6 +276,7 @@
<Compile Include="TypeSystem\ParameterizedType.cs" />
<Compile Include="TypeSystem\ParameterListComparer.cs" />
<Compile Include="TypeSystem\ReflectionNameParseException.cs" />
<Compile Include="TypeSystem\TypeKind.cs" />
<Compile Include="TypeSystem\TypeVisitor.cs" />
<Compile Include="TypeSystem\IVariable.cs" />
<Compile Include="TypeSystem\PointerType.cs" />

4
ICSharpCode.NRefactory/TypeSystem/ArrayType.cs

@ -21,6 +21,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -21,6 +21,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
this.dimensions = dimensions;
}
public override TypeKind Kind {
get { return TypeKind.Array; }
}
public int Dimensions {
get { return dimensions; }
}

4
ICSharpCode.NRefactory/TypeSystem/ByReferenceType.cs

@ -10,6 +10,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,6 +10,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
}
public override TypeKind Kind {
get { return TypeKind.ByReference; }
}
public override string NameSuffix {
get {
return "&";

16
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -836,17 +836,17 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -836,17 +836,17 @@ namespace ICSharpCode.NRefactory.TypeSystem
TypeDefinition td = this.typeDefinition;
// set classtype
if (td.IsInterface) {
this.ClassType = ClassType.Interface;
this.Kind = TypeKind.Interface;
} else if (td.IsEnum) {
this.ClassType = ClassType.Enum;
this.Kind = TypeKind.Enum;
} else if (td.IsValueType) {
this.ClassType = ClassType.Struct;
this.Kind = TypeKind.Struct;
} else if (IsDelegate(td)) {
this.ClassType = ClassType.Delegate;
this.Kind = TypeKind.Delegate;
} else if (IsModule(td)) {
this.ClassType = ClassType.Module;
this.Kind = TypeKind.Module;
} else {
this.ClassType = ClassType.Class;
this.Kind = TypeKind.Class;
}
this.IsSealed = td.IsSealed;
this.IsAbstract = td.IsAbstract;
@ -902,7 +902,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -902,7 +902,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
void InitMembers(CecilLoader loader)
{
this.AddDefaultConstructorIfRequired = (this.ClassType == ClassType.Struct || this.ClassType == ClassType.Enum);
this.AddDefaultConstructorIfRequired = (this.Kind == TypeKind.Struct || this.Kind == TypeKind.Enum);
if (typeDefinition.HasMethods) {
foreach (MethodDefinition method in typeDefinition.Methods) {
if (loader.IsVisible(method.Attributes)) {
@ -1034,7 +1034,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1034,7 +1034,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
void TranslateModifiers(MethodDefinition method, AbstractMember m)
{
if (m.DeclaringTypeDefinition.ClassType == ClassType.Interface) {
if (m.DeclaringTypeDefinition.Kind == TypeKind.Interface) {
// interface members don't have modifiers, but we want to handle them as "public abstract"
m.Accessibility = Accessibility.Public;
m.IsAbstract = true;

17
ICSharpCode.NRefactory/TypeSystem/ClassType.cs

@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
// 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
{
public enum ClassType : byte
{
Class,
Enum,
Interface,
Struct,
Delegate,
Module,
}
}

13
ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs

@ -138,12 +138,12 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -138,12 +138,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Gets whether the type is an enumeration type.
/// </summary>
[Obsolete("Use type.Kind == TypeKind.Enum instead")]
public static bool IsEnum(this IType type)
{
if (type == null)
throw new ArgumentNullException("type");
ITypeDefinition def = type.GetDefinition();
return def != null && def.ClassType == ClassType.Enum;
return type.Kind == TypeKind.Enum;
}
/// <summary>
@ -156,13 +156,13 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -156,13 +156,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (context == null)
throw new ArgumentNullException("context");
ITypeDefinition def = enumType.GetDefinition();
if (def != null && def.ClassType == ClassType.Enum) {
if (def != null && def.Kind == TypeKind.Enum) {
if (def.BaseTypes.Count == 1)
return def.BaseTypes[0].Resolve(context);
else
return KnownTypeReference.Int32.Resolve(context);
} else {
throw new ArgumentException("enumType must be an enum");
return SharedTypes.UnknownType;
}
}
@ -174,8 +174,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -174,8 +174,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
if (type == null)
throw new ArgumentNullException("type");
ITypeDefinition def = type.GetDefinition();
return def != null && def.ClassType == ClassType.Delegate;
return type.Kind == TypeKind.Delegate;
}
/// <summary>
@ -189,7 +188,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -189,7 +188,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
if (type == null)
throw new ArgumentNullException("type");
ITypeDefinition def = type.GetDefinition();
if (def != null && def.ClassType == ClassType.Delegate) {
if (def != null && def.Kind == TypeKind.Delegate) {
foreach (IMethod method in def.Methods) {
if (method.Name == "Invoke") {
ParameterizedType pt = type as ParameterizedType;

32
ICSharpCode.NRefactory/TypeSystem/IType.cs

@ -12,6 +12,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -12,6 +12,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endif
public interface IType : ITypeReference, INamedElement, IEquatable<IType>
{
/// <summary>
/// Gets the type kind.
/// </summary>
TypeKind Kind { get; }
/// <summary>
/// Gets whether the type is a reference type or value type.
/// </summary>
@ -70,13 +75,32 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -70,13 +75,32 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
/// <param name="context">The context used for resolving type references</param>
/// <param name="filter">The filter used to select which types to return.
/// The filter is tested on the unparameterized types.</param>
/// The filter is tested on the original type definitions (before parameterization).</param>
/// <remarks>
/// If this type is parameterized, the nested type will also be parameterized.
/// Any additional type parameters on the nested type will be parameterized with
/// <see cref="SharedType.UnboundTypeArgument"/>.
/// If the nested type is generic (and has more type parameters than the outer class),
/// this method will return a parameterized type,
/// where the additional type parameters are set to <see cref="SharedType.UnboundTypeArgument"/>.
///
/// Type parameters belonging to the outer class will have the value copied from the outer type
/// if it is a parameterized type. Otherwise, those existing type parameters will be self-parameterized,
/// and thus 'leaked' to the caller in the same way the GetMembers() method does not specialize members
/// from an <see cref="ITypeDefinition"/> and 'leaks' type parameters in member signatures.
/// </remarks>
/// <example>
/// <code>
/// class Base&lt;T> {
/// class Nested&lt;X> {}
/// }
/// class Derived&lt;A, B> : Base&lt;B> {}
///
/// Derived[string,int].GetNestedTypes() = { Base`1+Nested`1[int, unbound] }
/// Derived.GetNestedTypes() = { Base`1+Nested`1[`1, unbound] }
/// Base[`1].GetNestedTypes() = { Base`1+Nested`1[`1, unbound] }
/// Base.GetNestedTypes() = { Base`1+Nested`1[`0, unbound] }
/// </code>
/// </example>
IEnumerable<IType> GetNestedTypes(ITypeResolveContext context, Predicate<ITypeDefinition> filter = null);
// Note that we cannot 'leak' the additional type parameter as we leak the normal type parameters, because
// the index might collide. For example,
// class Base<T> { class Nested<X> {} }

2
ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs

@ -15,8 +15,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -15,8 +15,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endif
public interface ITypeDefinition : IType, IEntity
{
ClassType ClassType { get; }
IList<ITypeReference> BaseTypes { get; }
IList<ITypeParameter> TypeParameters { get; }

12
ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

@ -57,18 +57,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -57,18 +57,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </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
/// is non-null only for constructed versions of generic methods.
/// </summary>
IType BoundTo { get; }
/// <summary>
/// If this type parameter was bound, returns the unbound version of it.
/// </summary>
ITypeParameter UnboundTypeParameter { get; }
/// <summary>
/// Gets the region where the type parameter is defined.
/// </summary>

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

@ -37,6 +37,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -37,6 +37,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public abstract bool? IsReferenceType(ITypeResolveContext context);
public abstract TypeKind Kind { get; }
public virtual int TypeParameterCount {
get { return 0; }
}

5
ICSharpCode.NRefactory/TypeSystem/Implementation/BaseTypeCollector.cs

@ -43,9 +43,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -43,9 +43,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
if (!this.Contains(type)) {
this.Add(type);
foreach (IType baseType in type.GetBaseTypes(context)) {
if (SkipImplementedInterfaces && def != null && def.ClassType != ClassType.Interface) {
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef != null && baseTypeDef.ClassType == ClassType.Interface) {
if (SkipImplementedInterfaces && def != null && def.Kind != TypeKind.Interface) {
if (baseType.Kind == TypeKind.Interface) {
// skip the interface
continue;
}

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

@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
DomRegion bodyRegion;
// 1 byte per enum + 2 bytes for flags
ClassType classType;
TypeKind kind = TypeKind.Class;
Accessibility accessibility;
BitVector16 flags;
const ushort FlagSealed = 0x0001;
@ -77,11 +77,26 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -77,11 +77,26 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.name = name;
}
public ClassType ClassType {
get { return classType; }
public TypeKind Kind {
get { return kind; }
set {
CheckBeforeMutation();
classType = value;
kind = value;
}
}
public bool? IsReferenceType(ITypeResolveContext context)
{
switch (kind) {
case TypeKind.Class:
case TypeKind.Interface:
case TypeKind.Delegate:
return true;
case TypeKind.Enum:
case TypeKind.Struct:
return false;
default:
return null;
}
}
@ -161,21 +176,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -161,21 +176,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public bool? IsReferenceType(ITypeResolveContext context)
{
switch (this.ClassType) {
case ClassType.Class:
case ClassType.Interface:
case ClassType.Delegate:
return true;
case ClassType.Enum:
case ClassType.Struct:
return false;
default:
return null;
}
}
public string FullName {
get {
if (declaringTypeDefinition != null) {
@ -350,25 +350,25 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -350,25 +350,25 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public IEnumerable<IType> GetBaseTypes(ITypeResolveContext context)
{
bool hasNonInterface = false;
if (baseTypes != null && this.ClassType != ClassType.Enum) {
if (baseTypes != null && kind != TypeKind.Enum) {
foreach (ITypeReference baseTypeRef in baseTypes) {
IType baseType = baseTypeRef.Resolve(context);
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null || baseTypeDef.ClassType != ClassType.Interface)
if (baseType.Kind != TypeKind.Interface)
hasNonInterface = true;
yield return baseType;
}
}
if (!hasNonInterface && !(this.Name == "Object" && this.Namespace == "System" && this.TypeParameterCount == 0)) {
Type primitiveBaseType;
switch (classType) {
case ClassType.Enum:
switch (kind) {
case TypeKind.Enum:
primitiveBaseType = typeof(Enum);
break;
case ClassType.Struct:
case TypeKind.Struct:
case TypeKind.Void:
primitiveBaseType = typeof(ValueType);
break;
case ClassType.Delegate:
case TypeKind.Delegate:
primitiveBaseType = typeof(Delegate);
break;
default:
@ -405,30 +405,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -405,30 +405,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public virtual IEnumerable<IType> GetNestedTypes(ITypeResolveContext context, Predicate<ITypeDefinition> filter = null)
{
ITypeDefinition compound = GetCompoundClass();
if (compound != this)
return compound.GetNestedTypes(context, filter);
List<IType> nestedTypes = new List<IType>();
using (var busyLock = BusyManager.Enter(this)) {
if (busyLock.Success) {
foreach (var baseTypeRef in this.BaseTypes) {
IType baseType = baseTypeRef.Resolve(context);
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef != null && baseTypeDef.ClassType != ClassType.Interface) {
// get nested types from baseType (not baseTypeDef) so that generics work correctly
nestedTypes.AddRange(baseType.GetNestedTypes(context, filter));
break; // there is at most 1 non-interface base
}
}
foreach (ITypeDefinition nestedType in this.NestedTypes) {
if (filter == null || filter(nestedType)) {
nestedTypes.Add(nestedType);
}
}
}
}
return nestedTypes;
return ParameterizedType.GetNestedTypes(this, context, filter);
}
public virtual IEnumerable<IMethod> GetMethods(ITypeResolveContext context, Predicate<IMethod> filter = null)
@ -451,8 +428,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -451,8 +428,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
if (this.AddDefaultConstructorIfRequired) {
if (this.ClassType == ClassType.Class && methods.Count == 0
|| this.ClassType == ClassType.Enum || this.ClassType == ClassType.Struct)
if (kind == TypeKind.Class && methods.Count == 0 && !this.IsStatic
|| kind == TypeKind.Enum || kind == TypeKind.Struct)
{
var m = DefaultMethod.CreateDefaultConstructor(this);
if (filter == null || filter(m))

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

@ -50,6 +50,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -50,6 +50,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
this.name = name;
}
public TypeKind Kind {
get { return TypeKind.TypeParameter; }
}
public string Name {
get { return name; }
}
@ -87,7 +91,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -87,7 +91,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
ITypeDefinition constraintDef = constraint.GetDefinition();
// While interfaces are reference types, an interface constraint does not
// force the type parameter to be a reference type; so we need to explicitly look for classes here.
if (constraintDef != null && constraintDef.ClassType == ClassType.Class)
if (constraintDef != null && constraintDef.Kind == TypeKind.Class)
return true;
if (constraint is ITypeParameter) {
bool? isReferenceType = constraint.IsReferenceType(context);
@ -204,14 +208,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -204,14 +208,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
IType ITypeParameter.BoundTo {
get { return null; }
}
ITypeParameter ITypeParameter.UnboundTypeParameter {
get { return null; }
}
public IType AcceptVisitor(TypeVisitor visitor)
{
return visitor.VisitTypeParameter(this);
@ -229,11 +225,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -229,11 +225,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
DefaultTypeDefinition c = new DefaultTypeDefinition(dummyProjectContent, string.Empty, this.Name);
c.Region = this.Region;
if (HasValueTypeConstraint) {
c.ClassType = ClassType.Struct;
c.Kind = TypeKind.Struct;
} else if (HasDefaultConstructorConstraint) {
c.ClassType = ClassType.Class;
c.Kind = TypeKind.Class;
} else {
c.ClassType = ClassType.Interface;
c.Kind = TypeKind.Interface;
}
return c;
}
@ -324,7 +320,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -324,7 +320,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
if (parameter == this)
return true;
foreach (DefaultTypeParameter parameterBaseType in parameter.GetNonCircularBaseTypes(context).Where(t => t is DefaultTypeParameter)) {
stack.Push(parameterBaseType);
stack.Push(parameterBaseType);
}
if (stack.Count == 0)
return false;
@ -343,8 +339,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -343,8 +339,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
foreach (ITypeReference constraint in this.Constraints) {
IType c = constraint.Resolve(context);
yield return c;
ITypeDefinition cdef = c.GetDefinition();
if (!(cdef != null && cdef.ClassType == ClassType.Interface))
if (c.Kind != TypeKind.Interface)
hasNonInterfaceConstraint = true;
}
// Do not add the 'System.Object' constraint if there is another constraint with a base class.

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

@ -14,7 +14,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -14,7 +14,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public VoidTypeDefinition(IProjectContent projectContent)
: base(projectContent, "System", "Void")
{
this.ClassType = ClassType.Struct;
this.Kind = TypeKind.Void;
this.Accessibility = Accessibility.Public;
this.IsSealed = true;
}
@ -43,5 +43,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -43,5 +43,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
return EmptyList<IProperty>.Instance;
}
public override IEnumerable<IMember> GetMembers(ITypeResolveContext context, Predicate<IMember> filter)
{
return EmptyList<IMember>.Instance;
}
}
}

4
ICSharpCode.NRefactory/TypeSystem/IntersectionType.cs

@ -40,6 +40,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -40,6 +40,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
return new IntersectionType(arr);
}
public override TypeKind Kind {
get { return TypeKind.Intersection; }
}
public override string Name {
get {
StringBuilder b = new StringBuilder();

69
ICSharpCode.NRefactory/TypeSystem/ParameterizedType.cs

@ -78,6 +78,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -78,6 +78,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
this.typeArguments = typeArguments;
}
public TypeKind Kind {
get { return genericType.Kind; }
}
public bool? IsReferenceType(ITypeResolveContext context)
{
return genericType.IsReferenceType(context);
@ -174,38 +178,43 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -174,38 +178,43 @@ namespace ICSharpCode.NRefactory.TypeSystem
public IEnumerable<IType> GetNestedTypes(ITypeResolveContext context, Predicate<ITypeDefinition> filter = null)
{
/*
class Base<T> {
class Nested<X> {}
}
class Derived<A, B> : Base<B> {}
Derived<string,int>.GetNestedTypes() = { Base`1+Nested<int, > }
Derived.GetNestedTypes() = { Base`1+Nested<`1, > }
Base<`1>.GetNestedTypes() = { Base`1+Nested<`1, > }
Base.GetNestedTypes() = { Base`1+Nested }
Empty type arguments are represented by SharedTypes.UnboundTypeArgument.
*/
Substitution substitution = new Substitution(typeArguments);
List<IType> types = genericType.GetNestedTypes(context, filter).ToList();
for (int i = 0; i < types.Count; i++) {
ITypeDefinition def = types[i] as ITypeDefinition;
if (def != null && def.TypeParameterCount > 0) {
// (partially) parameterize the nested type definition
IType[] newTypeArgs = new IType[def.TypeParameterCount];
for (int j = 0; j < newTypeArgs.Length; j++) {
if (j < typeArguments.Length)
newTypeArgs[j] = typeArguments[j];
else
newTypeArgs[j] = SharedTypes.UnboundTypeArgument;
}
types[i] = new ParameterizedType(def, newTypeArgs);
return GetNestedTypes(this, context, filter);
}
internal static IEnumerable<IType> GetNestedTypes(IType type, ITypeResolveContext context, Predicate<ITypeDefinition> filter)
{
return type.GetNonInterfaceBaseTypes(context).SelectMany(t => GetNestedTypesInternal(t, context, filter));
}
static IEnumerable<IType> GetNestedTypesInternal(IType baseType, ITypeResolveContext context, Predicate<ITypeDefinition> filter)
{
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
yield break;
baseTypeDef = baseTypeDef.GetCompoundClass();
int outerTypeParameterCount = baseTypeDef.TypeParameterCount;
ParameterizedType pt = baseType as ParameterizedType;
foreach (ITypeDefinition nestedType in baseTypeDef.NestedTypes) {
if (!(filter == null || filter(nestedType)))
continue;
int innerTypeParameterCount = nestedType.TypeParameterCount;
if (innerTypeParameterCount == 0 || (pt == null && innerTypeParameterCount == outerTypeParameterCount)) {
// The nested type has no new type parameters, and there are no type arguments
// to copy from the outer type
// -> we can directly return the nested type definition
yield return nestedType;
} else {
types[i] = types[i].AcceptVisitor(substitution);
// We need to parameterize the nested type
IType[] newTypeArguments = new IType[innerTypeParameterCount];
for (int i = 0; i < outerTypeParameterCount; i++) {
newTypeArguments[i] = pt != null ? pt.typeArguments[i] : baseTypeDef.TypeParameters[i];
}
for (int i = outerTypeParameterCount; i < innerTypeParameterCount; i++) {
newTypeArguments[i] = SharedTypes.UnboundTypeArgument;
}
yield return new ParameterizedType(nestedType, newTypeArguments);
}
}
return types;
}
public IEnumerable<IMethod> GetConstructors(ITypeResolveContext context, Predicate<IMethod> filter = null)
@ -471,7 +480,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -471,7 +480,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
return new ParameterizedType(def, ta);
}
}
/// <summary>
/// ParameterizedTypeReference is a reference to generic class that specifies the type parameters.
/// Example: List&lt;string&gt;

4
ICSharpCode.NRefactory/TypeSystem/PointerType.cs

@ -12,6 +12,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -12,6 +12,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
}
public override TypeKind Kind {
get { return TypeKind.Pointer; }
}
public override string NameSuffix {
get {
return "*";

96
ICSharpCode.NRefactory/TypeSystem/SharedTypes.cs

@ -15,26 +15,26 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -15,26 +15,26 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Gets the type representing resolve errors.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "It's immutable")]
public readonly static IType UnknownType = new UnknownTypeImpl();
public readonly static IType UnknownType = new SharedTypeImpl(TypeKind.Unknown, "?", isReferenceType: null);
/// <summary>
/// The null type is used as type of the null literal. It is a reference type without any members; and it is a subtype of all reference types.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "It's immutable")]
public readonly static IType Null = new NullType();
public readonly static IType Null = new SharedTypeImpl(TypeKind.Null, "null", isReferenceType: true);
/// <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();
public readonly static IType Dynamic = new SharedTypeImpl(TypeKind.Dynamic, "dynamic", isReferenceType: true);
/// <summary>
/// A type used for unbound type arguments in partially parameterized types.
/// </summary>
/// <see cref="IType.GetNestedTypes"/>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "It's immutable")]
public readonly static IType UnboundTypeArgument = new UnboundType();
public readonly static IType UnboundTypeArgument = new SharedTypeImpl(TypeKind.UnboundTypeArgument, "", isReferenceType: null);
/*
* I'd like to define static instances for common types like
@ -55,100 +55,40 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -55,100 +55,40 @@ namespace ICSharpCode.NRefactory.TypeSystem
* would have to return true even though these are two distinct definitions.
*/
/// <summary>
/// Type representing resolve errors.
/// </summary>
sealed class UnknownTypeImpl : AbstractType
{
public override string Name {
get { return "?"; }
}
public override bool? IsReferenceType(ITypeResolveContext context)
{
return null;
}
public override bool Equals(IType other)
{
return other is UnknownTypeImpl;
}
public override int GetHashCode()
{
return 950772036;
}
}
/// <summary>
/// Type of the 'null' literal.
/// </summary>
sealed class NullType : AbstractType
{
public override string Name {
get { return "null"; }
}
public override bool? IsReferenceType(ITypeResolveContext context)
{
return true;
}
public override bool Equals(IType other)
{
return other is NullType;
}
public override int GetHashCode()
{
return 362709548;
}
}
/// <summary>
/// Type representing the C# 'dynamic' type.
/// </summary>
sealed class DynamicType : AbstractType
sealed class SharedTypeImpl : AbstractType
{
public override string Name {
get { return "dynamic"; }
}
readonly TypeKind kind;
readonly string name;
readonly bool? isReferenceType;
public override bool? IsReferenceType(ITypeResolveContext context)
public SharedTypeImpl(TypeKind kind, string name, bool? isReferenceType)
{
return true;
this.kind = kind;
this.name = name;
this.isReferenceType = isReferenceType;
}
public override bool Equals(IType other)
{
return other is DynamicType;
public override TypeKind Kind {
get { return kind; }
}
public override int GetHashCode()
{
return 31986112;
}
}
sealed class UnboundType : AbstractType
{
public override string Name {
get { return string.Empty; }
get { return name; }
}
public override bool? IsReferenceType(ITypeResolveContext context)
{
return null;
return isReferenceType;
}
public override bool Equals(IType other)
{
return other is UnboundType;
return other != null && other.Kind == kind;
}
public override int GetHashCode()
{
return 151719123;
return (int)kind;
}
}
}

66
ICSharpCode.NRefactory/TypeSystem/TypeKind.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// .
/// </summary>
public enum TypeKind : byte
{
/// <summary>Language-specific type that is not part of NRefactory.TypeSystem itself.</summary>
Other,
/// <summary>A <see cref="ITypeDefinition"/> or <see cref="ParameterizedType"/> that is a class.</summary>
Class,
/// <summary>A <see cref="ITypeDefinition"/> or <see cref="ParameterizedType"/> that is an interface.</summary>
Interface,
/// <summary>A <see cref="ITypeDefinition"/> or <see cref="ParameterizedType"/> that is a struct.</summary>
Struct,
/// <summary>A <see cref="ITypeDefinition"/> or <see cref="ParameterizedType"/> that is a delegate.</summary>
/// <remarks><c>System.Delegate</c> itself is TypeKind.Class</remarks>
Delegate,
/// <summary>A <see cref="ITypeDefinition"/> that is an enum.</summary>
/// <remarks><c>System.Enum</c> itself is TypeKind.Class</remarks>
Enum,
/// <summary>A <see cref="ITypeDefinition"/> that is a module (VB).</summary>
Module,
/// <summary>The <c>System.Void</c> type.</summary>
/// <see cref="KnownTypeReference.Void"/>
Void,
/// <see cref="SharedTypes.UnknownType"/>
Unknown,
/// <summary>The type of the null literal.</summary>
/// <see cref="SharedTypes.NullType"/>
Null,
/// <summary>Type representing the C# 'dynamic' type.</summary>
/// <see cref="SharedTypes.DynamicType"/>
Dynamic,
/// <summary>Represents missing type arguments in partially parameterized types.</summary>
/// <see cref="SharedTypes.UnboundTypeArgument"/>
/// <see cref="IType.GetNestedTypes"/>
UnboundTypeArgument,
/// <summary>The type is a type parameter.</summary>
/// <see cref="ITypeParameter"/>
TypeParameter,
/// <summary>An array type</summary>
/// <see cref="ArrayType"/>
Array,
/// <summary>A pointer type</summary>
/// <see cref="PointerType"/>
Pointer,
/// <summary>A managed reference type</summary>
/// <see cref="ByReferenceType"/>
ByReference,
/// <summary>Intersection of several types</summary>
/// <see cref="IntersectionType"/>
Intersection
}
}
Loading…
Cancel
Save