From c73dcd6958ed73daff240ca46cc8b0f774a28e22 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 23 Jan 2021 10:14:19 +0100 Subject: [PATCH] skeletons: introduce "slot"s for symbols Extracted from d9cf99b6a5cb0345e91dfb90fe6d6473024ea97a, in the master branch. * data/skeletons/bison.m4 (b4_symbol_slot): New, with safer semantics than type and type_tag. --- data/README.md | 8 +++++++- data/skeletons/bison.m4 | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/data/README.md b/data/README.md index 50fbe525..59b220b0 100644 --- a/data/README.md +++ b/data/README.md @@ -142,11 +142,17 @@ The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS: When api.value.type=union, the generated name for the union member. yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc. -- `type` +- `type`: string If it has a semantic value, its type tag, or, if variant are used, its type. In the case of api.value.type=union, type is the real type (e.g. int). +- `slot`: string + If it has a semantic value, the name of the union member (i.e., bounces to + either `type_tag` or `type`). It would be better to fix our mess and + always use `type` for the true type of the member, and `type_tag` for the + name of the union member. + - `has_printer`: 0, 1 - `printer`: string - `printer_file`: string diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4 index 12155123..156b0689 100644 --- a/data/skeletons/bison.m4 +++ b/data/skeletons/bison.m4 @@ -465,6 +465,19 @@ m4_case([$1], # but are S_YYEMPTY and symbol_kind::S_YYEMPTY in C++. m4_copy([b4_symbol_kind_base], [b4_symbol_kind]) + +# b4_symbol_slot(NUM) +# ------------------- +# The name of union member that contains the value of these symbols. +# Currently, we are messy, this should actually be type_tag, but type_tag +# has several meanings. +m4_define([b4_symbol_slot], +[m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_symbol([$1], [type_tag])], + [variant], [b4_symbol([$1], [type_tag])], + [b4_symbol([$1], [type])])]) + + # b4_symbol(NUM, FIELD) # --------------------- # Fetch FIELD of symbol #NUM (or "orig NUM"). Fail if undefined. @@ -475,6 +488,7 @@ m4_define([b4_symbol], [id], [b4_symbol_token_kind([$1])], [kind_base], [b4_symbol_kind_base([$1])], [kind], [b4_symbol_kind([$1])], + [slot], [b4_symbol_slot([$1])], [_b4_symbol($@)])])