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

Diff of /bison/src/muscle_tab.c

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

revision 1.20 by akim, Fri Jun 14 17:36:24 2002 UTC revision 1.21 by akim, Sat Oct 19 14:38:06 2002 UTC
# Line 1  Line 1 
1  /* Macro table manager for Bison,  /* Muscle table manager for Bison,
2     Copyright (C) 2001, 2002 Free Software Foundation, Inc.     Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3    
4     This file is part of Bison, the GNU Compiler Compiler.     This file is part of Bison, the GNU Compiler Compiler.
# Line 56  hash_muscle (const void *x, unsigned int Line 56  hash_muscle (const void *x, unsigned int
56  void  void
57  muscle_init (void)  muscle_init (void)
58  {  {
59      /* Initialize the muscle obstack.  */
60      obstack_init (&muscle_obstack);
61    
62    muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,    muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
63                                    hash_compare_muscles, free);                                    hash_compare_muscles, free);
64    
65    /* Version and input file.  */    /* Version and input file.  */
66    muscle_insert ("version", VERSION);    MUSCLE_INSERT_STRING ("version", VERSION);
67    muscle_insert ("filename", infile);    MUSCLE_INSERT_STRING ("filename", infile);
68    
69    /* FIXME: there should probably be no default here, only in the    /* FIXME: there should probably be no default here, only in the
70       skeletons.  */       skeletons.  */
71    
72    /* Types.  */    /* Types.  */
73    muscle_insert ("ltype", "yyltype");    MUSCLE_INSERT_STRING ("ltype", "yyltype");
74    
75    /* Default #line formatting.  */    /* Default #line formatting.  */
76    muscle_insert ("linef", "#line %d %s\n");    MUSCLE_INSERT_STRING ("linef", "#line %d %s\n");
77    
78    /* Stack parameters.  */    /* Stack parameters.  */
79    muscle_insert ("maxdepth", "10000");    MUSCLE_INSERT_STRING ("maxdepth", "10000");
80    muscle_insert ("initdepth", "200");    MUSCLE_INSERT_STRING ("initdepth", "200");
81    
82    /* C++ macros.  */    /* C++ macros.  */
83    muscle_insert ("name", "Parser");    MUSCLE_INSERT_STRING ("name", "Parser");
   
   /* Initialize the muscle obstack.  */  
   obstack_init (&muscle_obstack);  
84  }  }
85    
86    
# Line 97  muscle_free (void) Line 97  muscle_free (void)
97    
98    
99    
100    /*------------------------------------------------------------.
101    | Insert (KEY, VALUE).  If KEY already existed, overwrite the |
102    | previous value.                                             |
103    `------------------------------------------------------------*/
104    
105  void  void
106  muscle_insert (const char *key, const char *value)  muscle_insert (const char *key, char *value)
107  {  {
108    muscle_entry_t pair;    muscle_entry_t probe;
109    muscle_entry_t *entry = NULL;    muscle_entry_t *entry = NULL;
110    
111    pair.key = key;    probe.key = key;
112    entry = hash_lookup (muscle_table, &pair);    entry = hash_lookup (muscle_table, &probe);
113    
114    if (!entry)    if (!entry)
115      {      {
# Line 116  muscle_insert (const char *key, const ch Line 121  muscle_insert (const char *key, const ch
121    entry->value = value;    entry->value = value;
122  }  }
123    
124  const char*  
125    /*-------------------------------------------------------------------.
126    | Insert (KEY, VALUE).  If KEY already existed, overwrite the        |
127    | previous value.  Uses MUSCLE_OBSTACK.  De-allocates the previously |
128    | associated value.  VALUE and SEPARATOR are copied.                 |
129    `-------------------------------------------------------------------*/
130    
131    void
132    muscle_grow (const char *key, const char *val, const char *separator)
133    {
134      muscle_entry_t probe;
135      muscle_entry_t *entry = NULL;
136    
137      probe.key = key;
138      entry = hash_lookup (muscle_table, &probe);
139    
140      if (!entry)
141        {
142          /* First insertion in the hash. */
143          entry = XMALLOC (muscle_entry_t, 1);
144          entry->key = key;
145          hash_insert (muscle_table, entry);
146          entry->value = xstrdup (val);
147        }
148      else
149        {
150          /* Grow the current value. */
151          char *new_val;
152          fprintf (stderr, "<= %s + %s\n", entry->value, val);
153          obstack_sgrow (&muscle_obstack, entry->value);
154          free (entry->value);
155          obstack_sgrow (&muscle_obstack, separator);
156          obstack_sgrow (&muscle_obstack, val);
157          obstack_1grow (&muscle_obstack, 0);
158          new_val = obstack_finish (&muscle_obstack);
159          entry->value = xstrdup (new_val);
160          fprintf (stderr, "=> %s\n", new_val);
161          obstack_free (&muscle_obstack, new_val);
162        }
163    }
164    
165    
166    /*-------------------------------------------------------------------.
167    | MUSCLE is an M4 list of pairs.  Create or extend it with the pair  |
168    | (A1, A2).  Note that because the muscle values are output *double* |
169    | quoted, one needs to strip the first level of quotes to reach the  |
170    | list itself.                                                       |
171    `-------------------------------------------------------------------*/
172    
173    void muscle_pair_list_grow (const char *muscle,
174                                const char *a1, const char *a2)
175    {
176      char *value;
177      obstack_fgrow2 (&muscle_obstack, "[[[%s]], [[%s]]]", a1, a2);
178      obstack_1grow (&muscle_obstack, 0);
179      value = obstack_finish (&muscle_obstack);
180      muscle_grow (muscle, value, ",\n");
181      obstack_free (&muscle_obstack, value);
182    }
183    
184    /*-------------------------------.
185    | Find the value of muscle KEY.  |
186    `-------------------------------*/
187    
188    char*
189  muscle_find (const char *key)  muscle_find (const char *key)
190  {  {
191    muscle_entry_t pair;    muscle_entry_t probe;
192    muscle_entry_t *result = NULL;    muscle_entry_t *result = NULL;
193    
194    pair.key = key;    probe.key = key;
195    result = hash_lookup (muscle_table, &pair);    result = hash_lookup (muscle_table, &probe);
196    return result ? result->value : NULL;    return result ? result->value : NULL;
197  }  }
198    
199    
200  /* Output the definition of all the current muscles into a list of  /*------------------------------------------------.
201     m4_defines.  */  | Output the definition of ENTRY as a m4_define.  |
202    `------------------------------------------------*/
203    
204  static int  static int
205  muscle_m4_output (muscle_entry_t *entry, FILE *out)  muscle_m4_output (muscle_entry_t *entry, FILE *out)
206  {  {
207    fprintf (out, "m4_define([b4_%s],\n", entry->key);    fprintf (out, "m4_define([b4_%s],\n", entry->key);
208    fprintf (out, "          [[%s]])\n\n\n", entry->value);    fprintf (out, "[[%s]])\n\n\n", entry->value);
209    return 1;    return 1;
210  }  }
211    
212    
213  /* Output the definition of all the current muscles into a list of  /*----------------------------------------------------------------.
214     m4_defines.  */  | Output the definition of all the current muscles into a list of |
215    | m4_defines.                                                     |
216    `----------------------------------------------------------------*/
217    
218  void  void
219  muscles_m4_output (FILE *out)  muscles_m4_output (FILE *out)

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

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