Skip to content

Commit 7c82cde

Browse files
committed
unified: Simplify with getParentIndex
1 parent 6aeead3 commit 7c82cde

1 file changed

Lines changed: 1 addition & 36 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,10 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
7070
}
7171

7272
private AstNode getChild1(AstNode n, int index) {
73-
result = n.(Block).getStmt(index) and
74-
not n instanceof BlockWithGuardStmts
75-
or
7673
result = n.(BlockWithGuardStmts).getTranslatedChild(index)
7774
or
7875
result = n.(LogicalAndRoot).getNthLeaf(index)
7976
or
80-
exists(PatternGuardExpr guard | n = guard |
81-
index = 0 and result = guard.getPattern()
82-
or
83-
index = 1 and result = guard.getValue()
84-
)
85-
or
86-
exists(IfExpr expr | n = expr |
87-
index = 0 and result = expr.getCondition()
88-
or
89-
index = 1 and result = expr.getThen()
90-
or
91-
index = 2 and result = expr.getElse()
92-
)
93-
or
94-
exists(VariableDeclaration decl | n = decl |
95-
index = 0 and result = decl.getPattern()
96-
or
97-
index = 1 and result = decl.getType()
98-
or
99-
index = 2 and result = decl.getValue()
100-
)
101-
or
102-
exists(FunctionExpr expr | n = expr |
103-
result = expr.getCaptureDeclaration(index)
104-
or
105-
// Put other children after the capture declarations.
106-
// They act as sibling-shadowing declarations, so they are in scope with in the other children.
107-
result = expr.getAFieldOrChild() and
108-
not result = expr.getACaptureDeclaration() and
109-
index = count(expr.getACaptureDeclaration())
110-
)
111-
or
11277
index = 0 and
11378
relocatedClassMember(n, result)
11479
}
@@ -131,7 +96,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
13196
not n instanceof LogicalAndExpr and // also ignore intermediate nodes within a 'logical and' tree
13297
not n instanceof GuardIfStmt and
13398
not relocatedClassMember(_, result) and
134-
index = 0 and
99+
index = result.getParentIndex() and
135100
result = n.getAFieldOrChild()
136101
}
137102

0 commit comments

Comments
 (0)