/[bison]/bison/src/output.c
ViewVC logotype

Diff of /bison/src/output.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.213 by eggert, Sat Dec 7 05:59:42 2002 UTC revision 1.214 by eggert, Wed Dec 11 06:39:20 2002 UTC
# Line 21  Line 21 
21    
22    
23  #include "system.h"  #include "system.h"
24  #include "quotearg.h"  
25  #include "error.h"  #include <error.h>
26  #include "subpipe.h"  #include <get-errno.h>
27  #include "getargs.h"  #include <quotearg.h>
28    #include <subpipe.h>
29    #include <timevar.h>
30    
31    #include "complain.h"
32  #include "files.h"  #include "files.h"
33    #include "getargs.h"
34  #include "gram.h"  #include "gram.h"
35  #include "complain.h"  #include "muscle_tab.h"
36  #include "output.h"  #include "output.h"
37  #include "reader.h"  #include "reader.h"
38  #include "symtab.h"  #include "symtab.h"
39  #include "tables.h"  #include "tables.h"
 #include "muscle_tab.h"  
40    
41  /* From src/scan-skel.l. */  /* From src/scan-skel.l. */
42  void scan_skel (FILE *);  void scan_skel (FILE *);
# Line 100  Name (const char *name,                                                        \ Line 104  Name (const char *name,                                                        \
104  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
105  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int)
106  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short)
107  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_t)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_number)
108  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number_t)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number)
109  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number)
110  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number)
111  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t)  GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number)
112    
113    
114  /*----------------------------------------------------------------------.  /*----------------------------------------------------------------------.
# Line 162  prepare_symbols (void) Line 166  prepare_symbols (void)
166                              symbols[i]->tag);                              symbols[i]->tag);
167          /* Width of the next token, including the two quotes, the comma          /* Width of the next token, including the two quotes, the comma
168             and the space.  */             and the space.  */
169          int strsize = strlen (cp) + 2;          int width = strlen (cp) + 2;
170    
171          if (j + strsize > 75)          if (j + width > 75)
172            {            {
173              obstack_sgrow (&format_obstack, "\n  ");              obstack_sgrow (&format_obstack, "\n  ");
174              j = 2;              j = 2;
# Line 172  prepare_symbols (void) Line 176  prepare_symbols (void)
176    
177          MUSCLE_OBSTACK_SGROW (&format_obstack, cp);          MUSCLE_OBSTACK_SGROW (&format_obstack, cp);
178          obstack_sgrow (&format_obstack, ", ");          obstack_sgrow (&format_obstack, ", ");
179          j += strsize;          j += width;
180        }        }
181      /* Add a NULL entry to list of tokens (well, 0, as NULL might not be      /* Add a NULL entry to list of tokens (well, 0, as NULL might not be
182         defined).  */         defined).  */
# Line 204  prepare_symbols (void) Line 208  prepare_symbols (void)
208  static void  static void
209  prepare_rules (void)  prepare_rules (void)
210  {  {
211    rule_number_t r;    rule_number r;
212    unsigned int i = 0;    unsigned int i = 0;
213    item_number_t *rhs = XMALLOC (item_number_t, nritems);    item_number *rhs = XMALLOC (item_number, nritems);
214    unsigned int *prhs = XMALLOC (unsigned int, nrules);    unsigned int *prhs = XMALLOC (unsigned int, nrules);
215    unsigned int *rline = XMALLOC (unsigned int, nrules);    unsigned int *rline = XMALLOC (unsigned int, nrules);
216    symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules);    symbol_number *r1 = XMALLOC (symbol_number, nrules);
217    unsigned int *r2 = XMALLOC (unsigned int, nrules);    unsigned int *r2 = XMALLOC (unsigned int, nrules);
218    short *dprec = XMALLOC (short, nrules);    short *dprec = XMALLOC (short, nrules);
219    short *merger = XMALLOC (short, nrules);    short *merger = XMALLOC (short, nrules);
220    
221    for (r = 0; r < nrules; ++r)    for (r = 0; r < nrules; ++r)
222      {      {
223        item_number_t *rhsp = NULL;        item_number *rhsp = NULL;
224        /* Index of rule R in RHS. */        /* Index of rule R in RHS. */
225        prhs[r] = i;        prhs[r] = i;
226        /* RHS of the rule R. */        /* RHS of the rule R. */
# Line 264  prepare_rules (void) Line 268  prepare_rules (void)
268  static void  static void
269  prepare_states (void)  prepare_states (void)
270  {  {
271    state_number_t i;    state_number i;
272    symbol_number_t *values =    symbol_number *values =
273      (symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates);      (symbol_number *) alloca (sizeof (symbol_number) * nstates);
274    for (i = 0; i < nstates; ++i)    for (i = 0; i < nstates; ++i)
275      values[i] = states[i]->accessing_symbol;      values[i] = states[i]->accessing_symbol;
276    muscle_insert_symbol_number_table ("stos", values,    muscle_insert_symbol_number_table ("stos", values,
# Line 286  prepare_states (void) Line 290  prepare_states (void)
290  static void  static void
291  user_actions_output (FILE *out)  user_actions_output (FILE *out)
292  {  {
293    rule_number_t r;    rule_number r;
294    
295    fputs ("m4_define([b4_actions], \n[[", out);    fputs ("m4_define([b4_actions], \n[[", out);
296    for (r = 0; r < nrules; ++r)    for (r = 0; r < nrules; ++r)
# Line 340  token_definitions_output (FILE *out) Line 344  token_definitions_output (FILE *out)
344    fputs ("m4_define([b4_tokens], \n[", out);    fputs ("m4_define([b4_tokens], \n[", out);
345    for (i = 0; i < ntokens; ++i)    for (i = 0; i < ntokens; ++i)
346      {      {
347        symbol_t *symbol = symbols[i];        symbol *sym = symbols[i];
348        int number = symbol->user_token_number;        int number = sym->user_token_number;
349    
350        /* At this stage, if there are literal aliases, they are part of        /* At this stage, if there are literal aliases, they are part of
351           SYMBOLS, so we should not find symbols which are the aliases           SYMBOLS, so we should not find symbols which are the aliases
# Line 350  token_definitions_output (FILE *out) Line 354  token_definitions_output (FILE *out)
354          abort ();          abort ();
355    
356        /* Skip error token.  */        /* Skip error token.  */
357        if (symbol == errtoken)        if (sym == errtoken)
358          continue;          continue;
359    
360        /* If this string has an alias, then it is necessarily the alias        /* If this string has an alias, then it is necessarily the alias
361           which is to be output.  */           which is to be output.  */
362        if (symbol->alias)        if (sym->alias)
363          symbol = symbol->alias;          sym = sym->alias;
364    
365        /* Don't output literal chars or strings (when defined only as a        /* Don't output literal chars or strings (when defined only as a
366           string).  Note that must be done after the alias resolution:           string).  Note that must be done after the alias resolution:
367           think about `%token 'f' "f"'.  */           think about `%token 'f' "f"'.  */
368        if (symbol->tag[0] == '\'' || symbol->tag[0] == '\"')        if (sym->tag[0] == '\'' || sym->tag[0] == '\"')
369          continue;          continue;
370    
371        /* Don't #define nonliteral tokens whose names contain periods        /* Don't #define nonliteral tokens whose names contain periods
372           or '$' (as does the default value of the EOF token).  */           or '$' (as does the default value of the EOF token).  */
373        if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$'))        if (strchr (sym->tag, '.') || strchr (sym->tag, '$'))
374          continue;          continue;
375    
376        fprintf (out, "%s[[[%s]], [%d]]",        fprintf (out, "%s[[[%s]], [%d]]",
377                 first ? "" : ",\n", symbol->tag, number);                 first ? "" : ",\n", sym->tag, number);
378    
379        first = 0;        first = 0;
380      }      }
# Line 392  symbol_destructors_output (FILE *out) Line 396  symbol_destructors_output (FILE *out)
396    for (i = 0; i < nsyms; ++i)    for (i = 0; i < nsyms; ++i)
397      if (symbols[i]->destructor)      if (symbols[i]->destructor)
398        {        {
399          symbol_t *symbol = symbols[i];          symbol *sym = symbols[i];
400    
401          /* Filename, lineno,          /* Filename, lineno,
402             Symbol-name, Symbol-number,             Symbol-name, Symbol-number,
403             destructor, typename. */             destructor, typename. */
404          fprintf (out, "%s[",          fprintf (out, "%s[",
405                   first ? "" : ",\n");                   first ? "" : ",\n");
406          escaped_file_name_output (out, symbol->destructor_location.start.file);          escaped_file_name_output (out, sym->destructor_location.start.file);
407          fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",          fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
408                   symbol->destructor_location.start.line,                   sym->destructor_location.start.line,
409                   symbol->tag,                   sym->tag,
410                   symbol->number,                   sym->number,
411                   symbol->destructor,                   sym->destructor,
412                   symbol->type_name);                   sym->type_name);
413    
414          first = 0;          first = 0;
415        }        }
# Line 427  symbol_printers_output (FILE *out) Line 431  symbol_printers_output (FILE *out)
431    for (i = 0; i < nsyms; ++i)    for (i = 0; i < nsyms; ++i)
432      if (symbols[i]->destructor)      if (symbols[i]->destructor)
433        {        {
434          symbol_t *symbol = symbols[i];          symbol *sym = symbols[i];
435    
436          /* Filename, lineno,          /* Filename, lineno,
437             Symbol-name, Symbol-number,             Symbol-name, Symbol-number,
438             printer, typename. */             printer, typename. */
439          fprintf (out, "%s[",          fprintf (out, "%s[",
440                   first ? "" : ",\n");                   first ? "" : ",\n");
441          escaped_file_name_output (out, symbol->printer_location.start.file);          escaped_file_name_output (out, sym->printer_location.start.file);
442          fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",          fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
443                   symbol->printer_location.start.line,                   sym->printer_location.start.line,
444                   symbol->tag,                   sym->tag,
445                   symbol->number,                   sym->number,
446                   symbol->printer,                   sym->printer,
447                   symbol->type_name);                   sym->type_name);
448    
449          first = 0;          first = 0;
450        }        }
# Line 551  output_skeleton (void) Line 555  output_skeleton (void)
555    
556    out = fdopen (filter_fd[0], "w");    out = fdopen (filter_fd[0], "w");
557    if (! out)    if (! out)
558      error (EXIT_FAILURE, errno, "fdopen");      error (EXIT_FAILURE, get_errno (), "fdopen");
559    
560    /* Output the definitions of all the muscles.  */    /* Output the definitions of all the muscles.  */
561    fputs ("m4_init()\n", out);    fputs ("m4_init()\n", out);
# Line 572  output_skeleton (void) Line 576  output_skeleton (void)
576    timevar_push (TV_M4);    timevar_push (TV_M4);
577    in = fdopen (filter_fd[1], "r");    in = fdopen (filter_fd[1], "r");
578    if (! in)    if (! in)
579      error (EXIT_FAILURE, errno, "fdopen");      error (EXIT_FAILURE, get_errno (), "fdopen");
580    scan_skel (in);    scan_skel (in);
581    xfclose (in);    xfclose (in);
582    reap_subpipe (pid, m4);    reap_subpipe (pid, m4);

Legend:
Removed from v.1.213  
changed lines
  Added in v.1.214

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26