Skip to content

Commit 36f54cc

Browse files
committed
Rust: Clean up the query output.
1 parent 57eafb8 commit 36f54cc

File tree

2 files changed

+1743
-8046
lines changed

2 files changed

+1743
-8046
lines changed
Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
11
/**
22
* @name Missing Elements
33
* @description List all elements that weren't extracted due to unimplemented features or parse errors.
4-
* @kind diagnostic
54
* @id rust/diagnostics/missing-elements
65
*/
76

87
import rust
98

10-
query predicate listUnimplemented(AstNode n, string msg) {
11-
// not extracted yet
12-
n instanceof Unimplemented and
13-
msg = "Not yet implemented."
9+
/**
10+
* Gets `l.toString()`, but with any locations outside of the source location prefix cleaned up.
11+
*/
12+
bindingset[l]
13+
string cleanLocationString(Location l) {
14+
if exists(l.getFile().getRelativePath()) or l instanceof EmptyLocation
15+
then result = l.toString()
16+
else l.getFile().getParentContainer().getAbsolutePath() + result = l.toString() // remove the directory from the string
17+
}
18+
19+
/**
20+
* Gets a string along the lines of " (x2)", corresponding to the number `i`. For `i = 1`, the result is the empty string.
21+
*/
22+
bindingset[i]
23+
string multipleString(int i) {
24+
i = 1 and result = ""
25+
or
26+
i > 1 and result = " (x" + i.toString() + ")"
27+
}
28+
29+
query predicate listUnimplemented(string location, string msg) {
30+
// something that is not extracted yet
31+
exists(int c |
32+
c = strictcount(Unimplemented n | cleanLocationString(n.getLocation()) = location) and
33+
msg = "Not yet implemented" + multipleString(c) + "."
34+
)
1435
}
1536

16-
query predicate listMissingExpr(Expr e, string msg) {
37+
query predicate listMissingExpr(string location, string msg) {
1738
// gaps in the AST due to parse errors
18-
e instanceof MissingExpr and
19-
msg = "Missing expression."
39+
exists(int c |
40+
c = strictcount(MissingExpr e | cleanLocationString(e.getLocation()) = location) and
41+
msg = "Missing expression" + multipleString(c) + "."
42+
)
2043
}
2144

22-
query predicate listMissingPat(Pat p, string msg) {
45+
query predicate listMissingPat(string location, string msg) {
2346
// gaps in the AST due to parse errors
24-
p instanceof MissingPat and
25-
msg = "Missing pattern."
47+
exists(int c |
48+
c = strictcount(MissingPat p | cleanLocationString(p.getLocation()) = location) and
49+
msg = "Missing pattern" + multipleString(c) + "."
50+
)
2651
}

0 commit comments

Comments
 (0)