Skip to content

Commit dde054d

Browse files
authored
Merge pull request github#357 from github/erik-krogh/fix-implicit-this
Add explicit `this` qualifiers
2 parents 236643f + 3dc09a3 commit dde054d

22 files changed

+86
-80
lines changed

ql/lib/codeql/Locations.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class Location extends @location {
2525
int getEndColumn() { locations_default(this, _, _, _, _, result) }
2626

2727
/** Gets the number of lines covered by this location. */
28-
int getNumLines() { result = getEndLine() - getStartLine() + 1 }
28+
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
2929

3030
/** Gets a textual representation of this element. */
3131
string toString() {
3232
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
33-
hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
33+
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
3434
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
3535
)
3636
}

ql/lib/codeql/files/FileSystem.qll

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ abstract class Container extends @container {
88
Container getAChildContainer() { this = result.getParentContainer() }
99

1010
/** Gets a file in this container. */
11-
File getAFile() { result = getAChildContainer() }
11+
File getAFile() { result = this.getAChildContainer() }
1212

1313
/** Gets a sub-folder in this container. */
14-
Folder getAFolder() { result = getAChildContainer() }
14+
Folder getAFolder() { result = this.getAChildContainer() }
1515

1616
/**
1717
* Gets the absolute, canonical path of this container, using forward slashes
@@ -57,7 +57,7 @@ abstract class Container extends @container {
5757
* </table>
5858
*/
5959
string getBaseName() {
60-
result = getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
60+
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
6161
}
6262

6363
/**
@@ -83,17 +83,19 @@ abstract class Container extends @container {
8383
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
8484
* </table>
8585
*/
86-
string getExtension() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3) }
86+
string getExtension() {
87+
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3)
88+
}
8789

8890
/** Gets the file in this container that has the given `baseName`, if any. */
8991
File getFile(string baseName) {
90-
result = getAFile() and
92+
result = this.getAFile() and
9193
result.getBaseName() = baseName
9294
}
9395

9496
/** Gets the sub-folder in this container that has the given `baseName`, if any. */
9597
Folder getFolder(string baseName) {
96-
result = getAFolder() and
98+
result = this.getAFolder() and
9799
result.getBaseName() = baseName
98100
}
99101

@@ -110,7 +112,7 @@ abstract class Container extends @container {
110112
*/
111113
string getRelativePath() {
112114
exists(string absPath, string pref |
113-
absPath = getAbsolutePath() and sourceLocationPrefix(pref)
115+
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
114116
|
115117
absPath = pref and result = ""
116118
or
@@ -136,7 +138,9 @@ abstract class Container extends @container {
136138
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
137139
* </table>
138140
*/
139-
string getStem() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1) }
141+
string getStem() {
142+
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1)
143+
}
140144

141145
/**
142146
* Gets a URL representing the location of this container.
@@ -150,15 +154,15 @@ abstract class Container extends @container {
150154
*
151155
* This is the absolute path of the container.
152156
*/
153-
string toString() { result = getAbsolutePath() }
157+
string toString() { result = this.getAbsolutePath() }
154158
}
155159

156160
/** A folder. */
157161
class Folder extends Container, @folder {
158162
override string getAbsolutePath() { folders(this, result) }
159163

160164
/** Gets the URL of this folder. */
161-
override string getURL() { result = "folder://" + getAbsolutePath() }
165+
override string getURL() { result = "folder://" + this.getAbsolutePath() }
162166
}
163167

164168
/** A file. */

ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module API {
4747
* Gets a call to a method on the receiver represented by this API component.
4848
*/
4949
DataFlow::CallNode getAMethodCall(string method) {
50-
result = getReturn(method).getAnImmediateUse()
50+
result = this.getReturn(method).getAnImmediateUse()
5151
}
5252

5353
/**
@@ -60,21 +60,21 @@ module API {
6060
*/
6161
bindingset[m]
6262
bindingset[result]
63-
Node getMember(string m) { result = getASuccessor(Label::member(m)) }
63+
Node getMember(string m) { result = this.getASuccessor(Label::member(m)) }
6464

6565
/**
6666
* Gets a node representing a member of this API component where the name of the member is
6767
* not known statically.
6868
*/
69-
Node getUnknownMember() { result = getASuccessor(Label::unknownMember()) }
69+
Node getUnknownMember() { result = this.getASuccessor(Label::unknownMember()) }
7070

7171
/**
7272
* Gets a node representing a member of this API component where the name of the member may
7373
* or may not be known statically.
7474
*/
7575
Node getAMember() {
76-
result = getASuccessor(Label::member(_)) or
77-
result = getUnknownMember()
76+
result = this.getASuccessor(Label::member(_)) or
77+
result = this.getUnknownMember()
7878
}
7979

8080
/**
@@ -88,28 +88,30 @@ module API {
8888
* This predicate may have multiple results when there are multiple constructor calls invoking this API component.
8989
* Consider using `getAnInstantiation()` if there is a need to distinguish between individual constructor calls.
9090
*/
91-
Node getInstance() { result = getASuccessor(Label::instance()) }
91+
Node getInstance() { result = this.getASuccessor(Label::instance()) }
9292

9393
/**
9494
* Gets a node representing the result of calling a method on the receiver represented by this node.
9595
*/
96-
Node getReturn(string method) { result = getASuccessor(Label::return(method)) }
96+
Node getReturn(string method) { result = this.getASuccessor(Label::return(method)) }
9797

9898
/**
9999
* Gets a `new` call to the function represented by this API component.
100100
*/
101-
DataFlow::Node getAnInstantiation() { result = getInstance().getAnImmediateUse() }
101+
DataFlow::Node getAnInstantiation() { result = this.getInstance().getAnImmediateUse() }
102102

103103
/**
104104
* Gets a node representing a subclass of the class represented by this node.
105105
*/
106-
Node getASubclass() { result = getASuccessor(Label::subclass()) }
106+
Node getASubclass() { result = this.getASuccessor(Label::subclass()) }
107107

108108
/**
109109
* Gets a string representation of the lexicographically least among all shortest access paths
110110
* from the root to this node.
111111
*/
112-
string getPath() { result = min(string p | p = getAPath(Impl::distanceFromRoot(this)) | p) }
112+
string getPath() {
113+
result = min(string p | p = this.getAPath(Impl::distanceFromRoot(this)) | p)
114+
}
113115

114116
/**
115117
* Gets a node such that there is an edge in the API graph between this node and the other
@@ -127,13 +129,13 @@ module API {
127129
* Gets a node such that there is an edge in the API graph between this node and the other
128130
* one.
129131
*/
130-
Node getAPredecessor() { result = getAPredecessor(_) }
132+
Node getAPredecessor() { result = this.getAPredecessor(_) }
131133

132134
/**
133135
* Gets a node such that there is an edge in the API graph between that other node and
134136
* this one.
135137
*/
136-
Node getASuccessor() { result = getASuccessor(_) }
138+
Node getASuccessor() { result = this.getASuccessor(_) }
137139

138140
/**
139141
* Gets the data-flow node that gives rise to this node, if any.
@@ -146,7 +148,7 @@ module API {
146148
or
147149
// For nodes that do not have a meaningful location, `path` is the empty string and all other
148150
// parameters are zero.
149-
not exists(getInducingNode()) and
151+
not exists(this.getInducingNode()) and
150152
result instanceof EmptyLocation
151153
}
152154

@@ -189,7 +191,7 @@ module API {
189191
class Use extends Node, Impl::MkUse {
190192
override string toString() {
191193
exists(string type | type = "Use " |
192-
result = type + getPath()
194+
result = type + this.getPath()
193195
or
194196
not exists(this.getPath()) and result = type + "with no path"
195197
)

ql/lib/codeql/ruby/ast/Control.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class UnlessExpr extends ConditionalExpr, TUnlessExpr {
184184
final Stmt getElse() { toGenerated(result) = g.getAlternative() }
185185

186186
final override Expr getBranch(boolean cond) {
187-
cond = false and result = getThen()
187+
cond = false and result = this.getThen()
188188
or
189-
cond = true and result = getElse()
189+
cond = true and result = this.getElse()
190190
}
191191

192192
final override string toString() { result = "unless ..." }
@@ -292,9 +292,9 @@ class TernaryIfExpr extends ConditionalExpr, TTernaryIfExpr {
292292
final Stmt getElse() { toGenerated(result) = g.getAlternative() }
293293

294294
final override Stmt getBranch(boolean cond) {
295-
cond = true and result = getThen()
295+
cond = true and result = this.getThen()
296296
or
297-
cond = false and result = getElse()
297+
cond = false and result = this.getElse()
298298
}
299299

300300
final override string toString() { result = "... ? ... : ..." }
@@ -349,10 +349,10 @@ class CaseExpr extends ControlExpr, TCaseExpr {
349349
final Expr getABranch() { result = this.getBranch(_) }
350350

351351
/** Gets a `when` branch of this case expression. */
352-
final WhenExpr getAWhenBranch() { result = getABranch() }
352+
final WhenExpr getAWhenBranch() { result = this.getABranch() }
353353

354354
/** Gets the `else` branch of this case expression, if any. */
355-
final StmtSequence getElseBranch() { result = getABranch() }
355+
final StmtSequence getElseBranch() { result = this.getABranch() }
356356

357357
/**
358358
* Gets the number of branches of this case expression.

ql/lib/codeql/ruby/ast/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class BodyStmt extends StmtSequence, TBodyStmt {
183183
/** Gets the `n`th rescue clause in this block. */
184184
final RescueClause getRescue(int n) {
185185
result =
186-
rank[n + 1](RescueClause node, int i | toGenerated(node) = getChild(i) | node order by i)
186+
rank[n + 1](RescueClause node, int i | toGenerated(node) = this.getChild(i) | node order by i)
187187
}
188188

189189
/** Gets a rescue clause in this block. */

ql/lib/codeql/ruby/ast/Literal.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class HereDoc extends StringlikeLiteral, THereDoc {
631631
* COMMAND
632632
* ```
633633
*/
634-
final predicate isSubShell() { getQuoteStyle() = "`" }
634+
final predicate isSubShell() { this.getQuoteStyle() = "`" }
635635

636636
/**
637637
* Gets the quotation mark (`"`, `'` or `` ` ``) that surrounds the here document identifier, if any.

ql/lib/codeql/ruby/ast/Module.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Toplevel extends ModuleBase, TToplevel {
125125
/**
126126
* Gets a `BEGIN` block.
127127
*/
128-
final BeginBlock getABeginBlock() { result = getBeginBlock(_) }
128+
final BeginBlock getABeginBlock() { result = this.getBeginBlock(_) }
129129

130130
final override AstNode getAChild(string pred) {
131131
result = super.getAChild(pred)

ql/lib/codeql/ruby/ast/Operation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ class Assignment extends Operation instanceof AssignmentImpl {
453453
override AstNode getAChild(string pred) {
454454
result = Operation.super.getAChild(pred)
455455
or
456-
pred = "getLeftOperand" and result = getLeftOperand()
456+
pred = "getLeftOperand" and result = this.getLeftOperand()
457457
or
458-
pred = "getRightOperand" and result = getRightOperand()
458+
pred = "getRightOperand" and result = this.getRightOperand()
459459
}
460460
}
461461

ql/lib/codeql/ruby/ast/Pattern.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ class TuplePattern extends Pattern, TTuplePattern {
9292

9393
override string toString() { result = "(..., ...)" }
9494

95-
override AstNode getAChild(string pred) { pred = "getElement" and result = getElement(_) }
95+
override AstNode getAChild(string pred) { pred = "getElement" and result = this.getElement(_) }
9696
}

ql/lib/codeql/ruby/ast/Statement.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class UndefStmt extends Stmt, TUndefStmt {
9797
final MethodName getMethodName(int n) { toGenerated(result) = g.getChild(n) }
9898

9999
/** Gets a method name to undefine. */
100-
final MethodName getAMethodName() { result = getMethodName(_) }
100+
final MethodName getAMethodName() { result = this.getMethodName(_) }
101101

102102
final override string getAPrimaryQlClass() { result = "UndefStmt" }
103103

0 commit comments

Comments
 (0)