From a9c2549c2758b93b3a018dd3033d34ad0ce9eb64 Mon Sep 17 00:00:00 2001 From: Adela Vais Date: Sat, 13 Mar 2021 22:15:05 +0200 Subject: [PATCH] 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. --- data/skeletons/d.m4 | 32 ++++++++++++++++++-------------- 1 file 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_; }]])[