mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Merge pull request #357 from github/erik-krogh/fix-implicit-this
Add explicit `this` qualifiers
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,10 +8,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
|
||||
@@ -57,7 +57,7 @@ abstract class Container extends @container {
|
||||
* </table>
|
||||
*/
|
||||
string getBaseName() {
|
||||
result = getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
|
||||
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,17 +83,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
|
||||
}
|
||||
|
||||
@@ -110,7 +112,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
|
||||
@@ -136,7 +138,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.
|
||||
@@ -150,7 +154,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. */
|
||||
@@ -158,7 +162,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. */
|
||||
|
||||
@@ -47,7 +47,7 @@ module API {
|
||||
* Gets a call to a method on the receiver represented by this API component.
|
||||
*/
|
||||
DataFlow::CallNode getAMethodCall(string method) {
|
||||
result = getReturn(method).getAnImmediateUse()
|
||||
result = this.getReturn(method).getAnImmediateUse()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,21 +60,21 @@ module API {
|
||||
*/
|
||||
bindingset[m]
|
||||
bindingset[result]
|
||||
Node getMember(string m) { result = getASuccessor(Label::member(m)) }
|
||||
Node getMember(string m) { result = this.getASuccessor(Label::member(m)) }
|
||||
|
||||
/**
|
||||
* Gets a node representing a member of this API component where the name of the member is
|
||||
* not known statically.
|
||||
*/
|
||||
Node getUnknownMember() { result = getASuccessor(Label::unknownMember()) }
|
||||
Node getUnknownMember() { result = this.getASuccessor(Label::unknownMember()) }
|
||||
|
||||
/**
|
||||
* Gets a node representing a member of this API component where the name of the member may
|
||||
* or may not be known statically.
|
||||
*/
|
||||
Node getAMember() {
|
||||
result = getASuccessor(Label::member(_)) or
|
||||
result = getUnknownMember()
|
||||
result = this.getASuccessor(Label::member(_)) or
|
||||
result = this.getUnknownMember()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,28 +88,30 @@ module API {
|
||||
* This predicate may have multiple results when there are multiple constructor calls invoking this API component.
|
||||
* Consider using `getAnInstantiation()` if there is a need to distinguish between individual constructor calls.
|
||||
*/
|
||||
Node getInstance() { result = getASuccessor(Label::instance()) }
|
||||
Node getInstance() { result = this.getASuccessor(Label::instance()) }
|
||||
|
||||
/**
|
||||
* Gets a node representing the result of calling a method on the receiver represented by this node.
|
||||
*/
|
||||
Node getReturn(string method) { result = getASuccessor(Label::return(method)) }
|
||||
Node getReturn(string method) { result = this.getASuccessor(Label::return(method)) }
|
||||
|
||||
/**
|
||||
* Gets a `new` call to the function represented by this API component.
|
||||
*/
|
||||
DataFlow::Node getAnInstantiation() { result = getInstance().getAnImmediateUse() }
|
||||
DataFlow::Node getAnInstantiation() { result = this.getInstance().getAnImmediateUse() }
|
||||
|
||||
/**
|
||||
* Gets a node representing a subclass of the class represented by this node.
|
||||
*/
|
||||
Node getASubclass() { result = getASuccessor(Label::subclass()) }
|
||||
Node getASubclass() { result = this.getASuccessor(Label::subclass()) }
|
||||
|
||||
/**
|
||||
* Gets a string representation of the lexicographically least among all shortest access paths
|
||||
* from the root to this node.
|
||||
*/
|
||||
string getPath() { result = min(string p | p = getAPath(Impl::distanceFromRoot(this)) | p) }
|
||||
string getPath() {
|
||||
result = min(string p | p = this.getAPath(Impl::distanceFromRoot(this)) | p)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
* Gets a node such that there is an edge in the API graph between this node and the other
|
||||
* one.
|
||||
*/
|
||||
Node getAPredecessor() { result = getAPredecessor(_) }
|
||||
Node getAPredecessor() { result = this.getAPredecessor(_) }
|
||||
|
||||
/**
|
||||
* Gets a node such that there is an edge in the API graph between that other node and
|
||||
* this one.
|
||||
*/
|
||||
Node getASuccessor() { result = getASuccessor(_) }
|
||||
Node getASuccessor() { result = this.getASuccessor(_) }
|
||||
|
||||
/**
|
||||
* Gets the data-flow node that gives rise to this node, if any.
|
||||
@@ -146,7 +148,7 @@ module API {
|
||||
or
|
||||
// For nodes that do not have a meaningful location, `path` is the empty string and all other
|
||||
// parameters are zero.
|
||||
not exists(getInducingNode()) and
|
||||
not exists(this.getInducingNode()) and
|
||||
result instanceof EmptyLocation
|
||||
}
|
||||
|
||||
@@ -189,7 +191,7 @@ module API {
|
||||
class Use extends Node, Impl::MkUse {
|
||||
override string toString() {
|
||||
exists(string type | type = "Use " |
|
||||
result = type + getPath()
|
||||
result = type + this.getPath()
|
||||
or
|
||||
not exists(this.getPath()) and result = type + "with no path"
|
||||
)
|
||||
|
||||
@@ -184,9 +184,9 @@ class UnlessExpr extends ConditionalExpr, TUnlessExpr {
|
||||
final Stmt getElse() { toGenerated(result) = g.getAlternative() }
|
||||
|
||||
final override Expr getBranch(boolean cond) {
|
||||
cond = false and result = getThen()
|
||||
cond = false and result = this.getThen()
|
||||
or
|
||||
cond = true and result = getElse()
|
||||
cond = true and result = this.getElse()
|
||||
}
|
||||
|
||||
final override string toString() { result = "unless ..." }
|
||||
@@ -292,9 +292,9 @@ class TernaryIfExpr extends ConditionalExpr, TTernaryIfExpr {
|
||||
final Stmt getElse() { toGenerated(result) = g.getAlternative() }
|
||||
|
||||
final override Stmt getBranch(boolean cond) {
|
||||
cond = true and result = getThen()
|
||||
cond = true and result = this.getThen()
|
||||
or
|
||||
cond = false and result = getElse()
|
||||
cond = false and result = this.getElse()
|
||||
}
|
||||
|
||||
final override string toString() { result = "... ? ... : ..." }
|
||||
@@ -349,10 +349,10 @@ class CaseExpr extends ControlExpr, TCaseExpr {
|
||||
final Expr getABranch() { result = this.getBranch(_) }
|
||||
|
||||
/** Gets a `when` branch of this case expression. */
|
||||
final WhenExpr getAWhenBranch() { result = getABranch() }
|
||||
final WhenExpr getAWhenBranch() { result = this.getABranch() }
|
||||
|
||||
/** Gets the `else` branch of this case expression, if any. */
|
||||
final StmtSequence getElseBranch() { result = getABranch() }
|
||||
final StmtSequence getElseBranch() { result = this.getABranch() }
|
||||
|
||||
/**
|
||||
* Gets the number of branches of this case expression.
|
||||
|
||||
@@ -183,7 +183,7 @@ class BodyStmt extends StmtSequence, TBodyStmt {
|
||||
/** Gets the `n`th rescue clause in this block. */
|
||||
final RescueClause getRescue(int n) {
|
||||
result =
|
||||
rank[n + 1](RescueClause node, int i | toGenerated(node) = getChild(i) | node order by i)
|
||||
rank[n + 1](RescueClause node, int i | toGenerated(node) = this.getChild(i) | node order by i)
|
||||
}
|
||||
|
||||
/** Gets a rescue clause in this block. */
|
||||
|
||||
@@ -631,7 +631,7 @@ class HereDoc extends StringlikeLiteral, THereDoc {
|
||||
* COMMAND
|
||||
* ```
|
||||
*/
|
||||
final predicate isSubShell() { getQuoteStyle() = "`" }
|
||||
final predicate isSubShell() { this.getQuoteStyle() = "`" }
|
||||
|
||||
/**
|
||||
* Gets the quotation mark (`"`, `'` or `` ` ``) that surrounds the here document identifier, if any.
|
||||
|
||||
@@ -125,7 +125,7 @@ class Toplevel extends ModuleBase, TToplevel {
|
||||
/**
|
||||
* Gets a `BEGIN` block.
|
||||
*/
|
||||
final BeginBlock getABeginBlock() { result = getBeginBlock(_) }
|
||||
final BeginBlock getABeginBlock() { result = this.getBeginBlock(_) }
|
||||
|
||||
final override AstNode getAChild(string pred) {
|
||||
result = super.getAChild(pred)
|
||||
|
||||
@@ -453,9 +453,9 @@ class Assignment extends Operation instanceof AssignmentImpl {
|
||||
override AstNode getAChild(string pred) {
|
||||
result = Operation.super.getAChild(pred)
|
||||
or
|
||||
pred = "getLeftOperand" and result = getLeftOperand()
|
||||
pred = "getLeftOperand" and result = this.getLeftOperand()
|
||||
or
|
||||
pred = "getRightOperand" and result = getRightOperand()
|
||||
pred = "getRightOperand" and result = this.getRightOperand()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,5 +92,5 @@ class TuplePattern extends Pattern, TTuplePattern {
|
||||
|
||||
override string toString() { result = "(..., ...)" }
|
||||
|
||||
override AstNode getAChild(string pred) { pred = "getElement" and result = getElement(_) }
|
||||
override AstNode getAChild(string pred) { pred = "getElement" and result = this.getElement(_) }
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class UndefStmt extends Stmt, TUndefStmt {
|
||||
final MethodName getMethodName(int n) { toGenerated(result) = g.getChild(n) }
|
||||
|
||||
/** Gets a method name to undefine. */
|
||||
final MethodName getAMethodName() { result = getMethodName(_) }
|
||||
final MethodName getAMethodName() { result = this.getMethodName(_) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "UndefStmt" }
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ class BasicBlock extends TBasicBlockStart {
|
||||
*/
|
||||
predicate inDominanceFrontier(BasicBlock df) {
|
||||
this.dominatesPredecessor(df) and
|
||||
not strictlyDominates(df)
|
||||
not this.strictlyDominates(df)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,7 +373,7 @@ private module JoinBlockPredecessors {
|
||||
|
||||
/** A basic block with more than one predecessor. */
|
||||
class JoinBlock extends BasicBlock {
|
||||
JoinBlock() { getFirstNode().isJoin() }
|
||||
JoinBlock() { this.getFirstNode().isJoin() }
|
||||
|
||||
/**
|
||||
* Gets the `i`th predecessor of this join block, with respect to some
|
||||
|
||||
@@ -98,7 +98,7 @@ module SuccessorTypes {
|
||||
/** Gets the Boolean value of this successor. */
|
||||
final boolean getValue() { result = value }
|
||||
|
||||
override string toString() { result = getValue().toString() }
|
||||
override string toString() { result = this.getValue().toString() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -241,7 +241,7 @@ module Trees {
|
||||
c instanceof NormalCompletion
|
||||
or
|
||||
// Flow into `ensure` block
|
||||
pred = getAnEnsurePredecessor(c, true) and
|
||||
pred = this.getAnEnsurePredecessor(c, true) and
|
||||
first(this.getEnsure(), succ)
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ module EnsureSplitting {
|
||||
*/
|
||||
private predicate exit(Trees::BodyStmtTree block, AstNode pred, Completion c, boolean inherited) {
|
||||
exists(EnsureSplitType type |
|
||||
exit0(pred, block, this.getNestLevel(), c) and
|
||||
this.exit0(pred, block, this.getNestLevel(), c) and
|
||||
type = this.getType()
|
||||
|
|
||||
if last(block.getEnsure(), pred, c)
|
||||
@@ -303,18 +303,18 @@ module EnsureSplitting {
|
||||
override predicate hasExit(AstNode pred, AstNode succ, Completion c) {
|
||||
succ(pred, succ, c) and
|
||||
(
|
||||
exit(_, pred, c, _)
|
||||
this.exit(_, pred, c, _)
|
||||
or
|
||||
exit(_, pred, c.(NestedBreakCompletion).getAnInnerCompatibleCompletion(), _)
|
||||
this.exit(_, pred, c.(NestedBreakCompletion).getAnInnerCompatibleCompletion(), _)
|
||||
)
|
||||
}
|
||||
|
||||
override predicate hasExitScope(CfgScope scope, AstNode last, Completion c) {
|
||||
succExit(scope, last, c) and
|
||||
(
|
||||
exit(_, last, c, _)
|
||||
this.exit(_, last, c, _)
|
||||
or
|
||||
exit(_, last, c.(NestedBreakCompletion).getAnInnerCompatibleCompletion(), _)
|
||||
this.exit(_, last, c.(NestedBreakCompletion).getAnInnerCompatibleCompletion(), _)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -373,15 +373,15 @@ private module ParameterNodes {
|
||||
override CfgScope getCfgScope() { result = method }
|
||||
|
||||
override Location getLocationImpl() {
|
||||
result = getParameter().getLocation()
|
||||
result = this.getParameter().getLocation()
|
||||
or
|
||||
not exists(getParameter()) and result = method.getLocation()
|
||||
not exists(this.getParameter()) and result = method.getLocation()
|
||||
}
|
||||
|
||||
override string toStringImpl() {
|
||||
result = getParameter().toString()
|
||||
result = this.getParameter().toString()
|
||||
or
|
||||
not exists(getParameter()) and result = "&block"
|
||||
not exists(this.getParameter()) and result = "&block"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class Node extends TNode {
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,7 +126,7 @@ class SubshellLiteralExecution extends SystemCommandExecution::Range {
|
||||
|
||||
override DataFlow::Node getAnArgument() { result.asExpr().getExpr() = literal.getComponent(_) }
|
||||
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) { arg = getAnArgument() }
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) { arg = this.getAnArgument() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ class SubshellHeredocExecution extends SystemCommandExecution::Range {
|
||||
|
||||
override DataFlow::Node getAnArgument() { result.asExpr().getExpr() = heredoc.getComponent(_) }
|
||||
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) { arg = getAnArgument() }
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) { arg = this.getAnArgument() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +182,7 @@ class KernelSystemCall extends SystemCommandExecution::Range, KernelMethodCall {
|
||||
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) {
|
||||
// Kernel.system invokes a subshell if you provide a single string as argument
|
||||
this.getNumberOfArguments() = 1 and arg = getAnArgument()
|
||||
this.getNumberOfArguments() = 1 and arg = this.getAnArgument()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ class KernelExecCall extends SystemCommandExecution::Range, KernelMethodCall {
|
||||
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) {
|
||||
// Kernel.exec invokes a subshell if you provide a single string as argument
|
||||
this.getNumberOfArguments() = 1 and arg = getAnArgument()
|
||||
this.getNumberOfArguments() = 1 and arg = this.getAnArgument()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ class KernelSpawnCall extends SystemCommandExecution::Range, KernelMethodCall {
|
||||
|
||||
override predicate isShellInterpreted(DataFlow::Node arg) {
|
||||
// Kernel.spawn invokes a subshell if you provide a single string as argument
|
||||
this.getNumberOfArguments() = 1 and arg = getAnArgument()
|
||||
this.getNumberOfArguments() = 1 and arg = this.getAnArgument()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ private newtype TFeature =
|
||||
class Feature extends TFeature {
|
||||
abstract int getValue();
|
||||
|
||||
string toString() { result = getConstantName() }
|
||||
string toString() { result = this.getConstantName() }
|
||||
|
||||
abstract string getConstantName();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class PrintAstNode extends TPrintNode {
|
||||
PrintAstNode getChild(string edgeName) { none() }
|
||||
|
||||
/** Gets a child of this node. */
|
||||
final PrintAstNode getAChild() { result = getChild(_) }
|
||||
final PrintAstNode getAChild() { result = this.getChild(_) }
|
||||
|
||||
/** Gets the parent of this node, if any. */
|
||||
final PrintAstNode getParent() { result.getAChild() = this }
|
||||
|
||||
@@ -229,8 +229,8 @@ class RegExp extends AST::RegExpLiteral {
|
||||
|
||||
/** Matches named character properties such as `\p{Word}` and `[[:digit:]]` */
|
||||
predicate namedCharacterProperty(int start, int end, string name) {
|
||||
pStyleNamedCharacterProperty(start, end, name) or
|
||||
posixStyleNamedCharacterProperty(start, end, name)
|
||||
this.pStyleNamedCharacterProperty(start, end, name) or
|
||||
this.posixStyleNamedCharacterProperty(start, end, name)
|
||||
}
|
||||
|
||||
/** Gets the name of the character property in start,end */
|
||||
|
||||
@@ -143,7 +143,7 @@ class RegExpRoot extends RegExpTerm {
|
||||
// there are no lookbehinds
|
||||
not exists(RegExpLookbehind lbh | getRoot(lbh) = this) and
|
||||
// is actually used as a RegExp
|
||||
isUsedAsRegExp() //and
|
||||
this.isUsedAsRegExp() //and
|
||||
// // pragmatic performance optimization: ignore minified files.
|
||||
// not getRootTerm().getParent().(Expr).getTopLevel().isMinified()
|
||||
}
|
||||
@@ -277,7 +277,7 @@ abstract private class CharacterClass extends InputSymbol {
|
||||
/**
|
||||
* Gets a character matched by this character class.
|
||||
*/
|
||||
string choose() { result = getARelevantChar() and matches(result) }
|
||||
string choose() { result = this.getARelevantChar() and this.matches(result) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,9 +12,9 @@ class RegExpParent extends TRegExpParent {
|
||||
|
||||
RegExpTerm getChild(int i) { none() }
|
||||
|
||||
RegExpTerm getAChild() { result = getChild(_) }
|
||||
RegExpTerm getAChild() { result = this.getChild(_) }
|
||||
|
||||
int getNumChild() { result = count(getAChild()) }
|
||||
int getNumChild() { result = count(this.getAChild()) }
|
||||
|
||||
/**
|
||||
* Gets the name of a primary CodeQL class to which this regular
|
||||
@@ -72,7 +72,7 @@ class RegExpTerm extends RegExpParent {
|
||||
RegExpTerm getRootTerm() {
|
||||
this.isRootTerm() and result = this
|
||||
or
|
||||
result = getParent().(RegExpTerm).getRootTerm()
|
||||
result = this.getParent().(RegExpTerm).getRootTerm()
|
||||
}
|
||||
|
||||
predicate isUsedAsRegExp() { any() }
|
||||
@@ -137,7 +137,7 @@ class RegExpTerm extends RegExpParent {
|
||||
|
||||
/** Gets the regular expression term that is matched (textually) before this one, if any. */
|
||||
RegExpTerm getPredecessor() {
|
||||
exists(RegExpTerm parent | parent = getParent() |
|
||||
exists(RegExpTerm parent | parent = this.getParent() |
|
||||
result = parent.(RegExpSequence).previousElement(this)
|
||||
or
|
||||
not exists(parent.(RegExpSequence).previousElement(this)) and
|
||||
@@ -148,7 +148,7 @@ class RegExpTerm extends RegExpParent {
|
||||
|
||||
/** Gets the regular expression term that is matched (textually) after this one, if any. */
|
||||
RegExpTerm getSuccessor() {
|
||||
exists(RegExpTerm parent | parent = getParent() |
|
||||
exists(RegExpTerm parent | parent = this.getParent() |
|
||||
result = parent.(RegExpSequence).nextElement(this)
|
||||
or
|
||||
not exists(parent.(RegExpSequence).nextElement(this)) and
|
||||
@@ -255,7 +255,7 @@ class RegExpSequence extends RegExpTerm, TRegExpSequence {
|
||||
override RegExpTerm getChild(int i) { result = seqChild(re, start, end, i) }
|
||||
|
||||
/** Gets the element preceding `element` in this sequence. */
|
||||
RegExpTerm previousElement(RegExpTerm element) { element = nextElement(result) }
|
||||
RegExpTerm previousElement(RegExpTerm element) { element = this.nextElement(result) }
|
||||
|
||||
/** Gets the element following `element` in this sequence. */
|
||||
RegExpTerm nextElement(RegExpTerm element) {
|
||||
@@ -335,8 +335,8 @@ class RegExpEscape extends RegExpNormalChar {
|
||||
or
|
||||
this.getUnescaped() = "t" and result = "\t"
|
||||
or
|
||||
isUnicode() and
|
||||
result = getUnicode()
|
||||
this.isUnicode() and
|
||||
result = this.getUnicode()
|
||||
}
|
||||
|
||||
predicate isIdentityEscape() { not this.getUnescaped() in ["n", "r", "t"] }
|
||||
@@ -349,14 +349,14 @@ class RegExpEscape extends RegExpNormalChar {
|
||||
/**
|
||||
* Holds if this is a unicode escape.
|
||||
*/
|
||||
private predicate isUnicode() { getText().prefix(2) = ["\\u", "\\U"] }
|
||||
private predicate isUnicode() { this.getText().prefix(2) = ["\\u", "\\U"] }
|
||||
|
||||
/**
|
||||
* Gets the unicode char for this escape.
|
||||
* E.g. for `\u0061` this returns "a".
|
||||
*/
|
||||
private string getUnicode() {
|
||||
exists(int codepoint | codepoint = sum(getHexValueFromUnicode(_)) |
|
||||
exists(int codepoint | codepoint = sum(this.getHexValueFromUnicode(_)) |
|
||||
result = codepoint.toUnicode()
|
||||
)
|
||||
}
|
||||
@@ -366,8 +366,8 @@ class RegExpEscape extends RegExpNormalChar {
|
||||
* E.g. for `\u0061` and `index = 2` this returns 96 (the number `6` interpreted as hex).
|
||||
*/
|
||||
private int getHexValueFromUnicode(int index) {
|
||||
isUnicode() and
|
||||
exists(string hex, string char | hex = getText().suffix(2) |
|
||||
this.isUnicode() and
|
||||
exists(string hex, string char | hex = this.getText().suffix(2) |
|
||||
char = hex.charAt(index) and
|
||||
result = 16.pow(hex.length() - index - 1) * toHex(char)
|
||||
)
|
||||
@@ -436,13 +436,13 @@ class RegExpCharacterClass extends RegExpTerm, TRegExpCharacterClass {
|
||||
|
||||
predicate isUniversalClass() {
|
||||
// [^]
|
||||
isInverted() and not exists(getAChild())
|
||||
this.isInverted() and not exists(this.getAChild())
|
||||
or
|
||||
// [\w\W] and similar
|
||||
not isInverted() and
|
||||
not this.isInverted() and
|
||||
exists(string cce1, string cce2 |
|
||||
cce1 = getAChild().(RegExpCharacterClassEscape).getValue() and
|
||||
cce2 = getAChild().(RegExpCharacterClassEscape).getValue()
|
||||
cce1 = this.getAChild().(RegExpCharacterClassEscape).getValue() and
|
||||
cce2 = this.getAChild().(RegExpCharacterClassEscape).getValue()
|
||||
|
|
||||
cce1 != cce2 and cce1.toLowerCase() = cce2.toLowerCase()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user