mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Merge pull request #15717 from hvitved/csharp/view-cfg
Shared `View CFG` implementation
This commit is contained in:
50
csharp/ql/lib/printCfg.ql
Normal file
50
csharp/ql/lib/printCfg.ql
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @name Print CFG
|
||||
* @description Produces a representation of a file's Control Flow Graph.
|
||||
* This query is used by the VS Code extension.
|
||||
* @id cs/print-cfg
|
||||
* @kind graph
|
||||
* @tags ide-contextual-queries/print-cfg
|
||||
*/
|
||||
|
||||
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl
|
||||
|
||||
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(
|
||||
CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
|
||||
) {
|
||||
file = scope.getFile() and
|
||||
scope.getLocation().getStartLine() = startLine and
|
||||
scope.getLocation().getStartColumn() = startColumn and
|
||||
exists(Location loc |
|
||||
loc.getEndLine() = endLine and
|
||||
loc.getEndColumn() = endColumn
|
||||
|
|
||||
loc = scope.(Callable).getBody().getLocation()
|
||||
or
|
||||
loc = scope.(Field).getInitializer().getLocation()
|
||||
or
|
||||
loc = scope.(Property).getInitializer().getLocation()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import ViewCfgQuery<File, ViewCfgQueryInput>
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
import csharp
|
||||
import Common
|
||||
import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl::TestOutput
|
||||
|
||||
private class MyRelevantNode extends RelevantNode, SourceControlFlowNode { }
|
||||
private class MyRelevantNode extends SourceControlFlowNode {
|
||||
string getOrderDisambiguation() { result = "" }
|
||||
}
|
||||
|
||||
import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl::TestOutput<MyRelevantNode>
|
||||
|
||||
Reference in New Issue
Block a user