Skip to content

Commit

Permalink
Add op= assignments
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Dodd <[email protected]>
  • Loading branch information
ChrisDodd committed Feb 4, 2025
1 parent c25a780 commit 178029a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions p4-16/spec/P4-16-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5498,6 +5498,15 @@ types (e.g. ``struct``s) are copied recursively, and all components
of ``header``s are copied, including "validity" bits. Assignment is
not defined for `extern` values.

An assignment may also be written with a binary arithmetic or bit manipulation
operator immediately before the `=` sign. This performs the binary operator on
the old value of the left sub-expression and the right sub-expression and assigns
the result to the l-value. Thus an assignment like `A += B` is equivalent
to `A = A + B`, except that `A` is only evaluated once. This means that
any side-effects within this operand (eg, a function call inside an array index
or slice expression) only occur once. This is not valid
for comparison operators, logical operators, concat, range, or mask operators.

[#sec-empty-stmt]
=== Empty statement

Expand Down
14 changes: 13 additions & 1 deletion p4-16/spec/grammar.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,19 @@ typedefDeclaration
assignmentOrMethodCallStatement
: lvalue "(" argumentList ")" ";"
| lvalue "<" typeArgumentList ">" "(" argumentList ")" ";"
| lvalue "=" expression ";"
| lvalue "=" expression ";"
| lvalue "*=" expression ";"
| lvalue "/=" expression ";"
| lvalue "%=" expression ";"
| lvalue "+=" expression ";"
| lvalue "-=" expression ";"
| lvalue "|+|=" expression ";"
| lvalue "|-|=" expression ";"
| lvalue "<<=" expression ";"
| lvalue ">>=" expression ";"
| lvalue "&=" expression ";"
| lvalue "|=" expression ";"
| lvalue "^=" expression ";"
;
// end::assignmentOrMethodCallStatement[]

Expand Down

0 comments on commit 178029a

Please sign in to comment.