mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Merge pull request #15696 from michaelnebel/csharp/compilergeneratedstmt
C#: Compiler generated statements.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
class Modifiable extends @modifiable {
|
||||
Modifiable() { compiler_generated(this) }
|
||||
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
select any(Modifiable m)
|
||||
@@ -0,0 +1,7 @@
|
||||
class Expression extends @expr {
|
||||
Expression() { compiler_generated(this) }
|
||||
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
select any(Expression e)
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
description: Split `compiler_generated` into `expr_compiler_generated` and `compiler_generated`.
|
||||
compatibility: backwards
|
||||
compiler_generated.rel: run compiler_generated.qlo
|
||||
expr_compiler_generated.rel: run expr_compiler_generated.qlo
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* C#: The table `expr_compiler_generated` has been deleted and its content has been added to `compiler_generated`.
|
||||
@@ -27,7 +27,8 @@ class PrintAstConfiguration extends TPrintAstConfiguration {
|
||||
}
|
||||
|
||||
private predicate shouldPrint(Element e, Location l) {
|
||||
exists(PrintAstConfiguration config | config.shouldPrint(e, l))
|
||||
exists(PrintAstConfiguration config | config.shouldPrint(e, l)) and
|
||||
not e.(Stmt).isCompilerGenerated()
|
||||
}
|
||||
|
||||
private predicate isImplicitExpression(ControlFlowElement element) {
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Element extends @element {
|
||||
Element() { expr_compiler_generated(this) or compiler_generated(this) }
|
||||
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
select any(Element e)
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
description: Merge `expr_compiler_generated` into `compiler_generated` and add support for compiler generated statements.
|
||||
compatibility: backwards
|
||||
compiler_generated.rel: run compiler_generated.qlo
|
||||
expr_compiler_generated.rel: delete
|
||||
@@ -25,7 +25,6 @@ constructors.cs:
|
||||
# 23| -1: [TypeMention] object
|
||||
# 23| 1: [Parameter] s
|
||||
# 23| -1: [TypeMention] string
|
||||
# 23| 4: [BlockStmt] {...}
|
||||
# 25| 5: [InstanceConstructor] C1
|
||||
#-----| 2: (Parameters)
|
||||
# 25| 0: [Parameter] o
|
||||
@@ -48,4 +47,3 @@ constructors.cs:
|
||||
# 28| 3: [ConstructorInitializer] call to constructor C1
|
||||
# 28| 0: [ParameterAccess] access to parameter o
|
||||
# 28| 1: [ParameterAccess] access to parameter s
|
||||
# 28| 4: [BlockStmt] {...}
|
||||
|
||||
@@ -884,7 +884,6 @@ Record.cs:
|
||||
# 27| -1: [TypeMention] string
|
||||
# 27| 1: [Parameter] LastName
|
||||
# 27| -1: [TypeMention] string
|
||||
# 27| 4: [BlockStmt] {...}
|
||||
# 27| 16: [Property] FirstName
|
||||
# 27| 3: [Getter] get_FirstName
|
||||
# 27| 4: [Setter] set_FirstName
|
||||
@@ -917,7 +916,6 @@ Record.cs:
|
||||
# 30| 3: [ConstructorInitializer] call to constructor Person1
|
||||
# 30| 0: [ParameterAccess] access to parameter FirstName
|
||||
# 30| 1: [ParameterAccess] access to parameter LastName
|
||||
# 29| 4: [BlockStmt] {...}
|
||||
# 29| 17: [Property] Subject
|
||||
# 29| 3: [Getter] get_Subject
|
||||
# 29| 4: [Setter] set_Subject
|
||||
@@ -945,7 +943,6 @@ Record.cs:
|
||||
# 33| 3: [ConstructorInitializer] call to constructor Person1
|
||||
# 33| 0: [ParameterAccess] access to parameter FirstName
|
||||
# 33| 1: [ParameterAccess] access to parameter LastName
|
||||
# 32| 4: [BlockStmt] {...}
|
||||
# 32| 17: [Property] Level
|
||||
# 32| 3: [Getter] get_Level
|
||||
# 32| 4: [Setter] set_Level
|
||||
@@ -966,7 +963,6 @@ Record.cs:
|
||||
#-----| 2: (Parameters)
|
||||
# 35| 0: [Parameter] Name
|
||||
# 35| -1: [TypeMention] string
|
||||
# 35| 4: [BlockStmt] {...}
|
||||
# 35| 16: [Property] Name
|
||||
# 35| 3: [Getter] get_Name
|
||||
# 35| 4: [Setter] set_Name
|
||||
@@ -993,7 +989,6 @@ Record.cs:
|
||||
# 41| -1: [TypeMention] string
|
||||
# 41| 3: [ConstructorInitializer] call to constructor Pet
|
||||
# 41| 0: [ParameterAccess] access to parameter Name
|
||||
# 41| 4: [BlockStmt] {...}
|
||||
# 41| 15: [Property] EqualityContract
|
||||
# 41| 3: [Getter] get_EqualityContract
|
||||
# 43| 16: [Method] WagTail
|
||||
@@ -1035,7 +1030,6 @@ Record.cs:
|
||||
#-----| 2: (Parameters)
|
||||
# 54| 0: [Parameter] A
|
||||
# 54| -1: [TypeMention] string
|
||||
# 54| 4: [BlockStmt] {...}
|
||||
# 54| 16: [Property] A
|
||||
# 54| 3: [Getter] get_A
|
||||
# 54| 4: [Setter] set_A
|
||||
@@ -1060,7 +1054,6 @@ Record.cs:
|
||||
# 56| -1: [TypeMention] string
|
||||
# 56| 3: [ConstructorInitializer] call to constructor R1
|
||||
# 56| 0: [ParameterAccess] access to parameter A
|
||||
# 56| 4: [BlockStmt] {...}
|
||||
# 56| 17: [Property] B
|
||||
# 56| 3: [Getter] get_B
|
||||
# 56| 4: [Setter] set_B
|
||||
|
||||
@@ -369,7 +369,6 @@ Tuples.cs:
|
||||
# 95| -1: [TypeMention] string
|
||||
# 95| 1: [Parameter] j
|
||||
# 95| -1: [TypeMention] int
|
||||
# 95| 4: [BlockStmt] {...}
|
||||
# 95| 16: [Property] i
|
||||
# 95| 3: [Getter] get_i
|
||||
# 95| 4: [Setter] set_i
|
||||
|
||||
@@ -2411,7 +2411,6 @@ expressions.cs:
|
||||
#-----| 2: (Parameters)
|
||||
# 518| 0: [Parameter] oc1
|
||||
# 518| -1: [TypeMention] object
|
||||
# 518| 4: [BlockStmt] {...}
|
||||
# 520| 23: [Class] ClassC2
|
||||
#-----| 3: (Base types)
|
||||
# 520| 0: [TypeMention] ClassC1
|
||||
@@ -2421,4 +2420,3 @@ expressions.cs:
|
||||
# 520| -1: [TypeMention] object
|
||||
# 520| 3: [ConstructorInitializer] call to constructor ClassC1
|
||||
# 520| 0: [ParameterAccess] access to parameter oc2
|
||||
# 520| 4: [BlockStmt] {...}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
| fixed.cs:3:7:3:11 | {...} | fixed.cs:3:7:3:11 | Fixed |
|
||||
| statements.cs:7:11:7:15 | {...} | statements.cs:7:11:7:15 | Class |
|
||||
| statements.cs:243:15:243:25 | {...} | statements.cs:243:15:243:25 | AccountLock |
|
||||
@@ -0,0 +1,5 @@
|
||||
import csharp
|
||||
|
||||
from Stmt stmt
|
||||
where stmt.isCompilerGenerated()
|
||||
select stmt, stmt.getEnclosingCallable()
|
||||
Reference in New Issue
Block a user