Merge pull request #113 from github/erik-krogh/fix-implcit-this

fix implicit this
This commit is contained in:
Mathias Vorreiter Pedersen
2021-10-15 08:28:19 +01:00
committed by GitHub
3 changed files with 67 additions and 61 deletions

View File

@@ -9,10 +9,10 @@ abstract class Container extends @container {
Container getAChildContainer() { this = result.getParentContainer() }
/** Gets a file in this container. */
File getAFile() { result = getAChildContainer() }
File getAFile() { result = this.getAChildContainer() }
/** Gets a sub-folder in this container. */
Folder getAFolder() { result = getAChildContainer() }
Folder getAFolder() { result = this.getAChildContainer() }
/**
* Gets the absolute, canonical path of this container, using forward slashes
@@ -58,7 +58,7 @@ abstract class Container extends @container {
* </table>
*/
string getBaseName() {
result = getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
}
/**
@@ -84,17 +84,19 @@ abstract class Container extends @container {
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
* </table>
*/
string getExtension() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3) }
string getExtension() {
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3)
}
/** Gets the file in this container that has the given `baseName`, if any. */
File getFile(string baseName) {
result = getAFile() and
result = this.getAFile() and
result.getBaseName() = baseName
}
/** Gets the sub-folder in this container that has the given `baseName`, if any. */
Folder getFolder(string baseName) {
result = getAFolder() and
result = this.getAFolder() and
result.getBaseName() = baseName
}
@@ -111,7 +113,7 @@ abstract class Container extends @container {
*/
string getRelativePath() {
exists(string absPath, string pref |
absPath = getAbsolutePath() and sourceLocationPrefix(pref)
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
|
absPath = pref and result = ""
or
@@ -137,7 +139,9 @@ abstract class Container extends @container {
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
* </table>
*/
string getStem() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1) }
string getStem() {
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1)
}
/**
* Gets a URL representing the location of this container.
@@ -151,7 +155,7 @@ abstract class Container extends @container {
*
* This is the absolute path of the container.
*/
string toString() { result = getAbsolutePath() }
string toString() { result = this.getAbsolutePath() }
}
/** A folder. */
@@ -159,7 +163,7 @@ class Folder extends Container, @folder {
override string getAbsolutePath() { folders(this, result, _) }
/** Gets the URL of this folder. */
override string getURL() { result = "folder://" + getAbsolutePath() }
override string getURL() { result = "folder://" + this.getAbsolutePath() }
}
/** A file. */

View File

@@ -19,7 +19,7 @@ private string stringIndexedMember(string name, string index) {
/** An AST node of a QL program */
class AstNode extends TAstNode {
string toString() { result = getAPrimaryQlClass() }
string toString() { result = this.getAPrimaryQlClass() }
/**
* Gets the location of the AST node.
@@ -35,8 +35,8 @@ class AstNode extends TAstNode {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
if exists(getLocation())
then getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
if exists(this.getLocation())
then this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
else (
filepath = "" and
startline = 0 and
@@ -92,7 +92,7 @@ class TopLevel extends TTopLevel, AstNode {
* Gets a member from contained in this top-level module.
* Includes private members.
*/
ModuleMember getAMember() { result = getMember(_) }
ModuleMember getAMember() { result = this.getMember(_) }
/** Gets the `i`'th member of this top-level module. */
ModuleMember getMember(int i) {
@@ -201,13 +201,13 @@ class PredicateOrBuiltin extends TPredOrBuiltin, AstNode {
Type getReturnType() { none() }
int getArity() { result = count(getParameterType(_)) }
int getArity() { result = count(this.getParameterType(_)) }
predicate isPrivate() { none() }
}
class BuiltinPredicate extends PredicateOrBuiltin, TBuiltin {
override string toString() { result = getName() }
override string toString() { result = this.getName() }
override string getAPrimaryQlClass() { result = "BuiltinPredicate" }
}
@@ -268,7 +268,7 @@ class Predicate extends TPredicate, AstNode, PredicateOrBuiltin, Declaration {
*/
override int getArity() {
not this.(ClasslessPredicate).getAlias() instanceof PredicateExpr and
result = count(getParameter(_))
result = count(this.getParameter(_))
or
exists(PredicateExpr alias | alias = this.(ClasslessPredicate).getAlias() |
result = alias.getArity()
@@ -278,7 +278,7 @@ class Predicate extends TPredicate, AstNode, PredicateOrBuiltin, Declaration {
/**
* Holds if this predicate is private.
*/
override predicate isPrivate() { hasAnnotation("private") }
override predicate isPrivate() { this.hasAnnotation("private") }
/**
* Gets the return type (if any) of the predicate.
@@ -325,18 +325,18 @@ class Relation extends TDBRelation, AstNode, Declaration {
}
/** Gets the `i`th parameter name */
string getParameterName(int i) { result = getColumn(i).getColName().getValue() }
string getParameterName(int i) { result = this.getColumn(i).getColName().getValue() }
/** Gets the `i`th parameter type */
string getParameterType(int i) {
// TODO: This is just using the name of the type, not the actual type. Checkout Type.qll
result = getColumn(i).getColType().getChild().(Generated::Token).getValue()
result = this.getColumn(i).getColType().getChild().(Generated::Token).getValue()
}
/**
* Gets the number of parameters.
*/
int getArity() { result = count(getColumn(_)) }
int getArity() { result = count(this.getColumn(_)) }
override string getAPrimaryQlClass() { result = "Relation" }
}
@@ -472,7 +472,7 @@ class ClassPredicate extends TClassPredicate, Predicate {
/**
* Holds if this predicate is annotated as overriding another predicate.
*/
predicate isOverride() { hasAnnotation("override") }
predicate isOverride() { this.hasAnnotation("override") }
override VarDecl getParameter(int i) {
toGenerated(result) =
@@ -486,7 +486,7 @@ class ClassPredicate extends TClassPredicate, Predicate {
/**
* Gets the type representing this class.
*/
override ClassType getDeclaringType() { result.getDeclaration() = getParent() }
override ClassType getDeclaringType() { result.getDeclaration() = this.getParent() }
predicate overrides(ClassPredicate other) { predOverrides(this, other) }
@@ -515,7 +515,7 @@ class CharPred extends TCharPred, Predicate {
override Formula getBody() { toGenerated(result) = pred.getBody() }
override string getName() { result = getParent().(Class).getName() }
override string getName() { result = this.getParent().(Class).getName() }
override AstNode getAChild(string pred_name) {
result = super.getAChild(pred_name)
@@ -523,7 +523,7 @@ class CharPred extends TCharPred, Predicate {
pred_name = directMember("getBody") and result = this.getBody()
}
override ClassType getDeclaringType() { result.getDeclaration() = getParent() }
override ClassType getDeclaringType() { result.getDeclaration() = this.getParent() }
}
/**
@@ -685,7 +685,7 @@ class Module extends TModule, ModuleDeclaration {
*/
class ModuleMember extends TModuleMember, AstNode {
/** Holds if this member is declared as `private`. */
predicate isPrivate() { hasAnnotation("private") }
predicate isPrivate() { this.hasAnnotation("private") }
}
/** A declaration. E.g. a class, type, predicate, newtype... */
@@ -756,7 +756,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
* Gets predicate `name` implemented in this class.
*/
ClassPredicate getClassPredicate(string name) {
result = getAClassPredicate() and
result = this.getAClassPredicate() and
result.getName() = name
}
@@ -894,7 +894,7 @@ class Call extends TCall, Expr, Formula {
}
/** Gets an argument of this call, if any. */
final Expr getAnArgument() { result = getArgument(_) }
final Expr getAnArgument() { result = this.getArgument(_) }
PredicateOrBuiltin getTarget() { resolveCall(this, result) }
@@ -1271,7 +1271,7 @@ class ComparisonFormula extends TComparisonFormula, Formula {
Expr getRightOperand() { toGenerated(result) = comp.getRight() }
/** Gets an operand of this comparison. */
Expr getAnOperand() { result in [getLeftOperand(), getRightOperand()] }
Expr getAnOperand() { result in [this.getLeftOperand(), this.getRightOperand()] }
/** Gets the operator of this comparison. */
ComparisonOp getOperator() { toGenerated(result) = comp.getChild() }
@@ -1329,7 +1329,7 @@ class Quantifier extends TQuantifier, Formula {
* Holds if this is the "expression only" form of an exists quantifier.
* In other words, the quantifier is of the form `exists( expr )`.
*/
predicate hasExpr() { exists(getExpr()) }
predicate hasExpr() { exists(this.getExpr()) }
override string getAPrimaryQlClass() { result = "Quantifier" }
@@ -1501,7 +1501,7 @@ class HigherOrderFormula extends THigherOrderFormula, Formula {
* Gets the `i`th argument to this higher-order formula.
* E.g. for `fastTC(pathSucc/2)(n1, n2)` the result is `n1` and `n2`.
*/
Expr getArgument(int i) { toGenerated(result) = hop.getChild(i + getNumInputs()) }
Expr getArgument(int i) { toGenerated(result) = hop.getChild(i + this.getNumInputs()) }
/**
* Gets the name of this higher-order predicate.
@@ -1590,7 +1590,7 @@ class ExprAggregate extends TExprAggregate, Aggregate {
)
or
not kind = ["count", "strictcount"] and
result = getExpr(0).getType()
result = this.getExpr(0).getType()
}
}
@@ -1654,11 +1654,11 @@ class FullAggregate extends TFullAggregate, Aggregate {
)
or
kind = ["any", "min", "max", "unique"] and
not exists(getExpr(_)) and
result = getArgument(0).getTypeExpr().getResolvedType()
not exists(this.getExpr(_)) and
result = this.getArgument(0).getTypeExpr().getResolvedType()
or
not kind = ["count", "strictcount"] and
result = getExpr(0).getType()
result = this.getExpr(0).getType()
}
override AstNode getAChild(string pred) {
@@ -1882,7 +1882,7 @@ class BinOpExpr extends TBinOpExpr, Expr {
FunctionSymbol getOperator() { none() } // overriden in subclasses
/* Gets an operand of the binary expression. */
final Expr getAnOperand() { result = getLeftOperand() or result = getRightOperand() }
final Expr getAnOperand() { result = this.getLeftOperand() or result = this.getRightOperand() }
}
/**
@@ -2039,7 +2039,7 @@ class Range extends TRange, Expr {
/**
* Gets the lower and upper bounds of the range.
*/
Expr getAnEndpoint() { result = [getLowEndpoint(), getHighEndpoint()] }
Expr getAnEndpoint() { result = [this.getLowEndpoint(), this.getHighEndpoint()] }
override PrimitiveType getType() { result.getName() = "int" }
@@ -2070,12 +2070,12 @@ class Set extends TSet, Expr {
/**
* Gets an element in this set literal expression, if any.
*/
Expr getAnElement() { result = getElement(_) }
Expr getAnElement() { result = this.getElement(_) }
/**
* Gets the number of elements in this set literal expression.
*/
int getNumberOfElements() { result = count(getAnElement()) }
int getNumberOfElements() { result = count(this.getAnElement()) }
override Type getType() { result = this.getElement(0).getType() }
@@ -2084,7 +2084,7 @@ class Set extends TSet, Expr {
override AstNode getAChild(string pred) {
result = super.getAChild(pred)
or
exists(int i | pred = indexedMember("getElement", i) and result = getElement(i))
exists(int i | pred = indexedMember("getElement", i) and result = this.getElement(i))
}
}
@@ -2267,10 +2267,10 @@ class BindingSet extends Annotation {
string getBoundName(int index) { result = this.getArgs(index).getValue() }
/** Gets a name bound by this bindingset, if any. */
string getABoundName() { result = getBoundName(_) }
string getABoundName() { result = this.getBoundName(_) }
/** Gets the number of names bound by this bindingset. */
int getNumberOfBoundNames() { result = count(getABoundName()) }
int getNumberOfBoundNames() { result = count(this.getABoundName()) }
}
/**
@@ -2280,7 +2280,7 @@ module YAML {
/** A node in a YAML file */
class YAMLNode extends TYAMLNode, AstNode {
/** Holds if the predicate is a root node (has no parent) */
predicate isRoot() { not exists(getParent()) }
predicate isRoot() { not exists(this.getParent()) }
}
/** A YAML comment. */
@@ -2349,7 +2349,7 @@ module YAML {
* Dashes are replaced with `/` (because we don't have that information in the generated AST).
*/
string getQualifiedName() {
result = concat(string part, int i | part = getNamePart(i) | part, "/" order by i)
result = concat(string part, int i | part = this.getNamePart(i) | part, "/" order by i)
}
}
@@ -2402,15 +2402,15 @@ module YAML {
}
/** Gets the name of this qlpack */
string getName() { result = getProperty("name") }
string getName() { result = this.getProperty("name") }
/** Gets the version of this qlpack */
string getVersion() { result = getProperty("version") }
string getVersion() { result = this.getProperty("version") }
/** Gets the extractor of this qlpack */
string getExtractor() { result = getProperty("extractor") }
string getExtractor() { result = this.getProperty("extractor") }
string toString() { result = getName() }
string toString() { result = this.getName() }
/** Gets the file that this `QLPack` represents. */
File getFile() { result = file }
@@ -2425,7 +2425,7 @@ module YAML {
entry.getLocation().getStartColumn() > deps.getLocation().getStartColumn()
)
or
exists(YAMLEntry prev | isADependency(prev) |
exists(YAMLEntry prev | this.isADependency(prev) |
prev.getLocation().getFile() = file and
entry.getLocation().getFile() = file and
entry.getLocation().getStartLine() = 1 + prev.getLocation().getStartLine() and
@@ -2434,7 +2434,7 @@ module YAML {
}
predicate hasDependency(string name, string version) {
exists(YAMLEntry entry | isADependency(entry) |
exists(YAMLEntry entry | this.isADependency(entry) |
entry.getKey().getQualifiedName() = name and
entry.getValue().getValue() = version
)
@@ -2442,7 +2442,7 @@ module YAML {
/** Gets the database scheme of this qlpack */
File getDBScheme() {
result.getBaseName() = getProperty("dbscheme") and
result.getBaseName() = this.getProperty("dbscheme") and
result = file.getParentContainer().getFile(any(string s | s.matches("%.dbscheme")))
}
@@ -2450,14 +2450,16 @@ module YAML {
Container getAFileInPack() {
result.getParentContainer() = file.getParentContainer()
or
result = getAFileInPack().(Folder).getAChildContainer()
result = this.getAFileInPack().(Folder).getAChildContainer()
}
/**
* Gets a QLPack that this QLPack depends on.
*/
QLPack getADependency() {
exists(string name | hasDependency(name, _) | result.getName().replaceAll("-", "/") = name)
exists(string name | this.hasDependency(name, _) |
result.getName().replaceAll("-", "/") = name
)
}
Location getLocation() {

View File

@@ -27,7 +27,7 @@ private predicate isActualClass(Class c) {
* A type, such as `int` or `Node`.
*/
class Type extends TType {
string toString() { result = getName() }
string toString() { result = this.getName() }
string getName() { result = "???" }
@@ -48,9 +48,9 @@ class Type extends TType {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
if exists(getDeclaration())
if exists(this.getDeclaration())
then
getDeclaration()
this.getDeclaration()
.getLocation()
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
else (
@@ -72,14 +72,14 @@ class Type extends TType {
private predicate getClassPredicate1(
string name, int arity, PredicateOrBuiltin p1, PredicateOrBuiltin p2
) {
getClassPredicate0(name, arity, p1, p2.getDeclaringType()) and
this.getClassPredicate0(name, arity, p1, p2.getDeclaringType()) and
p2 = classPredCandidate(this, name, arity)
}
cached
PredicateOrBuiltin getClassPredicate(string name, int arity) {
result = classPredCandidate(this, name, arity) and
not getClassPredicate1(name, arity, _, result)
not this.getClassPredicate1(name, arity, _, result)
}
}
@@ -179,7 +179,7 @@ class ClassDomainType extends Type, TClassDomain {
ClassType getClassType() { result = TClass(decl) }
override Type getAnInternalSuperType() { result = getClassType().getASuperType() }
override Type getAnInternalSuperType() { result = this.getClassType().getASuperType() }
}
class PrimitiveType extends Type, TPrimitive {
@@ -192,7 +192,7 @@ class PrimitiveType extends Type, TPrimitive {
override Type getASuperType() { name = "int" and result.(PrimitiveType).getName() = "float" }
override Type getAnInternalSuperType() {
result = getASuperType()
result = this.getASuperType()
or
result = super.getAnInternalSuperType()
}
@@ -232,7 +232,7 @@ class NewTypeBranchType extends Type, TNewTypeBranch {
}
override Type getAnInternalSuperType() {
result = getASuperType()
result = this.getASuperType()
or
result = super.getAnInternalSuperType()
}