Add query and script to plot CFG from DB

This commit is contained in:
Tamas Vajk
2022-04-11 10:09:17 +02:00
committed by Ian Lynagh
parent 037d66de15
commit 82b937dedd
4 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1 @@
outdir/

View File

@@ -0,0 +1,47 @@
/**
* @id test-plot-cfg
* @kind graph
*/
import java
class RelevantNode extends ControlFlowNode {
RelevantNode() { this.getLocation().getFile().isSourceFile() }
}
query predicate nodes(RelevantNode n, string attr, string val) {
attr = "semmle.order" and
val =
any(int i |
n =
rank[i](RelevantNode p, Location l |
l = p.getLocation()
|
p
order by
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), p.toString()
)
).toString()
}
query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
attr = "semmle.label" and
succ = pred.getASuccessor() and
val = ""
or
attr = "semmle.order" and
val =
any(int i |
succ =
rank[i](RelevantNode s, Location l |
s = pred.getASuccessor() and
l = s.getLocation()
|
s
order by
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
l.getStartColumn(), l.getEndLine(), l.getEndColumn()
)
).toString()
}

View File

@@ -0,0 +1,3 @@
codeql database analyze ../basic/basic.testproj --format=dot nodeGraph.ql --output=outdir --rerun
dot -Tpdf -O outdir/test-plot-cfg.dot
open outdir/test-plot-cfg.dot.pdf