-
Notifications
You must be signed in to change notification settings - Fork 82
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
Added structure-valued expressions #773
Conversation
Fixes #772 |
Can we also agree that if a field is not mentioned in kvlist, it will be automatically assigned a 0 value and also agree that kvlist can be empty, meaning that:
will do the right thing? |
@vgurevich : There is a discussion on this topic #717 |
p4-16/spec/P4-16-spec.mdk
Outdated
| '{' kvList '}' | ||
| typeName '{' kvList '}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates the awkward situation where all of the following are valid syntax:
{ a=0, b=1 }
S { a=0, b=1 }
(S) { a=0, b=1 }
(S1) S2 { a=0, b=1 }
One way around this awkwardness would be to only allow the '{' kvList '}'
production and remove the typeName '{' kvList '}'
production, but then typing of struct-valued expressions can become ambiguous when the program has defined multiple types that match.
Another alternative would be demote '{' kvList '}'
from being a first-class expression, and only allow it as a struct initializer: S s = { a=0, b=1 };
. Then, struct-valued expressions would always use the S { a=0, b=1 }
form. My impression is that this would be compatible with what we released in 1.2.0, but I haven't confirmed. (This is what I was previously advocating for, but I guess that wasn't clear.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the typechecker will reject today casts with struct types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe that's a good rule: if a cast is to a Struct or header type then it is only allowed for struct-valued expressions.
We should try the syntax with a cast instead of a type. |
Would it make sense that if/when this is merged in, it should replace the text about structure initializers? It seems that this proposal does everything that does, and more. Also, is it fair to say that while this proposal is not identical to "Compound literals" in C/C++, it is pretty close? |
54c7df1
to
5bde224
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This should be merged after #717