]> git.saurik.com Git - bison.git/blobdiff - data/c.m4
Rule length is unsigned.
[bison.git] / data / c.m4
index 5d74e8668f4539dc4d2a09d7f50d5b64e547f7f8..f0b5f14d2f7a4e3edc7b8d6dcbb2d8ae141276a9 100644 (file)
--- a/data/c.m4
+++ b/data/c.m4
 ## Identification.  ##
 ## ---------------- ##
 
-# b4_comment(TEXT)
-# ----------------
-m4_define([b4_comment], [/* m4_bpatsubst([$1], [
-], [
-   ])  */])
+# b4_comment_(TEXT, OPEN, CONTINUE, END)
+# -------------------------------------
+# Put TEXT in comment.  Avoid trailing spaces: don't indent empty lines.
+# Avoid adding indentation to the first line, as the indentation comes
+# from OPEN.  That's why we don't patsubst([$1], [^\(.\)], [   \1]).
+#
+# Prefix all the output lines with PREFIX.
+m4_define([b4_comment_], [$2[]m4_bpatsubst([$1], [
+\(.\)], [
+$3\1])$4])
+
+
+# b4_c_comment(TEXT, [PREFIX])
+# ----------------------------
+# Put TEXT in comment.  Avoid trailing spaces: don't indent empty lines.
+# Avoid adding indentation to the first line, as the indentation comes
+# from "/*".  That's why we don't patsubst([$1], [^\(.\)], [   \1]).
+#
+# Prefix all the output lines with PREFIX.
+m4_define([b4_c_comment],
+[b4_comment_([$1], [$2/* ], [$2   ], [$2  */])])
+
+
+# b4_comment(TEXT, [PREFIX])
+# --------------------------
+# By default, C comments.
+m4_define([b4_comment], [b4_c_comment($@)])
+
 
 # b4_identification
 # -----------------
@@ -133,6 +156,8 @@ m4_define([b4_int_type],
 m4_define([b4_int_type_for],
 [b4_int_type($1_min, $1_max)])
 
+
+
 ## ---------##
 ## Values.  ##
 ## ---------##
@@ -144,6 +169,8 @@ m4_define([b4_int_type_for],
 m4_define([b4_null], [0])
 
 
+
+
 ## ------------------------- ##
 ## Assigning token numbers.  ##
 ## ------------------------- ##
@@ -152,7 +179,7 @@ m4_define([b4_null], [0])
 # -----------------------------------------
 # Output the definition of this token as #define.
 m4_define([b4_token_define],
-[#define $1 $2
+[#define b4_percent_define_get([token.prefix])$1 $2
 ])
 
 
@@ -170,7 +197,7 @@ m4_map([b4_token_define], [$@])])
 # ---------------------------------------
 # Output the definition of this token as an enum.
 m4_define([b4_token_enum],
-[$1 = $2])
+[b4_percent_define_get([token.prefix])$1 = $2])
 
 
 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
@@ -201,6 +228,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.  ##
@@ -348,6 +390,7 @@ m4_define([b4_sync_start], [[#]line $1 $2])
 m4_define([b4_case],
 [  case $1:
 $2
+b4_syncline([@oline@], [@ofile@])
     break;])
 
 # b4_symbol_actions(FILENAME, LINENO,
@@ -356,7 +399,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])