Skip to content

Commit a1b876c

Browse files
committed
C#: Only create a single empty location element.
1 parent 76befd1 commit a1b876c

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.IO;
2+
3+
namespace Semmle.Extraction.CSharp.Entities
4+
{
5+
/// <summary>
6+
/// Only used in buildless extraction to ensure that we create a single * empty location.
7+
/// </summary>
8+
public class EmptyLocation : SourceLocation
9+
{
10+
private readonly File generatedFile;
11+
12+
private EmptyLocation(Context cx) : base(cx, null)
13+
{
14+
generatedFile = GeneratedFile.Create(cx);
15+
}
16+
17+
public override void Populate(TextWriter trapFile)
18+
{
19+
trapFile.locations_default(this, generatedFile, 0, 0, 0, 0);
20+
}
21+
22+
public override void WriteId(EscapingTextWriter trapFile)
23+
{
24+
WriteStarId(trapFile);
25+
}
26+
27+
public static EmptyLocation Create(Context cx) => EmptyLocationFactory.Instance.CreateEntity(cx, typeof(GeneratedLocation), null);
28+
29+
private class EmptyLocationFactory : CachedEntityFactory<string?, EmptyLocation>
30+
{
31+
public static EmptyLocationFactory Instance { get; } = new EmptyLocationFactory();
32+
33+
public override EmptyLocation Create(Context cx, string? init) => new EmptyLocation(cx);
34+
}
35+
}
36+
37+
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedLocation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ private GeneratedLocation(Context cx)
1414

1515
public override void Populate(TextWriter trapFile)
1616
{
17+
if (Context.ExtractionContext.IsStandalone)
18+
{
19+
return;
20+
}
21+
1722
trapFile.locations_default(this, generatedFile, 0, 0, 0, 0);
1823
}
1924

2025
public override void WriteId(EscapingTextWriter trapFile)
2126
{
2227
if (Context.ExtractionContext.IsStandalone)
2328
{
24-
WriteStarId(trapFile);
2529
return;
2630
}
2731

csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ private void DoAnalyseCompilation()
238238

239239
compilationEntity = Entities.Compilation.Create(cx);
240240

241+
if (cx.ExtractionContext.IsStandalone)
242+
{
243+
// Add a single empty location
244+
Entities.EmptyLocation.Create(cx);
245+
}
246+
241247
ExtractionContext.CompilationInfos.ForEach(ci => trapWriter.Writer.compilation_info(compilationEntity, ci.key, ci.value));
242248

243249
ReportProgressTaskDone(currentTaskId, assemblyPath, trapWriter.TrapFile, stopwatch.Elapsed, AnalysisAction.Extracted);

0 commit comments

Comments
 (0)