Cpp1 reflection: Cpp2 syntax #774
Replies: 8 comments 37 replies
-
This is the idea that motivated me to start this discussion. The idea is to complement This formulation isn't problematic like multi-token types are (e.g, Grammar diff //G postfix-operator:
-//G one of '++' '--' '*' '&' '~' '$' '...'
+//G one of '++' '--' '*' '&' '~' '$' '...' 'v'
//G
//G postfix-expression:
//G primary-expression
-//G postfix-expression postfix-operator [Note: without whitespace before the operator]
+//G postfix-expression postfix-operator [Note: without whitespace before the operator, except for `v`]
//G
//G unqualified-id:
//G identifier
//G keyword
//G template-id
//GTODO operator-function-id
//G ...
+//G '(' expression 'v' ')' New semanticsCpp2 Why not prefix.Under the usual rules (except for If If
|
Beta Was this translation helpful? Give feedback.
-
On a discussion on reddit about reflection, someone pointed out that
I don't know if they're correct or not but i think it makes sense. Secondly, the |
Beta Was this translation helpful? Give feedback.
-
I think #774 (reply in thread) is my favorite. |
Beta Was this translation helpful? Give feedback.
-
It seems operator xabx: == 10;
a: = xabx^++; // ERROR: std::meta::info doesn't have operator++ So operator xabx: == 10;
a: = ^xabx; |
Beta Was this translation helpful? Give feedback.
-
Currently xabx: = int^;
var1: $<xabx> = 10;
member: = /*reflection*/;
obj.$<member> = 10; Why Because its behavior is similar to On the other hands, necessarily its syntax is different from both capturing and template argument/parameter list. |
Beta Was this translation helpful? Give feedback.
-
Question: Why not just take the C++ reflection syntax? While cpp2 has been a syntax overhaul, operators have not been changed, merely made postfix. The symbol for a specific operator has been same. Then why change reflection syntax? Note: One notable change could be |
Beta Was this translation helpful? Give feedback.
-
r/cpp post: Anyone find the proposed reflection syntax distracting?. |
Beta Was this translation helpful? Give feedback.
-
For reflection, so far I've implemented only reflection on a whole type's source grammar in order to apply a metafunction. There's not as yet a reflection operator to explicitly reflect on a different entity. For generation, the Cpp2 approach is to always inject (capture) strings that are valid source code grammar, and the context you're asking to parse it as is explicit in the function doing the generation. So far I've implemented one kind of the latter, which is to add to a type scope:
|
Beta Was this translation helpful? Give feedback.
-
Let's discuss the Cpp2 syntax for https://wg21.link/P2996.
I take it for granted that Cpp1 syntax for reflecting
^int
will be Cpp2int^
.So what about the syntax for splicing (https://wg21.link/p2996r0#splicers)?
Below is a tony table based on R0 ("Reflection for C++26") for you to fill in the
?
s.Note that Cpp2 already uses
@
for type metafunctions(with interpretation in the message of commit d8c1a50,
see the first list item under "Re syntax:").
With #533 and #727, I hope we don't need disambiguating
typename
ortemplate
for Cpp2.The grammar should make it clear what kind of entity is expected where.
I think it's reasonable to also aim for a single splicing syntax without disambiguating keywords.
Markdown table to be filled.
Beta Was this translation helpful? Give feedback.
All reactions