Skip to content

Go: Make implicit this receivers explicit #13006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/ql/lib/printAst.ql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ external string selectedSourceFile();
* A hook to customize the functions printed by this query.
*/
class Cfg extends PrintAstConfiguration {
override predicate shouldPrintFunction(FuncDecl func) { shouldPrintFile(func.getFile()) }
override predicate shouldPrintFunction(FuncDecl func) { this.shouldPrintFile(func.getFile()) }

override predicate shouldPrintFile(File file) {
file = getFileBySourceArchiveName(selectedSourceFile())
Expand Down
4 changes: 2 additions & 2 deletions go/ql/lib/semmle/go/Errors.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Error extends @error {
int getIndex() { errors(this, _, _, _, _, _, _, _, result) }

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

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

/** Gets a textual representation of this error. */
string toString() { result = getMessage() }
string toString() { result = this.getMessage() }
}

/** An error reported by an unknown part of the Go frontend. */
Expand Down
26 changes: 14 additions & 12 deletions go/ql/lib/semmle/go/HTML.qll
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ module HTML {
/**
* Holds if this is a toplevel element, that is, if it does not have a parent element.
*/
predicate isTopLevel() { not exists(getParent()) }
predicate isTopLevel() { not exists(this.getParent()) }

/**
* Gets the root HTML document element in which this element is contained.
*/
DocumentElement getDocument() { result = getRoot() }
DocumentElement getDocument() { result = this.getRoot() }

/**
* Gets the root element in which this element is contained.
*/
Element getRoot() { if isTopLevel() then result = this else result = getParent().getRoot() }
Element getRoot() {
if this.isTopLevel() then result = this else result = this.getParent().getRoot()
}

/**
* Gets the `i`th child element (0-based) of this element.
Expand All @@ -52,7 +54,7 @@ module HTML {
/**
* Gets a child element of this element.
*/
Element getChild() { result = getChild(_) }
Element getChild() { result = this.getChild(_) }

/**
* Gets the `i`th attribute (0-based) of this element.
Expand All @@ -62,13 +64,13 @@ module HTML {
/**
* Gets an attribute of this element.
*/
Attribute getAnAttribute() { result = getAttribute(_) }
Attribute getAnAttribute() { result = this.getAttribute(_) }

/**
* Gets an attribute of this element that has the given name.
*/
Attribute getAttributeByName(string name) {
result = getAnAttribute() and
result = this.getAnAttribute() and
result.getName() = name
}

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

override string toString() { result = "<" + getName() + ">...</>" }
override string toString() { result = "<" + this.getName() + ">...</>" }
}

/**
Expand Down Expand Up @@ -106,7 +108,7 @@ module HTML {
* Gets the root element in which the element to which this attribute
* belongs is contained.
*/
Element getRoot() { result = getElement().getRoot() }
Element getRoot() { result = this.getElement().getRoot() }

/**
* Gets the name of this attribute.
Expand All @@ -121,7 +123,7 @@ module HTML {
*/
string getValue() { xmlAttrs(this, _, _, result, _, _) }

override string toString() { result = getName() + "=" + getValue() }
override string toString() { result = this.getName() + "=" + this.getValue() }
}

/**
Expand All @@ -138,7 +140,7 @@ module HTML {
* ```
*/
class DocumentElement extends Element {
DocumentElement() { getName() = "html" }
DocumentElement() { this.getName() = "html" }
}

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

override string toString() { result = getText() }
override string toString() { result = this.getText() }

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

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

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

Expand Down
10 changes: 5 additions & 5 deletions go/ql/lib/semmle/go/Locations.qll
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class Location extends @location {
int getEndColumn() { locations_default(this, _, _, _, _, result) }

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

/** Gets a textual representation of this element. */
string toString() {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
Expand All @@ -55,13 +55,13 @@ class Location extends @location {
/** A program element with a location. */
class Locatable extends @locatable {
/** Gets the file this program element comes from. */
File getFile() { result = getLocation().getFile() }
File getFile() { result = this.getLocation().getFile() }

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

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

/**
* Holds if this element is at the specified location.
Expand All @@ -73,7 +73,7 @@ class Locatable extends @locatable {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}

/** Gets a textual representation of this element. */
Expand Down
2 changes: 1 addition & 1 deletion go/ql/lib/semmle/go/Packages.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Package extends @package {
PackageScope getScope() { packages(this, _, _, result) }

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

/**
Expand Down
14 changes: 7 additions & 7 deletions go/ql/lib/semmle/go/PrintAst.qll
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ class PrintAstNode extends TPrintAstNode {
* within a function are printed, but the query can override
* `PrintAstConfiguration.shouldPrintFunction` to filter the output.
*/
predicate shouldPrint() { exists(getLocation()) }
predicate shouldPrint() { exists(this.getLocation()) }

/**
* Gets a child of this node.
*/
PrintAstNode getAChild() { result = getChild(_) }
PrintAstNode getAChild() { result = this.getChild(_) }

/**
* Gets the location of this node in the source code.
Expand All @@ -103,7 +103,7 @@ class PrintAstNode extends TPrintAstNode {
*/
string getProperty(string key) {
key = "semmle.label" and
result = toString()
result = this.toString()
}

/**
Expand All @@ -112,7 +112,7 @@ class PrintAstNode extends TPrintAstNode {
* this.
*/
string getChildEdgeLabel(int childIndex) {
exists(getChild(childIndex)) and
exists(this.getChild(childIndex)) and
result = childIndex.toString()
}

Expand Down Expand Up @@ -191,7 +191,7 @@ class FileNode extends BaseAstNode {
result = super.getProperty(key)
or
key = "semmle.order" and
result = getSortOrder().toString()
result = this.getSortOrder().toString()
}

/**
Expand Down Expand Up @@ -220,7 +220,7 @@ class FileNode extends BaseAstNode {
*/
override BaseAstNode getChild(int childIndex) {
if exists(ast.getPackageNameExpr())
then result = getChildPackageFirst(childIndex, TAstNode(ast.getPackageNameExpr()), _)
then result = this.getChildPackageFirst(childIndex, TAstNode(ast.getPackageNameExpr()), _)
else result = super.getChild(childIndex)
}

Expand All @@ -230,7 +230,7 @@ class FileNode extends BaseAstNode {
* of this method.
*/
override string getChildEdgeLabel(int childIndex) {
if getChild(childIndex) = TAstNode(ast.getPackageNameExpr())
if this.getChild(childIndex) = TAstNode(ast.getPackageNameExpr())
then result = "package"
else result = super.getChildEdgeLabel(childIndex)
}
Expand Down
Loading