C#: Merge expr_compiler_generated and compiler_generated and add compiler generated statements.

This commit is contained in:
Michael Nebel
2024-02-22 15:31:07 +01:00
parent 606a8fed0c
commit bf4e3a7d1c
6 changed files with 16 additions and 10 deletions

View File

@@ -54,7 +54,7 @@ namespace Semmle.Extraction.CSharp.Entities
}
if (info.IsCompilerGenerated)
trapFile.expr_compiler_generated(this);
trapFile.compiler_generated(this);
if (info.ExprValue is string value)
trapFile.expr_value(this, value);

View File

@@ -9,12 +9,14 @@ namespace Semmle.Extraction.CSharp.Entities
{
protected readonly TSyntax Stmt;
private readonly Location location;
private readonly bool isCompilerGenerated;
protected Statement(Context cx, TSyntax stmt, Kinds.StmtKind kind, IStatementParentEntity parent, int child, Location location, bool isCompilerGenerated = false)
: base(cx, kind, parent, child)
{
Stmt = stmt;
this.location = location;
this.isCompilerGenerated = isCompilerGenerated;
if (!isCompilerGenerated)
{
cx.BindComments(this, location.Symbol);
@@ -29,6 +31,11 @@ namespace Semmle.Extraction.CSharp.Entities
base.Populate(trapFile);
trapFile.stmt_location(this, location);
if (isCompilerGenerated)
{
trapFile.compiler_generated(this);
}
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => Stmt.GetLocation();

View File

@@ -164,9 +164,6 @@ namespace Semmle.Extraction.CSharp
internal static void expr_call(this TextWriter trapFile, Expression expr, Method target) =>
trapFile.WriteTuple("expr_call", expr, target);
internal static void expr_compiler_generated(this TextWriter trapFile, Expression expr) =>
trapFile.WriteTuple("expr_compiler_generated", expr);
internal static void expr_flowstate(this TextWriter trapFile, Expression expr, int flowState) =>
trapFile.WriteTuple("expr_flowstate", expr, flowState);

View File

@@ -43,6 +43,9 @@ class Stmt extends ControlFlowElement, @stmt {
* For example converts `{ { return x; } }` to `return x;`.
*/
Stmt stripSingletonBlocks() { result = this }
/** Holds if this statement is compiler generated. */
predicate isCompilerGenerated() { compiler_generated(this) }
}
/**

View File

@@ -65,7 +65,7 @@ class Expr extends DotNet::Expr, ControlFlowElement, @expr {
* Holds if this expression is generated by the compiler and does not appear
* explicitly in the source code.
*/
predicate isImplicit() { expr_compiler_generated(this) }
predicate isImplicit() { compiler_generated(this) }
/**
* Gets an expression that is the result of stripping (recursively) all

View File

@@ -682,8 +682,6 @@ has_modifiers(
int id: @modifiable_direct ref,
int mod_id: @modifier ref);
compiler_generated(unique int id: @modifiable ref);
/** MEMBERS **/
@member = @method | @constructor | @destructor | @field | @property | @event | @operator | @indexer | @type;
@@ -1271,9 +1269,6 @@ mutator_invocation_mode(
unique int id: @operator_invocation_expr ref,
int mode: int ref /* prefix = 1, postfix = 2*/);
expr_compiler_generated(
unique int id: @expr ref);
expr_value(
unique int id: @expr ref,
string value: string ref);
@@ -1316,6 +1311,10 @@ lambda_expr_return_type(
unique int id: @lambda_expr ref,
int type_id: @type_or_ref ref);
/* Compiler generated */
compiler_generated(unique int id: @element ref);
/** CONTROL/DATA FLOW **/
@control_flow_element = @stmt | @expr;