From eb9b54f595d99b77b6936cddfe71a1dd09278d2f Mon Sep 17 00:00:00 2001 From: kfcripps Date: Tue, 4 Feb 2025 10:13:03 -0800 Subject: [PATCH] clarifications around switch statements used in action bodies Signed-off-by: kfcripps --- p4-16/spec/P4-16-spec.adoc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/p4-16/spec/P4-16-spec.adoc b/p4-16/spec/P4-16-spec.adoc index ea4df01d5..e8850195e 100644 --- a/p4-16/spec/P4-16-spec.adoc +++ b/p4-16/spec/P4-16-spec.adoc @@ -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] ---- @@ -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] ---- @@ -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 -<>). 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 <>). All switch labels must be names of actions of the table `t`, or `default`. [source,p4]