mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C#: Address review comments.
This commit is contained in:
@@ -8,22 +8,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
internal class LineDirective : LineOrSpanDirective<LineDirectiveTriviaSyntax>
|
||||
{
|
||||
private LineDirective(Context cx, LineDirectiveTriviaSyntax trivia)
|
||||
: base(cx, 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")
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
protected override void PopulatePreprocessor(TextWriter trapFile)
|
||||
{
|
||||
var type = Symbol.Line.Kind() switch
|
||||
{
|
||||
SyntaxKind.DefaultKeyword => LineDirectiveKind.Default,
|
||||
SyntaxKind.HiddenKeyword => LineDirectiveKind.Hidden,
|
||||
SyntaxKind.NumericLiteralToken => LineDirectiveKind.Numeric,
|
||||
_ => throw new InternalError(Symbol, "Unhandled line token kind")
|
||||
};
|
||||
|
||||
trapFile.directive_lines(this, type);
|
||||
|
||||
if (Symbol.Line.IsKind(SyntaxKind.NumericLiteralToken))
|
||||
{
|
||||
var value = (int)Symbol.Line.Value!;
|
||||
|
||||
@@ -15,13 +15,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
internal abstract class LineOrSpanDirective<T> : PreprocessorDirective<T> where T : LineOrSpanDirectiveTriviaSyntax
|
||||
{
|
||||
protected LineOrSpanDirective(Context cx, T trivia)
|
||||
private readonly LineDirectiveKind kind;
|
||||
|
||||
protected LineOrSpanDirective(Context cx, T trivia, LineDirectiveKind k)
|
||||
: base(cx, trivia)
|
||||
{
|
||||
kind = k;
|
||||
}
|
||||
|
||||
protected override void PopulatePreprocessor(TextWriter trapFile)
|
||||
{
|
||||
trapFile.directive_lines(this, kind);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Symbol.File.ValueText))
|
||||
{
|
||||
var file = File.Create(Context, Symbol.File.ValueText);
|
||||
|
||||
@@ -8,25 +8,24 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
internal class LineSpanDirective : LineOrSpanDirective<LineSpanDirectiveTriviaSyntax>
|
||||
{
|
||||
private LineSpanDirective(Context cx, LineSpanDirectiveTriviaSyntax trivia)
|
||||
: base(cx, trivia) { }
|
||||
: base(cx, trivia, LineDirectiveKind.Span) { }
|
||||
|
||||
public static LineSpanDirective Create(Context cx, LineSpanDirectiveTriviaSyntax line) =>
|
||||
LineSpanDirectiveFactory.Instance.CreateEntity(cx, line, line);
|
||||
|
||||
protected override void PopulatePreprocessor(TextWriter trapFile)
|
||||
{
|
||||
trapFile.directive_lines(this, LineDirectiveKind.Span);
|
||||
|
||||
var startLine = (int)Symbol.Start.Line.Value!;
|
||||
var startColumn = (int)Symbol.Start.Character.Value!;
|
||||
var endLine = (int)Symbol.End.Line.Value!;
|
||||
var endColumn = (int)Symbol.End.Character.Value!;
|
||||
trapFile.directive_line_span(this, startLine, startColumn, endLine, endColumn);
|
||||
|
||||
var offset = Symbol.CharacterOffset.Value;
|
||||
if (offset is not null)
|
||||
if (Symbol.CharacterOffset.Value is int offset)
|
||||
{
|
||||
trapFile.directive_line_offset(this, (int)offset);
|
||||
trapFile.directive_line_offset(this, offset);
|
||||
}
|
||||
|
||||
base.PopulatePreprocessor(trapFile);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user