mirror of
https://github.com/github/codeql.git
synced 2026-02-11 20:51:06 +01:00
Java: Add support for "View CFG".
This commit is contained in:
45
java/ql/lib/printCfg.ql
Normal file
45
java/ql/lib/printCfg.ql
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @name Print CFG
|
||||
* @description Produces a representation of a file's Control Flow Graph.
|
||||
* This query is used by the VS Code extension.
|
||||
* @id java/print-cfg
|
||||
* @kind graph
|
||||
* @tags ide-contextual-queries/print-cfg
|
||||
*/
|
||||
|
||||
import java
|
||||
|
||||
external string selectedSourceFile();
|
||||
|
||||
private predicate selectedSourceFileAlias = selectedSourceFile/0;
|
||||
|
||||
external int selectedSourceLine();
|
||||
|
||||
private predicate selectedSourceLineAlias = selectedSourceLine/0;
|
||||
|
||||
external int selectedSourceColumn();
|
||||
|
||||
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
|
||||
|
||||
module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
|
||||
predicate selectedSourceFile = selectedSourceFileAlias/0;
|
||||
|
||||
predicate selectedSourceLine = selectedSourceLineAlias/0;
|
||||
|
||||
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
|
||||
|
||||
predicate cfgScopeSpan(
|
||||
Callable callable, File file, int startLine, int startColumn, int endLine, int endColumn
|
||||
) {
|
||||
file = callable.getFile() and
|
||||
callable.getLocation().getStartLine() = startLine and
|
||||
callable.getLocation().getStartColumn() = startColumn and
|
||||
exists(Location loc |
|
||||
loc.getEndLine() = endLine and
|
||||
loc.getEndColumn() = endColumn and
|
||||
loc = callable.getBody().getLocation()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import ViewCfgQuery<File, ViewCfgQueryInput>
|
||||
@@ -1775,3 +1775,17 @@ class ConditionNode extends ControlFlow::Node {
|
||||
/** Gets the condition of this `ConditionNode`. */
|
||||
ExprParent getCondition() { result = this.asExpr() or result = this.asStmt() }
|
||||
}
|
||||
|
||||
private import codeql.controlflow.PrintGraph as PrintGraph
|
||||
|
||||
private module PrintGraphInput implements PrintGraph::InputSig<Location> {
|
||||
private import java as J
|
||||
|
||||
class Callable = J::Callable;
|
||||
|
||||
class ControlFlowNode = J::ControlFlowNode;
|
||||
|
||||
ControlFlowNode getASuccessor(ControlFlowNode n, SuccessorType t) { result = n.getASuccessor(t) }
|
||||
}
|
||||
|
||||
import PrintGraph::PrintGraph<Location, PrintGraphInput>
|
||||
|
||||
Reference in New Issue
Block a user