add explicit this

This commit is contained in:
erik-krogh
2022-08-16 22:56:41 +02:00
parent b9823cf335
commit 2e44fba67d
13 changed files with 45 additions and 39 deletions

View File

@@ -268,7 +268,11 @@ class PathElement extends TPathElement {
predicate isSink(IRBlock block) { exists(this.asSink(block)) }
string toString() {
result = [asStore().toString(), asCall(_).toString(), asMid().toString(), asSink(_).toString()]
result =
[
this.asStore().toString(), this.asCall(_).toString(), this.asMid().toString(),
this.asSink(_).toString()
]
}
predicate hasLocationInfo(

View File

@@ -28,12 +28,12 @@ class AstNode extends @node, Locatable {
/**
* Gets a child node of this node.
*/
AstNode getAChild() { result = getChild(_) }
AstNode getAChild() { result = this.getChild(_) }
/**
* Gets the number of child nodes of this node.
*/
int getNumChild() { result = count(getAChild()) }
int getNumChild() { result = count(this.getAChild()) }
/**
* Gets a child with the given index and of the given kind, if one exists.
@@ -63,7 +63,7 @@ class AstNode extends @node, Locatable {
AstNode getUniquelyNumberedChild(int index) {
result =
rank[index + 1](AstNode child, string kind, int i |
child = getChildOfKind(kind, i)
child = this.getChildOfKind(kind, i)
|
child order by kind, i
)
@@ -74,17 +74,17 @@ class AstNode extends @node, Locatable {
/** Gets the parent node of this AST node, but without crossing function boundaries. */
private AstNode parentInSameFunction() {
result = getParent() and
result = this.getParent() and
not this instanceof FuncDef
}
/** Gets the innermost function definition to which this AST node belongs, if any. */
FuncDef getEnclosingFunction() { result = getParent().parentInSameFunction*() }
FuncDef getEnclosingFunction() { result = this.getParent().parentInSameFunction*() }
/**
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
*/
final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") }
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
/**
* Gets the name of a primary CodeQL class to which this node belongs.
@@ -116,12 +116,12 @@ class ExprParent extends @exprparent, AstNode {
/**
* Gets an expression that is a child node of this node in the AST.
*/
Expr getAChildExpr() { result = getChildExpr(_) }
Expr getAChildExpr() { result = this.getChildExpr(_) }
/**
* Gets the number of child expressions of this node.
*/
int getNumChildExpr() { result = count(getAChildExpr()) }
int getNumChildExpr() { result = count(this.getAChildExpr()) }
}
/**
@@ -139,12 +139,12 @@ class GoModExprParent extends @modexprparent, AstNode {
/**
* Gets an expression that is a child node of this node in the AST.
*/
GoModExpr getAChildGoModExpr() { result = getChildGoModExpr(_) }
GoModExpr getAChildGoModExpr() { result = this.getChildGoModExpr(_) }
/**
* Gets the number of child expressions of this node.
*/
int getNumChildGoModExpr() { result = count(getAChildGoModExpr()) }
int getNumChildGoModExpr() { result = count(this.getAChildGoModExpr()) }
}
/**
@@ -162,12 +162,12 @@ class StmtParent extends @stmtparent, AstNode {
/**
* Gets a statement that is a child node of this node in the AST.
*/
Stmt getAChildStmt() { result = getChildStmt(_) }
Stmt getAChildStmt() { result = this.getChildStmt(_) }
/**
* Gets the number of child statements of this node.
*/
int getNumChildStmt() { result = count(getAChildStmt()) }
int getNumChildStmt() { result = count(this.getAChildStmt()) }
}
/**
@@ -185,12 +185,12 @@ class DeclParent extends @declparent, AstNode {
/**
* Gets a child declaration of this node in the AST.
*/
Decl getADecl() { result = getDecl(_) }
Decl getADecl() { result = this.getDecl(_) }
/**
* Gets the number of child declarations of this node.
*/
int getNumDecl() { result = count(getADecl()) }
int getNumDecl() { result = count(this.getADecl()) }
}
/**
@@ -208,12 +208,12 @@ class FieldParent extends @fieldparent, AstNode {
/**
* Gets a child field of this node in the AST.
*/
FieldBase getAField() { result = getField(_) }
FieldBase getAField() { result = this.getField(_) }
/**
* Gets the number of child fields of this node.
*/
int getNumFields() { result = count(getAField()) }
int getNumFields() { result = count(this.getAField()) }
}
/**

View File

@@ -787,7 +787,7 @@ class InterfaceType extends @interfacetype, CompositeType {
* Note that the indexes are not contiguous.
*/
TypeSetLiteralType getDirectlyEmbeddedTypeSetLiteral(int index) {
hasDirectlyEmbeddedType(index, result)
this.hasDirectlyEmbeddedType(index, result)
}
/**
@@ -798,7 +798,7 @@ class InterfaceType extends @interfacetype, CompositeType {
TypeSetLiteralType getAnEmbeddedTypeSetLiteral() {
result = this.getDirectlyEmbeddedTypeSetLiteral(_) or
result =
getADirectlyEmbeddedInterface()
this.getADirectlyEmbeddedInterface()
.getUnderlyingType()
.(InterfaceType)
.getAnEmbeddedTypeSetLiteral()

View File

@@ -9,21 +9,23 @@ private import semmle.code.java.frameworks.android.Android
* The class `android.database.sqlite.SQLiteDatabase`.
*/
class TypeSQLiteDatabase extends Class {
TypeSQLiteDatabase() { hasQualifiedName("android.database.sqlite", "SQLiteDatabase") }
TypeSQLiteDatabase() { this.hasQualifiedName("android.database.sqlite", "SQLiteDatabase") }
}
/**
* The class `android.database.sqlite.SQLiteQueryBuilder`.
*/
class TypeSQLiteQueryBuilder extends Class {
TypeSQLiteQueryBuilder() { hasQualifiedName("android.database.sqlite", "SQLiteQueryBuilder") }
TypeSQLiteQueryBuilder() {
this.hasQualifiedName("android.database.sqlite", "SQLiteQueryBuilder")
}
}
/**
* The class `android.database.DatabaseUtils`.
*/
class TypeDatabaseUtils extends Class {
TypeDatabaseUtils() { hasQualifiedName("android.database", "DatabaseUtils") }
TypeDatabaseUtils() { this.hasQualifiedName("android.database", "DatabaseUtils") }
}
/**

View File

@@ -53,7 +53,7 @@ private class FileSetRedableMethodAccess extends MethodAccess {
private predicate isCallToSecondArgumentWithValue(boolean value) {
this.getMethod().getNumberOfParameters() = 1 and value = true
or
isCallWithArgument(1, value)
this.isCallWithArgument(1, value)
}
private predicate isCallWithArgument(int index, boolean arg) {

View File

@@ -84,8 +84,8 @@ class Assertion extends Comment {
string tryExplainFailure() {
exists(int i, API::Node nd, string prefix, string suffix |
nd = this.lookup(i) and
i < getPathLength() and
not exists(this.lookup([i + 1 .. getPathLength()])) and
i < this.getPathLength() and
not exists(this.lookup([i + 1 .. this.getPathLength()])) and
prefix = nd + " has no outgoing edge labelled " + this.getEdgeLabel(i) + ";" and
if exists(nd.getASuccessor())
then

View File

@@ -11,7 +11,7 @@ class XmlRecordedCall extends XMLElement {
XmlCall getXmlCall() { result.getParent() = this }
/** DEPRECATED: Alias for getXmlCall */
deprecated XMLCall getXMLCall() { result = getXmlCall() }
deprecated XMLCall getXMLCall() { result = this.getXmlCall() }
/** Gets a call matching the recorded information. */
Call getACall() { result = this.getXmlCall().getACall() }
@@ -20,7 +20,7 @@ class XmlRecordedCall extends XMLElement {
XmlCallee getXmlCallee() { result.getParent() = this }
/** DEPRECATED: Alias for getXmlCallee */
deprecated XMLCallee getXMLCallee() { result = getXmlCallee() }
deprecated XMLCallee getXMLCallee() { result = this.getXmlCallee() }
/** Gets a python function matching the recorded information of the callee. */
Function getAPythonCallee() { result = this.getXmlCallee().(XmlPythonCallee).getACallee() }
@@ -90,10 +90,10 @@ class XmlCall extends XMLElement {
expr.(Name).getId() = bytecode.(XmlBytecodeVariableName).get_name_data()
or
expr.(Attribute).getName() = bytecode.(XmlBytecodeAttribute).get_attr_name_data() and
matchBytecodeExpr(expr.(Attribute).getObject(),
this.matchBytecodeExpr(expr.(Attribute).getObject(),
bytecode.(XmlBytecodeAttribute).get_object_data())
or
matchBytecodeExpr(expr.(Call).getFunc(), bytecode.(XmlBytecodeCall).get_function_data())
this.matchBytecodeExpr(expr.(Call).getFunc(), bytecode.(XmlBytecodeCall).get_function_data())
//
// I considered allowing a partial match as well. That is, if the bytecode
// expression information only tells us `<unknown>.foo()`, and we find an AST

View File

@@ -176,7 +176,7 @@ private module ParameterNodes {
)
}
override DataFlowCallable getEnclosingCallable() { isParameterOf(result, _) }
override DataFlowCallable getEnclosingCallable() { this.isParameterOf(result, _) }
}
}

View File

@@ -2,7 +2,7 @@ private import codeql.swift.generated.Comment
class Comment extends CommentBase {
/** toString */
override string toString() { result = getText() }
override string toString() { result = this.getText() }
}
class SingleLineComment extends Comment {

View File

@@ -3,7 +3,7 @@ private import codeql.swift.generated.Element
class Element extends ElementBase {
private predicate resolvesFrom(Element e) { e.getResolveStep() = this }
override string toString() { result = getPrimaryQlClasses() }
override string toString() { result = this.getPrimaryQlClasses() }
Element getFullyUnresolved() {
not this.resolvesFrom(_) and result = this
@@ -16,5 +16,5 @@ class Element extends ElementBase {
}
class UnknownElement extends Element {
UnknownElement() { isUnknown() }
UnknownElement() { this.isUnknown() }
}

View File

@@ -2,13 +2,13 @@ private import codeql.swift.generated.File
class File extends FileBase {
/** toString */
override string toString() { result = getAbsolutePath() }
override string toString() { result = this.getAbsolutePath() }
/** Gets the absolute path of this file. */
string getAbsolutePath() { result = getName() }
string getAbsolutePath() { result = this.getName() }
/** Gets the full name of this file. */
string getFullName() { result = getAbsolutePath() }
string getFullName() { result = this.getAbsolutePath() }
/** Gets the URL of this file. */
string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }

View File

@@ -12,9 +12,9 @@ class ElementBase extends Synth::TElement {
ElementBase getResolveStep() { none() } // overridden by subclasses
final ElementBase resolve() {
not exists(getResolveStep()) and result = this
not exists(this.getResolveStep()) and result = this
or
result = getResolveStep().resolve()
result = this.getResolveStep().resolve()
}
predicate isUnknown() { Synth::convertElementToRaw(this).isUnknown() }

View File

@@ -7,7 +7,7 @@ import codeql.swift.controlflow.ControlFlowGraph
import codeql.swift.controlflow.internal.ControlFlowGraphImpl::TestOutput
class MyRelevantNode extends RelevantNode {
MyRelevantNode() { getScope().getLocation().getFile().getName().matches("%swift/ql/test%") }
MyRelevantNode() { this.getScope().getLocation().getFile().getName().matches("%swift/ql/test%") }
private AstNode asAstNode() { result = this.getNode().asAstNode() }