Skip to content

Commit 16cef92

Browse files
committed
JS: Add DataFlow::Node.getLocation
1 parent 35a8e7c commit 16cef92

File tree

22 files changed

+235
-97
lines changed

22 files changed

+235
-97
lines changed

config/identical-files.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@
255255
"cpp/ql/lib/semmle/code/cpp/XML.qll",
256256
"csharp/ql/lib/semmle/code/csharp/XML.qll",
257257
"java/ql/lib/semmle/code/xml/XML.qll",
258-
"javascript/ql/lib/semmle/javascript/XML.qll",
259258
"python/ql/lib/semmle/python/xml/XML.qll"
260259
],
261260
"DuplicationProblems.inc.qhelp": [
@@ -372,4 +371,4 @@
372371
"python/ql/test/experimental/dataflow/model-summaries/InlineTaintTest.ext.yml",
373372
"python/ql/test/experimental/dataflow/model-summaries/NormalDataflowTest.ext.yml"
374373
]
375-
}
374+
}

javascript/ql/lib/semmle/javascript/AST.qll

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,27 @@ private import semmle.javascript.internal.CachedStages
2323
* ```
2424
*/
2525
class AstNode extends @ast_node, NodeInStmtContainer {
26-
override Location getLocation() { hasLocation(this, result) }
27-
2826
override File getFile() {
2927
result = this.getLocation().getFile() // Specialized for performance reasons
3028
}
3129

3230
/** Gets the first token belonging to this element. */
3331
Token getFirstToken() {
34-
exists(Location l1, Location l2 |
32+
exists(DbLocation l1, DbLocation l2, string filepath, int startline, int startcolumn |
3533
l1 = this.getLocation() and
3634
l2 = result.getLocation() and
37-
l1.getFile() = l2.getFile() and
38-
l1.getStartLine() = l2.getStartLine() and
39-
l1.getStartColumn() = l2.getStartColumn()
35+
l1.hasLocationInfo(filepath, startline, startcolumn, _, _) and
36+
l2.hasLocationInfo(filepath, startline, startcolumn, _, _)
4037
)
4138
}
4239

4340
/** Gets the last token belonging to this element. */
4441
Token getLastToken() {
45-
exists(Location l1, Location l2 |
42+
exists(DbLocation l1, DbLocation l2, string filepath, int endline, int endcolumn |
4643
l1 = this.getLocation() and
4744
l2 = result.getLocation() and
48-
l1.getFile() = l2.getFile() and
49-
l1.getEndLine() = l2.getEndLine() and
50-
l1.getEndColumn() = l2.getEndColumn()
45+
l1.hasLocationInfo(filepath, _, _, endline, endcolumn) and
46+
l2.hasLocationInfo(filepath, _, _, endline, endcolumn)
5147
) and
5248
// exclude empty EOF token
5349
not result instanceof EOFToken

javascript/ql/lib/semmle/javascript/CFG.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,7 @@ class ControlFlowNode extends @cfg_node, Locatable, NodeInStmtContainer {
356356
* A synthetic CFG node that does not correspond to a statement or expression;
357357
* examples include guard nodes and entry/exit nodes.
358358
*/
359-
class SyntheticControlFlowNode extends @synthetic_cfg_node, ControlFlowNode {
360-
override Location getLocation() { hasLocation(this, result) }
361-
}
359+
class SyntheticControlFlowNode extends @synthetic_cfg_node, ControlFlowNode { }
362360

363361
/** A synthetic CFG node marking the entry point of a function or toplevel script. */
364362
class ControlFlowEntryNode extends SyntheticControlFlowNode, @entry_node {

javascript/ql/lib/semmle/javascript/Comments.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import javascript
1515
* </pre>
1616
*/
1717
class Comment extends @comment, Locatable {
18-
override Location getLocation() { hasLocation(this, result) }
19-
2018
/** Gets the toplevel element this comment belongs to. */
2119
TopLevel getTopLevel() { comments(this, _, result, _, _) }
2220

javascript/ql/lib/semmle/javascript/Errors.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import javascript
44

55
/** An error encountered during extraction. */
66
abstract class Error extends Locatable {
7-
override Location getLocation() { hasLocation(this, result) }
8-
97
/** Gets the message associated with this error. */
108
abstract string getMessage();
119

javascript/ql/lib/semmle/javascript/Files.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import javascript
44
private import NodeModuleResolutionImpl
55
private import codeql.util.FileSystem
6+
private import internal.Locations
67

78
private module FsInput implements InputSig {
89
abstract class ContainerBase extends @container {
@@ -83,7 +84,7 @@ class File extends Container, Impl::File {
8384
*
8485
* Note that files have special locations starting and ending at line zero, column zero.
8586
*/
86-
Location getLocation() { hasLocation(this, result) }
87+
DbLocation getLocation() { result = getLocatableLocation(this) }
8788

8889
/** Gets the number of lines in this file. */
8990
int getNumberOfLines() { result = sum(int loc | numlines(this, loc, _, _) | loc) }

javascript/ql/lib/semmle/javascript/HTML.qll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ module HTML {
4343
class Element extends Locatable, @xmlelement {
4444
Element() { exists(FileContainingHtml f | xmlElements(this, _, _, _, f)) }
4545

46-
override Location getLocation() { xmllocations(this, result) }
47-
4846
/**
4947
* Gets the name of this HTML element.
5048
*
@@ -122,8 +120,6 @@ module HTML {
122120
class Attribute extends Locatable, @xmlattribute {
123121
Attribute() { exists(FileContainingHtml f | xmlAttrs(this, _, _, _, _, f)) }
124122

125-
override Location getLocation() { xmllocations(this, result) }
126-
127123
/**
128124
* Gets the inline script of this attribute, if any.
129125
*/
@@ -326,8 +322,6 @@ module HTML {
326322
* Holds if this text node is inside a `CDATA` tag.
327323
*/
328324
predicate isCData() { xmlChars(this, _, _, _, 1, _) }
329-
330-
override Location getLocation() { xmllocations(this, result) }
331325
}
332326

333327
/**
@@ -349,7 +343,5 @@ module HTML {
349343
string getText() { result = this.toString().regexpCapture("(?s)<!--(.*)-->", 1) }
350344

351345
override string toString() { xmlComments(this, result, _, _) }
352-
353-
override Location getLocation() { xmllocations(this, result) }
354346
}
355347
}

javascript/ql/lib/semmle/javascript/JSDoc.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ private import semmle.javascript.internal.CachedStages
1818
* </pre>
1919
*/
2020
class JSDoc extends @jsdoc, Locatable {
21-
override Location getLocation() { hasLocation(this, result) }
22-
2321
/** Gets the description text of this JSDoc comment. */
2422
string getDescription() { jsdoc(this, result, _) }
2523

@@ -75,8 +73,6 @@ abstract class Documentable extends AstNode {
7573
* ```
7674
*/
7775
class JSDocTypeExprParent extends @jsdoc_type_expr_parent, Locatable {
78-
override Location getLocation() { hasLocation(this, result) }
79-
8076
/** Gets the JSDoc comment to which this element belongs. */
8177
JSDoc getJSDocComment() { none() }
8278
}

javascript/ql/lib/semmle/javascript/JSON.qll

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import javascript
6+
private import semmle.javascript.internal.Locations
67

78
/**
89
* A JSON-encoded value, which may be a primitive value, an array or an object.
@@ -20,8 +21,6 @@ import javascript
2021
* ```
2122
*/
2223
class JsonValue extends @json_value, Locatable {
23-
override Location getLocation() { json_locations(this, result) }
24-
2524
/** Gets the parent value to which this value belongs, if any. */
2625
JsonValue getParent() { json(this, _, result, _, _) }
2726

@@ -34,12 +33,7 @@ class JsonValue extends @json_value, Locatable {
3433
override string toString() { json(this, _, _, _, result) }
3534

3635
/** Gets the JSON file containing this value. */
37-
File getJsonFile() {
38-
exists(Location loc |
39-
json_locations(this, loc) and
40-
result = loc.getFile()
41-
)
42-
}
36+
File getJsonFile() { result = getLocatableLocation(this).getFile() }
4337

4438
/** If this is an object, gets the value of property `name`. */
4539
JsonValue getPropValue(string name) { json_properties(this, name, result) }
@@ -172,7 +166,5 @@ class JsonObject extends @json_object, JsonValue {
172166
* An error reported by the JSON parser.
173167
*/
174168
class JsonParseError extends @json_parse_error, Error {
175-
override Location getLocation() { json_locations(this, result) }
176-
177169
override string getMessage() { json_errors(this, result) }
178170
}

javascript/ql/lib/semmle/javascript/Lines.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import javascript
1414
* extracted with the `--extract-program-text` flag.
1515
*/
1616
class Line extends @line, Locatable {
17-
override Location getLocation() { hasLocation(this, result) }
18-
1917
/** Gets the toplevel element this line belongs to. */
2018
TopLevel getTopLevel() { lines(this, result, _, _) }
2119

0 commit comments

Comments
 (0)