Move semmle.order property to printAst.qll

This commit is contained in:
Arthur Baars
2021-03-15 10:27:55 +01:00
parent 3e5ff1d042
commit d54db292f7
2 changed files with 21 additions and 34 deletions

View File

@@ -27,6 +27,19 @@ class PrintAstNode extends AstNode {
string getProperty(string key) {
key = "semmle.label" and
result = "[" + concat(this.getAPrimaryQlClass(), ", ") + "] " + this.toString()
or
key = "semmle.order" and
result =
any(int i |
this =
rank[i](AstNode p |
|
p
order by
p.getLocation().getFile().getBaseName(), p.getLocation().getFile().getAbsolutePath(),
p.getLocation().getStartLine(), p.getLocation().getStartColumn()
)
).toString()
}
/**
@@ -62,9 +75,14 @@ query predicate nodes(PrintAstNode node, string key, string value) {
query predicate edges(PrintAstNode source, PrintAstNode target, string key, string value) {
source.shouldPrint() and
target.shouldPrint() and
key = "semmle.label" and
target = source.getAChild() and
value = concat(string name | source.getChild(name) = target | name, "/")
(
key = "semmle.label" and
value = concat(string name | source.getChild(name) = target | name, "/")
or
key = "semmle.order" and
value = target.getProperty("semmle.order")
)
}
/**

View File

@@ -2,35 +2,4 @@
* @kind graph
*/
import codeql_ruby.printAst as P
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
key = "semmle.order" and
result =
any(int i |
this =
rank[i](P::AstNode p |
|
p
order by
p.getLocation().getFile().getBaseName(), p.getLocation().getFile().getAbsolutePath(),
p.getLocation().getStartLine(), p.getLocation().getStartColumn()
)
).toString()
}
}
import codeql_ruby.printAst