make strictlyBefore a member predicate on Location

This commit is contained in:
Alex Ford
2021-08-31 16:24:32 +01:00
parent d84731bcc7
commit df9e0dfcb2
3 changed files with 10 additions and 11 deletions

View File

@@ -50,12 +50,11 @@ class Location extends @location {
filepath = f.getAbsolutePath()
)
}
}
/** Holds if location `one` starts strictly before location `two` */
pragma[inline]
predicate strictlyBefore(Location one, Location two) {
one.getStartLine() < two.getStartLine()
or
one.getStartLine() = two.getStartLine() and one.getStartColumn() < two.getStartColumn()
}
/** Holds if this location starts strictly before the specified location. */
predicate strictlyBefore(Location other) {
this.getStartLine() < other.getStartLine()
or
this.getStartLine() = other.getStartLine() and this.getStartColumn() < other.getStartColumn()
}
}

View File

@@ -143,7 +143,7 @@ class ErbDirective extends TDirectiveNode, ErbAstNode {
Stmt getTerminalStmt() {
result = this.getAChildStmt() and
forall(Stmt s | s = this.getAChildStmt() and not s = result |
strictlyBefore(s.getLocation(), result.getLocation())
s.getLocation().strictlyBefore(result.getLocation())
)
}

View File

@@ -288,7 +288,7 @@ private module Cached {
name = access.getValue()
|
variable.getDeclaringScope() = scopeOf(access) and
not strictlyBefore(access.getLocation(), variable.getLocation()) and
not access.getLocation().strictlyBefore(variable.getLocation()) and
// In case of overlapping parameter names, later parameters should not
// be considered accesses to the first parameter
if parameterAssignment(_, _, access)
@@ -358,7 +358,7 @@ private predicate inherits(Scope::Range scope, string name, Scope::Range outer)
or
exists(Ruby::Identifier i |
scopeAssigns(outer, name, i) and
strictlyBefore(i.getLocation(), scope.getLocation())
i.getLocation().strictlyBefore(scope.getLocation())
)
)
or