summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim@epita.fr>2001-08-15 08:40:19 +0000
committerAkim Demaille <akim@epita.fr>2001-08-15 08:40:19 +0000
commit0b8afb77232cbc73af84bff12306b86e4e098f31 (patch)
tree547c8962466996500335ed8304026b671a89f3ad
parent683e29a634ff798e38e45aa2680ec1a377741c5b (diff)
downloadbison-0b8afb77232cbc73af84bff12306b86e4e098f31.tar.gz
* src/reader.c (readgram): Indent output macro YYSTYPE.
(packsymbols): Likewise. (output_token_defines): Likewise. * src/files.c: Standardize. (compute_header_macro): New. (defines_obstack_save): New. Use compute_header_macro. (output_files): Update. Use defines_obstack_save.
-rw-r--r--ChangeLog10
-rw-r--r--src/files.c53
-rw-r--r--src/reader.c12
3 files changed, 67 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index d1358cb6..a2f4c315 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2001-08-15 Marc Autret <prog@epita.fr>
+
+ * src/reader.c (readgram): Indent output macro YYSTYPE.
+ (packsymbols): Likewise.
+ (output_token_defines): Likewise.
+ * src/files.c: Standardize.
+ (compute_header_macro): New.
+ (defines_obstack_save): New. Use compute_header_macro.
+ (output_files): Update. Use defines_obstack_save.
+
2001-08-15 Akim Demaille <akim@epita.fr>
* doc/bison.texinfo (Table of Symbols): Document
diff --git a/src/files.c b/src/files.c
index 033d2816..f1cdfe6c 100644
--- a/src/files.c
+++ b/src/files.c
@@ -84,6 +84,37 @@ stringappend (const char *string1, const char *string2)
return res;
}
+
+/*---------------------------------------------------------------.
+| Computes the macro name used to avoid double inclusion in the |
+| header of the parser and store it in header_macro_name. |
+`---------------------------------------------------------------*/
+
+static const char *
+compute_header_macro (void)
+{
+ int ite;
+ char *macro_name;
+
+ macro_name = XMALLOC (char,
+ strlen (base_name) +
+ strlen (header_extension) + 1);
+
+ stpcpy (macro_name, base_name);
+ strcat (macro_name, header_extension);
+
+ for (ite = 0; macro_name[ite]; ite++)
+ if (macro_name[ite] == '.')
+ macro_name[ite] = '_';
+ else
+ {
+ if (islower (macro_name[ite]))
+ macro_name[ite] -= ('a' - 'A');
+ }
+ return macro_name;
+}
+
+
/*-----------------------------------------------------------------.
| Try to open file NAME with mode MODE, and print an error message |
| if fails. |
@@ -133,6 +164,25 @@ obstack_save (struct obstack *obs, const char *filename)
xfclose (out);
}
+/*---------------------------------------------------------------------.
+| Output double inclusion protection macros and saves defines_obstack |
+`---------------------------------------------------------------------*/
+
+static void
+defines_obstack_save (const char *filename)
+{
+ FILE *out = xfopen (filename, "w");
+ size_t size = obstack_object_size (&defines_obstack);
+ char *macro_name = compute_header_macro ();
+
+ fprintf (out, "#ifndef %s\n", macro_name);
+ fprintf (out, "# define %s\n\n", macro_name);
+ fwrite (obstack_finish (&defines_obstack), 1, size, out);
+ fprintf (out, "\n#endif /* not %s */\n", macro_name);
+
+ free (macro_name);
+ xfclose (out);
+}
/*------------------------------------------------------------------.
| Return the path to the skeleton which locaction might be given in |
@@ -397,8 +447,7 @@ output_files (void)
/* Output the header file if wanted. */
if (defines_flag)
- obstack_save (&defines_obstack,
- stringappend (base_name, header_extension));
+ defines_obstack_save (stringappend (base_name, header_extension));
/* If we output only the table, dump the actions in ACTFILE. */
if (no_parser_flag)
diff --git a/src/reader.c b/src/reader.c
index 1cf688a4..7e23c0ef 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -1575,9 +1575,9 @@ readgram (void)
"#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
if (defines_flag)
obstack_sgrow (&defines_obstack, "\
-#ifndef YYSTYPE\n\
-# define YYSTYPE int\n\
-#endif\n");
+# ifndef YYSTYPE\n\
+# define YYSTYPE int\n\
+# endif\n");
}
/* Report any undefined symbols and consider them nonterminals. */
@@ -1634,11 +1634,11 @@ output_token_defines (struct obstack *oout)
if (c != '\0')
continue;
- obstack_fgrow2 (oout, "#define\t%s\t%d\n",
+ obstack_fgrow2 (oout, "# define\t%s\t%d\n",
symbol,
(translations ? bp->user_token_number : bp->value));
if (semantic_parser)
- obstack_fgrow2 (oout, "#define\tT%s\t%d\n", symbol, bp->value);
+ obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);
}
obstack_1grow (oout, '\n');
@@ -1793,7 +1793,7 @@ packsymbols (void)
/* don't make these for dummy nonterminals made by gensym. */
if (*tags[i] != '@')
obstack_fgrow2 (&defines_obstack,
- "#define\tNT%s\t%d\n", tags[i], i);
+ "# define\tNT%s\t%d\n", tags[i], i);
}
#if 0
/* `fdefines' is now a temporary file, so we need to copy its