Skip to content

Commit 830908b

Browse files
committed
Address comments
1 parent 1e026ef commit 830908b

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

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

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import codeql.ruby.AST
22
private import internal.AST
3+
private import internal.Control
34
private import internal.TreeSitter
45

56
/**
@@ -337,9 +338,7 @@ class TernaryIfExpr extends ConditionalExpr, TTernaryIfExpr {
337338
* end
338339
* ```
339340
*/
340-
class CaseExpr extends ControlExpr, TCase {
341-
final override string getAPrimaryQlClass() { result = "CaseExpr" }
342-
341+
class CaseExpr extends ControlExpr instanceof CaseExprImpl {
343342
/**
344343
* Gets the expression being compared, if any. For example, `foo` in the following example.
345344
* ```rb
@@ -359,17 +358,17 @@ class CaseExpr extends ControlExpr, TCase {
359358
* end
360359
* ```
361360
*/
362-
Expr getValue() { none() }
361+
final Expr getValue() { result = super.getValue() }
363362

364363
/**
365-
* Gets the `n`th branch of this case expression, either a `WhenExpr`, or a
366-
* `InClause` or a `StmtSequence`.
364+
* Gets the `n`th branch of this case expression, either a `WhenExpr`, an
365+
* `InClause`, or a `StmtSequence`.
367366
*/
368-
Expr getBranch(int n) { none() }
367+
final Expr getBranch(int n) { result = super.getBranch(n) }
369368

370369
/**
371-
* Gets a branch of this case expression, either a `WhenExpr`, or a
372-
* `InClause` or a `StmtSequence`.
370+
* Gets a branch of this case expression, either a `WhenExpr`, an
371+
* `InClause`, or a `StmtSequence`.
373372
*/
374373
final Expr getABranch() { result = this.getBranch(_) }
375374

@@ -387,10 +386,12 @@ class CaseExpr extends ControlExpr, TCase {
387386
*/
388387
final int getNumberOfBranches() { result = count(this.getBranch(_)) }
389388

389+
final override string getAPrimaryQlClass() { result = "CaseExpr" }
390+
390391
final override string toString() { result = "case ..." }
391392

392393
override AstNode getAChild(string pred) {
393-
result = super.getAChild(pred)
394+
result = ControlExpr.super.getAChild(pred)
394395
or
395396
pred = "getValue" and result = this.getValue()
396397
or
@@ -400,33 +401,6 @@ class CaseExpr extends ControlExpr, TCase {
400401
}
401402
}
402403

403-
private class CaseWhenExpr extends CaseExpr, TCaseExpr {
404-
private Ruby::Case g;
405-
406-
CaseWhenExpr() { this = TCaseExpr(g) }
407-
408-
final override Expr getValue() { toGenerated(result) = g.getValue() }
409-
410-
final override Expr getBranch(int n) {
411-
toGenerated(result) = g.getChild(n) or
412-
toGenerated(result) = g.getChild(n)
413-
}
414-
}
415-
416-
private class CaseMatch extends CaseExpr, TCaseMatch {
417-
private Ruby::CaseMatch g;
418-
419-
CaseMatch() { this = TCaseMatch(g) }
420-
421-
final override Expr getValue() { toGenerated(result) = g.getValue() }
422-
423-
final override Expr getBranch(int n) {
424-
toGenerated(result) = g.getClauses(n)
425-
or
426-
n = count(g.getClauses(_)) and toGenerated(result) = g.getElse()
427-
}
428-
}
429-
430404
/**
431405
* A `when` branch of a `case` expression.
432406
* ```rb
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
private import TreeSitter
2+
private import codeql.ruby.AST
3+
private import codeql.ruby.ast.internal.AST
4+
5+
abstract class CaseExprImpl extends ControlExpr, TCase {
6+
abstract Expr getValue();
7+
8+
abstract Expr getBranch(int n);
9+
}
10+
11+
class CaseWhenExpr extends CaseExprImpl, TCaseExpr {
12+
private Ruby::Case g;
13+
14+
CaseWhenExpr() { this = TCaseExpr(g) }
15+
16+
final override Expr getValue() { toGenerated(result) = g.getValue() }
17+
18+
final override Expr getBranch(int n) {
19+
toGenerated(result) = g.getChild(n) or
20+
toGenerated(result) = g.getChild(n)
21+
}
22+
}
23+
24+
class CaseMatch extends CaseExprImpl, TCaseMatch {
25+
private Ruby::CaseMatch g;
26+
27+
CaseMatch() { this = TCaseMatch(g) }
28+
29+
final override Expr getValue() { toGenerated(result) = g.getValue() }
30+
31+
final override Expr getBranch(int n) {
32+
toGenerated(result) = g.getClauses(n)
33+
or
34+
n = count(g.getClauses(_)) and toGenerated(result) = g.getElse()
35+
}
36+
}

0 commit comments

Comments
 (0)