]> git.saurik.com Git - bison.git/commitdiff
Parameterize the extraction of semantic values.
authorAkim Demaille <demaille@gostai.com>
Tue, 21 Oct 2008 22:20:22 +0000 (17:20 -0500)
committerAkim Demaille <demaille@gostai.com>
Mon, 3 Nov 2008 20:50:38 +0000 (21:50 +0100)
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
data/c++.m4
data/c.m4
data/glr.c
data/yacc.c

index 8f7f37b0f18883818a7148d01612f6c06382e4b5..83ae569ce52c786934d13d3e919976de0306fd03 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-11-03  Akim Demaille  <demaille@gostai.com>
+
+       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  <demaille@gostai.com>
 
        Prepare easier M4 changes.
index 593390d61abf90939504d4c45207b9175ba3abdd..a896b778bd53a0857ad43418b105baf0512847b9 100644 (file)
@@ -102,7 +102,7 @@ m4_map_sep([     b4_token_enum], [,
 # --------------------
 # Expansion of $<TYPE>$.
 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 $<TYPE>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()
 # -----------------
index 1fe4bc56c74d22f86a93dac51412a78034767cba..66d4f6d23aafc936f2a1dc14143131680d39553f 100644 (file)
--- 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])
index c6de6d8f007695dc1178eaae97ac47c8a234a4bd..67c2f85eef10550f896295c2115829ff3229a357 100644 (file)
@@ -109,7 +109,15 @@ m4_define([b4_pure_formals],
 # --------------------
 # Expansion of $<TYPE>$.
 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 $<TYPE>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)])
 
 
 
index 19f77a5fbf8480588beac69d4a1a768f397c75d5..9f54c3a798380c17dddcd40727b69fe3b7043774 100644 (file)
@@ -114,7 +114,7 @@ m4_define([b4_int_type],
 # --------------------
 # Expansion of $<TYPE>$.
 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 $<TYPE>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])])