Skip to content

Commit a86ba3b

Browse files
committed
Ruby: rename WhenExpr to WhenClause
1 parent 6c71148 commit a86ba3b

File tree

8 files changed

+30
-25
lines changed

8 files changed

+30
-25
lines changed

ruby/ql/lib/codeql/ruby/ast/Control.qll

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,22 @@ class CaseExpr extends ControlExpr instanceof CaseExprImpl {
361361
final Expr getValue() { result = super.getValue() }
362362

363363
/**
364-
* Gets the `n`th branch of this case expression, either a `WhenExpr`, an
364+
* Gets the `n`th branch of this case expression, either a `WhenClause`, an
365365
* `InClause`, or a `StmtSequence`.
366366
*/
367367
final AstNode getBranch(int n) { result = super.getBranch(n) }
368368

369369
/**
370-
* Gets a branch of this case expression, either a `WhenExpr`, an
370+
* Gets a branch of this case expression, either a `WhenClause`, an
371371
* `InClause`, or a `StmtSequence`.
372372
*/
373373
final AstNode getABranch() { result = this.getBranch(_) }
374374

375375
/** Gets the `n`th `when` branch of this case expression. */
376-
deprecated final WhenExpr getWhenBranch(int n) { result = this.getBranch(n) }
376+
deprecated final WhenClause getWhenBranch(int n) { result = this.getBranch(n) }
377377

378378
/** Gets a `when` branch of this case expression. */
379-
deprecated final WhenExpr getAWhenBranch() { result = this.getABranch() }
379+
deprecated final WhenClause getAWhenBranch() { result = this.getABranch() }
380380

381381
/** Gets the `else` branch of this case expression, if any. */
382382
final StmtSequence getElseBranch() { result = this.getABranch() }
@@ -401,6 +401,11 @@ class CaseExpr extends ControlExpr instanceof CaseExprImpl {
401401
}
402402
}
403403

404+
/**
405+
* DEPRECATED: Use `WhenClause` instead.
406+
*/
407+
deprecated class WhenExpr = WhenClause;
408+
404409
/**
405410
* A `when` branch of a `case` expression.
406411
* ```rb
@@ -409,12 +414,12 @@ class CaseExpr extends ControlExpr instanceof CaseExprImpl {
409414
* end
410415
* ```
411416
*/
412-
class WhenExpr extends AstNode, TWhenExpr {
417+
class WhenClause extends AstNode, TWhenClause {
413418
private Ruby::When g;
414419

415-
WhenExpr() { this = TWhenExpr(g) }
420+
WhenClause() { this = TWhenClause(g) }
416421

417-
final override string getAPrimaryQlClass() { result = "WhenExpr" }
422+
final override string getAPrimaryQlClass() { result = "WhenClause" }
418423

419424
/** Gets the body of this case-when expression. */
420425
final Stmt getBody() { toGenerated(result) = g.getBody() }

ruby/ql/lib/codeql/ruby/ast/internal/AST.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private module Cached {
305305
TUntilExpr(Ruby::Until g) or
306306
TUntilModifierExpr(Ruby::UntilModifier g) or
307307
TVariableReferencePattern(Ruby::VariableReferencePattern g) or
308-
TWhenExpr(Ruby::When g) or
308+
TWhenClause(Ruby::When g) or
309309
TWhileExpr(Ruby::While g) or
310310
TWhileModifierExpr(Ruby::WhileModifier g) or
311311
TYieldCall(Ruby::Yield g)
@@ -344,7 +344,7 @@ private module Cached {
344344
TTernaryIfExpr or TThen or TTokenConstantAccess or TTokenMethodName or TTokenSuperCall or
345345
TToplevel or TTrueLiteral or TUnaryMinusExpr or TUnaryPlusExpr or TUndefStmt or
346346
TUnlessExpr or TUnlessModifierExpr or TUntilExpr or TUntilModifierExpr or
347-
TVariableReferencePattern or TWhenExpr or TWhileExpr or TWhileModifierExpr or TYieldCall;
347+
TVariableReferencePattern or TWhenClause or TWhileExpr or TWhileModifierExpr or TYieldCall;
348348

349349
class TAstNodeSynth =
350350
TAddExprSynth or TAssignExprSynth or TBitwiseAndExprSynth or TBitwiseOrExprSynth or
@@ -511,7 +511,7 @@ private module Cached {
511511
n = TUntilExpr(result) or
512512
n = TUntilModifierExpr(result) or
513513
n = TVariableReferencePattern(result) or
514-
n = TWhenExpr(result) or
514+
n = TWhenClause(result) or
515515
n = TWhileExpr(result) or
516516
n = TWhileModifierExpr(result) or
517517
n = TYieldCall(result)

ruby/ql/lib/codeql/ruby/ast/internal/Control.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ abstract class CaseExprImpl extends ControlExpr, TCase {
88
abstract AstNode getBranch(int n);
99
}
1010

11-
class CaseWhenExpr extends CaseExprImpl, TCaseExpr {
11+
class CaseWhenClause extends CaseExprImpl, TCaseExpr {
1212
private Ruby::Case g;
1313

14-
CaseWhenExpr() { this = TCaseExpr(g) }
14+
CaseWhenClause() { this = TCaseExpr(g) }
1515

1616
final override Expr getValue() { toGenerated(result) = g.getValue() }
1717

ruby/ql/lib/codeql/ruby/controlflow/internal/Completion.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private predicate inBooleanContext(AstNode n) {
205205
or
206206
n = any(StmtSequence parent | inBooleanContext(parent)).getLastStmt()
207207
or
208-
exists(CaseExpr c, WhenExpr w |
208+
exists(CaseExpr c, WhenClause w |
209209
not exists(c.getValue()) and
210210
c.getABranch() = w and
211211
w.getPattern(_) = n
@@ -227,7 +227,7 @@ private predicate mustHaveMatchingCompletion(AstNode n) {
227227
private predicate inMatchingContext(AstNode n) {
228228
n = any(RescueClause r).getException(_)
229229
or
230-
exists(CaseExpr c, WhenExpr w |
230+
exists(CaseExpr c, WhenClause w |
231231
exists(c.getValue()) and
232232
c.getABranch() = w and
233233
w.getPattern(_) = n

ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ module Trees {
399399
(
400400
last(this.getValue(), pred, c) and not exists(this.getABranch())
401401
or
402-
last(this.getABranch().(WhenExpr).getBody(), pred, c)
402+
last(this.getABranch().(WhenClause).getBody(), pred, c)
403403
or
404404
exists(int i, ControlFlowTree lastBranch |
405405
lastBranch = this.getBranch(i) and
@@ -1370,7 +1370,7 @@ module Trees {
13701370
final override ControlFlowTree getChildElement(int i) { result = this.getMethodName(i) }
13711371
}
13721372

1373-
private class WhenTree extends PreOrderTree, WhenExpr {
1373+
private class WhenTree extends PreOrderTree, WhenClause {
13741374
final override predicate propagatesAbnormal(AstNode child) { child = this.getAPattern() }
13751375

13761376
final Expr getLastPattern() {

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module LocalFlow {
134134
|
135135
stmt = c.getElseBranch() or
136136
stmt = c.getABranch().(InClause).getBody() or
137-
stmt = c.getABranch().(WhenExpr).getBody()
137+
stmt = c.getABranch().(WhenClause).getBody()
138138
)
139139
or
140140
exists(CfgNodes::ExprCfgNode exprTo, ReturningStatementNode n |

ruby/ql/test/library-tests/ast/Ast.expected

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ calls/calls.rb:
170170
# 106| getStmt: [CaseExpr] case ...
171171
# 106| getValue: [MethodCall] call to foo
172172
# 106| getReceiver: [Self, SelfVariableAccess] self
173-
# 107| getBranch: [WhenExpr] when ...
173+
# 107| getBranch: [WhenClause] when ...
174174
# 107| getPattern: [MethodCall] call to bar
175175
# 107| getReceiver: [Self, SelfVariableAccess] self
176176
# 107| getBody: [StmtSequence] then ...
@@ -179,7 +179,7 @@ calls/calls.rb:
179179
# 110| getStmt: [CaseExpr] case ...
180180
# 110| getValue: [MethodCall] call to foo
181181
# 110| getReceiver: [ConstantReadAccess] X
182-
# 111| getBranch: [WhenExpr] when ...
182+
# 111| getBranch: [WhenClause] when ...
183183
# 111| getPattern: [MethodCall] call to bar
184184
# 111| getReceiver: [ConstantReadAccess] X
185185
# 111| getBody: [StmtSequence] then ...
@@ -689,31 +689,31 @@ control/cases.rb:
689689
# 5| getAnOperand/getRightOperand: [IntegerLiteral] 0
690690
# 8| getStmt: [CaseExpr] case ...
691691
# 8| getValue: [LocalVariableAccess] a
692-
# 9| getBranch: [WhenExpr] when ...
692+
# 9| getBranch: [WhenClause] when ...
693693
# 9| getPattern: [LocalVariableAccess] b
694694
# 9| getBody: [StmtSequence] then ...
695695
# 10| getStmt: [IntegerLiteral] 100
696-
# 11| getBranch: [WhenExpr] when ...
696+
# 11| getBranch: [WhenClause] when ...
697697
# 11| getPattern: [LocalVariableAccess] c
698698
# 11| getPattern: [LocalVariableAccess] d
699699
# 11| getBody: [StmtSequence] then ...
700700
# 12| getStmt: [IntegerLiteral] 200
701701
# 13| getBranch/getElseBranch: [StmtSequence] else ...
702702
# 14| getStmt: [IntegerLiteral] 300
703703
# 18| getStmt: [CaseExpr] case ...
704-
# 19| getBranch: [WhenExpr] when ...
704+
# 19| getBranch: [WhenClause] when ...
705705
# 19| getPattern: [GTExpr] ... > ...
706706
# 19| getAnOperand/getGreaterOperand/getLeftOperand/getReceiver: [LocalVariableAccess] a
707707
# 19| getAnOperand/getArgument/getLesserOperand/getRightOperand: [LocalVariableAccess] b
708708
# 19| getBody: [StmtSequence] then ...
709709
# 19| getStmt: [IntegerLiteral] 10
710-
# 20| getBranch: [WhenExpr] when ...
710+
# 20| getBranch: [WhenClause] when ...
711711
# 20| getPattern: [EqExpr] ... == ...
712712
# 20| getAnOperand/getLeftOperand/getReceiver: [LocalVariableAccess] a
713713
# 20| getAnOperand/getArgument/getRightOperand: [LocalVariableAccess] b
714714
# 20| getBody: [StmtSequence] then ...
715715
# 20| getStmt: [IntegerLiteral] 20
716-
# 21| getBranch: [WhenExpr] when ...
716+
# 21| getBranch: [WhenClause] when ...
717717
# 21| getPattern: [LTExpr] ... < ...
718718
# 21| getAnOperand/getLeftOperand/getLesserOperand/getReceiver: [LocalVariableAccess] a
719719
# 21| getAnOperand/getArgument/getGreaterOperand/getRightOperand: [LocalVariableAccess] b

ruby/ql/test/library-tests/ast/control/CaseExpr.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ query predicate caseElseBranches(CaseExpr c, StmtSequence elseBranch) {
1010

1111
query predicate caseNoElseBranches(CaseExpr c) { not exists(c.getElseBranch()) }
1212

13-
query predicate caseWhenBranches(CaseExpr c, WhenExpr when, int pIndex, Expr p, StmtSequence body) {
13+
query predicate caseWhenBranches(CaseExpr c, WhenClause when, int pIndex, Expr p, StmtSequence body) {
1414
when = c.getABranch() and
1515
p = when.getPattern(pIndex) and
1616
body = when.getBody()

0 commit comments

Comments
 (0)