-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLineDirective.cs
More file actions
42 lines (36 loc) · 1.59 KB
/
LineDirective.cs
File metadata and controls
42 lines (36 loc) · 1.59 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
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace Semmle.Extraction.CSharp.Entities
{
internal class LineDirective : LineOrSpanDirective<LineDirectiveTriviaSyntax>
{
private LineDirective(Context cx, LineDirectiveTriviaSyntax trivia)
: base(cx, trivia, trivia.Line.Kind() switch
{
SyntaxKind.DefaultKeyword => LineDirectiveKind.Default,
SyntaxKind.HiddenKeyword => LineDirectiveKind.Hidden,
SyntaxKind.NumericLiteralToken => LineDirectiveKind.Numeric,
_ => throw new InternalError(trivia, $"Unhandled line token kind {trivia.Line.Kind()}")
})
{
}
protected override void PopulatePreprocessor(TextWriter trapFile)
{
if (Symbol.Line.IsKind(SyntaxKind.NumericLiteralToken))
{
var value = (int)Symbol.Line.Value!;
trapFile.directive_line_value(this, value);
}
base.PopulatePreprocessor(trapFile);
}
public static LineDirective Create(Context cx, LineDirectiveTriviaSyntax line) =>
LineDirectiveFactory.Instance.CreateEntity(cx, line, line);
private class LineDirectiveFactory : CachedEntityFactory<LineDirectiveTriviaSyntax, LineDirective>
{
public static LineDirectiveFactory Instance { get; } = new LineDirectiveFactory();
public override LineDirective Create(Context cx, LineDirectiveTriviaSyntax init) => new(cx, init);
}
}
}