Skip to content

Commit

Permalink
clarifications around switch statements used in action bodies
Browse files Browse the repository at this point in the history
Signed-off-by: kfcripps <[email protected]>
  • Loading branch information
kfcripps committed Feb 4, 2025
1 parent c25a780 commit eb9b54f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions p4-16/spec/P4-16-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5463,12 +5463,12 @@ Statements can appear in several places:

* Within `parser` states
* Within a `control` block
* Within an `action`
* Within an `action` or function

There are restrictions for the kinds of statements that can appear in
each of these places. For example, ``return``s are not supported in
parsers, and `switch` statements are only supported in control
blocks. We present here the most general case, for control blocks.
each of these places. For example, neither ``return``s nor `switch`
statements are supported in parsers. We present here the most general
case, for control blocks.

[source,bison]
----
Expand Down Expand Up @@ -5621,7 +5621,8 @@ innermost `if` statement that does not have an `else` statement.
[#sec-switch-stmt]
=== Switch statement

The `switch` statement can only be used within `control` blocks.
The `switch` statement can only be used within `control` blocks, `action`
bodies, or function bodies.

[source,bison]
----
Expand All @@ -5646,9 +5647,10 @@ separately in the following two subsections.

==== Switch statement with `action_run` expression

For this variant of `switch` statement, the expression must be of the
form `t.apply().action_run`, where `t` is the name of a table (see
<<sec-invoke-mau>>). All switch labels must be names of
This type of `switch` statement can only be used within control `apply`
blocks. For this variant of `switch` statement, the expression must be
of the form `t.apply().action_run`, where `t` is the name of a table
(see <<sec-invoke-mau>>). All switch labels must be names of
actions of the table `t`, or `default`.

[source,p4]
Expand Down

0 comments on commit eb9b54f

Please sign in to comment.