Skip to content

Commit 08c655e

Browse files
authored
Merge pull request #99 from github/hvitved/cfg/to-string
CFG: Use manual `toString()`s for `AstCfgNode` when available
2 parents 78771ba + bf7eb02 commit 08c655e

3 files changed

Lines changed: 539 additions & 528 deletions

File tree

ql/src/codeql_ruby/AST.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ private import ast.internal.TreeSitter
1212
* A node in the abstract syntax tree. This class is the base class for all Ruby
1313
* program elements.
1414
*/
15+
// TODO: Replace base class with an abstract range class once we have full coverage
1516
class AstNode extends @ast_node {
1617
Generated::AstNode generated;
1718

ql/src/codeql_ruby/controlflow/ControlFlowGraph.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Provides classes representing the control flow graph. */
22

33
private import codeql.Locations
4+
private import codeql_ruby.AST as AST
45
private import codeql_ruby.ast.internal.TreeSitter::Generated
56
private import codeql_ruby.controlflow.BasicBlocks
67
private import SuccessorTypes
@@ -133,9 +134,18 @@ module CfgNodes {
133134
final override AstNode getNode() { result = n }
134135

135136
final override string toString() {
136-
result = "[" + this.getSplitsString() + "] " + n.toString()
137-
or
138-
not exists(this.getSplitsString()) and result = n.toString()
137+
exists(string s |
138+
// TODO: Remove once the SSA implementation is based on the AST layer
139+
s = n.(AST::AstNode).toString() and
140+
s != "AstNode"
141+
or
142+
n.(AST::AstNode).toString() = "AstNode" and
143+
s = n.toString()
144+
|
145+
result = "[" + this.getSplitsString() + "] " + s
146+
or
147+
not exists(this.getSplitsString()) and result = s
148+
)
139149
}
140150

141151
/** Gets a comma-separated list of strings for each split in this node, if any. */

0 commit comments

Comments
 (0)