static void prepare_symbols (void) { MUSCLE_INSERT_INT ("tokens_number", ntokens); MUSCLE_INSERT_INT ("nterms_number", nvars); MUSCLE_INSERT_INT ("symbols_number", nsyms); MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number); MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number); muscle_insert_symbol_number_table ("translate", token_translations, token_translations[0], 1, max_user_token_number + 1); /* tname -- token names. */ { int i; /* We assume that the table will be output starting at column 2. */ int j = 2; struct quoting_options *qo = clone_quoting_options (0); set_quoting_style (qo, c_quoting_style); set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS); for (i = 0; i < nsyms; i++) { char *cp = quotearg_alloc (symbols[i]->tag, -1, qo); /* Width of the next token, including the two quotes, the comma and the space. */ int width = strlen (cp) + 2; if (j + width > 75) { obstack_sgrow (&format_obstack, "\n "); j = 1; } if (i) obstack_1grow (&format_obstack, ' '); obstack_escape (&format_obstack, cp); free (cp); obstack_1grow (&format_obstack, ','); j += width; } free (qo); obstack_sgrow (&format_obstack, " ]b4_null["); /* Finish table and store. */ muscle_insert ("tname", obstack_finish0 (&format_obstack)); } /* Output YYTOKNUM. */ { int i; int *values = xnmalloc (ntokens, sizeof *values); for (i = 0; i < ntokens; ++i) values[i] = symbols[i]->user_token_number; muscle_insert_int_table ("toknum", values, values[0], 1, ntokens); free (values); } }
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) { obstack_sgrow (&muscle_obstack, entry->value); obstack_sgrow (&muscle_obstack, separator); free (entry->storage); } else 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); } }
void muscle_grow (const char *key, const char *val, const char *separator) { muscle_entry probe; muscle_entry *entry = NULL; probe.key = key; entry = hash_lookup (muscle_table, &probe); if (!entry) { /* First insertion in the hash. */ entry = xmalloc (sizeof *entry); entry->key = key; hash_insert (muscle_table, entry); entry->value = xstrdup (val); } else { /* Grow the current value. */ char *new_val; obstack_sgrow (&muscle_obstack, entry->value); free (entry->value); obstack_sgrow (&muscle_obstack, separator); obstack_sgrow (&muscle_obstack, val); obstack_1grow (&muscle_obstack, 0); new_val = obstack_finish (&muscle_obstack); entry->value = xstrdup (new_val); obstack_free (&muscle_obstack, new_val); } }
static void prepare_symbols (void) { MUSCLE_INSERT_BOOL ("token_table", token_table_flag); MUSCLE_INSERT_INT ("tokens_number", ntokens); MUSCLE_INSERT_INT ("nterms_number", nvars); MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number); MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number); muscle_insert_symbol_number_table ("translate", token_translations, token_translations[0], 1, max_user_token_number + 1); /* tname -- token names. */ { int i; /* We assume that the table will be output starting at column 2. */ int j = 2; for (i = 0; i < nsyms; i++) { char const *cp = quotearg_style (c_quoting_style, symbols[i]->tag); /* Width of the next token, including the two quotes, the comma and the space. */ int width = strlen (cp) + 2; if (j + width > 75) { obstack_sgrow (&format_obstack, "\n "); j = 1; } if (i) obstack_1grow (&format_obstack, ' '); MUSCLE_OBSTACK_SGROW (&format_obstack, cp); obstack_1grow (&format_obstack, ','); j += width; } /* Add a NULL entry to list of tokens (well, 0, as NULL might not be defined). */ obstack_sgrow (&format_obstack, " 0"); /* Finish table and store. */ obstack_1grow (&format_obstack, 0); muscle_insert ("tname", obstack_finish (&format_obstack)); } /* Output YYTOKNUM. */ { int i; int *values = xnmalloc (ntokens, sizeof *values); for (i = 0; i < ntokens; ++i) values[i] = symbols[i]->user_token_number; muscle_insert_int_table ("toknum", values, values[0], 1, ntokens); free (values); } }
static bool print_token (struct obstack *out, bool first, char const *tok) { char const *q = escape (tok); if (! first) obstack_sgrow (out, ", "); obstack_sgrow (out, q); return false; }
void muscle_code_grow (const char *key, const char *val, location loc) { char *extension = NULL; obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, [[", loc.start.line); MUSCLE_OBSTACK_SGROW (&muscle_obstack, quotearg_style (c_quoting_style, loc.start.file)); obstack_sgrow (&muscle_obstack, "]])[\n"); obstack_sgrow (&muscle_obstack, val); obstack_1grow (&muscle_obstack, 0); extension = obstack_finish (&muscle_obstack); muscle_grow (key, extension, ""); }
void muscle_pair_list_grow (const char *muscle, const char *a1, const char *a2) { char *pair; obstack_sgrow (&muscle_obstack, "["); obstack_quote (&muscle_obstack, a1); obstack_sgrow (&muscle_obstack, ", "); obstack_quote (&muscle_obstack, a2); obstack_sgrow (&muscle_obstack, "]"); pair = obstack_finish0 (&muscle_obstack); muscle_grow (muscle, pair, ",\n", ""); obstack_free (&muscle_obstack, pair); }
static void muscle_boundary_grow (char const *key, boundary bound) { char *extension; obstack_sgrow (&muscle_obstack, "[["); 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, "", ""); obstack_free (&muscle_obstack, extension); }
static void muscle_syncline_grow (char const *key, location loc) { char *extension = NULL; obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line); obstack_quote (&muscle_obstack, quotearg_style (c_quoting_style, loc.start.file)); obstack_sgrow (&muscle_obstack, ")["); extension = obstack_finish0 (&muscle_obstack); muscle_grow (key, extension, "", ""); obstack_free (&muscle_obstack, extension); }
static inline void log_resolution (rule *r, symbol_number token, enum conflict_resolution resolution) { if (report_flag & report_solved_conflicts) { /* The description of the resolution. */ switch (resolution) { case shift_resolution: case right_resolution: obstack_fgrow2 (&solved_conflicts_obstack, _(" Conflict between rule %d and token %s" " resolved as shift"), r->number, symbols[token]->tag); break; case reduce_resolution: case left_resolution: obstack_fgrow2 (&solved_conflicts_obstack, _(" Conflict between rule %d and token %s" " resolved as reduce"), r->number, symbols[token]->tag); break; case nonassoc_resolution: obstack_fgrow2 (&solved_conflicts_obstack, _(" Conflict between rule %d and token %s" " resolved as an error"), r->number, symbols[token]->tag); break; } /* The reason. */ switch (resolution) { case shift_resolution: obstack_fgrow2 (&solved_conflicts_obstack, " (%s < %s)", r->prec->tag, symbols[token]->tag); break; case reduce_resolution: obstack_fgrow2 (&solved_conflicts_obstack, " (%s < %s)", symbols[token]->tag, r->prec->tag); break; case left_resolution: obstack_fgrow1 (&solved_conflicts_obstack, " (%%left %s)", symbols[token]->tag); break; case right_resolution: obstack_fgrow1 (&solved_conflicts_obstack, " (%%right %s)", symbols[token]->tag); break; case nonassoc_resolution: obstack_fgrow1 (&solved_conflicts_obstack, " (%%nonassoc %s)", symbols[token]->tag); break; } obstack_sgrow (&solved_conflicts_obstack, ".\n"); } /* XML report */ if (xml_flag) { /* The description of the resolution. */ switch (resolution) { case shift_resolution: case right_resolution: obstack_fgrow2 (&solved_conflicts_xml_obstack, " <resolution rule=\"%d\" symbol=\"%s\"" " type=\"shift\">", r->number, xml_escape (symbols[token]->tag)); break; case reduce_resolution: case left_resolution: obstack_fgrow2 (&solved_conflicts_xml_obstack, " <resolution rule=\"%d\" symbol=\"%s\"" " type=\"reduce\">", r->number, xml_escape (symbols[token]->tag)); break; case nonassoc_resolution: obstack_fgrow2 (&solved_conflicts_xml_obstack, " <resolution rule=\"%d\" symbol=\"%s\"" " type=\"error\">", r->number, xml_escape (symbols[token]->tag)); break; } /* The reason. */ switch (resolution) { case shift_resolution: obstack_fgrow2 (&solved_conflicts_xml_obstack, "%s < %s", xml_escape_n (0, r->prec->tag), xml_escape_n (1, symbols[token]->tag)); break; case reduce_resolution: obstack_fgrow2 (&solved_conflicts_xml_obstack, "%s < %s", xml_escape_n (0, symbols[token]->tag), xml_escape_n (1, r->prec->tag)); break; case left_resolution: obstack_fgrow1 (&solved_conflicts_xml_obstack, "%%left %s", xml_escape (symbols[token]->tag)); break; case right_resolution: obstack_fgrow1 (&solved_conflicts_xml_obstack, "%%right %s", xml_escape (symbols[token]->tag)); break; case nonassoc_resolution: obstack_fgrow1 (&solved_conflicts_xml_obstack, "%%nonassoc %s", xml_escape (symbols[token]->tag)); break; } obstack_sgrow (&solved_conflicts_xml_obstack, "</resolution>\n"); } }