From b2d0c60a0203b2004a08eece9b51b44c9ed0780b Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Thu, 16 Sep 2021 14:49:36 +0200 Subject: [PATCH] Replace `hasLocationInfo` with `getLocation` in `API::Node` --- ql/lib/codeql/Locations.qll | 5 +++++ ql/lib/codeql/ruby/ApiGraphs.qll | 20 ++++---------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ql/lib/codeql/Locations.qll b/ql/lib/codeql/Locations.qll index 89b01951f05..98aa1a980b6 100644 --- a/ql/lib/codeql/Locations.qll +++ b/ql/lib/codeql/Locations.qll @@ -59,3 +59,8 @@ class Location extends @location { this.getStartLine() = other.getStartLine() and this.getStartColumn() < other.getStartColumn() } } + +/** An entity representing an empty location. */ +class EmptyLocation extends Location { + EmptyLocation() { this.hasLocationInfo("", 0, 0, 0, 0) } +} diff --git a/ql/lib/codeql/ruby/ApiGraphs.qll b/ql/lib/codeql/ruby/ApiGraphs.qll index 16b92747b56..4645879d55a 100644 --- a/ql/lib/codeql/ruby/ApiGraphs.qll +++ b/ql/lib/codeql/ruby/ApiGraphs.qll @@ -140,26 +140,14 @@ module API { */ DataFlow::Node getInducingNode() { this = Impl::MkUse(result) } - /** - * Holds if this element is at the specified location. - * The location spans column `startcolumn` of line `startline` to - * column `endcolumn` of line `endline` in file `filepath`. - * For more information, see - * [Locations](https://help.semmle.com/QL/learn-ql/locations.html). - */ - predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - getInducingNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + /** Gets the location of this node. */ + Location getLocation() { + result = this.getInducingNode().getLocation() 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 - filepath = "" and - startline = 0 and - startcolumn = 0 and - endline = 0 and - endcolumn = 0 + result instanceof EmptyLocation } /**