Skip to content

Commit bf4e3a7

Browse files
committed
C#: Merge expr_compiler_generated and compiler_generated and add compiler generated statements.
1 parent 606a8fe commit bf4e3a7

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected sealed override void Populate(TextWriter trapFile)
5454
}
5555

5656
if (info.IsCompilerGenerated)
57-
trapFile.expr_compiler_generated(this);
57+
trapFile.compiler_generated(this);
5858

5959
if (info.ExprValue is string value)
6060
trapFile.expr_value(this, value);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Statement`1.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ internal abstract class Statement<TSyntax> : Statement where TSyntax : CSharpSyn
99
{
1010
protected readonly TSyntax Stmt;
1111
private readonly Location location;
12+
private readonly bool isCompilerGenerated;
1213

1314
protected Statement(Context cx, TSyntax stmt, Kinds.StmtKind kind, IStatementParentEntity parent, int child, Location location, bool isCompilerGenerated = false)
1415
: base(cx, kind, parent, child)
1516
{
1617
Stmt = stmt;
1718
this.location = location;
19+
this.isCompilerGenerated = isCompilerGenerated;
1820
if (!isCompilerGenerated)
1921
{
2022
cx.BindComments(this, location.Symbol);
@@ -29,6 +31,11 @@ protected sealed override void Populate(TextWriter trapFile)
2931
base.Populate(trapFile);
3032

3133
trapFile.stmt_location(this, location);
34+
35+
if (isCompilerGenerated)
36+
{
37+
trapFile.compiler_generated(this);
38+
}
3239
}
3340

3441
public override Microsoft.CodeAnalysis.Location ReportingLocation => Stmt.GetLocation();

csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ internal static void expr_argument_name(this TextWriter trapFile, Expression exp
164164
internal static void expr_call(this TextWriter trapFile, Expression expr, Method target) =>
165165
trapFile.WriteTuple("expr_call", expr, target);
166166

167-
internal static void expr_compiler_generated(this TextWriter trapFile, Expression expr) =>
168-
trapFile.WriteTuple("expr_compiler_generated", expr);
169-
170167
internal static void expr_flowstate(this TextWriter trapFile, Expression expr, int flowState) =>
171168
trapFile.WriteTuple("expr_flowstate", expr, flowState);
172169

csharp/ql/lib/semmle/code/csharp/Stmt.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Stmt extends ControlFlowElement, @stmt {
4343
* For example converts `{ { return x; } }` to `return x;`.
4444
*/
4545
Stmt stripSingletonBlocks() { result = this }
46+
47+
/** Holds if this statement is compiler generated. */
48+
predicate isCompilerGenerated() { compiler_generated(this) }
4649
}
4750

4851
/**

csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Expr extends DotNet::Expr, ControlFlowElement, @expr {
6565
* Holds if this expression is generated by the compiler and does not appear
6666
* explicitly in the source code.
6767
*/
68-
predicate isImplicit() { expr_compiler_generated(this) }
68+
predicate isImplicit() { compiler_generated(this) }
6969

7070
/**
7171
* Gets an expression that is the result of stripping (recursively) all

csharp/ql/lib/semmlecode.csharp.dbscheme

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,6 @@ has_modifiers(
682682
int id: @modifiable_direct ref,
683683
int mod_id: @modifier ref);
684684

685-
compiler_generated(unique int id: @modifiable ref);
686-
687685
/** MEMBERS **/
688686

689687
@member = @method | @constructor | @destructor | @field | @property | @event | @operator | @indexer | @type;
@@ -1271,9 +1269,6 @@ mutator_invocation_mode(
12711269
unique int id: @operator_invocation_expr ref,
12721270
int mode: int ref /* prefix = 1, postfix = 2*/);
12731271

1274-
expr_compiler_generated(
1275-
unique int id: @expr ref);
1276-
12771272
expr_value(
12781273
unique int id: @expr ref,
12791274
string value: string ref);
@@ -1316,6 +1311,10 @@ lambda_expr_return_type(
13161311
unique int id: @lambda_expr ref,
13171312
int type_id: @type_or_ref ref);
13181313

1314+
/* Compiler generated */
1315+
1316+
compiler_generated(unique int id: @element ref);
1317+
13191318
/** CONTROL/DATA FLOW **/
13201319

13211320
@control_flow_element = @stmt | @expr;

0 commit comments

Comments
 (0)