@@ -25,40 +25,37 @@ class Top extends Element {
2525 * For more information, see
2626 * [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
2727 */
28+ pragma [ noopt]
29+ final
2830 predicate hasLocationInfo ( string filepath ,
2931 int startline , int startcolumn ,
3032 int endline , int endcolumn ) {
31- exists ( Location l | l = this .getLocation ( )
32- and filepath = l .getFile ( ) .getAbsolutePath ( )
33- and startline = l .getStartLine ( )
34- and startcolumn = l .getStartColumn ( )
35- and endline = l .getEndLine ( )
36- and endcolumn = l .getEndColumn ( ) )
37- }
38- }
39-
40- /**
41- * A `MacroAccess` with a `hasLocationInfo` predicate.
42- *
43- * This has a location that covers only the name of the accessed
44- * macro, not its arguments (which are included by `MacroAccess`'s
45- * `getLocation()`).
46- */
47- class MacroAccessWithHasLocationInfo extends Top {
48- MacroAccessWithHasLocationInfo ( ) {
49- this instanceof MacroAccess
50- }
51-
52- override
53- predicate hasLocationInfo ( string path , int sl , int sc , int el , int ec ) {
54- exists ( MacroAccess ma , Location l |
55- ma = this
56- and l = ma .getLocation ( )
57- and path = l .getFile ( ) .getAbsolutePath ( )
58- and sl = l .getStartLine ( )
59- and sc = l .getStartColumn ( )
60- and el = sl
61- and ec = sc + ma .getMacroName ( ) .length ( ) - 1 )
33+ interestingElement ( this ) and
34+ not this instanceof MacroAccess and
35+ not this instanceof Include and
36+ exists ( Location l |
37+ l = this .getLocation ( ) and
38+ l .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
39+ )
40+ or
41+ // This has a location that covers only the name of the accessed
42+ // macro, not its arguments (which are included by `MacroAccess`'s
43+ // `getLocation()`).
44+ exists ( Location l , MacroAccess ma |
45+ ma instanceof MacroAccess and
46+ ma = this and
47+ l = ma .getLocation ( ) and
48+ l .hasLocationInfo ( filepath , startline , startcolumn , _, _) and
49+ endline = startline and
50+ exists ( string macroName , int nameLength , int nameLengthMinusOne |
51+ macroName = ma .getMacroName ( ) and
52+ nameLength = macroName .length ( ) and
53+ nameLengthMinusOne = nameLength - 1 and
54+ endcolumn = startcolumn + nameLengthMinusOne
55+ )
56+ )
57+ or
58+ hasLocationInfo_Include ( this , filepath , startline , startcolumn , endline , endcolumn )
6259 }
6360}
6461
@@ -68,23 +65,22 @@ class MacroAccessWithHasLocationInfo extends Top {
6865 * This has a location that covers only the name of the included
6966 * file, not the `#include` text or whitespace before it.
7067 */
71- class IncludeWithHasLocationInfo extends Top {
72- IncludeWithHasLocationInfo ( ) {
73- this instanceof Include
74- }
68+ predicate hasLocationInfo_Include ( Include i , string path , int sl , int sc , int el , int ec ) {
69+ exists ( Location l |
70+ l = i .getLocation ( ) and
71+ path = l .getFile ( ) .getAbsolutePath ( ) and
72+ sl = l .getEndLine ( ) and
73+ sc = l .getEndColumn ( ) + 1 - i .getIncludeText ( ) .length ( ) and
74+ el = l .getEndLine ( ) and
75+ ec = l .getEndColumn ( )
76+ )
77+ }
7578
76- override
77- predicate hasLocationInfo ( string path , int sl , int sc , int el , int ec ) {
78- exists ( Include i , Location l |
79- i = this and
80- l = i .getLocation ( ) and
81- path = l .getFile ( ) .getAbsolutePath ( ) and
82- sl = l .getEndLine ( ) and
83- sc = l .getEndColumn ( ) + 1 - i .getIncludeText ( ) .length ( ) and
84- el = l .getEndLine ( ) and
85- ec = l .getEndColumn ( )
86- )
87- }
79+ /** Holds if `e` is a source or a target of jump-to-definition. */
80+ predicate interestingElement ( Element e ) {
81+ exists ( definitionOf ( e , _) )
82+ or
83+ e = definitionOf ( _, _)
8884}
8985
9086/**
0 commit comments