forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmptyLocation.cs
More file actions
58 lines (47 loc) · 1.75 KB
/
EmptyLocation.cs
File metadata and controls
58 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.IO;
using System.Threading;
namespace Semmle.Extraction.CSharp.Entities
{
public class EmptyLocation : SourceLocation
{
private readonly File generatedFile;
// The Ql library assumes the presence of a single "empty" location.
private static EmptyLocation? instance;
private static readonly Lock instanceLock = new();
private EmptyLocation(Context cx)
: base(cx, null)
{
generatedFile = GeneratedFile.Create(cx);
}
public override void Populate(TextWriter trapFile)
{
trapFile.locations_default(this, generatedFile, 0, 0, 0, 0);
}
public override void WriteId(EscapingTextWriter trapFile)
{
if (Context.ExtractionContext.IsStandalone)
{
WriteStarId(trapFile);
return;
}
trapFile.Write("loc,");
trapFile.WriteSubId(generatedFile);
trapFile.Write(",0,0,0,0");
}
public override int GetHashCode() => 98732567;
public override bool Equals(object? obj) => obj is not null && obj.GetType() == typeof(EmptyLocation);
public static EmptyLocation Create(Context cx)
{
lock (instanceLock)
{
instance ??= EmptyLocationFactory.Instance.CreateEntity(cx, typeof(EmptyLocation), null);
return instance;
}
}
private class EmptyLocationFactory : CachedEntityFactory<string?, EmptyLocation>
{
public static EmptyLocationFactory Instance { get; } = new EmptyLocationFactory();
public override EmptyLocation Create(Context cx, string? init) => new EmptyLocation(cx);
}
}
}