Skip to content

Commit c80dd0e

Browse files
committed
Move getExpr to SwitchExpr
1 parent de20d07 commit c80dd0e

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

go/ql/lib/semmle/go/Stmt.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,12 @@ class SwitchStmt extends @switchstmt, Stmt, ScopeNode {
832832
/** Gets the init statement of this `switch` statement, if any. */
833833
Stmt getInit() { result = this.getChildStmt(0) }
834834

835+
/**
836+
* Gets the expression whose value or type is examined by this `switch`
837+
* statement, if any.
838+
*/
839+
Expr getExpr() { none() }
840+
835841
/** Gets the body of this `switch` statement. */
836842
BlockStmt getBody() { result = this.getChildStmt(2) }
837843

@@ -880,8 +886,7 @@ class SwitchStmt extends @switchstmt, Stmt, ScopeNode {
880886
* ```
881887
*/
882888
class ExpressionSwitchStmt extends @exprswitchstmt, SwitchStmt {
883-
/** Gets the switch expression of this `switch` statement. */
884-
Expr getExpr() { result = this.getChildExpr(1) }
889+
override Expr getExpr() { result = this.getChildExpr(1) }
885890

886891
override predicate mayHaveSideEffects() {
887892
this.getInit().mayHaveSideEffects() or
@@ -912,14 +917,13 @@ class ExpressionSwitchStmt extends @exprswitchstmt, SwitchStmt {
912917
* ```
913918
*/
914919
class TypeSwitchStmt extends @typeswitchstmt, SwitchStmt {
915-
/** Gets the assign statement of this type-switch statement. */
916920
SimpleAssignStmt getAssign() { result = this.getChildStmt(1) }
917921

918922
/** Gets the test statement of this type-switch statement. This is a `SimpleAssignStmt` or `ExprStmt`. */
919923
Stmt getTest() { result = this.getChildStmt(1) }
920924

921925
/** Gets the expression whose type is examined by this `switch` statement. */
922-
Expr getExpr() {
926+
override Expr getExpr() {
923927
result = this.getAssign().getRhs() or result = this.getChildStmt(1).(ExprStmt).getExpr()
924928
}
925929

go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,7 @@ module CfgImpl {
265265
}
266266

267267
class Switch extends AstNode instanceof Go::SwitchStmt {
268-
Expr getExpr() {
269-
result = this.(Go::ExpressionSwitchStmt).getExpr()
270-
or
271-
// For a type switch the "switch expression" is the type-assertion
272-
// expression `x.(type)`; evaluating it directly (rather than the
273-
// wrapping `y := x.(type)` statement) lets the shared switch model
274-
// drive the per-case type tests.
275-
result = this.(Go::TypeSwitchStmt).getExpr()
276-
}
268+
Expr getExpr() { result = this.(Go::SwitchStmt).getExpr() }
277269

278270
Case getCase(int index) { result = this.(Go::SwitchStmt).getCase(index) }
279271

0 commit comments

Comments
 (0)