mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Extract pragma checksum directives
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
internal interface IPreprocessorDirective { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
internal class PragmaChecksumDirective : PreprocessorDirective<PragmaChecksumDirectiveTriviaSyntax>
|
||||
{
|
||||
public PragmaChecksumDirective(Context cx, PragmaChecksumDirectiveTriviaSyntax trivia)
|
||||
: base(cx, trivia)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void PopulatePreprocessor(TextWriter trapFile)
|
||||
{
|
||||
trapFile.pragma_checksums(this, trivia.File.ToString(), trivia.Guid.ToString(), trivia.Bytes.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,18 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
internal class PragmaWarningDirective : FreshEntity, IPreprocessorDirective
|
||||
internal class PragmaWarningDirective : PreprocessorDirective<PragmaWarningDirectiveTriviaSyntax>
|
||||
{
|
||||
private readonly PragmaWarningDirectiveTriviaSyntax trivia;
|
||||
|
||||
public PragmaWarningDirective(Context cx, PragmaWarningDirectiveTriviaSyntax trivia)
|
||||
: base(cx)
|
||||
: base(cx, trivia)
|
||||
{
|
||||
this.trivia = trivia;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
protected override void PopulatePreprocessor(TextWriter trapFile)
|
||||
{
|
||||
trapFile.pragma_warnings(this, trivia.DisableOrRestoreKeyword.IsKind(SyntaxKind.DisableKeyword) ? 0 : 1);
|
||||
|
||||
@@ -26,18 +21,6 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
trapFile.pragma_warning_error_codes(this, code.ToString(), childIndex++);
|
||||
}
|
||||
|
||||
trapFile.preprocessor_directive_location(this, cx.Create(ReportingLocation));
|
||||
|
||||
if (!cx.Extractor.Standalone)
|
||||
{
|
||||
var assembly = Assembly.CreateOutputAssembly(cx);
|
||||
trapFile.preprocessor_directive_assembly(this, assembly);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override Microsoft.CodeAnalysis.Location ReportingLocation => trivia.GetLocation();
|
||||
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.OptionalLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
internal abstract class PreprocessorDirective<TDirective> : FreshEntity where TDirective : DirectiveTriviaSyntax
|
||||
{
|
||||
protected readonly TDirective trivia;
|
||||
|
||||
protected PreprocessorDirective(Context cx, TDirective trivia)
|
||||
: base(cx)
|
||||
{
|
||||
this.trivia = trivia;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
protected sealed override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulatePreprocessor(trapFile);
|
||||
|
||||
trapFile.preprocessor_directive_location(this, cx.Create(ReportingLocation));
|
||||
|
||||
if (!cx.Extractor.Standalone)
|
||||
{
|
||||
var assembly = Assembly.CreateOutputAssembly(cx);
|
||||
trapFile.preprocessor_directive_assembly(this, assembly);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void PopulatePreprocessor(TextWriter trapFile);
|
||||
|
||||
public sealed override Microsoft.CodeAnalysis.Location ReportingLocation => trivia.GetLocation();
|
||||
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.OptionalLabel;
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,10 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
{
|
||||
new Entities.PragmaWarningDirective(cx, node);
|
||||
}
|
||||
|
||||
public override void VisitPragmaChecksumDirectiveTrivia(PragmaChecksumDirectiveTriviaSyntax node)
|
||||
{
|
||||
new Entities.PragmaChecksumDirective(cx, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.CommentProcessing;
|
||||
using Semmle.Extraction.CSharp.Entities;
|
||||
using Semmle.Extraction.Entities;
|
||||
@@ -591,12 +592,16 @@ namespace Semmle.Extraction.CSharp
|
||||
trapFile.WriteTuple("using_static_directives", @using, type);
|
||||
}
|
||||
|
||||
internal static void preprocessor_directive_location(this TextWriter trapFile, IPreprocessorDirective directive, Location location)
|
||||
internal static void preprocessor_directive_location<TDirective>(this TextWriter trapFile,
|
||||
PreprocessorDirective<TDirective> directive, Location location)
|
||||
where TDirective : DirectiveTriviaSyntax
|
||||
{
|
||||
trapFile.WriteTuple("preprocessor_directive_location", directive, location);
|
||||
}
|
||||
|
||||
internal static void preprocessor_directive_assembly(this TextWriter trapFile, IPreprocessorDirective directive, Assembly assembly)
|
||||
internal static void preprocessor_directive_assembly<TDirective>(this TextWriter trapFile,
|
||||
PreprocessorDirective<TDirective> directive, Assembly assembly)
|
||||
where TDirective : DirectiveTriviaSyntax
|
||||
{
|
||||
trapFile.WriteTuple("preprocessor_directive_assembly", directive, assembly);
|
||||
}
|
||||
@@ -610,5 +615,10 @@ namespace Semmle.Extraction.CSharp
|
||||
{
|
||||
trapFile.WriteTuple("pragma_warning_error_codes", pragma, errorCode, child);
|
||||
}
|
||||
|
||||
internal static void pragma_checksums(this TextWriter trapFile, PragmaChecksumDirective pragma, string file, string guid, string bytes)
|
||||
{
|
||||
trapFile.WriteTuple("pragma_checksums", pragma, file, guid, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user