Skip to content

Commit

Permalink
Rust: PrintAst improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Oct 8, 2024
1 parent 5a4cd1c commit 55458a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 15 additions & 9 deletions rust/ql/lib/codeql/rust/printast/PrintAst.qll
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

import PrintAstNode

pragma[nomagic]
private predicate orderBy(
PrintAstNode n, string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
n.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}

cached
private int getOrder(PrintAstNode node) {
node =
rank[result](PrintAstNode n, Location loc |
loc = n.getLocation()
|
n
order by
loc.getFile().getAbsolutePath(), loc.getStartLine(), loc.getStartColumn(), loc.getEndLine(),
loc.getEndColumn()
)
exists(string filepath |
node =
rank[result](PrintAstNode n, int startline, int startcolumn, int endline, int endcolumn |
orderBy(n, filepath, startline, startcolumn, endline, endcolumn)
|
n order by startline, startcolumn, endline, endcolumn
)
)
}

/** Holds if `node` belongs to the output tree, and its property `key` has the given `value`. */
Expand Down
4 changes: 1 addition & 3 deletions rust/ql/lib/codeql/rust/printast/PrintAstNode.qll
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ class PrintAstNode extends TPrintAstNode {
abstract Locatable getAstNode();
}

private string prettyPrint(Locatable e) {
result = "[" + concat(e.getPrimaryQlClasses(), ", ") + "] " + e
}
private string prettyPrint(Locatable e) { result = "[" + e.getPrimaryQlClasses() + "] " + e }

private class Unresolved extends Locatable {
Unresolved() { this != this.resolve() }
Expand Down

0 comments on commit 55458a5

Please sign in to comment.