Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix translation of DefiningType and DefiningMember for Roslyn
Browse files Browse the repository at this point in the history
Fixes #118
  • Loading branch information
sharwell committed Jul 11, 2015
1 parent 94fa4e7 commit 5453d6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public bool TryGetTypeReference(ITypeSymbol semanticType, IAssemblyReference cci
}
}
ITypeReference genericType = null;
if (!TryGetTypeReference(semanticType.ContainingType, out genericType)) {
if (!TryGetTypeReference(semanticType.DefiningType(), out genericType)) {
goto ReturnFalse;
}
cciType = new Microsoft.Cci.MutableCodeModel.GenericTypeInstanceReference() {
Expand Down Expand Up @@ -659,20 +659,20 @@ public bool TryGetTypeReference(ITypeSymbol semanticType, IAssemblyReference cci
#endregion
#region If type parameter
if (semanticType.TypeKind == TypeKind.TypeParameter) {
if (semanticType.ContainingSymbol != null && semanticType.ContainingSymbol.Kind == SymbolKind.Method) {
if (semanticType.DefiningMember() != null) {
cciType = new Microsoft.Cci.MutableCodeModel.GenericMethodParameterReference() {
Index = (ushort)(!semanticType.ContainingSymbol.TypeParameters().IsDefault ? semanticType.ContainingSymbol.TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
Index = (ushort)(!semanticType.DefiningMember().TypeParameters().IsDefault ? semanticType.DefiningMember().TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
InternFactory = this.Host.InternFactory,
Name = Host.NameTable.GetNameFor(semanticType.Name != null ? semanticType.Name : "T"),
};
goto ReturnTrue;
} else if (semanticType.ContainingType != null) {
} else if (semanticType.DefiningType() != null) {
ITypeReference cciDefiningType;
if (!TryGetTypeReference(semanticType.ContainingType, out cciDefiningType))
if (!TryGetTypeReference(semanticType.DefiningType(), out cciDefiningType))
goto ReturnFalse;
cciType = new Microsoft.Cci.MutableCodeModel.GenericTypeParameterReference() {
DefiningType = cciDefiningType,
Index = (ushort)(semanticType.ContainingType.TypeParameters != null ? semanticType.ContainingType.TypeParameters.IndexOf((ITypeParameterSymbol)semanticType) : 0),
Index = (ushort)(!semanticType.DefiningType().TypeParameters().IsDefaultOrEmpty ? semanticType.DefiningType().TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
InternFactory = this.Host.InternFactory,
Name = Host.NameTable.GetNameFor(semanticType.Name != null ? semanticType.Name : "T"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ public static ITypeSymbol ElementType(this ITypeSymbol symbol)
}
}

public static IMethodSymbol DefiningMember(this ITypeSymbol symbol)
{
ITypeParameterSymbol typeParameterSymbol = symbol as ITypeParameterSymbol;
if (typeParameterSymbol != null)
return typeParameterSymbol.DeclaringMethod;

return null;
}

public static ITypeSymbol DefiningType(this ITypeSymbol symbol)
{
ITypeParameterSymbol typeParameterSymbol = symbol as ITypeParameterSymbol;
if (typeParameterSymbol != null)
return typeParameterSymbol.DeclaringType;

ITypeSymbol originalDefinition = symbol.OriginalDefinition;
if (originalDefinition != symbol)
return originalDefinition;

return null;
}

public static ImmutableArray<ITypeParameterSymbol> TypeParameters(this ISymbol symbol)
{
switch (symbol.Kind)
Expand Down

0 comments on commit 5453d6d

Please sign in to comment.