mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Rename GeneratedLocation to EmptyLocation and make sure that we always create one such location.
This commit is contained in:
@@ -2,11 +2,11 @@ using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
public class GeneratedLocation : SourceLocation
|
||||
public class EmptyLocation : SourceLocation
|
||||
{
|
||||
private readonly File generatedFile;
|
||||
|
||||
private GeneratedLocation(Context cx)
|
||||
private EmptyLocation(Context cx)
|
||||
: base(cx, null)
|
||||
{
|
||||
generatedFile = GeneratedFile.Create(cx);
|
||||
@@ -26,15 +26,16 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override int GetHashCode() => 98732567;
|
||||
|
||||
public override bool Equals(object? obj) => obj is not null && obj.GetType() == typeof(GeneratedLocation);
|
||||
public override bool Equals(object? obj) => obj is not null && obj.GetType() == typeof(EmptyLocation);
|
||||
|
||||
public static GeneratedLocation Create(Context cx) => GeneratedLocationFactory.Instance.CreateEntity(cx, typeof(GeneratedLocation), null);
|
||||
public static EmptyLocation Create(Context cx)
|
||||
=> EmptyLocationFactory.Instance.CreateEntity(cx, typeof(EmptyLocation), null);
|
||||
|
||||
private class GeneratedLocationFactory : CachedEntityFactory<string?, GeneratedLocation>
|
||||
private class EmptyLocationFactory : CachedEntityFactory<string?, EmptyLocation>
|
||||
{
|
||||
public static GeneratedLocationFactory Instance { get; } = new GeneratedLocationFactory();
|
||||
public static EmptyLocationFactory Instance { get; } = new EmptyLocationFactory();
|
||||
|
||||
public override GeneratedLocation Create(Context cx, string? init) => new GeneratedLocation(cx);
|
||||
public override EmptyLocation Create(Context cx, string? init) => new EmptyLocation(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,6 +238,9 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
compilationEntity = Entities.Compilation.Create(cx);
|
||||
|
||||
// Ensure that the empty location is always created.
|
||||
Entities.EmptyLocation.Create(cx);
|
||||
|
||||
ExtractionContext.CompilationInfos.ForEach(ci => trapWriter.Writer.compilation_info(compilationEntity, ci.key, ci.value));
|
||||
|
||||
ReportProgressTaskDone(currentTaskId, assemblyPath, trapWriter.TrapFile, stopwatch.Elapsed, AnalysisAction.Extracted);
|
||||
|
||||
@@ -550,6 +550,10 @@ namespace Semmle.Extraction.CSharp
|
||||
!SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) ||
|
||||
scope.InScope(symbol);
|
||||
|
||||
public bool ExtractLocation(ISymbol symbol) =>
|
||||
SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) &&
|
||||
scope.InScope(symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Runs the given action <paramref name="a"/>, guarding for trap duplication
|
||||
/// based on key <paramref name="key"/>.
|
||||
@@ -582,14 +586,14 @@ namespace Semmle.Extraction.CSharp
|
||||
public Entities.Location CreateLocation()
|
||||
{
|
||||
return SourceTree is null
|
||||
? Entities.GeneratedLocation.Create(this)
|
||||
? Entities.EmptyLocation.Create(this)
|
||||
: CreateLocation(Microsoft.CodeAnalysis.Location.Create(SourceTree, Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(0, 0)));
|
||||
}
|
||||
|
||||
public Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? location)
|
||||
{
|
||||
return (location is null || location.Kind == LocationKind.None)
|
||||
? Entities.GeneratedLocation.Create(this)
|
||||
? Entities.EmptyLocation.Create(this)
|
||||
: location.IsInSource
|
||||
? Entities.NonGeneratedSourceLocation.Create(this, location)
|
||||
: Entities.Assembly.Create(this, location);
|
||||
|
||||
Reference in New Issue
Block a user