Skip to content

Commit e969018

Browse files
committed
Go: Make implicit this receivers explicit
1 parent e9c2594 commit e969018

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+302
-284
lines changed

go/ql/lib/printAst.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ external string selectedSourceFile();
2020
* A hook to customize the functions printed by this query.
2121
*/
2222
class Cfg extends PrintAstConfiguration {
23-
override predicate shouldPrintFunction(FuncDecl func) { shouldPrintFile(func.getFile()) }
23+
override predicate shouldPrintFunction(FuncDecl func) { this.shouldPrintFile(func.getFile()) }
2424

2525
override predicate shouldPrintFile(File file) {
2626
file = getFileBySourceArchiveName(selectedSourceFile())

go/ql/lib/semmle/go/Errors.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Error extends @error {
1919
int getIndex() { errors(this, _, _, _, _, _, _, _, result) }
2020

2121
/** Gets the file in which this error was reported, if it can be determined. */
22-
ExtractedOrExternalFile getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
22+
ExtractedOrExternalFile getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
2323

2424
/**
2525
* Holds if this element is at the specified location.
@@ -37,7 +37,7 @@ class Error extends @error {
3737
}
3838

3939
/** Gets a textual representation of this error. */
40-
string toString() { result = getMessage() }
40+
string toString() { result = this.getMessage() }
4141
}
4242

4343
/** An error reported by an unknown part of the Go frontend. */

go/ql/lib/semmle/go/HTML.qll

+14-12
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ module HTML {
3232
/**
3333
* Holds if this is a toplevel element, that is, if it does not have a parent element.
3434
*/
35-
predicate isTopLevel() { not exists(getParent()) }
35+
predicate isTopLevel() { not exists(this.getParent()) }
3636

3737
/**
3838
* Gets the root HTML document element in which this element is contained.
3939
*/
40-
DocumentElement getDocument() { result = getRoot() }
40+
DocumentElement getDocument() { result = this.getRoot() }
4141

4242
/**
4343
* Gets the root element in which this element is contained.
4444
*/
45-
Element getRoot() { if isTopLevel() then result = this else result = getParent().getRoot() }
45+
Element getRoot() {
46+
if this.isTopLevel() then result = this else result = this.getParent().getRoot()
47+
}
4648

4749
/**
4850
* Gets the `i`th child element (0-based) of this element.
@@ -52,7 +54,7 @@ module HTML {
5254
/**
5355
* Gets a child element of this element.
5456
*/
55-
Element getChild() { result = getChild(_) }
57+
Element getChild() { result = this.getChild(_) }
5658

5759
/**
5860
* Gets the `i`th attribute (0-based) of this element.
@@ -62,13 +64,13 @@ module HTML {
6264
/**
6365
* Gets an attribute of this element.
6466
*/
65-
Attribute getAnAttribute() { result = getAttribute(_) }
67+
Attribute getAnAttribute() { result = this.getAttribute(_) }
6668

6769
/**
6870
* Gets an attribute of this element that has the given name.
6971
*/
7072
Attribute getAttributeByName(string name) {
71-
result = getAnAttribute() and
73+
result = this.getAnAttribute() and
7274
result.getName() = name
7375
}
7476

@@ -77,7 +79,7 @@ module HTML {
7779
*/
7880
TextNode getTextNode() { result.getParent() = this }
7981

80-
override string toString() { result = "<" + getName() + ">...</>" }
82+
override string toString() { result = "<" + this.getName() + ">...</>" }
8183
}
8284

8385
/**
@@ -106,7 +108,7 @@ module HTML {
106108
* Gets the root element in which the element to which this attribute
107109
* belongs is contained.
108110
*/
109-
Element getRoot() { result = getElement().getRoot() }
111+
Element getRoot() { result = this.getElement().getRoot() }
110112

111113
/**
112114
* Gets the name of this attribute.
@@ -121,7 +123,7 @@ module HTML {
121123
*/
122124
string getValue() { xmlAttrs(this, _, _, result, _, _) }
123125

124-
override string toString() { result = getName() + "=" + getValue() }
126+
override string toString() { result = this.getName() + "=" + this.getValue() }
125127
}
126128

127129
/**
@@ -138,7 +140,7 @@ module HTML {
138140
* ```
139141
*/
140142
class DocumentElement extends Element {
141-
DocumentElement() { getName() = "html" }
143+
DocumentElement() { this.getName() = "html" }
142144
}
143145

144146
/**
@@ -155,7 +157,7 @@ module HTML {
155157
class TextNode extends Locatable, @xmlcharacters {
156158
TextNode() { exists(HtmlFile f | xmlChars(this, _, _, _, _, f)) }
157159

158-
override string toString() { result = getText() }
160+
override string toString() { result = this.getText() }
159161

160162
/**
161163
* Gets the content of this text node.
@@ -198,7 +200,7 @@ module HTML {
198200
Element getParent() { xmlComments(this, _, result, _) }
199201

200202
/** Gets the text of this comment, not including delimiters. */
201-
string getText() { result = toString().regexpCapture("(?s)<!--(.*)-->", 1) }
203+
string getText() { result = this.toString().regexpCapture("(?s)<!--(.*)-->", 1) }
202204

203205
override string toString() { xmlComments(this, result, _, _) }
204206

go/ql/lib/semmle/go/Locations.qll

+5-5
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
}
@@ -55,13 +55,13 @@ class Location extends @location {
5555
/** A program element with a location. */
5656
class Locatable extends @locatable {
5757
/** Gets the file this program element comes from. */
58-
File getFile() { result = getLocation().getFile() }
58+
File getFile() { result = this.getLocation().getFile() }
5959

6060
/** Gets this element's location. */
6161
Location getLocation() { has_location(this, result) }
6262

6363
/** Gets the number of lines covered by this element. */
64-
int getNumLines() { result = getLocation().getNumLines() }
64+
int getNumLines() { result = this.getLocation().getNumLines() }
6565

6666
/**
6767
* Holds if this element is at the specified location.
@@ -73,7 +73,7 @@ class Locatable extends @locatable {
7373
predicate hasLocationInfo(
7474
string filepath, int startline, int startcolumn, int endline, int endcolumn
7575
) {
76-
getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
76+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
7777
}
7878

7979
/** Gets a textual representation of this element. */

go/ql/lib/semmle/go/Packages.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Package extends @package {
2222
PackageScope getScope() { packages(this, _, _, result) }
2323

2424
/** Gets a textual representation of this element. */
25-
string toString() { result = "package " + getPath() }
25+
string toString() { result = "package " + this.getPath() }
2626
}
2727

2828
/**

go/ql/lib/semmle/go/PrintAst.qll

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class PrintAstNode extends TPrintAstNode {
8585
* within a function are printed, but the query can override
8686
* `PrintAstConfiguration.shouldPrintFunction` to filter the output.
8787
*/
88-
predicate shouldPrint() { exists(getLocation()) }
88+
predicate shouldPrint() { exists(this.getLocation()) }
8989

9090
/**
9191
* Gets a child of this node.
9292
*/
93-
PrintAstNode getAChild() { result = getChild(_) }
93+
PrintAstNode getAChild() { result = this.getChild(_) }
9494

9595
/**
9696
* Gets the location of this node in the source code.
@@ -103,7 +103,7 @@ class PrintAstNode extends TPrintAstNode {
103103
*/
104104
string getProperty(string key) {
105105
key = "semmle.label" and
106-
result = toString()
106+
result = this.toString()
107107
}
108108

109109
/**
@@ -112,7 +112,7 @@ class PrintAstNode extends TPrintAstNode {
112112
* this.
113113
*/
114114
string getChildEdgeLabel(int childIndex) {
115-
exists(getChild(childIndex)) and
115+
exists(this.getChild(childIndex)) and
116116
result = childIndex.toString()
117117
}
118118

@@ -191,7 +191,7 @@ class FileNode extends BaseAstNode {
191191
result = super.getProperty(key)
192192
or
193193
key = "semmle.order" and
194-
result = getSortOrder().toString()
194+
result = this.getSortOrder().toString()
195195
}
196196

197197
/**
@@ -220,7 +220,7 @@ class FileNode extends BaseAstNode {
220220
*/
221221
override BaseAstNode getChild(int childIndex) {
222222
if exists(ast.getPackageNameExpr())
223-
then result = getChildPackageFirst(childIndex, TAstNode(ast.getPackageNameExpr()), _)
223+
then result = this.getChildPackageFirst(childIndex, TAstNode(ast.getPackageNameExpr()), _)
224224
else result = super.getChild(childIndex)
225225
}
226226

@@ -230,7 +230,7 @@ class FileNode extends BaseAstNode {
230230
* of this method.
231231
*/
232232
override string getChildEdgeLabel(int childIndex) {
233-
if getChild(childIndex) = TAstNode(ast.getPackageNameExpr())
233+
if this.getChild(childIndex) = TAstNode(ast.getPackageNameExpr())
234234
then result = "package"
235235
else result = super.getChildEdgeLabel(childIndex)
236236
}

0 commit comments

Comments
 (0)