From 1fa5d8bbf92cc7ab3f7294b8f4f4465b04d4444a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 21 Oct 2008 17:20:22 -0500 Subject: [PATCH] Parameterize the extraction of semantic values. To make future changes easier, no longer rely on ".TYPE" being the way to get a semantic value. * data/c.m4 (b4_symbol_value): New. Use it. * data/c++.m4, data/yacc.c: Use it. * data/glr.c: Use b4_symbol_value. (b4_rhs_data): New. Use it. --- ChangeLog | 13 +++++++++++++ data/c++.m4 | 5 +++-- data/c.m4 | 17 ++++++++++++++++- data/glr.c | 14 +++++++++++--- data/yacc.c | 4 ++-- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f7f37b0..83ae569c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-11-03 Akim Demaille + + Parameterize the extraction of semantic values. + To make future changes easier, no longer rely on ".TYPE" being the + way to get a semantic value. + + * data/c.m4 (b4_symbol_value): New. + Use it. + * data/c++.m4, data/yacc.c: Use it. + * data/glr.c: Use b4_symbol_value. + (b4_rhs_data): New. + Use it. + 2008-11-03 Akim Demaille Prepare easier M4 changes. diff --git a/data/c++.m4 b/data/c++.m4 index 593390d6..a896b778 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -102,7 +102,7 @@ m4_map_sep([ b4_token_enum], [, # -------------------- # Expansion of $$. m4_define([b4_lhs_value], -[(yyval[]m4_ifval([$1], [.$1]))]) +[b4_symbol_value([yyval], [$1])]) # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) @@ -110,7 +110,8 @@ m4_define([b4_lhs_value], # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))]) +[b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])]) + # b4_lhs_location() # ----------------- diff --git a/data/c.m4 b/data/c.m4 index 1fe4bc56..66d4f6d2 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -205,6 +205,21 @@ m4_define([b4_token_enums_defines], ]) +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_value(VAL, [TYPE]) +# ---------------------------- +# Given a semantic value VAL ($$, $1 etc.), extract its value of type +# TYPE if TYPE is given, otherwise just return VAL. The result can be +# used safetly, it is put in parens to avoid nasty precedence issues. +# TYPE is *not* put in braces, provide some if needed. +m4_define([b4_symbol_value], +[($1[]m4_ifval([$2], [.$2]))]) + + ## --------------------------------------------- ## ## Defining C functions in both K&R and ANSI-C. ## @@ -360,7 +375,7 @@ $2 # ------------------------------------------------- m4_define([b4_symbol_actions], [m4_pushdef([b4_dollar_dollar], - [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl + [b4_symbol_value([(*yyvaluep)], [$6])])dnl m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl case $4: /* $3 */ b4_syncline([$2], [$1]) diff --git a/data/glr.c b/data/glr.c index c6de6d8f..67c2f85e 100644 --- a/data/glr.c +++ b/data/glr.c @@ -109,7 +109,15 @@ m4_define([b4_pure_formals], # -------------------- # Expansion of $$. m4_define([b4_lhs_value], -[((*yyvalp)[]m4_ifval([$1], [.$1]))]) +[b4_symbol_value([(*yyvalp)], [$1])]) + + +# b4_rhs_data(RULE-LENGTH, NUM) +# ----------------------------- +# Expand to the semantic stack place that contains value and location +# of symbol number NUM in a rule of length RULE-LENGTH. +m4_define([b4_rhs_data], +[((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate]) # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) @@ -117,7 +125,7 @@ m4_define([b4_lhs_value], # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))]) +[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])]) @@ -137,7 +145,7 @@ m4_define([b4_lhs_location], # Expansion of @NUM, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], -[(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yyloc)]) +[(b4_rhs_data([$1], [$2]).yyloc)]) diff --git a/data/yacc.c b/data/yacc.c index 19f77a5f..9f54c3a7 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -114,7 +114,7 @@ m4_define([b4_int_type], # -------------------- # Expansion of $$. m4_define([b4_lhs_value], -[(yyval[]m4_ifval([$1], [.$1]))]) +[b4_symbol_value(yyval, [$1])]) # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) @@ -122,7 +122,7 @@ m4_define([b4_lhs_value], # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[(yyvsp@{($2) - ($1)@}m4_ifval([$3], [.$3]))]) +[b4_symbol_value([yyvsp@{($2) - ($1)@}], [$3])]) -- 2.45.2