Skip to content

Commit 20e6cb4

Browse files
committed
Apply review suggestions
Signed-off-by: Vladimir Still <git@vstill.eu>
1 parent 27fef74 commit 20e6cb4

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

p4-16/spec/P4-16-spec.mdk

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,9 +1306,16 @@ represent legal UTF-8 encodings).
13061306

13071307
Since P4 does not allow strings to exist at runtime, string literals
13081308
are generally passed unchanged through the P4 compiler to
1309-
other third-party tools or compiler-backends, including the
1310-
terminating quotes. These tools can define their own handling of
1311-
escape sequences (e.g., how to specify Unicode characters, or handle
1309+
other third-party tools or compiler-backends. The compiler can, however,
1310+
perform compile-time concatenation (constant-folding) of concatenation
1311+
expressions into single literal. When such concatenation is performed,
1312+
the binary representation of the string literals (excluding the quotes)
1313+
is concatenated in the order they appears in the source code. There are
1314+
no escape sequences that would be treated specially when strings are
1315+
concatenated.
1316+
1317+
The backends and other tools can define their own handling of escape
1318+
sequences (e.g., how to specify Unicode characters, or handle
13121319
unprintable ASCII characters).
13131320

13141321
Here are 3 examples of string literals:
@@ -1319,6 +1326,16 @@ Here are 3 examples of string literals:
13191326
line terminator"
13201327
~ End P4Example
13211328

1329+
Here is an example of concatenation expression and an equivalent string
1330+
literal:
1331+
1332+
~ Begin P4Example
1333+
"one string \" with a quote inside;" ++ (" " ++ "another string")
1334+
// can be constant folded to
1335+
"one string \" with a quote inside; another string")
1336+
~ End P4Example
1337+
1338+
13221339
### Optional trailing commas { #sec-trailing-commas }
13231340

13241341
The P4 grammar allows several kinds of comma-separated lists to end in
@@ -1911,10 +1928,10 @@ be performed on booleans are described in Section [#sec-bool-exprs].
19111928

19121929
### Strings { #sec-string-type }
19131930

1914-
The type `string` represents strings. The values are either string
1915-
literals, or concatenations of multiple string literals. Operations
1916-
that can be performed on strings are described in Section
1917-
[#sec-string-ops].
1931+
The type `string` represents strings. The values of type `string` are
1932+
either string literals, or concatenations of multiple `string`-typed
1933+
expression. Operations that can be performed on strings are described in
1934+
Section [#sec-string-ops].
19181935

19191936
One cannot declare variables with a `string` type. Parameters with
19201937
type `string` can be only directionless (see Section
@@ -3748,7 +3765,7 @@ compile-time (Section [#sec-minsizeinbits]).
37483765

37493766
The only operation allowed on strings is concatenation, denoted by
37503767
`++`. For string concatenation, both operands must be strings and
3751-
the result is also a string. String concatenation can be only
3768+
the result is also a string. String concatenation can only be
37523769
performed at compile time.
37533770

37543771
~ Begin P4Example
@@ -8509,7 +8526,7 @@ table t {
85098526
The `@name` annotation directs the compiler to use a different
85108527
local name when generating the external APIs used to manipulate a
85118528
language element from the control plane. This annotation takes a local
8512-
compile-time know value of type `string` (typically a string literal).
8529+
compile-time known value of type `string` (typically a string literal).
85138530
In the following example, the fully-qualified name of the table is
85148531
`c_inst.t1`.
85158532

@@ -8611,7 +8628,7 @@ absence), allowing architecture-independent analysis of P4 programs.
86118628
The `deprecated` annotation has a required string argument that is a
86128629
message that will be printed by a compiler when a program is using the
86138630
deprecated construct. This is mostly useful for annotating library
8614-
constructs, such as externs. The parameter needs to be local
8631+
constructs, such as externs. The parameter must be a local
86158632
compile-time known value of type `string`.
86168633

86178634
~ Begin P4Example
@@ -8627,7 +8644,7 @@ extern Checker {
86278644
The `noWarn` annotation has a required string argument that indicates
86288645
a compiler warning that will be inhibited. For example
86298646
`@noWarn("unused")` on a declaration will prevent a compiler warning
8630-
if that declaration is not used. The parameter needs to be local
8647+
if that declaration is not used. The parameter must be a local
86318648
compile-time known value of type `string`.
86328649

86338650
## Target-specific annotations

0 commit comments

Comments
 (0)