codeql-development-mcp-server 2.24.2-rc2 → 2.24.2
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 +44 -0
- package/ql/cpp/tools/src/CallGraphTo/CallGraphTo.md +41 -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 +44 -0
- package/ql/csharp/tools/src/CallGraphTo/CallGraphTo.md +41 -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 +44 -0
- package/ql/go/tools/src/CallGraphTo/CallGraphTo.md +41 -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 +44 -0
- package/ql/java/tools/src/CallGraphTo/CallGraphTo.md +41 -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 +47 -0
- package/ql/javascript/tools/src/CallGraphTo/CallGraphTo.md +45 -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 +46 -0
- package/ql/python/tools/src/CallGraphTo/CallGraphTo.md +45 -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 +48 -0
- package/ql/ruby/tools/src/CallGraphTo/CallGraphTo.md +47 -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 +44 -0
- package/ql/swift/tools/src/CallGraphTo/CallGraphTo.md +41 -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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# CallGraphTo for Java
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following Java code demonstrates inbound calls to `targetMethod`:
|
|
22
|
+
|
|
23
|
+
```java
|
|
24
|
+
void targetMethod() {} // Target method for analysis
|
|
25
|
+
|
|
26
|
+
void caller1() { targetMethod(); }
|
|
27
|
+
void caller2() { targetMethod(); }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Running with `targetFunction = "targetMethod"` produces results showing each call site with the message pattern ``Call to `targetMethod` from `caller1``.
|
|
31
|
+
|
|
32
|
+
## Output Format
|
|
33
|
+
|
|
34
|
+
The query is a `@kind problem` query producing rows of:
|
|
35
|
+
|
|
36
|
+
- ``select call, "Call to `target` from `caller`"``
|
|
37
|
+
|
|
38
|
+
## References
|
|
39
|
+
|
|
40
|
+
- [Java Methods](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html)
|
|
41
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Print AST for Java
|
|
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 Java 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 Java classes, methods, and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between packages, types, and members
|
|
18
|
+
- Verifying extractor behavior for generics, annotations, and lambda expressions
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following Java code demonstrates AST structure through class and method declarations:
|
|
24
|
+
|
|
25
|
+
```java
|
|
26
|
+
public class Example {
|
|
27
|
+
public void greet(String name) { // Method declaration in AST
|
|
28
|
+
System.out.println("Hello, " + name + "!");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static void main(String[] args) { // Entry point declaration
|
|
32
|
+
Example e = new Example();
|
|
33
|
+
e.greet("World");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In the resulting AST:
|
|
39
|
+
|
|
40
|
+
- The class declaration contains method declarations as children
|
|
41
|
+
- Each method body contains a block with statement nodes
|
|
42
|
+
- Call expressions reference their target and arguments as child nodes
|
|
43
|
+
|
|
44
|
+
## Output Format
|
|
45
|
+
|
|
46
|
+
The query produces a graph via the `PrintAstConfiguration` library:
|
|
47
|
+
|
|
48
|
+
- `nodes`: Each AST node with its type, label, and properties
|
|
49
|
+
- `edges`: Parent-child relationships forming the syntax tree
|
|
50
|
+
|
|
51
|
+
## References
|
|
52
|
+
|
|
53
|
+
- [Java Language Specification](https://docs.oracle.com/javase/specs/)
|
|
54
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -24,13 +24,13 @@ The following Java code demonstrates control flow through conditional statements
|
|
|
24
24
|
|
|
25
25
|
```java
|
|
26
26
|
public void example(int x) {
|
|
27
|
-
if (x > 0) {
|
|
27
|
+
if (x > 0) { // Branching creates CFG edges
|
|
28
28
|
System.out.println("Positive");
|
|
29
29
|
} else {
|
|
30
30
|
System.out.println("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
|
System.out.println(i);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# CallGraphFrom for JavaScript
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following JavaScript code demonstrates outbound calls from `sourceFunc`:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
function helper1() {}
|
|
25
|
+
function helper2() {
|
|
26
|
+
helper1();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sourceFunc() {
|
|
30
|
+
// Source function for analysis
|
|
31
|
+
helper1();
|
|
32
|
+
helper2();
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Running with `sourceFunction = "sourceFunc"` produces results showing each call site with the message pattern ``Call from `sourceFunc` to `helper1``.
|
|
37
|
+
|
|
38
|
+
## Output Format
|
|
39
|
+
|
|
40
|
+
The query is a `@kind problem` query producing rows of:
|
|
41
|
+
|
|
42
|
+
- ``select call, "Call from `source` to `callee`"``
|
|
43
|
+
|
|
44
|
+
## References
|
|
45
|
+
|
|
46
|
+
- [JavaScript Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions)
|
|
47
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CallGraphTo for JavaScript
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following JavaScript code demonstrates inbound calls to `targetFunc`:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
function targetFunc() {} // Target function for analysis
|
|
25
|
+
|
|
26
|
+
function caller1() {
|
|
27
|
+
targetFunc();
|
|
28
|
+
}
|
|
29
|
+
function caller2() {
|
|
30
|
+
targetFunc();
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Running with `targetFunction = "targetFunc"` produces results showing each call site with the message pattern ``Call to `targetFunc` from `caller1``.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
The query is a `@kind problem` query producing rows of:
|
|
39
|
+
|
|
40
|
+
- ``select call, "Call to `target` from `caller`"``
|
|
41
|
+
|
|
42
|
+
## References
|
|
43
|
+
|
|
44
|
+
- [JavaScript Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions)
|
|
45
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Print AST for JavaScript
|
|
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 JavaScript source files, which is useful for understanding code structure, inspecting how the CodeQL extractor parses functions 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 JavaScript functions, classes, and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between modules, declarations, and statements
|
|
18
|
+
- Verifying extractor behavior for arrow functions, destructuring, and async/await
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following JavaScript code demonstrates AST structure through function and class declarations:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
class Example {
|
|
27
|
+
constructor(name = 'World') {
|
|
28
|
+
// Constructor in AST
|
|
29
|
+
this.name = name;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
greet() {
|
|
33
|
+
// Method declaration in AST
|
|
34
|
+
console.log(`Hello, ${this.name}!`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const e = new Example();
|
|
39
|
+
e.greet();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
In the resulting AST:
|
|
43
|
+
|
|
44
|
+
- The class declaration contains method definitions as children
|
|
45
|
+
- Each method body contains a block with statement nodes
|
|
46
|
+
- Call expressions and template literals reference their components 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
|
+
- [JavaScript Language Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
|
|
58
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -25,14 +25,14 @@ The following JavaScript code demonstrates control flow through conditional stat
|
|
|
25
25
|
```javascript
|
|
26
26
|
function example(x) {
|
|
27
27
|
if (x > 0) {
|
|
28
|
-
//
|
|
28
|
+
// Branching creates CFG edges
|
|
29
29
|
console.log('Positive');
|
|
30
30
|
} else {
|
|
31
31
|
console.log('Non-positive');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
for (let i = 0; i < 3; i++) {
|
|
35
|
-
//
|
|
35
|
+
// Loop creates cyclic CFG
|
|
36
36
|
console.log(i);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# CallGraphFrom for Python
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following Python code demonstrates outbound calls from `source_func`:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
def helper1():
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
def helper2():
|
|
28
|
+
helper1()
|
|
29
|
+
|
|
30
|
+
def source_func(): # Source function for analysis
|
|
31
|
+
helper1()
|
|
32
|
+
helper2()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Running with `sourceFunction = "source_func"` produces results showing each call site with the message pattern ``Call from `source_func` to `helper1``.
|
|
36
|
+
|
|
37
|
+
## Output Format
|
|
38
|
+
|
|
39
|
+
The query is a `@kind problem` query producing rows of:
|
|
40
|
+
|
|
41
|
+
- ``select call, "Call from `source` to `callee`"``
|
|
42
|
+
|
|
43
|
+
## References
|
|
44
|
+
|
|
45
|
+
- [Python Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions)
|
|
46
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CallGraphTo for Python
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following Python code demonstrates inbound calls to `target_func`:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
def target_func(): # Target function for analysis
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
def caller1():
|
|
28
|
+
target_func()
|
|
29
|
+
|
|
30
|
+
def caller2():
|
|
31
|
+
target_func()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Running with `targetFunction = "target_func"` produces results showing each call site with the message pattern ``Call to `target_func` from `caller1``.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
The query is a `@kind problem` query producing rows of:
|
|
39
|
+
|
|
40
|
+
- ``select call, "Call to `target` from `caller`"``
|
|
41
|
+
|
|
42
|
+
## References
|
|
43
|
+
|
|
44
|
+
- [Python Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions)
|
|
45
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Print AST for Python
|
|
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 Python source files, which is useful for understanding code structure, inspecting how the CodeQL extractor parses classes 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 Python classes, functions, and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between modules, classes, and statements
|
|
18
|
+
- Verifying extractor behavior for decorators, comprehensions, and f-strings
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following Python code demonstrates AST structure through class and function declarations:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
class Example:
|
|
27
|
+
def __init__(self, name="World"): # Method definition in AST
|
|
28
|
+
self.name = name
|
|
29
|
+
|
|
30
|
+
def greet(self): # Method definition in AST
|
|
31
|
+
print(f"Hello, {self.name}!")
|
|
32
|
+
|
|
33
|
+
example = Example()
|
|
34
|
+
example.greet()
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
In the resulting AST:
|
|
38
|
+
|
|
39
|
+
- The class definition contains function definitions as children
|
|
40
|
+
- Each function body contains a statement list
|
|
41
|
+
- Call expressions and f-strings reference their components as child nodes
|
|
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
|
+
- [Python Language Reference](https://docs.python.org/3/reference/)
|
|
53
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -24,12 +24,12 @@ The following Python code demonstrates control flow through conditional statemen
|
|
|
24
24
|
|
|
25
25
|
```python
|
|
26
26
|
def example(x):
|
|
27
|
-
if x > 0:
|
|
27
|
+
if x > 0: # Branching creates CFG edges
|
|
28
28
|
print("Positive")
|
|
29
29
|
else:
|
|
30
30
|
print("Non-positive")
|
|
31
31
|
|
|
32
|
-
for i in range(3):
|
|
32
|
+
for i in range(3): # Loop creates cyclic CFG
|
|
33
33
|
print(i)
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# CallGraphFrom for Ruby
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following Ruby code demonstrates outbound calls from `source_func`:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
def helper1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def helper2
|
|
28
|
+
helper1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def source_func # Source method for analysis
|
|
32
|
+
helper1
|
|
33
|
+
helper2
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Running with `sourceFunction = "source_func"` produces results showing each call site with the message pattern ``Call from `source_func` to `helper1``.
|
|
38
|
+
|
|
39
|
+
## Output Format
|
|
40
|
+
|
|
41
|
+
The query is a `@kind problem` query producing rows of:
|
|
42
|
+
|
|
43
|
+
- ``select call, "Call from `source` to `callee`"``
|
|
44
|
+
|
|
45
|
+
## References
|
|
46
|
+
|
|
47
|
+
- [Ruby Methods](https://ruby-doc.org/core/doc/syntax/methods_rdoc.html)
|
|
48
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# CallGraphTo for Ruby
|
|
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
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
The following Ruby code demonstrates inbound calls to `target_func`:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
def target_func # Target method for analysis
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def caller1
|
|
28
|
+
target_func
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def caller2
|
|
32
|
+
target_func
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Running with `targetFunction = "target_func"` produces results showing each call site with the message pattern ``Call to `target_func` from `caller1``.
|
|
37
|
+
|
|
38
|
+
## Output Format
|
|
39
|
+
|
|
40
|
+
The query is a `@kind problem` query producing rows of:
|
|
41
|
+
|
|
42
|
+
- ``select call, "Call to `target` from `caller`"``
|
|
43
|
+
|
|
44
|
+
## References
|
|
45
|
+
|
|
46
|
+
- [Ruby Methods](https://ruby-doc.org/core/doc/syntax/methods_rdoc.html)
|
|
47
|
+
- [CodeQL Call Graph Analysis](https://codeql.github.com/docs/writing-codeql-queries/about-data-flow-analysis/)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Print AST for Ruby
|
|
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 Ruby 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 Ruby classes, methods, and expressions
|
|
16
|
+
- Debugging queries that match on AST node types
|
|
17
|
+
- Understanding parent-child relationships between modules, classes, and methods
|
|
18
|
+
- Verifying extractor behavior for blocks, procs, and metaprogramming constructs
|
|
19
|
+
- IDE integration for syntax tree visualization
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The following Ruby code demonstrates AST structure through class and method definitions:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
class Example
|
|
27
|
+
def initialize(name = "World") # Method definition in AST
|
|
28
|
+
@name = name
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def greet # Method definition in AST
|
|
32
|
+
puts "Hello, #{@name}!"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
e = Example.new
|
|
37
|
+
e.greet
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
In the resulting AST:
|
|
41
|
+
|
|
42
|
+
- The class definition contains method definitions as children
|
|
43
|
+
- Each method body contains a statement list
|
|
44
|
+
- Method calls and string interpolations reference their components 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
|
+
- [Ruby Language Documentation](https://ruby-doc.org/core/)
|
|
56
|
+
- [CodeQL Abstract Syntax Trees](https://codeql.github.com/docs/writing-codeql-queries/abstract-syntax-tree/)
|
|
@@ -24,13 +24,13 @@ The following Ruby code demonstrates control flow through conditional statements
|
|
|
24
24
|
|
|
25
25
|
```ruby
|
|
26
26
|
def example(x)
|
|
27
|
-
if x > 0
|
|
27
|
+
if x > 0 # Branching creates CFG edges
|
|
28
28
|
puts "Positive"
|
|
29
29
|
else
|
|
30
30
|
puts "Non-positive"
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
(0..2).each do |i|
|
|
33
|
+
(0..2).each do |i| # Iterator creates CFG paths
|
|
34
34
|
puts i
|
|
35
35
|
end
|
|
36
36
|
end
|