Merge pull request #2494 from calumgrant/cs/roslyn-3.4

C#: Upgrade Roslyn to 3.4
This commit is contained in:
Tom Hvitved
2019-12-09 12:21:30 +01:00
committed by GitHub
26 changed files with 351 additions and 92 deletions

View File

@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
// But for properties/indexers that implement explicit interfaces, Roslyn
// does not properly populate `AssociatedSymbol`
var props = symbol.ContainingType.GetMembers().OfType<IPropertySymbol>();
props = props.Where(p => symbol.Equals(p.GetMethod) || symbol.Equals(p.SetMethod));
props = props.Where(p => SymbolEqualityComparer.Default.Equals(symbol, p.GetMethod) || SymbolEqualityComparer.Default.Equals(symbol, p.SetMethod));
return props.SingleOrDefault();
}
}
@@ -47,12 +47,12 @@ namespace Semmle.Extraction.CSharp.Entities
var parent = Property.Create(Context, prop);
int kind;
Accessor unboundAccessor;
if (symbol.Equals(prop.GetMethod))
if (SymbolEqualityComparer.Default.Equals(symbol, prop.GetMethod))
{
kind = 1;
unboundAccessor = Create(Context, prop.OriginalDefinition.GetMethod);
}
else if (symbol.Equals(prop.SetMethod))
else if (SymbolEqualityComparer.Default.Equals(symbol, prop.SetMethod))
{
kind = 2;
unboundAccessor = Create(Context, prop.OriginalDefinition.SetMethod);

View File

@@ -20,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities
static new Destructor OriginalDefinition(Context cx, Destructor original, IMethodSymbol symbol)
{
return symbol.OriginalDefinition == null || Equals(symbol.OriginalDefinition, symbol) ? original : Create(cx, symbol.OriginalDefinition);
return symbol.OriginalDefinition == null || SymbolEqualityComparer.Default.Equals(symbol.OriginalDefinition, symbol) ? original : Create(cx, symbol.OriginalDefinition);
}
public new static Destructor Create(Context cx, IMethodSymbol symbol) =>

View File

@@ -28,12 +28,12 @@ namespace Semmle.Extraction.CSharp.Entities
var parent = Event.Create(Context, @event);
int kind;
EventAccessor unboundAccessor;
if (symbol.Equals(@event.AddMethod))
if (SymbolEqualityComparer.Default.Equals(symbol, @event.AddMethod))
{
kind = 1;
unboundAccessor = Create(Context, @event.OriginalDefinition.AddMethod);
}
else if (symbol.Equals(@event.RemoveMethod))
else if (SymbolEqualityComparer.Default.Equals(symbol, @event.RemoveMethod))
{
kind = 2;
unboundAccessor = Create(Context, @event.OriginalDefinition.RemoveMethod);

View File

@@ -106,7 +106,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
{
var collectionInfo = cx.GetModel(Syntax).GetCollectionInitializerSymbolInfo(i);
var addMethod = Method.Create(cx, collectionInfo.Symbol as IMethodSymbol);
var voidType = Entities.Type.Create(cx, new AnnotatedTypeSymbol(cx.Compilation.GetSpecialType(SpecialType.System_Void), NullableAnnotation.NotApplicable));
var voidType = Entities.Type.Create(cx, new AnnotatedTypeSymbol(cx.Compilation.GetSpecialType(SpecialType.System_Void), NullableAnnotation.None));
var invocation = new Expression(new ExpressionInfo(cx, voidType, cx.Create(i.GetLocation()), ExprKind.METHOD_INVOCATION, this, child++, false, null));

View File

@@ -40,7 +40,7 @@ namespace Semmle.Extraction.CSharp.Entities
foreach (var p in parameters.Zip(originalParameters, (paramSymbol, originalParam) => new { paramSymbol, originalParam }))
{
var original = Equals(p.paramSymbol, p.originalParam) ? null : Parameter.Create(Context, p.originalParam, originalMethod);
var original = SymbolEqualityComparer.Default.Equals(p.paramSymbol, p.originalParam) ? null : Parameter.Create(Context, p.originalParam, originalMethod);
Parameter.Create(Context, p.paramSymbol, this, original);
}
@@ -117,7 +117,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (m.symbol.IsGenericMethod)
{
if (Equals(m.symbol, m.symbol.OriginalDefinition))
if (SymbolEqualityComparer.Default.Equals(m.symbol, m.symbol.OriginalDefinition))
{
trapFile.Write('`');
trapFile.Write(m.symbol.TypeParameters.Length);
@@ -318,7 +318,7 @@ namespace Semmle.Extraction.CSharp.Entities
/// <summary>
/// Whether this method has unbound type parameters.
/// </summary>
public bool IsUnboundGeneric => IsGeneric && Equals(symbol.ConstructedFrom, symbol);
public bool IsUnboundGeneric => IsGeneric && SymbolEqualityComparer.Default.Equals(symbol.ConstructedFrom, symbol);
public bool IsBoundGeneric => IsGeneric && !IsUnboundGeneric;

View File

@@ -272,7 +272,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (other == null || other.GetType() != typeof(ConstructedExtensionParameter))
return false;
return Equals(symbol, other.symbol) && Equals(ConstructedType, other.ConstructedType);
return SymbolEqualityComparer.Default.Equals(symbol, other.symbol) && SymbolEqualityComparer.Default.Equals(ConstructedType, other.ConstructedType);
}
public static ConstructedExtensionParameter Create(Context cx, Method method, Parameter parameter) =>

View File

@@ -32,7 +32,7 @@ namespace Semmle.Extraction.CSharp.Entities
public bool IsOblivious => Annotation == 0 && NullableParameters.Length == 0;
static readonly Nullability oblivious = new Nullability(NullableAnnotation.Disabled);
static readonly Nullability oblivious = new Nullability(NullableAnnotation.None);
static readonly Nullability annotated = new Nullability(NullableAnnotation.Annotated);
static readonly Nullability notannotated = new Nullability(NullableAnnotation.NotAnnotated);
@@ -244,14 +244,14 @@ namespace Semmle.Extraction.CSharp.Entities
/// This has not yet been exposed on the public API.
/// </summary>
public static IEnumerable<AnnotatedTypeSymbol> GetAnnotatedTypeArguments(this INamedTypeSymbol symbol) =>
symbol.TypeArguments.Zip(symbol.TypeArgumentsNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a));
symbol.TypeArguments.Zip(symbol.TypeArgumentNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a));
/// <summary>
/// Gets the annotated type arguments of an IMethodSymbol.
/// This has not yet been exposed on the public API.
/// </summary>
public static IEnumerable<AnnotatedTypeSymbol> GetAnnotatedTypeArguments(this IMethodSymbol symbol) =>
symbol.TypeArguments.Zip(symbol.TypeArgumentsNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a));
symbol.TypeArguments.Zip(symbol.TypeArgumentNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a));
/// <summary>
/// Gets the annotated type constraints of an ITypeParameterSymbol.

View File

@@ -36,7 +36,7 @@ namespace Semmle.Extraction.CSharp.Entities
public static bool ConstructedOrParentIsConstructed(INamedTypeSymbol symbol)
{
return !Equals(symbol, symbol.OriginalDefinition) ||
return !SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) ||
symbol.ContainingType != null && ConstructedOrParentIsConstructed(symbol.ContainingType);
}
@@ -155,7 +155,7 @@ namespace Semmle.Extraction.CSharp.Entities
{
var param = invokeMethod.Parameters[i];
var originalParam = invokeMethod.OriginalDefinition.Parameters[i];
var originalParamEntity = Equals(param, originalParam) ? null :
var originalParamEntity = SymbolEqualityComparer.Default.Equals(param, originalParam) ? null :
DelegateTypeParameter.Create(Context, originalParam, Create(Context, ((INamedTypeSymbol)symbol).OriginalDefinition));
DelegateTypeParameter.Create(Context, param, this, originalParamEntity);
}

View File

@@ -19,7 +19,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
</ItemGroup>
</Project>

View File

@@ -115,7 +115,7 @@ namespace Semmle.Extraction.CSharp
case TypeKind.TypeParameter:
var tp = (ITypeParameterSymbol)type;
var declaringGen = tp.TypeParameterKind == TypeParameterKind.Method ? tp.DeclaringMethod : (ISymbol)tp.DeclaringType;
return Equals(declaringGen, declaringGeneric);
return SymbolEqualityComparer.Default.Equals(declaringGen, declaringGeneric);
default:
return false;
}
@@ -373,7 +373,7 @@ namespace Semmle.Extraction.CSharp
}
public static bool IsReallyUnbound(this INamedTypeSymbol type) =>
Equals(type.ConstructedFrom, type) || type.IsUnboundGenericType;
SymbolEqualityComparer.Default.Equals(type.ConstructedFrom, type) || type.IsUnboundGenericType;
public static bool IsReallyBound(this INamedTypeSymbol type) => !IsReallyUnbound(type);
@@ -413,13 +413,13 @@ namespace Semmle.Extraction.CSharp
/// <summary>
/// Holds if this symbol is a source declaration.
/// </summary>
public static bool IsSourceDeclaration(this ISymbol symbol) => Equals(symbol, symbol.OriginalDefinition);
public static bool IsSourceDeclaration(this ISymbol symbol) => SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition);
/// <summary>
/// Holds if this method is a source declaration.
/// </summary>
public static bool IsSourceDeclaration(this IMethodSymbol method) =>
IsSourceDeclaration((ISymbol)method) && Equals(method, method.ConstructedFrom) && method.ReducedFrom == null;
IsSourceDeclaration((ISymbol)method) && SymbolEqualityComparer.Default.Equals(method, method.ConstructedFrom) && method.ReducedFrom == null;
/// <summary>
/// Holds if this parameter is a source declaration.
@@ -477,6 +477,6 @@ namespace Semmle.Extraction.CSharp
/// This has not yet been exposed on the public API.
/// </summary>
public static IEnumerable<AnnotatedTypeSymbol> GetAnnotatedTypeArguments(this INamedTypeSymbol symbol) =>
symbol.TypeArguments.Zip(symbol.TypeArgumentsNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a));
symbol.TypeArguments.Zip(symbol.TypeArgumentNullableAnnotations, (t, a) => new AnnotatedTypeSymbol(t, a));
}
}