[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Parameterize the extraction of semantic values.
From: |
Akim Demaille |
Subject: |
[PATCH] Parameterize the extraction of semantic values. |
Date: |
Tue, 21 Oct 2008 17:20:22 -0500 |
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 8f7f37b..83ae569 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2008-11-03 Akim Demaille <address@hidden>
+ 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 <address@hidden>
+
Prepare easier M4 changes.
* data/lalr1.cc: Use escaped [] instead of literals to prepare
future changes.
diff --git a/data/c++.m4 b/data/c++.m4
index 593390d..a896b77 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -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],
-[(address@hidden($1) - ($2)@}m4_ifval([$3], [.$3]))])
+[b4_symbol_value(address@hidden($1) - ($2)@}], [$3])])
+
# b4_lhs_location()
# -----------------
diff --git a/data/c.m4 b/data/c.m4
index 1fe4bc5..66d4f6d 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 c6de6d8..67c2f85 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -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)])
diff --git a/data/yacc.c b/data/yacc.c
index 19f77a5..9f54c3a 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -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],
-[(address@hidden($2) - ($1)@}m4_ifval([$3], [.$3]))])
+[b4_symbol_value(address@hidden($2) - ($1)@}], [$3])])
--
1.6.0.2.588.g3102
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Parameterize the extraction of semantic values.,
Akim Demaille <=