|
| 1 | +/** |
| 2 | + * @name Unextracted Elements |
| 3 | + * @description List all elements that weren't extracted due to unimplemented features or parse errors. |
| 4 | + * @id rust/diagnostics/unextracted-elements |
| 5 | + */ |
| 6 | + |
| 7 | +import rust |
| 8 | + |
| 9 | +/** |
| 10 | + * Gets a location for an `Unimplemented` node. |
| 11 | + */ |
| 12 | +Location getUnimplementedLocation(Unimplemented node) { |
| 13 | + result = node.(Locatable).getLocation() |
| 14 | + or |
| 15 | + not node instanceof Locatable and |
| 16 | + result instanceof EmptyLocation |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * Gets `l.toString()`, but with any locations outside of the source location prefix cleaned up. |
| 21 | + */ |
| 22 | +bindingset[l] |
| 23 | +string cleanLocationString(Location l) { |
| 24 | + if exists(l.getFile().getRelativePath()) or l instanceof EmptyLocation |
| 25 | + then result = l.toString() |
| 26 | + else l.getFile().getParentContainer().getAbsolutePath() + result = l.toString() // remove the directory from the string |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Gets a string along the lines of " (x2)", corresponding to the number `i`. For `i = 1`, the result is the empty string. |
| 31 | + */ |
| 32 | +bindingset[i] |
| 33 | +string multipleString(int i) { |
| 34 | + i = 1 and result = "" |
| 35 | + or |
| 36 | + i > 1 and result = " (x" + i.toString() + ")" |
| 37 | +} |
| 38 | + |
| 39 | +query predicate listUnimplemented(string location, string msg) { |
| 40 | + // something that is not extracted yet |
| 41 | + exists(int c | |
| 42 | + c = strictcount(Unimplemented n | cleanLocationString(getUnimplementedLocation(n)) = location) and |
| 43 | + msg = "Not yet implemented" + multipleString(c) + "." |
| 44 | + ) |
| 45 | +} |
| 46 | + |
| 47 | +query predicate listMissingExpr(string location, string msg) { |
| 48 | + // gaps in the AST due to parse errors |
| 49 | + exists(int c | |
| 50 | + c = strictcount(MissingExpr e | cleanLocationString(e.getLocation()) = location) and |
| 51 | + msg = "Missing expression" + multipleString(c) + "." |
| 52 | + ) |
| 53 | +} |
| 54 | + |
| 55 | +query predicate listMissingPat(string location, string msg) { |
| 56 | + // gaps in the AST due to parse errors |
| 57 | + exists(int c | |
| 58 | + c = strictcount(MissingPat p | cleanLocationString(p.getLocation()) = location) and |
| 59 | + msg = "Missing pattern" + multipleString(c) + "." |
| 60 | + ) |
| 61 | +} |
0 commit comments