mirror of
https://github.com/github/codeql.git
synced 2026-02-19 16:33:40 +01:00
AST: order edges by target node
When printing a tree CodeQL iterates over the nodes and for each node prints the successor edges as children. If the the successor edges are ordered by target node then the children printe in the right order in the expected output.
This commit is contained in:
@@ -2,9 +2,21 @@
|
||||
* @kind graph
|
||||
*/
|
||||
|
||||
import codeql_ruby.printAst
|
||||
import codeql_ruby.printAst as P
|
||||
|
||||
class OrderedAstNode extends PrintAstNode {
|
||||
query predicate nodes = P::nodes/3;
|
||||
|
||||
query predicate graphProperties = P::graphProperties/2;
|
||||
|
||||
query predicate edges(P::PrintAstNode source, P::PrintAstNode target, string key, string value) {
|
||||
P::edges(source, target, key, value)
|
||||
or
|
||||
P::edges(source, target, _, _) and
|
||||
key = "semmle.order" and
|
||||
value = target.(OrderedAstNode).getProperty("semmle.order")
|
||||
}
|
||||
|
||||
class OrderedAstNode extends P::PrintAstNode {
|
||||
override string getProperty(string key) {
|
||||
result = super.getProperty(key)
|
||||
or
|
||||
@@ -12,12 +24,12 @@ class OrderedAstNode extends PrintAstNode {
|
||||
result =
|
||||
any(int i |
|
||||
this =
|
||||
rank[i](AstNode p |
|
||||
rank[i](P::AstNode p |
|
||||
|
|
||||
p
|
||||
order by
|
||||
p.getLocation().getFile().getBaseName(), p.getLocation().getFile().getAbsolutePath(),
|
||||
p.getLocation().getStartLine()
|
||||
p.getLocation().getStartLine(), p.getLocation().getStartColumn()
|
||||
)
|
||||
).toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user