Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local typedef declarations #1011

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions p4-16/spec/P4-16-spec.mdk
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,7 @@ to a `set` type. These types are used during type-checking.
typeDeclaration
: derivedTypeDeclaration
| typedefDeclaration
| newtypeDeclaration
| parserTypeDeclaration ';'
| controlTypeDeclaration ';'
| packageTypeDeclaration ';'
Expand Down Expand Up @@ -2992,7 +2993,8 @@ Similarly to `typedef`, the keyword `type` can be used to introduce a
new type.

~ Begin P4Grammar
| optAnnotations TYPE typeRef name
newtypeDeclaration
: optAnnotations TYPE typeRef name
| optAnnotations TYPE derivedTypeDeclaration name
~ End P4Grammar

Expand Down Expand Up @@ -5160,10 +5162,10 @@ emptyStatement

## Block statement { #sec-block-stmt }

A block statement is denoted by curly braces. It contains a
sequence of statements and declarations, which are executed
sequentially. The variables and constants within a
block statement are only visible within the block.
A block statement is denoted by curly braces. It contains a sequence
of statements and declarations, which are executed sequentially. The
variables, constants, typedefs, and instantiations within a block
statement are only visible within the block.

~ Begin P4Grammar
blockStatement
Expand All @@ -5178,6 +5180,7 @@ statOrDeclList
statementOrDeclaration
: variableDeclaration
| constantDeclaration
| typedefDeclaration
| statement
;
~ End P4Grammar
Expand Down
5 changes: 5 additions & 0 deletions p4-16/spec/grammar.mdk
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ typeArgumentList
typeDeclaration
: derivedTypeDeclaration
| typedefDeclaration
| newtypeDeclaration
| parserTypeDeclaration ';'
| controlTypeDeclaration ';'
| packageTypeDeclaration ';'
Expand Down Expand Up @@ -441,6 +442,9 @@ specifiedIdentifier
typedefDeclaration
: optAnnotations TYPEDEF typeRef name ';'
| optAnnotations TYPEDEF derivedTypeDeclaration name ';'
;

newtypeDeclaration
| optAnnotations TYPE typeRef name ';'
| optAnnotations TYPE derivedTypeDeclaration name ';'
;
Expand Down Expand Up @@ -518,6 +522,7 @@ switchLabel
statementOrDeclaration
: variableDeclaration
| constantDeclaration
| typedefDeclaration
| statement
;

Expand Down