summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorAdela Vais <adela.vais99@gmail.com>2021-03-13 22:15:05 +0200
committerAkim Demaille <akim.demaille@gmail.com>2021-03-26 06:49:32 +0100
commita9c2549c2758b93b3a018dd3033d34ad0ce9eb64 (patch)
tree97f27472346921c54ea46445fd4c1e3699c9041a /data
parentfb032a28df76b6f489617f35989b7644df5cd566 (diff)
downloadbison-a9c2549c2758b93b3a018dd3033d34ad0ce9eb64.tar.gz
d: rewrite Symbol's constructors in M4
The D code was becoming too complex. M4 is easier to maintain in the long run. * data/skeletons/d.m4: Here.
Diffstat (limited to 'data')
-rw-r--r--data/skeletons/d.m432
1 files changed, 18 insertions, 14 deletions
diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4
index 83eb0517..e4e60c8c 100644
--- a/data/skeletons/d.m4
+++ b/data/skeletons/d.m4
@@ -448,6 +448,22 @@ alias Position = ]b4_position_type[;]])[
]])
+# b4_basic_symbol_constructor_define
+# ----------------------------------
+# Create Symbol struct constructors for all the visible types.
+m4_define([b4_basic_symbol_constructor_define],
+[b4_token_visible_if([$1],
+[ this(TokenKind token]b4_symbol_if([$1], [has_type],
+[[, typeof(YYSemanticType.]b4_symbol([$1], [type])dnl
+[) val]])[]b4_locations_if([[, Location loc]])[)
+ {
+ kind = yytranslate_(token);]b4_symbol_if([$1], [has_type], [[
+ value_.]b4_symbol([$1], [type])[ = val;]])[]b4_locations_if([
+ location_ = loc;])[
+ }
+])])
+
+
# b4_symbol_type_define
# ---------------------
# Define symbol_type, the external type for symbols used for symbol
@@ -462,20 +478,8 @@ m4_define([b4_symbol_type_define],
private SymbolKind kind;
private Value value_;]b4_locations_if([[
private Location location_;]])[
- this(TokenKind token]b4_locations_if([[, Location loc]])[)
- {
- kind = yytranslate_(token);]b4_locations_if([
- location_ = loc;])[
- }
- static foreach (member; __traits(allMembers, YYSemanticType))
- {
- this(TokenKind token, typeof(mixin("YYSemanticType." ~ member)) val]b4_locations_if([[, Location loc]])[)
- {
- kind = yytranslate_(token);
- mixin("value_." ~ member ~ " = val;");]b4_locations_if([
- location_ = loc;])[
- }
- }
+
+]b4_type_foreach([b4_basic_symbol_constructor_define])[
SymbolKind token() { return kind; }
Value value() { return value_; }]b4_locations_if([[
Location location() { return location_; }]])[