Skip to content

Commit 30e9b94

Browse files
committed
unified: Add IdentifierExpr and use it in CFG
1 parent 9df4aa9 commit 30e9b94

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,16 @@ module Public {
6868
final class TopLevelStmt extends Stmt {
6969
TopLevelStmt() { this = any(TopLevel t).getBody().getAStmt() }
7070
}
71+
72+
/** An identifier appearing in the context of an expression, pattern, or type annotation. */
73+
final class IdentifierExpr extends Identifier {
74+
IdentifierExpr() {
75+
not this = any(MemberAccessExpr e).getMemberNameNode() and
76+
not this = any(Argument a).getNameNode() and
77+
not this = any(Parameter p).getExternalNameNode() and
78+
not this = any(LabeledStmt stmt).getLabelNameNode() and
79+
not this = any(BreakExpr expr).getLabelNameNode() and
80+
not this = any(ContinueExpr expr).getLabelNameNode()
81+
}
82+
}
7183
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ private module Ast implements AstSig<Location> {
2525

2626
class AstNode = U::AstNode;
2727

28-
private predicate skipControlFlow(AstNode e) { e instanceof Modifier or e instanceof Identifier }
28+
private predicate skipControlFlow(AstNode e) {
29+
e instanceof Modifier
30+
or
31+
e instanceof Identifier and not e instanceof IdentifierExpr
32+
}
2933

3034
AstNode getChild(AstNode n, int index) {
3135
result.getParent() = n and

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,7 @@ module Public {
387387
* }
388388
* ```
389389
*/
390-
class PotentialLocalNameAccess extends Identifier {
391-
PotentialLocalNameAccess() {
392-
not this = any(MemberAccessExpr e).getMemberNameNode() and
393-
not this = any(Argument a).getNameNode() and
394-
not this = any(Parameter p).getExternalNameNode() and
395-
not this = any(LabeledStmt stmt).getLabelNameNode() and
396-
not this = any(BreakExpr expr).getLabelNameNode() and
397-
not this = any(ContinueExpr expr).getLabelNameNode()
398-
}
399-
390+
class PotentialLocalNameAccess extends IdentifierExpr {
400391
LocalName getLocalName() { result = this.(LocalNameBindingOutput::LocalAccess).getLocal() }
401392

402393
string getName() { result = this.getValue() }

0 commit comments

Comments
 (0)