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

const not allowed inside parser state definition #422

Closed
jafingerhut opened this issue Apr 3, 2017 · 4 comments
Closed

const not allowed inside parser state definition #422

jafingerhut opened this issue Apr 3, 2017 · 4 comments

Comments

@jafingerhut
Copy link
Contributor

jafingerhut commented Apr 3, 2017

The attached program demonstrates this with 2017-Mar-30 version of p4test and p4c-bm2-ss.

Both const and variable declarations are allowed in all of these places by current P4_16 compiler:

  • top level
  • inside parser directly (outside of parser state definition)
  • inside control directly (outside of table or action definition)
  • inside action
  • inside control apply block
  • inside inner blocks enclosed by braces in any of the above places that allow block statements (i.e., actions, control apply blocks)

The unusual one is that parser states allow variable declarations, but not const. Not a hard restriction to live with, but seems fairly odd given the consistency in all of the other places above.
const-error-in-state.p4.txt

mihaibudiu pushed a commit to mihaibudiu/p4c-clone that referenced this issue Apr 3, 2017
@mihaibudiu
Copy link
Contributor

Actually variable declarations at the top-level should be illegal. If they are not, it's a bug.
At the toplevel you should only be allowed instances.

@mihaibudiu
Copy link
Contributor

I could not reproduce the claim that variable declarations are allowed at the top-level. If you have a counter-example please share it.

Please note that we make a clear distinction between variables and instances. Variables live on the "stack", while instances are statically allocated. We allow instances at the top-level, but not variables.

@jafingerhut
Copy link
Contributor Author

I was mistaken about variable declarations being allowed at the top-level. Thanks for the correction.

ChrisDodd pushed a commit that referenced this issue Apr 4, 2017
@jafingerhut
Copy link
Contributor Author

jafingerhut commented Apr 4, 2017

Github did not auto-close this issue when the commit to fix it went in: b85401c

I have tested with compiler and failing test case after that commit, and it is accepting const inside parser state definition now, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants