Skip to content

Commit f7752b0

Browse files
committed
C++/C#: add IRParameter subclass of IRVariable
1 parent 45e555c commit f7752b0

File tree

5 files changed

+145
-10
lines changed

5 files changed

+145
-10
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRVariable.qll

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,23 @@ class IRThrowVariable extends IRTempVariable {
217217
* A temporary variable generated to hold the contents of all arguments passed to the `...` of a
218218
* function that accepts a variable number of arguments.
219219
*/
220-
class IREllipsisVariable extends IRTempVariable {
220+
class IREllipsisVariable extends IRTempVariable, IRParameter {
221221
IREllipsisVariable() { tag = EllipsisTempVar() }
222222

223223
final override string toString() { result = "#ellipsis" }
224+
225+
final override int getIndex() { result = func.getNumberOfParameters() }
224226
}
225227

226228
/**
227229
* A temporary variable generated to hold the `this` pointer.
228230
*/
229-
class IRThisVariable extends IRTempVariable {
231+
class IRThisVariable extends IRTempVariable, IRParameter {
230232
IRThisVariable() { tag = ThisTempVar() }
231233

232234
final override string toString() { result = "#this" }
235+
236+
final override int getIndex() { result = -1 }
233237
}
234238

235239
/**
@@ -274,3 +278,26 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
274278

275279
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
276280
}
281+
282+
/**
283+
* An IR variable which acts like a function parameter, including positional parameters and the
284+
* temporary variables generated for `this` and ellipsis parameters.
285+
*/
286+
class IRParameter extends IRAutomaticVariable {
287+
IRParameter() {
288+
this.(IRAutomaticUserVariable).getVariable() instanceof Language::Parameter
289+
or
290+
this = TIRTempVariable(_, _, ThisTempVar(), _)
291+
or
292+
this = TIRTempVariable(_, _, EllipsisTempVar(), _)
293+
}
294+
295+
/**
296+
* Gets the zero-based index of this parameter. The `this` parameter has index -1.
297+
*/
298+
int getIndex() { none() }
299+
}
300+
301+
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
302+
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
303+
}

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRVariable.qll

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,23 @@ class IRThrowVariable extends IRTempVariable {
217217
* A temporary variable generated to hold the contents of all arguments passed to the `...` of a
218218
* function that accepts a variable number of arguments.
219219
*/
220-
class IREllipsisVariable extends IRTempVariable {
220+
class IREllipsisVariable extends IRTempVariable, IRParameter {
221221
IREllipsisVariable() { tag = EllipsisTempVar() }
222222

223223
final override string toString() { result = "#ellipsis" }
224+
225+
final override int getIndex() { result = func.getNumberOfParameters() }
224226
}
225227

226228
/**
227229
* A temporary variable generated to hold the `this` pointer.
228230
*/
229-
class IRThisVariable extends IRTempVariable {
231+
class IRThisVariable extends IRTempVariable, IRParameter {
230232
IRThisVariable() { tag = ThisTempVar() }
231233

232234
final override string toString() { result = "#this" }
235+
236+
final override int getIndex() { result = -1 }
233237
}
234238

235239
/**
@@ -274,3 +278,26 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
274278

275279
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
276280
}
281+
282+
/**
283+
* An IR variable which acts like a function parameter, including positional parameters and the
284+
* temporary variables generated for `this` and ellipsis parameters.
285+
*/
286+
class IRParameter extends IRAutomaticVariable {
287+
IRParameter() {
288+
this.(IRAutomaticUserVariable).getVariable() instanceof Language::Parameter
289+
or
290+
this = TIRTempVariable(_, _, ThisTempVar(), _)
291+
or
292+
this = TIRTempVariable(_, _, EllipsisTempVar(), _)
293+
}
294+
295+
/**
296+
* Gets the zero-based index of this parameter. The `this` parameter has index -1.
297+
*/
298+
int getIndex() { none() }
299+
}
300+
301+
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
302+
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
303+
}

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRVariable.qll

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,23 @@ class IRThrowVariable extends IRTempVariable {
217217
* A temporary variable generated to hold the contents of all arguments passed to the `...` of a
218218
* function that accepts a variable number of arguments.
219219
*/
220-
class IREllipsisVariable extends IRTempVariable {
220+
class IREllipsisVariable extends IRTempVariable, IRParameter {
221221
IREllipsisVariable() { tag = EllipsisTempVar() }
222222

223223
final override string toString() { result = "#ellipsis" }
224+
225+
final override int getIndex() { result = func.getNumberOfParameters() }
224226
}
225227

226228
/**
227229
* A temporary variable generated to hold the `this` pointer.
228230
*/
229-
class IRThisVariable extends IRTempVariable {
231+
class IRThisVariable extends IRTempVariable, IRParameter {
230232
IRThisVariable() { tag = ThisTempVar() }
231233

232234
final override string toString() { result = "#this" }
235+
236+
final override int getIndex() { result = -1 }
233237
}
234238

235239
/**
@@ -274,3 +278,26 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
274278

275279
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
276280
}
281+
282+
/**
283+
* An IR variable which acts like a function parameter, including positional parameters and the
284+
* temporary variables generated for `this` and ellipsis parameters.
285+
*/
286+
class IRParameter extends IRAutomaticVariable {
287+
IRParameter() {
288+
this.(IRAutomaticUserVariable).getVariable() instanceof Language::Parameter
289+
or
290+
this = TIRTempVariable(_, _, ThisTempVar(), _)
291+
or
292+
this = TIRTempVariable(_, _, EllipsisTempVar(), _)
293+
}
294+
295+
/**
296+
* Gets the zero-based index of this parameter. The `this` parameter has index -1.
297+
*/
298+
int getIndex() { none() }
299+
}
300+
301+
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
302+
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
303+
}

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IRVariable.qll

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,23 @@ class IRThrowVariable extends IRTempVariable {
217217
* A temporary variable generated to hold the contents of all arguments passed to the `...` of a
218218
* function that accepts a variable number of arguments.
219219
*/
220-
class IREllipsisVariable extends IRTempVariable {
220+
class IREllipsisVariable extends IRTempVariable, IRParameter {
221221
IREllipsisVariable() { tag = EllipsisTempVar() }
222222

223223
final override string toString() { result = "#ellipsis" }
224+
225+
final override int getIndex() { result = func.getNumberOfParameters() }
224226
}
225227

226228
/**
227229
* A temporary variable generated to hold the `this` pointer.
228230
*/
229-
class IRThisVariable extends IRTempVariable {
231+
class IRThisVariable extends IRTempVariable, IRParameter {
230232
IRThisVariable() { tag = ThisTempVar() }
231233

232234
final override string toString() { result = "#this" }
235+
236+
final override int getIndex() { result = -1 }
233237
}
234238

235239
/**
@@ -274,3 +278,26 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
274278

275279
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
276280
}
281+
282+
/**
283+
* An IR variable which acts like a function parameter, including positional parameters and the
284+
* temporary variables generated for `this` and ellipsis parameters.
285+
*/
286+
class IRParameter extends IRAutomaticVariable {
287+
IRParameter() {
288+
this.(IRAutomaticUserVariable).getVariable() instanceof Language::Parameter
289+
or
290+
this = TIRTempVariable(_, _, ThisTempVar(), _)
291+
or
292+
this = TIRTempVariable(_, _, EllipsisTempVar(), _)
293+
}
294+
295+
/**
296+
* Gets the zero-based index of this parameter. The `this` parameter has index -1.
297+
*/
298+
int getIndex() { none() }
299+
}
300+
301+
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
302+
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
303+
}

csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/IRVariable.qll

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,23 @@ class IRThrowVariable extends IRTempVariable {
217217
* A temporary variable generated to hold the contents of all arguments passed to the `...` of a
218218
* function that accepts a variable number of arguments.
219219
*/
220-
class IREllipsisVariable extends IRTempVariable {
220+
class IREllipsisVariable extends IRTempVariable, IRParameter {
221221
IREllipsisVariable() { tag = EllipsisTempVar() }
222222

223223
final override string toString() { result = "#ellipsis" }
224+
225+
final override int getIndex() { result = func.getNumberOfParameters() }
224226
}
225227

226228
/**
227229
* A temporary variable generated to hold the `this` pointer.
228230
*/
229-
class IRThisVariable extends IRTempVariable {
231+
class IRThisVariable extends IRTempVariable, IRParameter {
230232
IRThisVariable() { tag = ThisTempVar() }
231233

232234
final override string toString() { result = "#this" }
235+
236+
final override int getIndex() { result = -1 }
233237
}
234238

235239
/**
@@ -274,3 +278,26 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
274278

275279
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
276280
}
281+
282+
/**
283+
* An IR variable which acts like a function parameter, including positional parameters and the
284+
* temporary variables generated for `this` and ellipsis parameters.
285+
*/
286+
class IRParameter extends IRAutomaticVariable {
287+
IRParameter() {
288+
this.(IRAutomaticUserVariable).getVariable() instanceof Language::Parameter
289+
or
290+
this = TIRTempVariable(_, _, ThisTempVar(), _)
291+
or
292+
this = TIRTempVariable(_, _, EllipsisTempVar(), _)
293+
}
294+
295+
/**
296+
* Gets the zero-based index of this parameter. The `this` parameter has index -1.
297+
*/
298+
int getIndex() { none() }
299+
}
300+
301+
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
302+
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
303+
}

0 commit comments

Comments
 (0)