codeql-development-mcp-server 2.24.2-rc1 → 2.24.2-rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/ql/actions/tools/src/PrintAST/PrintAST.md +53 -0
- package/ql/actions/tools/src/PrintCFG/PrintCFG.md +3 -3
- package/ql/actions/tools/src/codeql-pack.yml +1 -1
- package/ql/cpp/tools/src/CallGraphFrom/CallGraphFrom.md +45 -0
- package/ql/cpp/tools/src/CallGraphTo/CallGraphTo.md +42 -0
- package/ql/cpp/tools/src/PrintAST/PrintAST.md +58 -0
- package/ql/cpp/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/cpp/tools/src/codeql-pack.yml +1 -1
- package/ql/csharp/tools/src/CallGraphFrom/CallGraphFrom.md +45 -0
- package/ql/csharp/tools/src/CallGraphTo/CallGraphTo.md +42 -0
- package/ql/csharp/tools/src/PrintAST/PrintAST.md +56 -0
- package/ql/csharp/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/csharp/tools/src/codeql-pack.yml +1 -1
- package/ql/go/tools/src/CallGraphFrom/CallGraphFrom.md +45 -0
- package/ql/go/tools/src/CallGraphTo/CallGraphTo.md +42 -0
- package/ql/go/tools/src/PrintAST/PrintAST.md +55 -0
- package/ql/go/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/go/tools/src/codeql-pack.yml +1 -1
- package/ql/java/tools/src/CallGraphFrom/CallGraphFrom.md +45 -0
- package/ql/java/tools/src/CallGraphTo/CallGraphTo.md +42 -0
- package/ql/java/tools/src/PrintAST/PrintAST.md +54 -0
- package/ql/java/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/java/tools/src/codeql-pack.yml +1 -1
- package/ql/javascript/tools/src/CallGraphFrom/CallGraphFrom.md +48 -0
- package/ql/javascript/tools/src/CallGraphTo/CallGraphTo.md +46 -0
- package/ql/javascript/tools/src/PrintAST/PrintAST.md +58 -0
- package/ql/javascript/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/javascript/tools/src/codeql-pack.yml +1 -1
- package/ql/python/tools/src/CallGraphFrom/CallGraphFrom.md +47 -0
- package/ql/python/tools/src/CallGraphTo/CallGraphTo.md +46 -0
- package/ql/python/tools/src/PrintAST/PrintAST.md +53 -0
- package/ql/python/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/python/tools/src/codeql-pack.yml +1 -1
- package/ql/ruby/tools/src/CallGraphFrom/CallGraphFrom.md +49 -0
- package/ql/ruby/tools/src/CallGraphTo/CallGraphTo.md +48 -0
- package/ql/ruby/tools/src/PrintAST/PrintAST.md +56 -0
- package/ql/ruby/tools/src/PrintCFG/PrintCFG.md +2 -2
- package/ql/ruby/tools/src/codeql-pack.yml +1 -1
- package/ql/swift/tools/src/CallGraphFrom/CallGraphFrom.md +45 -0
- package/ql/swift/tools/src/CallGraphTo/CallGraphTo.md +42 -0
- package/ql/swift/tools/src/PrintAST/PrintAST.md +54 -0
- package/ql/swift/tools/src/PrintCFG/PrintCFG.md +55 -0
- package/ql/swift/tools/src/codeql-pack.yml +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeql-development-mcp-server",
|
|
3
|
-
"version": "2.24.2-
|
|
3
|
+
"version": "2.24.2-rc3",
|
|
4
4
|
"description": "An MCP server supporting LLM requests for CodeQL development tools and resources.",
|
|
5
5
|
"main": "dist/codeql-development-mcp-server.js",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Print AST for GitHub Actions
|
|
2
|
+
|
|
3
|
+
Outputs a representation of the Abstract Syntax Tree (AST) for GitHub Actions workflows and composite actions.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Abstract Syntax Tree is a hierarchical representation of source code structure. Each node represents a syntactic construct (job, step, expression, etc.) and edges represent parent-child containment relationships.
|
|
8
|
+
|
|
9
|
+
This query produces the full AST for specified GitHub Actions YAML files, which is useful for understanding workflow structure, inspecting how the CodeQL extractor parses action definitions, and debugging query logic that operates on AST nodes.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Inspecting how CodeQL represents workflow structure
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between jobs, steps, and expressions
|
|
18
|
+
- Verifying extractor behavior for composite actions and reusable workflows
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following GitHub Actions workflow demonstrates AST structure through jobs and steps:
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
name: Example Workflow
|
|
27
|
+
on: [push]
|
|
28
|
+
jobs:
|
|
29
|
+
build: # Job node in AST
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v2 # Step node in AST
|
|
33
|
+
- name: Build
|
|
34
|
+
run: make build # Run step with expression
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
In the resulting AST:
|
|
38
|
+
|
|
39
|
+
- The workflow root contains job definitions as children
|
|
40
|
+
- Each job contains step nodes
|
|
41
|
+
- `uses` and `run` steps produce distinct AST node types
|
|
42
|
+
|
|
43
|
+
## Output Format
|
|
44
|
+
|
|
45
|
+
The query produces a graph via the `PrintAstConfiguration` library:
|
|
46
|
+
|
|
47
|
+
- `nodes`: Each AST node with its type, label, and properties
|
|
48
|
+
- `edges`: Parent-child relationships forming the syntax tree
|
|
49
|
+
|
|
50
|
+
## References
|
|
51
|
+
|
|
52
|
+
- [GitHub Actions Workflow Syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
|
|
53
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -26,11 +26,11 @@ The following GitHub Actions workflow demonstrates control flow through jobs and
|
|
|
26
26
|
name: Example Workflow
|
|
27
27
|
on: [push]
|
|
28
28
|
jobs:
|
|
29
|
-
test: #
|
|
29
|
+
test: # Job creates CFG node
|
|
30
30
|
runs-on: ubuntu-latest
|
|
31
31
|
steps:
|
|
32
|
-
- uses: actions/checkout@v2 #
|
|
33
|
-
- name: Run tests #
|
|
32
|
+
- uses: actions/checkout@v2 # Step creates CFG node
|
|
33
|
+
- name: Run tests # Steps execute sequentially
|
|
34
34
|
run: echo "Testing"
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CallGraphFrom for C++
|
|
2
|
+
|
|
3
|
+
Displays calls made from a specified function, showing the call graph outbound from the source function.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all function calls made within the body of a named function, producing an outbound call graph. Given a source function name, it reports each call site and the callee, which is useful for understanding function dependencies and call chains.
|
|
8
|
+
|
|
9
|
+
The query accepts function names via an external predicate (`sourceFunction`) and supports both simple and qualified name matching.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Mapping outbound dependencies of a specific function
|
|
16
|
+
- Understanding what a function calls and in what order
|
|
17
|
+
- Analyzing call chains for refactoring or security review
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following C++ code demonstrates outbound calls from `sourceFunc`:
|
|
23
|
+
|
|
24
|
+
```cpp
|
|
25
|
+
void helper1() {}
|
|
26
|
+
void helper2() { helper1(); }
|
|
27
|
+
|
|
28
|
+
void sourceFunc() { // Source function for analysis
|
|
29
|
+
helper1();
|
|
30
|
+
helper2();
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Running with `sourceFunction = "sourceFunc"` produces results showing each call site with the message pattern `Call from 'sourceFunc' to 'helper1'`.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
The query is a `@kind problem` query producing rows of:
|
|
39
|
+
|
|
40
|
+
- `select call, "Call from 'source' to 'callee'"`
|
|
41
|
+
|
|
42
|
+
## References
|
|
43
|
+
|
|
44
|
+
- [C++ Functions](https://en.cppreference.com/w/cpp/language/functions)
|
|
45
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# CallGraphTo for C++
|
|
2
|
+
|
|
3
|
+
Displays calls made to a specified function, showing the call graph inbound to the target function.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all call sites that invoke a named function, producing an inbound call graph. Given a target function name, it reports each caller and call location, which is useful for understanding how a function is used across the codebase.
|
|
8
|
+
|
|
9
|
+
The query accepts function names via an external predicate (`targetFunction`) and supports both simple and qualified name matching.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Finding all callers of a specific function
|
|
16
|
+
- Impact analysis before modifying a function signature
|
|
17
|
+
- Understanding usage patterns and entry points
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following C++ code demonstrates inbound calls to `targetFunc`:
|
|
23
|
+
|
|
24
|
+
```cpp
|
|
25
|
+
void targetFunc() {} // Target function for analysis
|
|
26
|
+
|
|
27
|
+
void caller1() { targetFunc(); }
|
|
28
|
+
void caller2() { targetFunc(); }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Running with `targetFunction = "targetFunc"` produces results showing each call site with the message pattern `Call to 'targetFunc' from 'caller1'`.
|
|
32
|
+
|
|
33
|
+
## Output Format
|
|
34
|
+
|
|
35
|
+
The query is a `@kind problem` query producing rows of:
|
|
36
|
+
|
|
37
|
+
- `select call, "Call to 'target' from 'caller'"`
|
|
38
|
+
|
|
39
|
+
## References
|
|
40
|
+
|
|
41
|
+
- [C++ Functions](https://en.cppreference.com/w/cpp/language/functions)
|
|
42
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Print AST for C++
|
|
2
|
+
|
|
3
|
+
Outputs a representation of the Abstract Syntax Tree (AST) for specified source files.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Abstract Syntax Tree is a hierarchical representation of source code structure. Each node represents a syntactic construct (declaration, statement, expression, etc.) and edges represent parent-child containment relationships.
|
|
8
|
+
|
|
9
|
+
This query produces the full AST for specified C++ source files, which is useful for understanding code structure, inspecting how the CodeQL extractor parses declarations and expressions, and debugging query logic that operates on AST nodes.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Inspecting how CodeQL represents C++ declarations and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between classes, functions, and statements
|
|
18
|
+
- Verifying extractor behavior for templates, macros, and overloaded operators
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following C++ code demonstrates AST structure through declarations and statements:
|
|
24
|
+
|
|
25
|
+
```cpp
|
|
26
|
+
#include <iostream>
|
|
27
|
+
|
|
28
|
+
class Example {
|
|
29
|
+
public:
|
|
30
|
+
void greet(const std::string& name) { // Function declaration in AST
|
|
31
|
+
std::cout << "Hello, " << name << "!" << std::endl;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
int main() { // Top-level declaration
|
|
36
|
+
Example e;
|
|
37
|
+
e.greet("World");
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
In the resulting AST:
|
|
43
|
+
|
|
44
|
+
- The class declaration contains member function declarations as children
|
|
45
|
+
- Each function body contains a statement list
|
|
46
|
+
- Call expressions reference their target and arguments as child nodes
|
|
47
|
+
|
|
48
|
+
## Output Format
|
|
49
|
+
|
|
50
|
+
The query produces a graph via the `PrintAstConfiguration` library:
|
|
51
|
+
|
|
52
|
+
- `nodes`: Each AST node with its type, label, and properties
|
|
53
|
+
- `edges`: Parent-child relationships forming the syntax tree
|
|
54
|
+
|
|
55
|
+
## References
|
|
56
|
+
|
|
57
|
+
- [C++ Language Reference](https://en.cppreference.com/w/cpp/language)
|
|
58
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -25,13 +25,13 @@ The following C++ code demonstrates control flow through conditional statements
|
|
|
25
25
|
```cpp
|
|
26
26
|
void example(int x) {
|
|
27
27
|
int result = 0;
|
|
28
|
-
if (x > 0) {
|
|
28
|
+
if (x > 0) { // Branching creates CFG edges
|
|
29
29
|
result = 1;
|
|
30
30
|
} else {
|
|
31
31
|
result = -1;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
for (int i = 0; i < 3; i++) {
|
|
34
|
+
for (int i = 0; i < 3; i++) { // Loop creates cyclic CFG
|
|
35
35
|
result = result + i;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CallGraphFrom for `csharp` Source Files
|
|
2
|
+
|
|
3
|
+
Displays calls made from a specified method, showing the call graph outbound from the source method.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all method calls made within the body of a named method, producing an outbound call graph. Given a source method name, it reports each call site and the callee, which is useful for understanding method dependencies and call chains.
|
|
8
|
+
|
|
9
|
+
The query accepts method names via an external predicate (`sourceFunction`).
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Mapping outbound dependencies of a specific method
|
|
16
|
+
- Understanding what a method calls and in what order
|
|
17
|
+
- Analyzing call chains for refactoring or security review
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following C# code demonstrates outbound calls from `SourceMethod`:
|
|
23
|
+
|
|
24
|
+
```csharp
|
|
25
|
+
void Helper1() {}
|
|
26
|
+
void Helper2() { Helper1(); }
|
|
27
|
+
|
|
28
|
+
void SourceMethod() { // Source method for analysis
|
|
29
|
+
Helper1();
|
|
30
|
+
Helper2();
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Running with `sourceFunction = "SourceMethod"` produces results showing each call site with the message pattern `Call from 'SourceMethod' to 'Helper1'`.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
The query is a `@kind problem` query producing rows of:
|
|
39
|
+
|
|
40
|
+
- `select call, "Call from 'source' to 'callee'"`
|
|
41
|
+
|
|
42
|
+
## References
|
|
43
|
+
|
|
44
|
+
- [C# Methods](https://learn.microsoft.com/en-us/dotnet/csharp/methods)
|
|
45
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# CallGraphTo for `csharp` Source Files
|
|
2
|
+
|
|
3
|
+
Displays calls made to a specified method, showing the call graph inbound to the target method.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all call sites that invoke a named method, producing an inbound call graph. Given a target method name, it reports each caller and call location, which is useful for understanding how a method is used across the codebase.
|
|
8
|
+
|
|
9
|
+
The query accepts method names via an external predicate (`targetFunction`).
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Finding all callers of a specific method
|
|
16
|
+
- Impact analysis before modifying a method signature
|
|
17
|
+
- Understanding usage patterns and entry points
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following C# code demonstrates inbound calls to `TargetMethod`:
|
|
23
|
+
|
|
24
|
+
```csharp
|
|
25
|
+
void TargetMethod() {} // Target method for analysis
|
|
26
|
+
|
|
27
|
+
void Caller1() { TargetMethod(); }
|
|
28
|
+
void Caller2() { TargetMethod(); }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Running with `targetFunction = "TargetMethod"` produces results showing each call site with the message pattern `Call to 'TargetMethod' from 'Caller1'`.
|
|
32
|
+
|
|
33
|
+
## Output Format
|
|
34
|
+
|
|
35
|
+
The query is a `@kind problem` query producing rows of:
|
|
36
|
+
|
|
37
|
+
- `select call, "Call to 'target' from 'caller'"`
|
|
38
|
+
|
|
39
|
+
## References
|
|
40
|
+
|
|
41
|
+
- [C# Methods](https://learn.microsoft.com/en-us/dotnet/csharp/methods)
|
|
42
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Print AST for `csharp` Source Files
|
|
2
|
+
|
|
3
|
+
Outputs a representation of the Abstract Syntax Tree (AST) for specified source files.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Abstract Syntax Tree is a hierarchical representation of source code structure. Each node represents a syntactic construct (declaration, statement, expression, etc.) and edges represent parent-child containment relationships.
|
|
8
|
+
|
|
9
|
+
This query produces the full AST for specified C# source files, which is useful for understanding code structure, inspecting how the CodeQL extractor parses classes and methods, and debugging query logic that operates on AST nodes.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Inspecting how CodeQL represents C# classes, methods, and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between namespaces, types, and members
|
|
18
|
+
- Verifying extractor behavior for generics, LINQ, and async/await patterns
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following C# code demonstrates AST structure through class and method declarations:
|
|
24
|
+
|
|
25
|
+
```csharp
|
|
26
|
+
using System;
|
|
27
|
+
|
|
28
|
+
public class Example {
|
|
29
|
+
public void Greet(string name) { // Method declaration in AST
|
|
30
|
+
Console.WriteLine($"Hello, {name}!");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public static void Main(string[] args) { // Entry point declaration
|
|
34
|
+
var e = new Example();
|
|
35
|
+
e.Greet("World");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
In the resulting AST:
|
|
41
|
+
|
|
42
|
+
- The class declaration contains method declarations as children
|
|
43
|
+
- Each method body contains a block with statement nodes
|
|
44
|
+
- Call expressions reference their target and arguments as child nodes
|
|
45
|
+
|
|
46
|
+
## Output Format
|
|
47
|
+
|
|
48
|
+
The query produces a graph via the `PrintAstConfiguration` library:
|
|
49
|
+
|
|
50
|
+
- `nodes`: Each AST node with its type, label, and properties
|
|
51
|
+
- `edges`: Parent-child relationships forming the syntax tree
|
|
52
|
+
|
|
53
|
+
## References
|
|
54
|
+
|
|
55
|
+
- [C# Language Reference](https://learn.microsoft.com/en-us/dotnet/csharp/)
|
|
56
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -24,13 +24,13 @@ The following C# code demonstrates control flow through conditional statements a
|
|
|
24
24
|
|
|
25
25
|
```csharp
|
|
26
26
|
public void Example(int x) {
|
|
27
|
-
if (x > 0) {
|
|
27
|
+
if (x > 0) { // Branching creates CFG edges
|
|
28
28
|
Console.WriteLine("Positive");
|
|
29
29
|
} else {
|
|
30
30
|
Console.WriteLine("Non-positive");
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
for (int i = 0; i < 3; i++) {
|
|
33
|
+
for (int i = 0; i < 3; i++) { // Loop creates cyclic CFG
|
|
34
34
|
Console.WriteLine(i);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CallGraphFrom for Go
|
|
2
|
+
|
|
3
|
+
Displays calls made from a specified function, showing the call graph outbound from the source function.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all function calls made within the body of a named function, producing an outbound call graph. Given a source function name, it reports each call site and the callee, which is useful for understanding function dependencies and call chains.
|
|
8
|
+
|
|
9
|
+
The query accepts function names via an external predicate (`sourceFunction`).
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Mapping outbound dependencies of a specific function
|
|
16
|
+
- Understanding what a function calls and in what order
|
|
17
|
+
- Analyzing call chains for refactoring or security review
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following Go code demonstrates outbound calls from `sourceFunc`:
|
|
23
|
+
|
|
24
|
+
```go
|
|
25
|
+
func helper1() {}
|
|
26
|
+
func helper2() { helper1() }
|
|
27
|
+
|
|
28
|
+
func sourceFunc() { // Source function for analysis
|
|
29
|
+
helper1()
|
|
30
|
+
helper2()
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Running with `sourceFunction = "sourceFunc"` produces results showing each call site with the message pattern `Call from 'sourceFunc' to 'helper1'`.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
The query is a `@kind problem` query producing rows of:
|
|
39
|
+
|
|
40
|
+
- `select call, "Call from 'source' to 'callee'"`
|
|
41
|
+
|
|
42
|
+
## References
|
|
43
|
+
|
|
44
|
+
- [Go Functions](https://go.dev/doc/effective_go#functions)
|
|
45
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# CallGraphTo for Go
|
|
2
|
+
|
|
3
|
+
Displays calls made to a specified function, showing the call graph inbound to the target function.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all call sites that invoke a named function, producing an inbound call graph. Given a target function name, it reports each caller and call location, which is useful for understanding how a function is used across the codebase.
|
|
8
|
+
|
|
9
|
+
The query accepts function names via an external predicate (`targetFunction`).
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Finding all callers of a specific function
|
|
16
|
+
- Impact analysis before modifying a function signature
|
|
17
|
+
- Understanding usage patterns and entry points
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following Go code demonstrates inbound calls to `targetFunc`:
|
|
23
|
+
|
|
24
|
+
```go
|
|
25
|
+
func targetFunc() {} // Target function for analysis
|
|
26
|
+
|
|
27
|
+
func caller1() { targetFunc() }
|
|
28
|
+
func caller2() { targetFunc() }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Running with `targetFunction = "targetFunc"` produces results showing each call site with the message pattern `Call to 'targetFunc' from 'caller1'`.
|
|
32
|
+
|
|
33
|
+
## Output Format
|
|
34
|
+
|
|
35
|
+
The query is a `@kind problem` query producing rows of:
|
|
36
|
+
|
|
37
|
+
- `select call, "Call to 'target' from 'caller'"`
|
|
38
|
+
|
|
39
|
+
## References
|
|
40
|
+
|
|
41
|
+
- [Go Functions](https://go.dev/doc/effective_go#functions)
|
|
42
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Print AST for Go
|
|
2
|
+
|
|
3
|
+
Outputs a representation of the Abstract Syntax Tree (AST) for specified source files.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Abstract Syntax Tree is a hierarchical representation of source code structure. Each node represents a syntactic construct (declaration, statement, expression, etc.) and edges represent parent-child containment relationships.
|
|
8
|
+
|
|
9
|
+
This query produces the full AST for specified Go source files, which is useful for understanding code structure, inspecting how the CodeQL extractor parses packages and functions, and debugging query logic that operates on AST nodes.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Inspecting how CodeQL represents Go packages, functions, and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between declarations and statements
|
|
18
|
+
- Verifying extractor behavior for goroutines, channels, and interfaces
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following Go code demonstrates AST structure through function declarations and control flow:
|
|
24
|
+
|
|
25
|
+
```go
|
|
26
|
+
package main
|
|
27
|
+
|
|
28
|
+
import "fmt"
|
|
29
|
+
|
|
30
|
+
func greet(name string) { // Function declaration in AST
|
|
31
|
+
fmt.Println("Hello, " + name + "!")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func main() { // Entry point declaration
|
|
35
|
+
greet("World")
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
In the resulting AST:
|
|
40
|
+
|
|
41
|
+
- The package declaration contains function declarations as children
|
|
42
|
+
- Each function body contains a block with statement nodes
|
|
43
|
+
- Call expressions reference their target and arguments as child nodes
|
|
44
|
+
|
|
45
|
+
## Output Format
|
|
46
|
+
|
|
47
|
+
The query produces a graph via the `PrintAstConfiguration` library:
|
|
48
|
+
|
|
49
|
+
- `nodes`: Each AST node with its type, label, and properties
|
|
50
|
+
- `edges`: Parent-child relationships forming the syntax tree
|
|
51
|
+
|
|
52
|
+
## References
|
|
53
|
+
|
|
54
|
+
- [Go Language Specification](https://go.dev/ref/spec)
|
|
55
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -24,13 +24,13 @@ The following Go code demonstrates control flow through conditional statements a
|
|
|
24
24
|
|
|
25
25
|
```go
|
|
26
26
|
func example(x int) {
|
|
27
|
-
if x > 0 {
|
|
27
|
+
if x > 0 { // Branching creates CFG edges
|
|
28
28
|
fmt.Println("Positive")
|
|
29
29
|
} else {
|
|
30
30
|
fmt.Println("Non-positive")
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
for i := 0; i < 3; i++ {
|
|
33
|
+
for i := 0; i < 3; i++ { // Loop creates cyclic CFG
|
|
34
34
|
fmt.Println(i)
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CallGraphFrom for Java
|
|
2
|
+
|
|
3
|
+
Displays calls made from a specified method, showing the call graph outbound from the source method.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This query identifies all method calls made within the body of a named method, producing an outbound call graph. Given a source method name, it reports each call site and the callee, which is useful for understanding method dependencies and call chains.
|
|
8
|
+
|
|
9
|
+
The query accepts method names via an external predicate (`sourceFunction`).
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
This query is primarily used for:
|
|
14
|
+
|
|
15
|
+
- Mapping outbound dependencies of a specific method
|
|
16
|
+
- Understanding what a method calls and in what order
|
|
17
|
+
- Analyzing call chains for refactoring or security review
|
|
18
|
+
- IDE integration for call hierarchy navigation
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
The following Java code demonstrates outbound calls from `sourceMethod`:
|
|
23
|
+
|
|
24
|
+
```java
|
|
25
|
+
void helper1() {}
|
|
26
|
+
void helper2() { helper1(); }
|
|
27
|
+
|
|
28
|
+
void sourceMethod() { // Source method for analysis
|
|
29
|
+
helper1();
|
|
30
|
+
helper2();
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Running with `sourceFunction = "sourceMethod"` produces results showing each call site with the message pattern `Call from 'sourceMethod' to 'helper1'`.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
The query is a `@kind problem` query producing rows of:
|
|
39
|
+
|
|
40
|
+
- `select call, "Call from 'source' to 'callee'"`
|
|
41
|
+
|
|
42
|
+
## References
|
|
43
|
+
|
|
44
|
+
- [Java Methods](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html)
|
|
45
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|