Skip to content

Commit ead2a14

Browse files
author
Dave Bartolomeo
committed
C++: QLDoc for IRVariable
Moved a couple of predicates that were only needed by IR construction into `TranslatedElement.qll`
1 parent 1423ea0 commit ead2a14

File tree

7 files changed

+150
-65
lines changed

7 files changed

+150
-65
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ private import Imports::TTempVariableTag
77
private import Imports::TIRVariable
88
private import Imports::IRType
99

10-
IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var) {
11-
result.getVariable() = var and
12-
result.getEnclosingFunction() = func
13-
}
14-
1510
/**
16-
* A variable referenced by the IR for a function. The variable may be a user-declared variable
17-
* (`IRUserVariable`) or a temporary variable generated by the AST-to-IR translation
18-
* (`IRTempVariable`).
11+
* A variable referenced by the IR for a function.
12+
*
13+
* The variable may be a user-declared variable (`IRUserVariable`) or a temporary variable generated
14+
* by the AST-to-IR translation (`IRTempVariable`).
1915
*/
2016
class IRVariable extends TIRVariable {
2117
Language::Function func;
@@ -27,6 +23,7 @@ class IRVariable extends TIRVariable {
2723
this = TIRDynamicInitializationFlag(func, _, _)
2824
}
2925

26+
/** Gets a textual representation of this element. */
3027
string toString() { none() }
3128

3229
/**
@@ -162,20 +159,26 @@ class IRGeneratedVariable extends IRVariable {
162159

163160
override string getUniqueId() { none() }
164161

162+
/**
163+
* Gets a string containing the source code location of the AST that generated this variable.
164+
*
165+
* This is used by debugging and printing code only.
166+
*/
165167
final string getLocationString() {
166168
result =
167169
ast.getLocation().getStartLine().toString() + ":" +
168170
ast.getLocation().getStartColumn().toString()
169171
}
170172

173+
/**
174+
* Gets the string that is combined with the location of the variable to generate the string
175+
* representation of this variable.
176+
*
177+
* This is used by debugging and printing code only.
178+
*/
171179
string getBaseString() { none() }
172180
}
173181

174-
IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
175-
result.getAST() = ast and
176-
result.getTag() = tag
177-
}
178-
179182
/**
180183
* A temporary variable introduced by IR construction. The most common examples are the variable
181184
* generated to hold the return value of a function, or the variable generated to hold the result of
@@ -190,6 +193,10 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
190193
result = "Temp: " + Construction::getTempVariableUniqueId(this)
191194
}
192195

196+
/**
197+
* Gets the "tag" object that differentiates this temporary variable from other temporary
198+
* variables generated for the same AST.
199+
*/
193200
final TempVariableTag getTag() { result = tag }
194201

195202
override string getBaseString() { result = "#temp" }
@@ -253,6 +260,9 @@ class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
253260

254261
final override string getBaseString() { result = "#string" }
255262

263+
/**
264+
* Gets the AST of the string literal represented by this `IRStringLiteral`.
265+
*/
256266
final Language::StringLiteral getLiteral() { result = literal }
257267
}
258268

@@ -270,6 +280,9 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
270280

271281
final override string toString() { result = var.toString() + "#init" }
272282

283+
/**
284+
* Gets variable whose initialization is guarded by this flag.
285+
*/
273286
final Language::Variable getVariable() { result = var }
274287

275288
final override string getUniqueId() {

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ private import Imports::TTempVariableTag
77
private import Imports::TIRVariable
88
private import Imports::IRType
99

10-
IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var) {
11-
result.getVariable() = var and
12-
result.getEnclosingFunction() = func
13-
}
14-
1510
/**
16-
* A variable referenced by the IR for a function. The variable may be a user-declared variable
17-
* (`IRUserVariable`) or a temporary variable generated by the AST-to-IR translation
18-
* (`IRTempVariable`).
11+
* A variable referenced by the IR for a function.
12+
*
13+
* The variable may be a user-declared variable (`IRUserVariable`) or a temporary variable generated
14+
* by the AST-to-IR translation (`IRTempVariable`).
1915
*/
2016
class IRVariable extends TIRVariable {
2117
Language::Function func;
@@ -27,6 +23,7 @@ class IRVariable extends TIRVariable {
2723
this = TIRDynamicInitializationFlag(func, _, _)
2824
}
2925

26+
/** Gets a textual representation of this element. */
3027
string toString() { none() }
3128

3229
/**
@@ -162,20 +159,26 @@ class IRGeneratedVariable extends IRVariable {
162159

163160
override string getUniqueId() { none() }
164161

162+
/**
163+
* Gets a string containing the source code location of the AST that generated this variable.
164+
*
165+
* This is used by debugging and printing code only.
166+
*/
165167
final string getLocationString() {
166168
result =
167169
ast.getLocation().getStartLine().toString() + ":" +
168170
ast.getLocation().getStartColumn().toString()
169171
}
170172

173+
/**
174+
* Gets the string that is combined with the location of the variable to generate the string
175+
* representation of this variable.
176+
*
177+
* This is used by debugging and printing code only.
178+
*/
171179
string getBaseString() { none() }
172180
}
173181

174-
IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
175-
result.getAST() = ast and
176-
result.getTag() = tag
177-
}
178-
179182
/**
180183
* A temporary variable introduced by IR construction. The most common examples are the variable
181184
* generated to hold the return value of a function, or the variable generated to hold the result of
@@ -190,6 +193,10 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
190193
result = "Temp: " + Construction::getTempVariableUniqueId(this)
191194
}
192195

196+
/**
197+
* Gets the "tag" object that differentiates this temporary variable from other temporary
198+
* variables generated for the same AST.
199+
*/
193200
final TempVariableTag getTag() { result = tag }
194201

195202
override string getBaseString() { result = "#temp" }
@@ -253,6 +260,9 @@ class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
253260

254261
final override string getBaseString() { result = "#string" }
255262

263+
/**
264+
* Gets the AST of the string literal represented by this `IRStringLiteral`.
265+
*/
256266
final Language::StringLiteral getLiteral() { result = literal }
257267
}
258268

@@ -270,6 +280,9 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
270280

271281
final override string toString() { result = var.toString() + "#init" }
272282

283+
/**
284+
* Gets variable whose initialization is guarded by this flag.
285+
*/
273286
final Language::Variable getVariable() { result = var }
274287

275288
final override string getUniqueId() {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ private Element getRealParent(Expr expr) {
2424
result.(Destructor).getADestruction() = expr
2525
}
2626

27+
IRUserVariable getIRUserVariable(Function func, Variable var) {
28+
result.getVariable() = var and
29+
result.getEnclosingFunction() = func
30+
}
31+
32+
IRTempVariable getIRTempVariable(Locatable ast, TempVariableTag tag) {
33+
result.getAST() = ast and
34+
result.getTag() = tag
35+
}
36+
2737
/**
2838
* Holds if `expr` is a constant of a type that can be replaced directly with
2939
* its value in the IR. This does not include address constants as we have no

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ private import Imports::TTempVariableTag
77
private import Imports::TIRVariable
88
private import Imports::IRType
99

10-
IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var) {
11-
result.getVariable() = var and
12-
result.getEnclosingFunction() = func
13-
}
14-
1510
/**
16-
* A variable referenced by the IR for a function. The variable may be a user-declared variable
17-
* (`IRUserVariable`) or a temporary variable generated by the AST-to-IR translation
18-
* (`IRTempVariable`).
11+
* A variable referenced by the IR for a function.
12+
*
13+
* The variable may be a user-declared variable (`IRUserVariable`) or a temporary variable generated
14+
* by the AST-to-IR translation (`IRTempVariable`).
1915
*/
2016
class IRVariable extends TIRVariable {
2117
Language::Function func;
@@ -27,6 +23,7 @@ class IRVariable extends TIRVariable {
2723
this = TIRDynamicInitializationFlag(func, _, _)
2824
}
2925

26+
/** Gets a textual representation of this element. */
3027
string toString() { none() }
3128

3229
/**
@@ -162,20 +159,26 @@ class IRGeneratedVariable extends IRVariable {
162159

163160
override string getUniqueId() { none() }
164161

162+
/**
163+
* Gets a string containing the source code location of the AST that generated this variable.
164+
*
165+
* This is used by debugging and printing code only.
166+
*/
165167
final string getLocationString() {
166168
result =
167169
ast.getLocation().getStartLine().toString() + ":" +
168170
ast.getLocation().getStartColumn().toString()
169171
}
170172

173+
/**
174+
* Gets the string that is combined with the location of the variable to generate the string
175+
* representation of this variable.
176+
*
177+
* This is used by debugging and printing code only.
178+
*/
171179
string getBaseString() { none() }
172180
}
173181

174-
IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
175-
result.getAST() = ast and
176-
result.getTag() = tag
177-
}
178-
179182
/**
180183
* A temporary variable introduced by IR construction. The most common examples are the variable
181184
* generated to hold the return value of a function, or the variable generated to hold the result of
@@ -190,6 +193,10 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
190193
result = "Temp: " + Construction::getTempVariableUniqueId(this)
191194
}
192195

196+
/**
197+
* Gets the "tag" object that differentiates this temporary variable from other temporary
198+
* variables generated for the same AST.
199+
*/
193200
final TempVariableTag getTag() { result = tag }
194201

195202
override string getBaseString() { result = "#temp" }
@@ -253,6 +260,9 @@ class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
253260

254261
final override string getBaseString() { result = "#string" }
255262

263+
/**
264+
* Gets the AST of the string literal represented by this `IRStringLiteral`.
265+
*/
256266
final Language::StringLiteral getLiteral() { result = literal }
257267
}
258268

@@ -270,6 +280,9 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
270280

271281
final override string toString() { result = var.toString() + "#init" }
272282

283+
/**
284+
* Gets variable whose initialization is guarded by this flag.
285+
*/
273286
final Language::Variable getVariable() { result = var }
274287

275288
final override string getUniqueId() {

csharp/ql/src/experimental/ir/implementation/raw/IRVariable.qll

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ private import Imports::TTempVariableTag
77
private import Imports::TIRVariable
88
private import Imports::IRType
99

10-
IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var) {
11-
result.getVariable() = var and
12-
result.getEnclosingFunction() = func
13-
}
14-
1510
/**
16-
* A variable referenced by the IR for a function. The variable may be a user-declared variable
17-
* (`IRUserVariable`) or a temporary variable generated by the AST-to-IR translation
18-
* (`IRTempVariable`).
11+
* A variable referenced by the IR for a function.
12+
*
13+
* The variable may be a user-declared variable (`IRUserVariable`) or a temporary variable generated
14+
* by the AST-to-IR translation (`IRTempVariable`).
1915
*/
2016
class IRVariable extends TIRVariable {
2117
Language::Function func;
@@ -27,6 +23,7 @@ class IRVariable extends TIRVariable {
2723
this = TIRDynamicInitializationFlag(func, _, _)
2824
}
2925

26+
/** Gets a textual representation of this element. */
3027
string toString() { none() }
3128

3229
/**
@@ -162,20 +159,26 @@ class IRGeneratedVariable extends IRVariable {
162159

163160
override string getUniqueId() { none() }
164161

162+
/**
163+
* Gets a string containing the source code location of the AST that generated this variable.
164+
*
165+
* This is used by debugging and printing code only.
166+
*/
165167
final string getLocationString() {
166168
result =
167169
ast.getLocation().getStartLine().toString() + ":" +
168170
ast.getLocation().getStartColumn().toString()
169171
}
170172

173+
/**
174+
* Gets the string that is combined with the location of the variable to generate the string
175+
* representation of this variable.
176+
*
177+
* This is used by debugging and printing code only.
178+
*/
171179
string getBaseString() { none() }
172180
}
173181

174-
IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
175-
result.getAST() = ast and
176-
result.getTag() = tag
177-
}
178-
179182
/**
180183
* A temporary variable introduced by IR construction. The most common examples are the variable
181184
* generated to hold the return value of a function, or the variable generated to hold the result of
@@ -190,6 +193,10 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
190193
result = "Temp: " + Construction::getTempVariableUniqueId(this)
191194
}
192195

196+
/**
197+
* Gets the "tag" object that differentiates this temporary variable from other temporary
198+
* variables generated for the same AST.
199+
*/
193200
final TempVariableTag getTag() { result = tag }
194201

195202
override string getBaseString() { result = "#temp" }
@@ -253,6 +260,9 @@ class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
253260

254261
final override string getBaseString() { result = "#string" }
255262

263+
/**
264+
* Gets the AST of the string literal represented by this `IRStringLiteral`.
265+
*/
256266
final Language::StringLiteral getLiteral() { result = literal }
257267
}
258268

@@ -270,6 +280,9 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
270280

271281
final override string toString() { result = var.toString() + "#init" }
272282

283+
/**
284+
* Gets variable whose initialization is guarded by this flag.
285+
*/
273286
final Language::Variable getVariable() { result = var }
274287

275288
final override string getUniqueId() {

csharp/ql/src/experimental/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ ArrayType getArrayOfDim(int dim, Type type) {
2121
result.getElementType() = type
2222
}
2323

24+
IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var) {
25+
result.getVariable() = var and
26+
result.getEnclosingFunction() = func
27+
}
28+
29+
IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
30+
result.getAST() = ast and
31+
result.getTag() = tag
32+
}
33+
2434
private predicate canCreateCompilerGeneratedElement(Element generatedBy, int nth) {
2535
generatedBy instanceof ForeachStmt and nth in [0 .. ForeachElements::noGeneratedElements() - 1]
2636
or

0 commit comments

Comments
 (0)