Skip to content

Commit

Permalink
Revert "Rust: remove queries that no longer work"
Browse files Browse the repository at this point in the history
This reverts commit e19bca0.
  • Loading branch information
geoffw0 committed Sep 25, 2024
1 parent cc63abf commit 8f1c1a8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
61 changes: 61 additions & 0 deletions rust/ql/src/queries/diagnostics/UnextractedElements.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @name Unextracted Elements
* @description List all elements that weren't extracted due to unimplemented features or parse errors.
* @id rust/diagnostics/unextracted-elements
*/

import rust

/**
* Gets a location for an `Unimplemented` node.
*/
Location getUnimplementedLocation(Unimplemented node) {
result = node.(Locatable).getLocation()
or
not node instanceof Locatable and
result instanceof EmptyLocation
}

/**
* Gets `l.toString()`, but with any locations outside of the source location prefix cleaned up.
*/
bindingset[l]
string cleanLocationString(Location l) {
if exists(l.getFile().getRelativePath()) or l instanceof EmptyLocation
then result = l.toString()
else l.getFile().getParentContainer().getAbsolutePath() + result = l.toString() // remove the directory from the string
}

/**
* Gets a string along the lines of " (x2)", corresponding to the number `i`. For `i = 1`, the result is the empty string.
*/
bindingset[i]
string multipleString(int i) {
i = 1 and result = ""
or
i > 1 and result = " (x" + i.toString() + ")"
}

query predicate listUnimplemented(string location, string msg) {
// something that is not extracted yet
exists(int c |
c = strictcount(Unimplemented n | cleanLocationString(getUnimplementedLocation(n)) = location) and
msg = "Not yet implemented" + multipleString(c) + "."
)
}

query predicate listMissingExpr(string location, string msg) {
// gaps in the AST due to parse errors
exists(int c |
c = strictcount(MissingExpr e | cleanLocationString(e.getLocation()) = location) and
msg = "Missing expression" + multipleString(c) + "."
)
}

query predicate listMissingPat(string location, string msg) {
// gaps in the AST due to parse errors
exists(int c |
c = strictcount(MissingPat p | cleanLocationString(p.getLocation()) = location) and
msg = "Missing pattern" + multipleString(c) + "."
)
}
16 changes: 16 additions & 0 deletions rust/ql/test/query-tests/diagnostics/UnextractedElements.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
listUnimplemented
| @0:0:0:0 | Not yet implemented (x14). |
| does_not_compile.rs@2:2:2:5 | Not yet implemented. |
| does_not_compile.rs@2:7:2:8 | Not yet implemented. |
| does_not_compile.rs@2:10:2:12 | Not yet implemented. |
| does_not_compile.rs@2:14:2:20 | Not yet implemented. |
| does_not_compile.rs@2:22:2:25 | Not yet implemented. |
| does_not_compile.rs@2:27:2:30 | Not yet implemented. |
| main.rs@16:5:16:22 | Not yet implemented. |
| main.rs@17:5:17:21 | Not yet implemented. |
| my_struct.rs@2:1:13:1 | Not yet implemented. |
| my_struct.rs@24:9:27:9 | Not yet implemented. |
| my_struct.rs@25:19:25:30 | Not yet implemented. |
| my_struct.rs@29:5:29:5 | Not yet implemented. |
listMissingExpr
listMissingPat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
queries/diagnostics/UnextractedElements.ql

0 comments on commit 8f1c1a8

Please sign in to comment.