summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkim Demaille <akim@lrde.epita.fr>2013-04-11 09:21:08 +0200
committerAkim Demaille <akim@lrde.epita.fr>2013-04-11 09:21:08 +0200
commit08cc1a3b1801cafcd0354ce10161571fa45b4553 (patch)
tree78cb936107e1333cf3baff5105c6e5441d0473c1 /src
parentedaa22ec15eef6a61c4a07ed20dac63ffd7ddde6 (diff)
downloadbison-08cc1a3b1801cafcd0354ce10161571fa45b4553.tar.gz
muscles: be sure that %code snippets are not glue together on a single line
Recently "braceless" in the parser was changed so that an eol was no longer added to the value. This is not correct when a %code is used multiple times, because the syncline of the next snippet might be appended to the last (and not ended) line of the previous snippet. * src/muscle-tab.h (muscle_grow): Make it private. * src/muscle-tab.c (muscle_grow): Accept a fourth argument: a required terminator. Adjust callers. * tests/input.at (Multiple %code): New.
Diffstat (limited to 'src')
-rw-r--r--src/muscle-tab.c60
-rw-r--r--src/muscle-tab.h9
2 files changed, 35 insertions, 34 deletions
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 10a0a5cb..9d15cf76 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -153,33 +153,39 @@ muscle_insert (char const *key, char const *value)
}
-/*-------------------------------------------------------------------.
-| Append VALUE to the current value of KEY. If KEY did not already |
-| exist, create it. Use MUSCLE_OBSTACK. De-allocate the previously |
-| associated value. Copy VALUE and SEPARATOR. |
-`-------------------------------------------------------------------*/
+/* Append VALUE to the current value of KEY. If KEY did not already
+ exist, create it. Use MUSCLE_OBSTACK. De-allocate the previously
+ associated value. Copy VALUE and SEPARATOR. If VALUE does not end
+ with TERMINATOR, append one. */
-void
-muscle_grow (const char *key, const char *val, const char *separator)
+static void
+muscle_grow (const char *key, const char *val,
+ const char *separator, const char *terminator)
{
muscle_entry *entry = muscle_lookup (key);
+ size_t vals = strlen (val);
+ size_t terms = strlen (terminator);
if (entry)
{
- /* Grow the current value. */
- char *new_val;
- obstack_printf (&muscle_obstack, "%s%s%s", entry->value, separator, val);
+ obstack_sgrow (&muscle_obstack, entry->value);
+ obstack_sgrow (&muscle_obstack, separator);
free (entry->storage);
- new_val = obstack_finish0 (&muscle_obstack);
- entry->value = entry->storage = xstrdup (new_val);
- obstack_free (&muscle_obstack, new_val);
}
else
- {
- /* First insertion in the hash. */
- entry = muscle_entry_new (key);
- entry->value = entry->storage = xstrdup (val);
- }
+ entry = muscle_entry_new (key);
+
+ obstack_sgrow (&muscle_obstack, val);
+
+ if (terms <= vals
+ && STRNEQ (val + vals - terms, terminator))
+ obstack_sgrow (&muscle_obstack, terminator);
+
+ {
+ char *new_val = obstack_finish0 (&muscle_obstack);
+ entry->value = entry->storage = xstrdup (new_val);
+ obstack_free (&muscle_obstack, new_val);
+ }
}
/*------------------------------------------------------------------.
@@ -196,7 +202,7 @@ muscle_syncline_grow (char const *key, location loc)
quotearg_style (c_quoting_style, loc.start.file));
obstack_sgrow (&muscle_obstack, ")[");
extension = obstack_finish0 (&muscle_obstack);
- muscle_grow (key, extension, "");
+ muscle_grow (key, extension, "", "");
obstack_free (&muscle_obstack, extension);
}
@@ -210,7 +216,7 @@ void
muscle_code_grow (const char *key, const char *val, location loc)
{
muscle_syncline_grow (key, loc);
- muscle_grow (key, val, "\n");
+ muscle_grow (key, val, "\n", "\n");
}
@@ -225,7 +231,7 @@ muscle_pair_list_grow (const char *muscle,
obstack_quote (&muscle_obstack, a2);
obstack_sgrow (&muscle_obstack, "]");
pair = obstack_finish0 (&muscle_obstack);
- muscle_grow (muscle, pair, ",\n");
+ muscle_grow (muscle, pair, ",\n", "");
obstack_free (&muscle_obstack, pair);
}
@@ -262,7 +268,7 @@ muscle_boundary_grow (char const *key, boundary bound)
obstack_escape (&muscle_obstack, bound.file);
obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
extension = obstack_finish0 (&muscle_obstack);
- muscle_grow (key, extension, "");
+ muscle_grow (key, extension, "", "");
obstack_free (&muscle_obstack, extension);
}
@@ -275,7 +281,7 @@ static void
muscle_location_grow (char const *key, location loc)
{
muscle_boundary_grow (key, loc.start);
- muscle_grow (key, "", ", ");
+ muscle_grow (key, "", ", ", "");
muscle_boundary_grow (key, loc.end);
}
@@ -374,11 +380,11 @@ void
muscle_user_name_list_grow (char const *key, char const *user_name,
location loc)
{
- muscle_grow (key, "[[[[", ",");
- muscle_grow (key, user_name, "");
- muscle_grow (key, "]], ", "");
+ muscle_grow (key, "[[[[", ",", "");
+ muscle_grow (key, user_name, "", "");
+ muscle_grow (key, "]], ", "", "");
muscle_location_grow (key, loc);
- muscle_grow (key, "]]", "");
+ muscle_grow (key, "]]", "", "");
}
diff --git a/src/muscle-tab.h b/src/muscle-tab.h
index af6b615c..3199a2d4 100644
--- a/src/muscle-tab.h
+++ b/src/muscle-tab.h
@@ -99,14 +99,9 @@ extern struct obstack muscle_obstack;
MUSCLE_INSERT_STRING(Key, quotearg_style (c_quoting_style, Value))
-/* Append VALUE to the current value of KEY. If KEY did not already
- exist, create it. Use MUSCLE_OBSTACK. De-allocate the previously
- associated value. Copy VALUE and SEPARATOR. */
-void muscle_grow (const char *key, const char *value, const char *separator);
-
-
/* Append VALUE to the current value of KEY, using muscle_grow. But
- in addition, issue a synchronization line for the location LOC. */
+ in addition, issue a synchronization line for the location LOC.
+ Be sure to append on a new line. */
void muscle_code_grow (const char *key, const char *value, location loc);