Skip to content

Commit a129513

Browse files
committed
C#, C++: Make implicit this receivers explicit
1 parent ffa3028 commit a129513

39 files changed

+310
-281
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/IRType.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class IRType extends TIRType {
3939
* Gets a string that uniquely identifies this `IRType`. This string is often the same as the
4040
* result of `IRType.toString()`, but for some types it may be more verbose to ensure uniqueness.
4141
*/
42-
string getIdentityString() { result = toString() }
42+
string getIdentityString() { result = this.toString() }
4343

4444
/**
4545
* Gets the size of the type, in bytes, if known.
@@ -206,7 +206,7 @@ class IRFloatingPointType extends IRNumericType, TIRFloatingPointType {
206206
IRFloatingPointType() { this = TIRFloatingPointType(_, base, domain) }
207207

208208
final override string toString() {
209-
result = getDomainPrefix() + getBaseString() + byteSize.toString()
209+
result = this.getDomainPrefix() + this.getBaseString() + byteSize.toString()
210210
}
211211

212212
final override Language::LanguageType getCanonicalLanguageType() {

cpp/ql/lib/semmle/code/cpp/ir/implementation/Opcode.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ class Opcode extends TOpcode {
135135
* Holds if the instruction must have an operand with the specified `OperandTag`.
136136
*/
137137
final predicate hasOperand(OperandTag tag) {
138-
hasOperandInternal(tag)
138+
this.hasOperandInternal(tag)
139139
or
140-
hasAddressOperand() and tag instanceof AddressOperandTag
140+
this.hasAddressOperand() and tag instanceof AddressOperandTag
141141
or
142-
hasBufferSizeOperand() and tag instanceof BufferSizeOperandTag
142+
this.hasBufferSizeOperand() and tag instanceof BufferSizeOperandTag
143143
}
144144

145145
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/IRFunction.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class IRFunction extends IRFunctionBase {
4545
* Gets the block containing the entry point of this function.
4646
*/
4747
pragma[noinline]
48-
final IRBlock getEntryBlock() { result.getFirstInstruction() = getEnterFunctionInstruction() }
48+
final IRBlock getEntryBlock() {
49+
result.getFirstInstruction() = this.getEnterFunctionInstruction()
50+
}
4951

5052
/**
5153
* Gets all instructions in this function.

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ class IRVariable extends TIRVariable {
3939
/**
4040
* Gets the type of the variable.
4141
*/
42-
final Language::Type getType() { getLanguageType().hasType(result, false) }
42+
final Language::Type getType() { this.getLanguageType().hasType(result, false) }
4343

4444
/**
4545
* Gets the language-neutral type of the variable.
4646
*/
47-
final IRType getIRType() { result = getLanguageType().getIRType() }
47+
final IRType getIRType() { result = this.getLanguageType().getIRType() }
4848

4949
/**
5050
* Gets the type of the variable.
@@ -58,7 +58,7 @@ class IRVariable extends TIRVariable {
5858
Language::AST getAst() { none() }
5959

6060
/** DEPRECATED: Alias for getAst */
61-
deprecated Language::AST getAST() { result = getAst() }
61+
deprecated Language::AST getAST() { result = this.getAst() }
6262

6363
/**
6464
* Gets an identifier string for the variable. This identifier is unique
@@ -69,7 +69,7 @@ class IRVariable extends TIRVariable {
6969
/**
7070
* Gets the source location of this variable.
7171
*/
72-
final Language::Location getLocation() { result = getAst().getLocation() }
72+
final Language::Location getLocation() { result = this.getAst().getLocation() }
7373

7474
/**
7575
* Gets the IR for the function that references this variable.
@@ -91,15 +91,15 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
9191

9292
IRUserVariable() { this = TIRUserVariable(var, type, func) }
9393

94-
final override string toString() { result = getVariable().toString() }
94+
final override string toString() { result = this.getVariable().toString() }
9595

9696
final override Language::AST getAst() { result = var }
9797

9898
/** DEPRECATED: Alias for getAst */
99-
deprecated override Language::AST getAST() { result = getAst() }
99+
deprecated override Language::AST getAST() { result = this.getAst() }
100100

101101
final override string getUniqueId() {
102-
result = getVariable().toString() + " " + getVariable().getLocation().toString()
102+
result = this.getVariable().toString() + " " + this.getVariable().getLocation().toString()
103103
}
104104

105105
final override Language::LanguageType getLanguageType() { result = type }
@@ -166,9 +166,9 @@ class IRGeneratedVariable extends IRVariable {
166166
final override Language::AST getAst() { result = ast }
167167

168168
/** DEPRECATED: Alias for getAst */
169-
deprecated override Language::AST getAST() { result = getAst() }
169+
deprecated override Language::AST getAST() { result = this.getAst() }
170170

171-
override string toString() { result = getBaseString() + getLocationString() }
171+
override string toString() { result = this.getBaseString() + this.getLocationString() }
172172

173173
override string getUniqueId() { none() }
174174

@@ -272,7 +272,7 @@ class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
272272
final override predicate isReadOnly() { any() }
273273

274274
final override string getUniqueId() {
275-
result = "String: " + getLocationString() + "=" + Language::getStringLiteralText(literal)
275+
result = "String: " + this.getLocationString() + "=" + Language::getStringLiteralText(literal)
276276
}
277277

278278
final override string getBaseString() { result = "#string" }
@@ -303,7 +303,8 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
303303
final Language::Variable getVariable() { result = var }
304304

305305
final override string getUniqueId() {
306-
result = "Init: " + getVariable().toString() + " " + getVariable().getLocation().toString()
306+
result =
307+
"Init: " + this.getVariable().toString() + " " + this.getVariable().getLocation().toString()
307308
}
308309

309310
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
@@ -332,5 +333,5 @@ class IRParameter extends IRAutomaticVariable {
332333
* An IR variable representing a positional parameter.
333334
*/
334335
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
335-
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
336+
final override int getIndex() { result = this.getVariable().(Language::Parameter).getIndex() }
336337
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ abstract private class PrintableIRNode extends TPrintableIRNode {
127127
* Gets the value of the node property with the specified key.
128128
*/
129129
string getProperty(string key) {
130-
key = "semmle.label" and result = getLabel()
130+
key = "semmle.label" and result = this.getLabel()
131131
or
132-
key = "semmle.order" and result = getOrder().toString()
132+
key = "semmle.order" and result = this.getOrder().toString()
133133
or
134-
key = "semmle.graphKind" and result = getGraphKind()
134+
key = "semmle.graphKind" and result = this.getGraphKind()
135135
or
136-
key = "semmle.forceText" and forceText() and result = "true"
136+
key = "semmle.forceText" and this.forceText() and result = "true"
137137
}
138138
}
139139

@@ -178,7 +178,7 @@ private class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
178178

179179
PrintableIRBlock() { this = TPrintableIRBlock(block) }
180180

181-
override string toString() { result = getLabel() }
181+
override string toString() { result = this.getLabel() }
182182

183183
override Language::Location getLocation() { result = block.getLocation() }
184184

@@ -223,7 +223,7 @@ private class PrintableInstruction extends PrintableIRNode, TPrintableInstructio
223223
|
224224
resultString = instr.getResultString() and
225225
operationString = instr.getOperationString() and
226-
operandsString = getOperandsString() and
226+
operandsString = this.getOperandsString() and
227227
columnWidths(block, resultWidth, operationWidth) and
228228
result =
229229
resultString + getPaddingString(resultWidth - resultString.length()) + " = " +

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/ValueNumbering.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ private import internal.ValueNumberingImports
77
class ValueNumber extends TValueNumber {
88
final string toString() { result = "GVN" }
99

10-
final string getDebugString() { result = strictconcat(getAnInstruction().getResultId(), ", ") }
10+
final string getDebugString() {
11+
result = strictconcat(this.getAnInstruction().getResultId(), ", ")
12+
}
1113

1214
final Language::Location getLocation() {
1315
if
1416
exists(Instruction i |
15-
i = getAnInstruction() and not i.getLocation() instanceof Language::UnknownLocation
17+
i = this.getAnInstruction() and not i.getLocation() instanceof Language::UnknownLocation
1618
)
1719
then
1820
result =
1921
min(Language::Location l |
20-
l = getAnInstruction().getLocation() and not l instanceof Language::UnknownLocation
22+
l = this.getAnInstruction().getLocation() and not l instanceof Language::UnknownLocation
2123
|
2224
l
2325
order by
@@ -40,7 +42,7 @@ class ValueNumber extends TValueNumber {
4042
final Instruction getExampleInstruction() {
4143
result =
4244
min(Instruction instr |
43-
instr = getAnInstruction()
45+
instr = this.getAnInstruction()
4446
|
4547
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
4648
)

cpp/ql/lib/semmle/code/cpp/ir/implementation/internal/OperandTag.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ abstract class OperandTag extends TOperandTag {
4040
/**
4141
* Gets a label that will appear before the operand when the IR is printed.
4242
*/
43-
final string getLabel() { if alwaysPrintLabel() then result = getId() + ":" else result = "" }
43+
final string getLabel() {
44+
if this.alwaysPrintLabel() then result = this.getId() + ":" else result = ""
45+
}
4446

4547
/**
4648
* Gets an identifier that uniquely identifies this operand within its instruction.

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/IRFunction.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class IRFunction extends IRFunctionBase {
4545
* Gets the block containing the entry point of this function.
4646
*/
4747
pragma[noinline]
48-
final IRBlock getEntryBlock() { result.getFirstInstruction() = getEnterFunctionInstruction() }
48+
final IRBlock getEntryBlock() {
49+
result.getFirstInstruction() = this.getEnterFunctionInstruction()
50+
}
4951

5052
/**
5153
* Gets all instructions in this function.

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ class IRVariable extends TIRVariable {
3939
/**
4040
* Gets the type of the variable.
4141
*/
42-
final Language::Type getType() { getLanguageType().hasType(result, false) }
42+
final Language::Type getType() { this.getLanguageType().hasType(result, false) }
4343

4444
/**
4545
* Gets the language-neutral type of the variable.
4646
*/
47-
final IRType getIRType() { result = getLanguageType().getIRType() }
47+
final IRType getIRType() { result = this.getLanguageType().getIRType() }
4848

4949
/**
5050
* Gets the type of the variable.
@@ -58,7 +58,7 @@ class IRVariable extends TIRVariable {
5858
Language::AST getAst() { none() }
5959

6060
/** DEPRECATED: Alias for getAst */
61-
deprecated Language::AST getAST() { result = getAst() }
61+
deprecated Language::AST getAST() { result = this.getAst() }
6262

6363
/**
6464
* Gets an identifier string for the variable. This identifier is unique
@@ -69,7 +69,7 @@ class IRVariable extends TIRVariable {
6969
/**
7070
* Gets the source location of this variable.
7171
*/
72-
final Language::Location getLocation() { result = getAst().getLocation() }
72+
final Language::Location getLocation() { result = this.getAst().getLocation() }
7373

7474
/**
7575
* Gets the IR for the function that references this variable.
@@ -91,15 +91,15 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
9191

9292
IRUserVariable() { this = TIRUserVariable(var, type, func) }
9393

94-
final override string toString() { result = getVariable().toString() }
94+
final override string toString() { result = this.getVariable().toString() }
9595

9696
final override Language::AST getAst() { result = var }
9797

9898
/** DEPRECATED: Alias for getAst */
99-
deprecated override Language::AST getAST() { result = getAst() }
99+
deprecated override Language::AST getAST() { result = this.getAst() }
100100

101101
final override string getUniqueId() {
102-
result = getVariable().toString() + " " + getVariable().getLocation().toString()
102+
result = this.getVariable().toString() + " " + this.getVariable().getLocation().toString()
103103
}
104104

105105
final override Language::LanguageType getLanguageType() { result = type }
@@ -166,9 +166,9 @@ class IRGeneratedVariable extends IRVariable {
166166
final override Language::AST getAst() { result = ast }
167167

168168
/** DEPRECATED: Alias for getAst */
169-
deprecated override Language::AST getAST() { result = getAst() }
169+
deprecated override Language::AST getAST() { result = this.getAst() }
170170

171-
override string toString() { result = getBaseString() + getLocationString() }
171+
override string toString() { result = this.getBaseString() + this.getLocationString() }
172172

173173
override string getUniqueId() { none() }
174174

@@ -272,7 +272,7 @@ class IRStringLiteral extends IRGeneratedVariable, TIRStringLiteral {
272272
final override predicate isReadOnly() { any() }
273273

274274
final override string getUniqueId() {
275-
result = "String: " + getLocationString() + "=" + Language::getStringLiteralText(literal)
275+
result = "String: " + this.getLocationString() + "=" + Language::getStringLiteralText(literal)
276276
}
277277

278278
final override string getBaseString() { result = "#string" }
@@ -303,7 +303,8 @@ class IRDynamicInitializationFlag extends IRGeneratedVariable, TIRDynamicInitial
303303
final Language::Variable getVariable() { result = var }
304304

305305
final override string getUniqueId() {
306-
result = "Init: " + getVariable().toString() + " " + getVariable().getLocation().toString()
306+
result =
307+
"Init: " + this.getVariable().toString() + " " + this.getVariable().getLocation().toString()
307308
}
308309

309310
final override string getBaseString() { result = "#init:" + var.toString() + ":" }
@@ -332,5 +333,5 @@ class IRParameter extends IRAutomaticVariable {
332333
* An IR variable representing a positional parameter.
333334
*/
334335
class IRPositionalParameter extends IRParameter, IRAutomaticUserVariable {
335-
final override int getIndex() { result = getVariable().(Language::Parameter).getIndex() }
336+
final override int getIndex() { result = this.getVariable().(Language::Parameter).getIndex() }
336337
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ abstract private class PrintableIRNode extends TPrintableIRNode {
127127
* Gets the value of the node property with the specified key.
128128
*/
129129
string getProperty(string key) {
130-
key = "semmle.label" and result = getLabel()
130+
key = "semmle.label" and result = this.getLabel()
131131
or
132-
key = "semmle.order" and result = getOrder().toString()
132+
key = "semmle.order" and result = this.getOrder().toString()
133133
or
134-
key = "semmle.graphKind" and result = getGraphKind()
134+
key = "semmle.graphKind" and result = this.getGraphKind()
135135
or
136-
key = "semmle.forceText" and forceText() and result = "true"
136+
key = "semmle.forceText" and this.forceText() and result = "true"
137137
}
138138
}
139139

@@ -178,7 +178,7 @@ private class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
178178

179179
PrintableIRBlock() { this = TPrintableIRBlock(block) }
180180

181-
override string toString() { result = getLabel() }
181+
override string toString() { result = this.getLabel() }
182182

183183
override Language::Location getLocation() { result = block.getLocation() }
184184

@@ -223,7 +223,7 @@ private class PrintableInstruction extends PrintableIRNode, TPrintableInstructio
223223
|
224224
resultString = instr.getResultString() and
225225
operationString = instr.getOperationString() and
226-
operandsString = getOperandsString() and
226+
operandsString = this.getOperandsString() and
227227
columnWidths(block, resultWidth, operationWidth) and
228228
result =
229229
resultString + getPaddingString(resultWidth - resultString.length()) + " = " +

0 commit comments

Comments
 (0)