Skip to content

Commit affbd3f

Browse files
Copilotaschackmull
andauthored
Apply review fixes to AstConsistency.qll
Agent-Logs-Url: https://github.com/github/codeql/sessions/85daaeb0-9115-4937-af69-fbb3be5f3d64 Co-authored-by: aschackmull <28296824+aschackmull@users.noreply.github.com>
1 parent 0747432 commit affbd3f

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

shared/controlflow/codeql/controlflow/AstConsistency.qll

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ private import ControlFlowGraph
99
module MakeAstConsistency<LocationSig Location, AstSig<Location> Ast> {
1010
private import Ast
1111

12-
private predicate parentStep(AstNode child, AstNode parent) { child = getChild(parent, _) }
12+
private AstNode getParent(AstNode child) { child = getChild(result, _) }
1313

1414
private predicate astMemberChild(AstNode parent, AstNode child, string member) {
15-
callableGetBody(parent.(Callable)) = child and member = "Callable.getBody"
15+
callableGetBody(parent) = child and member = "Callable.getBody"
1616
or
17-
callableGetParameter(parent.(Callable), _) = child and member = "Callable.getParameter"
17+
callableGetParameter(parent, _) = child and member = "Callable.getParameter"
1818
or
1919
parent.(Parameter).getDefaultValue() = child and member = "Parameter.getDefaultValue"
2020
or
@@ -56,9 +56,9 @@ module MakeAstConsistency<LocationSig Location, AstSig<Location> Ast> {
5656
or
5757
parent.(TryStmt).getFinally() = child and member = "TryStmt.getFinally"
5858
or
59-
getTryInit(parent.(TryStmt), _) = child and member = "getTryInit"
59+
getTryInit(parent, _) = child and member = "getTryInit"
6060
or
61-
getTryElse(parent.(TryStmt)) = child and member = "getTryElse"
61+
getTryElse(parent) = child and member = "getTryElse"
6262
or
6363
parent.(CatchClause).getVariable() = child and member = "CatchClause.getVariable"
6464
or
@@ -121,6 +121,27 @@ module MakeAstConsistency<LocationSig Location, AstSig<Location> Ast> {
121121
}
122122

123123
module Consistency {
124+
/** Holds if the consistency query `query` has `results` results. */
125+
query predicate consistencyOverview(string query, int results) {
126+
query = "multipleParents" and
127+
results = strictcount(AstNode child | multipleParents(child, _, _))
128+
or
129+
query = "nonAncestorEnclosingCallable" and
130+
results = strictcount(AstNode node | nonAncestorEnclosingCallable(node, _))
131+
or
132+
query = "childAtMultipleIndices" and
133+
results = strictcount(AstNode child | childAtMultipleIndices(_, child, _, _))
134+
or
135+
query = "siblingsWithIdenticalIndex" and
136+
results = strictcount(AstNode parent, int index | siblingsWithIdenticalIndex(parent, index, _, _))
137+
or
138+
query = "memberChildMissingFromGetChild" and
139+
results = strictcount(AstNode parent, AstNode child | memberChildMissingFromGetChild(parent, child, _))
140+
or
141+
query = "getChildMissingFromMember" and
142+
results = strictcount(AstNode parent, int index | getChildMissingFromMember(parent, index, _))
143+
}
144+
124145
/** Holds if `child` has multiple AST parents. */
125146
query predicate multipleParents(AstNode child, AstNode parent1, AstNode parent2) {
126147
getChild(parent1, _) = child and
@@ -134,7 +155,7 @@ module MakeAstConsistency<LocationSig Location, AstSig<Location> Ast> {
134155
*/
135156
query predicate nonAncestorEnclosingCallable(AstNode node, Callable callable) {
136157
callable = getEnclosingCallable(node) and
137-
not parentStep*(node, callable)
158+
not getParent*(node) = callable
138159
}
139160

140161
/** Holds if `child` is assigned multiple child indices under `parent`. */

0 commit comments

Comments
 (0)