@@ -400,23 +400,43 @@ class SwitchStmt extends Stmt, @switchstmt {
400400}
401401
402402/**
403- * A case of a `switch` statement.
403+ * A case of a `switch` statement or expression .
404404 *
405405 * This includes both normal `case`s and the `default` case.
406406 */
407407class SwitchCase extends Stmt , @case {
408+ /** Gets the switch statement to which this case belongs, if any. */
408409 SwitchStmt getSwitch ( ) { result .getACase ( ) = this }
410+
411+ /** Gets the switch expression to which this case belongs, if any. */
412+ SwitchExpr getSwitchExpr ( ) { result .getACase ( ) = this }
413+
414+ /** Holds if this `case` is a switch labeled rule of the form `... -> ...`. */
415+ predicate isRule ( ) {
416+ exists ( Expr e | e .getParent ( ) = this | e .getIndex ( ) = - 1 )
417+ or
418+ exists ( Stmt s | s .getParent ( ) = this | s .getIndex ( ) = - 1 )
419+ }
409420}
410421
411422/** A constant `case` of a switch statement. */
412423class ConstCase extends SwitchCase {
413424 ConstCase ( ) { exists ( Expr e | e .getParent ( ) = this | e .getIndex ( ) >= 0 ) }
414425
415- /** Gets the expression of this `case`. */
426+ /** Gets the `case` constant at index 0 . */
416427 Expr getValue ( ) { result .getParent ( ) = this and result .getIndex ( ) = 0 }
417428
429+ /** Gets the `case` constant at the specified index. */
430+ Expr getValue ( int i ) { result .getParent ( ) = this and result .getIndex ( ) = i and i >= 0 }
431+
432+ /** Gets the expression on the right-hand side of the arrow, if any. */
433+ Expr getRuleExpression ( ) { result .getParent ( ) = this and result .getIndex ( ) = - 1 }
434+
435+ /** Gets the statement on the right-hand side of the arrow, if any. */
436+ Stmt getRuleStatement ( ) { result .getParent ( ) = this and result .getIndex ( ) = - 1 }
437+
418438 /** Gets a printable representation of this statement. May include more detail than `toString()`. */
419- override string pp ( ) { result = "case ...: " }
439+ override string pp ( ) { result = "case ..." }
420440
421441 /** This statement's Halstead ID (used to compute Halstead metrics). */
422442 override string getHalsteadID ( ) { result = "ConstCase" }
@@ -552,9 +572,17 @@ class BreakStmt extends Stmt, @breakstmt {
552572 /** Holds if this `break` statement has an explicit label. */
553573 predicate hasLabel ( ) { exists ( string s | s = this .getLabel ( ) ) }
554574
575+ /** Gets the value of this `break` statement, if any. */
576+ Expr getValue ( ) { result .getParent ( ) = this }
577+
578+ /** Holds if this `break` statement has a value. */
579+ predicate hasValue ( ) { exists ( Expr e | e .getParent ( ) = this ) }
580+
555581 /** Gets a printable representation of this statement. May include more detail than `toString()`. */
556582 override string pp ( ) {
557- if this .hasLabel ( ) then result = "break " + this .getLabel ( ) else result = "break"
583+ if this .hasLabel ( )
584+ then result = "break " + this .getLabel ( )
585+ else ( if this .hasValue ( ) then result = "break ..." else result = "break" )
558586 }
559587
560588 /** This statement's Halstead ID (used to compute Halstead metrics). */
0 commit comments