Address review comment

This commit is contained in:
Tom Hvitved
2024-03-13 20:03:01 +01:00
parent 16cef92106
commit 54fa8181da
4 changed files with 32 additions and 102 deletions

View File

@@ -488,6 +488,14 @@ class SsaDefinition extends TSsaDefinition {
string filepath, int startline, int startcolumn, int endline, int endcolumn
);
/** Gets the location of this element. */
final Location getLocation() {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
)
}
/** Gets the function or toplevel to which this definition belongs. */
StmtContainer getContainer() { result = this.getBasicBlock().getContainer() }
}

View File

@@ -145,20 +145,15 @@ module DataFlow {
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
cached
predicate hasLocationInfo(
final predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
none()
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
/** Gets the location of this node. */
Location getLocation() {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
)
}
cached
Location getLocation() { none() }
/** Gets the file this data flow node comes from. */
File getFile() { none() } // overridden in subclasses
@@ -300,11 +295,9 @@ module DataFlow {
override BasicBlock getBasicBlock() { astNode = result.getANode() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
override Location getLocation() {
Stages::DataFlowStage::ref() and
astNode.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
result = astNode.getLocation()
}
override File getFile() { result = astNode.getFile() }
@@ -325,11 +318,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = ssa.getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
ssa.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = ssa.getLocation() }
override string toString() { result = ssa.getSourceVariable().getName() }
@@ -348,13 +337,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = prop.(ControlFlowNode).getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
prop.(Locatable)
.getLocation()
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = prop.(Locatable).getLocation() }
override string toString() { result = prop.(AstNode).toString() }
@@ -375,11 +358,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = rest.getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
rest.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = rest.getLocation() }
override string toString() { result = "..." + rest.toString() }
@@ -400,11 +379,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = elt.getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
elt.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = elt.getLocation() }
override string toString() { result = elt.toString() }
@@ -429,11 +404,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = elt.getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
elt.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = elt.getLocation() }
override string toString() { result = elt.toString() }
@@ -453,11 +424,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = call.getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
call.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = call.getLocation() }
override string toString() { result = "reflective call" }
@@ -474,11 +441,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = imprt.getBasicBlock() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
imprt.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = imprt.getLocation() }
override string toString() { result = imprt.toString() }
@@ -968,11 +931,7 @@ module DataFlow {
override string toString() { result = attr.toString() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
attr.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = attr.getLocation() }
/** Gets the attribute corresponding to this data flow node. */
HTML::Attribute getAttribute() { result = attr }
@@ -990,11 +949,7 @@ module DataFlow {
override string toString() { result = attr.toString() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
attr.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = attr.getLocation() }
/** Gets the attribute corresponding to this data flow node. */
XmlAttribute getAttribute() { result = attr }
@@ -1012,11 +967,7 @@ module DataFlow {
override string toString() { result = "exceptional return of " + function.describe() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
function.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = function.getLocation() }
override BasicBlock getBasicBlock() { result = function.getExit().getBasicBlock() }
@@ -1038,11 +989,7 @@ module DataFlow {
override string toString() { result = "return of " + function.describe() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
function.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = function.getLocation() }
override BasicBlock getBasicBlock() { result = function.getExit().getBasicBlock() }
@@ -1064,11 +1011,7 @@ module DataFlow {
override string toString() { result = "'arguments' object of " + function.describe() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
function.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = function.getLocation() }
override BasicBlock getBasicBlock() { result = function.getEntry().getBasicBlock() }
@@ -1090,11 +1033,7 @@ module DataFlow {
override string toString() { result = "exceptional return of " + invoke.toString() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
invoke.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = invoke.getLocation() }
override BasicBlock getBasicBlock() { result = invoke.getBasicBlock() }
@@ -1366,15 +1305,10 @@ module DataFlow {
exists(StmtContainer container | this = TThisNode(container) | result = container.getEntry())
}
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
override Location getLocation() {
// Use the function entry as the location
exists(StmtContainer container | this = TThisNode(container) |
container
.getEntry()
.getLocation()
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
result = container.getEntry().getLocation()
)
}
@@ -1393,11 +1327,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { result = variable.getDeclaringContainer().getStartBB() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
variable.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = variable.getLocation() }
override string toString() { result = variable.getName() }
}
@@ -1409,13 +1339,7 @@ module DataFlow {
override BasicBlock getBasicBlock() { none() }
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.getTag()
.getLocation()
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
override Location getLocation() { result = this.getTag().getLocation() }
override string toString() { result = this.getTag().toString() }
}

View File

@@ -136,8 +136,6 @@ module Stages {
or
exists(DataFlow::ssaDefinitionNode(_))
or
any(DataFlow::Node node).hasLocationInfo(_, _, _, _, _)
or
exists(any(DataFlow::Node node).getLocation())
or
exists(any(DataFlow::Node node).toString())

View File

@@ -9,7 +9,7 @@ import javascript
newtype TLocation =
TDbLocation(@location loc) or
TSynthLocation(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
any(DataFlow::Node n).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
any(SsaDefinition def).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
// avoid overlap with existing DB locations
not exists(File f |
locations_default(_, f, startline, startcolumn, endline, endcolumn) and