You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clarify default mixed in with cases, fix rule about duplicate case values (gpuweb#3316)
- default can appear at most once in a case selector list
- Rephrase rule about duplicate case values. They are not always literals.
- Restate rules about "case bodies" to include the default-alone clause
- Fix the "declaration in a body" rule to mirror the clarifications
recently made for the 'loop' statement
- Rearrange to pull validation rules above behaviours.
- Pull initial "purpose" statement at the top, above grammar rules.
@@ -6699,48 +6712,62 @@ An `if` statement is executed as follows:
6699
6712
| [=syntax/expression=]
6700
6713
</div>
6701
6714
6702
-
A <dfn noexport dfn-for="statement">switch</dfn> statement transfers control to one of a set of case clauses, or to the `default` clause,
6703
-
depending on the evaluation of a selector expression.
6715
+
A <dfn noexport>case clause</dfn> is the [=syntax/case=] token followed by a comma-separated list of [=syntax/case_selector|case selectors=] and a
6716
+
body in the form of a [=compound statement=].
6704
6717
6705
-
If the selector value equals a value in a case selector list, then control is transferred to
6706
-
the body of that case clause.
6707
-
The expressions in the [=syntax/case_selectors=] [=shader-creation error|must=]
6708
-
be [=const-expressions=].
6709
-
If the selector value does not equal any of the case selector values, then control is
6710
-
transferred to the `default` clause.
6718
+
A <dfn noexport>default-alone clause</dfn> is the [=syntax/default=] token followed by a body in the form of a [=compound statement=].
6711
6719
6712
-
Each switch statement [=shader-creation error|must=] have exactly one default clause.
6720
+
A <dfn noexport>default clause</dfn> is either:
6721
+
* a [=case clause=] where [=syntax/default=] appears as one of its selectors, or
6722
+
* a [=default-alone clause=].
6723
+
6724
+
Each switch statement [=shader-creation error|must=] have exactly one [=default clause=].
6725
+
6726
+
The [=syntax/default=] token [=shader-creation error|must=] not appear more than once in a single [=syntax/case_selector=] list.
6713
6727
6714
6728
[=Type rule precondition=]:
6715
6729
For a single switch statement, the selector expression and all case selector expressions [=shader-creation error|must=] be of the same [=type/concrete=] [=integer scalar=] type.
6716
6730
6717
-
A literal value [=shader-creation error|must not=] appear more than once in the case selectors for a switch statement.
6731
+
The expressions in the [=syntax/case_selectors=] [=shader-creation error|must=]
6732
+
be [=const-expressions=].
6733
+
6734
+
Two different case selector expressions in the same switch statement [=shader-creation error|must not=] have the same value.
6718
6735
6719
-
Note: The value of the literal is what matters, not the spelling.
6720
-
For example `0` and `0x0000` both denote the zero value.
6736
+
If the selector value equals the value of an expression in a [=syntax/case_selector=] list,
6737
+
then control is transferred to the body of that [=case clause=].
6738
+
If the selector value does not equal any of the case selector values, then control is
6739
+
transferred to the body of the [=default clause=].
6721
6740
6722
-
When control reaches the end of a case body, control normally transfers to the first statement
6723
-
after the switch statement.
6724
-
When a [=declaration=] appears in a case body, its [=identifier=] is [=in scope=] from
6725
-
the start of the next statement until the end of the case body.
6741
+
When control reaches the end of the body of a clause, control transfers to the first statement after the switch statement.
6742
+
6743
+
When one of the statements in the body of a clause is a [=declaration=],
6744
+
it follows the normal [=scope=] and [=lifetime=] rules of a declaration in a [=compound statement=].
6745
+
That is, the body is a sequence of statements, and if one of those is a declaration
6746
+
then the scope of that declaration extends from the start of the next statement in the sequence
6747
+
until the end of the body.
6748
+
The declaration executes when it is reached,
6749
+
creating a new instance of the [=variable declaration|variable=] or [=value declaration|value=], and initializes it.
case 1, 2 { // multiple selector values can be used
6739
-
a = 3; // a will be overridden in the next case
6762
+
case 1, 2, { // Multiple selector values can be used
6763
+
a = 3;
6740
6764
}
6741
-
case 3 {
6765
+
case 3, { // The trailing comma is optional
6742
6766
a = 4;
6743
6767
}
6768
+
case 4 {
6769
+
a = 5;
6770
+
}
6744
6771
}
6745
6772
</xmp>
6746
6773
</div>
@@ -9012,7 +9039,7 @@ When several edges have to be created we use `X -> {Y, Z}` as a short-hand for `
9012
9039
Analysis of [[#for-statement|for]] and [[#while-statement|while]] loops follows
9013
9040
from their respective desugaring translations to [[#loop-statement|loop]] statements.
9014
9041
9015
-
In [[#switch-statement|switch]], a `default` block is treated exactly like a case block with regards to uniformity.
9042
+
In [[#switch-statement|switch]], a [=default-alone clause=] block is treated exactly like a [=case clause=] with regards to uniformity.
9016
9043
9017
9044
Note: If the set of behaviors (see [[#behaviors]]) for an if, switch, or loop statement is {Next}, this means that we either did not diverge within the statement, or we reconverged, so we pick the node corresponding to control flow at the start of the statement as the node corresponding to control flow at the exit of the statement.
0 commit comments