Comments (8)
We actually had a prototype for this at some point.
One important issue is the following: if we allow a full expression language for expressing widths, then the greater-than sign will make the grammar ambiguous: you don't know whether > is greater-than or the closing of the "template": bit<a > b ? c : d>
. So the grammar for expressions will have to require parentheses: bit<(8+8)>
. This is a usability concern. The alternative to restrict the expression language disallowing comparisons sounds like a bad idea.
from p4c.
Requiring parentheses in that context sounds reasonable to avoid the grammar ambiguity.
I would expect the common case for this would be having #define symbols that are sums of other #define symbols, and it is common practice to put parens around such expression anyway, to avoid syntax problems with the context of the C preprocessor textual substitution.
I haven't checked, but is it a workaround to this limitation in P4-16 to have one const be initialized via an arithmetic expression of other values defined as const, and use the const name as the width?
from p4c.
We only need to require the parentheses for expressions involving a >
token (including >>
or >=
), though doing so does involve some (minor) rule duplication in the grammar.
from p4c.
I'm curious how C++ deals with that ambiguity. This program actually compiles and runs fine:
template <bool V> struct foo { int value = V ? 10 : 20; };
int main() { return foo<1 < 2>().value; }
from p4c.
from p4c.
You want a tricky case, consider:
template <int V> struct foo {
int value = V ? 10 : 20;
foo(int a) : value(a) {}
operator int() { return value; }
};
int main() {
return foo<1 > (2)>(3);
}
from p4c.
Ah yes, that's a good point. C++'s grammar interprets >
in that case as closing the template argument list. That's considerably less impressive.
(FWIW, I'm familiar with how to handle this technically; I was more curious about what behavior they specified, but wasn't able to quickly find the appropriate section in the C++ standard.)
from p4c.
I think that this issue can now be closed permanently.
from p4c.
Related Issues (20)
- [P4Testgen] Build a Prototype which uses architecture templates
- [P4Testgen] Add a p4test-like target to testgen. HOT 7
- [P4Testgen] Coverage ignores empty actions HOT 5
- p4-ebpf permission denied: func 'map_initializer' doesn't have 1-th argument: invalid bpf_context HOT 5
- How to use p4lang to implement division operation in compile-time unknown value ? HOT 2
- MoveInitializers drops the srcInfo when moving to the top of a P4Control body
- Protobuf build errors with v1.2.4.7 HOT 5
- [P4Testgen] Revisit handling of varbit in P4Tools/P4Testgen
- Cannot use hvec_map for cstring keys HOT 3
- [P4Testgen] Validate options as early as possible
- [P4Testgen] The actions' coverage works weirdly if action is called from multiple tables HOT 4
- Port XDP tests from archived p4c-xdp repository
- Show a warning when a `@hidden` annotation is used on something where it is meaningless
- Clarify expected behavior of `--W*=diagnostic` option when `diagnostic` can be an error HOT 11
- Bug in p4c with some kinds of if statements inside of action bodies HOT 3
- `P4TEST_REPLACE` does not replace expected contents of `p4tc` test outputs HOT 4
- If and return/exit statements causing uninitialized_use warnings HOT 2
- hvec_map::insert has a non-standard behavior HOT 2
- P4C arm64/aarch64 support HOT 14
- Update the hash functions used in `hash.cpp` and `cstring.cpp` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p4c.