* src/system.h (obstack_finish0): New.
Use it to simplify several uses.
* src/muscle-tab.h (MUSCLE_INSERTF): New.
* src/muscle-tab.c: Use obstack_printf where simpler.
A stray $ is a warning in the actions, but an error in the epilogue.
IMHO, it should not even be a warning in the epilogue.
A stray $ is a warning in the actions, but an error in the epilogue.
IMHO, it should not even be a warning in the epilogue.
-** obstack_copy etc.
-There seems to be some other interesting functions for obstacks that
-we should consider using.
-
** stack.hh
Get rid of it. The original idea is nice, but actually it makes
the code harder to follow, and uselessly different from the other
** stack.hh
Get rid of it. The original idea is nice, but actually it makes
the code harder to follow, and uselessly different from the other
state_errs_set (s, nerrs, errors);
}
if (obstack_object_size (&solved_conflicts_obstack))
state_errs_set (s, nerrs, errors);
}
if (obstack_object_size (&solved_conflicts_obstack))
- {
- obstack_1grow (&solved_conflicts_obstack, '\0');
- s->solved_conflicts = obstack_finish (&solved_conflicts_obstack);
- }
+ s->solved_conflicts = obstack_finish0 (&solved_conflicts_obstack);
if (obstack_object_size (&solved_conflicts_xml_obstack))
if (obstack_object_size (&solved_conflicts_xml_obstack))
- {
- obstack_1grow (&solved_conflicts_xml_obstack, '\0');
- s->solved_conflicts_xml = obstack_finish (&solved_conflicts_xml_obstack);
- }
+ s->solved_conflicts_xml = obstack_finish0 (&solved_conflicts_xml_obstack);
/* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */
/* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */
obstack_grow (&obstack_for_string, yytext, yyleng)
# define STRING_FINISH \
obstack_grow (&obstack_for_string, yytext, yyleng)
# define STRING_FINISH \
- do { \
- obstack_1grow (&obstack_for_string, '\0'); \
- last_string = obstack_finish (&obstack_for_string); \
- } while (0)
+ (last_string = obstack_finish0 (&obstack_for_string))
# define STRING_FREE \
obstack_free (&obstack_for_string, last_string)
# define STRING_FREE \
obstack_free (&obstack_for_string, last_string)
{
/* Grow the current value. */
char *new_val;
{
/* Grow the current value. */
char *new_val;
- obstack_sgrow (&muscle_obstack, entry->value);
+ obstack_printf (&muscle_obstack, "%s%s%s", entry->value, separator, val);
- obstack_sgrow (&muscle_obstack, separator);
- obstack_sgrow (&muscle_obstack, val);
- obstack_1grow (&muscle_obstack, 0);
- new_val = obstack_finish (&muscle_obstack);
+ new_val = obstack_finish0 (&muscle_obstack);
entry->value = entry->storage = xstrdup (new_val);
obstack_free (&muscle_obstack, new_val);
}
entry->value = entry->storage = xstrdup (new_val);
obstack_free (&muscle_obstack, new_val);
}
obstack_quote (&muscle_obstack,
quotearg_style (c_quoting_style, loc.start.file));
obstack_sgrow (&muscle_obstack, ")[");
obstack_quote (&muscle_obstack,
quotearg_style (c_quoting_style, loc.start.file));
obstack_sgrow (&muscle_obstack, ")[");
- obstack_1grow (&muscle_obstack, 0);
- extension = obstack_finish (&muscle_obstack);
+ extension = obstack_finish0 (&muscle_obstack);
muscle_grow (key, extension, "");
obstack_free (&muscle_obstack, extension);
}
muscle_grow (key, extension, "");
obstack_free (&muscle_obstack, extension);
}
obstack_sgrow (&muscle_obstack, ", ");
obstack_quote (&muscle_obstack, a2);
obstack_sgrow (&muscle_obstack, "]");
obstack_sgrow (&muscle_obstack, ", ");
obstack_quote (&muscle_obstack, a2);
obstack_sgrow (&muscle_obstack, "]");
- obstack_1grow (&muscle_obstack, 0);
- pair = obstack_finish (&muscle_obstack);
+ pair = obstack_finish0 (&muscle_obstack);
muscle_grow (muscle, pair, ",\n");
obstack_free (&muscle_obstack, pair);
}
muscle_grow (muscle, pair, ",\n");
obstack_free (&muscle_obstack, pair);
}
char *extension;
obstack_sgrow (&muscle_obstack, "[[");
obstack_escape (&muscle_obstack, bound.file);
char *extension;
obstack_sgrow (&muscle_obstack, "[[");
obstack_escape (&muscle_obstack, bound.file);
- obstack_1grow (&muscle_obstack, ':');
- obstack_printf (&muscle_obstack, "%d", bound.line);
- obstack_1grow (&muscle_obstack, '.');
- obstack_printf (&muscle_obstack, "%d", bound.column);
- obstack_sgrow (&muscle_obstack, "]]");
- obstack_1grow (&muscle_obstack, '\0');
- extension = obstack_finish (&muscle_obstack);
+ obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
+ extension = obstack_finish0 (&muscle_obstack);
muscle_grow (key, extension, "");
obstack_free (&muscle_obstack, extension);
}
muscle_grow (key, extension, "");
obstack_free (&muscle_obstack, extension);
}
{
char *boundary_str;
aver (*++value == ']');
{
char *boundary_str;
aver (*++value == ']');
- obstack_1grow (&muscle_obstack, '\0');
- boundary_str = obstack_finish (&muscle_obstack);
+ boundary_str = obstack_finish0 (&muscle_obstack);
switch (*++value)
{
case ',':
switch (*++value)
{
case ',':
MUSCLE_INSERT_INT (Key, v__); \
} while (0)
MUSCLE_INSERT_INT (Key, v__); \
} while (0)
-#define MUSCLE_INSERT_INT(Key, Value) \
+#define MUSCLE_INSERTF(Key, Format, Value) \
- obstack_printf (&muscle_obstack, "%d", Value); \
- obstack_1grow (&muscle_obstack, 0); \
- muscle_insert (Key, obstack_finish (&muscle_obstack)); \
+ obstack_printf (&muscle_obstack, Format, Value); \
+ muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
+#define MUSCLE_INSERT_INT(Key, Value) \
+ MUSCLE_INSERTF(Key, "%d", Value)
+
#define MUSCLE_INSERT_LONG_INT(Key, Value) \
#define MUSCLE_INSERT_LONG_INT(Key, Value) \
- do { \
- obstack_printf (&muscle_obstack, "%ld", Value); \
- obstack_1grow (&muscle_obstack, 0); \
- muscle_insert (Key, obstack_finish (&muscle_obstack)); \
- } while (0)
+ MUSCLE_INSERTF(Key, "%ld", Value)
/* Key -> Value, but don't apply escaping to Value. */
#define MUSCLE_INSERT_STRING_RAW(Key, Value) \
/* Key -> Value, but don't apply escaping to Value. */
#define MUSCLE_INSERT_STRING_RAW(Key, Value) \
- do { \
- obstack_sgrow (&muscle_obstack, Value); \
- obstack_1grow (&muscle_obstack, 0); \
- muscle_insert (Key, obstack_finish (&muscle_obstack)); \
- } while (0)
+ MUSCLE_INSERTF(Key, "%s", Value)
/* Key -> Value, applying M4 escaping to Value. */
#define MUSCLE_INSERT_STRING(Key, Value) \
do { \
obstack_escape (&muscle_obstack, Value); \
/* Key -> Value, applying M4 escaping to Value. */
#define MUSCLE_INSERT_STRING(Key, Value) \
do { \
obstack_escape (&muscle_obstack, Value); \
- obstack_1grow (&muscle_obstack, 0); \
- muscle_insert (Key, obstack_finish (&muscle_obstack)); \
+ muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
} while (0)
#define MUSCLE_INSERT_C_STRING(Key, Value) \
do { \
obstack_escape (&muscle_obstack, \
quotearg_style (c_quoting_style, Value)); \
} while (0)
#define MUSCLE_INSERT_C_STRING(Key, Value) \
do { \
obstack_escape (&muscle_obstack, \
quotearg_style (c_quoting_style, Value)); \
- obstack_1grow (&muscle_obstack, 0); \
- muscle_insert (Key, obstack_finish (&muscle_obstack)); \
+ muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
} while (0)
/* Append VALUE to the current value of KEY. If KEY did not already
} while (0)
/* Append VALUE to the current value of KEY. If KEY did not already
if (max < table_data[i]) \
max = table_data[i]; \
} \
if (max < table_data[i]) \
max = table_data[i]; \
} \
- obstack_1grow (&format_obstack, 0); \
- muscle_insert (name, obstack_finish (&format_obstack)); \
+ muscle_insert (name, obstack_finish0 (&format_obstack)); \
\
lmin = min; \
lmax = max; \
/* Build `NAME_min' and `NAME_max' in the obstack. */ \
obstack_printf (&format_obstack, "%s_min", name); \
\
lmin = min; \
lmax = max; \
/* Build `NAME_min' and `NAME_max' in the obstack. */ \
obstack_printf (&format_obstack, "%s_min", name); \
- obstack_1grow (&format_obstack, 0); \
- MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmin); \
+ MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmin); \
obstack_printf (&format_obstack, "%s_max", name); \
obstack_printf (&format_obstack, "%s_max", name); \
- obstack_1grow (&format_obstack, 0); \
- MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmax); \
+ MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmax); \
}
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
}
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
obstack_sgrow (&format_obstack, " ]b4_null[");
/* Finish table and store. */
obstack_sgrow (&format_obstack, " ]b4_null[");
/* Finish table and store. */
- obstack_1grow (&format_obstack, 0);
- muscle_insert ("tname", obstack_finish (&format_obstack));
+ muscle_insert ("tname", obstack_finish0 (&format_obstack));
#define SET_KEY(Entry) \
obstack_printf (&format_obstack, "symbol(%d, %s)", \
i, Entry); \
#define SET_KEY(Entry) \
obstack_printf (&format_obstack, "symbol(%d, %s)", \
i, Entry); \
- obstack_1grow (&format_obstack, 0); \
- key = obstack_finish (&format_obstack);
+ key = obstack_finish0 (&format_obstack);
#define SET_KEY2(Entry, Suffix) \
obstack_printf (&format_obstack, "symbol(%d, %s_%s)", \
i, Entry, Suffix); \
#define SET_KEY2(Entry, Suffix) \
obstack_printf (&format_obstack, "symbol(%d, %s_%s)", \
i, Entry, Suffix); \
- obstack_1grow (&format_obstack, 0); \
- key = obstack_finish (&format_obstack);
+ key = obstack_finish0 (&format_obstack);
// Whether the symbol has an identifier.
value = symbol_id_get (sym);
// Whether the symbol has an identifier.
value = symbol_id_get (sym);
/* A node's label contains its items. */
obstack_init (&node_obstack);
print_core (&node_obstack, s);
/* A node's label contains its items. */
obstack_init (&node_obstack);
print_core (&node_obstack, s);
- obstack_1grow (&node_obstack, '\0');
- output_node (s->number, obstack_finish (&node_obstack), fgraph);
+ output_node (s->number, obstack_finish0 (&node_obstack), fgraph);
obstack_free (&node_obstack, 0);
/* Output the edges. */
obstack_free (&node_obstack, 0);
/* Output the edges. */
_(", cannot be accessed from mid-rule action at $%d"),
midrule_rhs_index);
_(", cannot be accessed from mid-rule action at $%d"),
midrule_rhs_index);
- obstack_1grow (&msg_buf, '\0');
complain_at_indent (id_loc, wflags, &indent, "%s",
complain_at_indent (id_loc, wflags, &indent, "%s",
- (char *) obstack_finish (&msg_buf));
+ obstack_finish0 (&msg_buf));
obstack_free (&msg_buf, 0);
}
}
obstack_free (&msg_buf, 0);
}
}
@[a-z_]+"(" {
yytext[yyleng-1] = '\0';
obstack_grow (&obstack_for_string, yytext, yyleng);
@[a-z_]+"(" {
yytext[yyleng-1] = '\0';
obstack_grow (&obstack_for_string, yytext, yyleng);
- at_directive_argv[at_directive_argc++] =
- obstack_finish (&obstack_for_string);
+ at_directive_argv[at_directive_argc++] = obstack_finish (&obstack_for_string);
BEGIN SC_AT_DIRECTIVE_ARGS;
}
BEGIN SC_AT_DIRECTIVE_ARGS;
}
if (at_directive_argc >= AT_DIRECTIVE_ARGC_MAX)
fail_for_at_directive_too_many_args (at_directive_argv[0]);
if (at_directive_argc >= AT_DIRECTIVE_ARGC_MAX)
fail_for_at_directive_too_many_args (at_directive_argv[0]);
- obstack_1grow (&obstack_for_string, '\0');
at_directive_argv[at_directive_argc++] =
at_directive_argv[at_directive_argc++] =
- obstack_finish (&obstack_for_string);
+ obstack_finish0 (&obstack_for_string);
/* Like M4, skip whitespace after a comma. */
if (yytext[1] == ',')
/* Like M4, skip whitespace after a comma. */
if (yytext[1] == ',')
#define obstack_chunk_free free
#include <obstack.h>
#define obstack_chunk_free free
#include <obstack.h>
+/* String-grow: append Str to Obs. */
+
#define obstack_sgrow(Obs, Str) \
obstack_grow (Obs, Str, strlen (Str))
#define obstack_sgrow(Obs, Str) \
obstack_grow (Obs, Str, strlen (Str))
+/* Append the ending 0, finish Obs, and return the string. */
+
+# define obstack_finish0(Obs) \
+ (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs))
+