]> git.saurik.com Git - bison.git/blob - src/muscle_tab.c
* src/muscle_tab.c (muscle_find, muscle_insert): Don't initialize
[bison.git] / src / muscle_tab.c
1 /* Macro table manager for Bison,
2 Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3
4 This file is part of Bison, the GNU Compiler Compiler.
5
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "system.h"
22 #include "hash.h"
23 #include "files.h"
24 #include "muscle_tab.h"
25 #include "getargs.h"
26
27 /* Initial capacity of muscles hash table. */
28 #define HT_INITIAL_CAPACITY 257
29
30 struct hash_table *muscle_table = NULL;
31
32 static bool
33 hash_compare_muscles (void const *x, void const *y)
34 {
35 const muscle_entry_t *m1 = x;
36 const muscle_entry_t *m2 = y;
37 return strcmp (m1->key, m2->key) ? FALSE : TRUE;
38 }
39
40 static unsigned int
41 hash_muscle (const void *x, unsigned int tablesize)
42 {
43 const muscle_entry_t *m = x;
44 return hash_string (m->key, tablesize);
45 }
46
47 void
48 muscle_init (void)
49 {
50 muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
51 hash_compare_muscles, NULL);
52
53 /* Version and input file. */
54 muscle_insert ("version", VERSION);
55 muscle_insert ("filename", infile);
56
57 /* Types. */
58 muscle_insert ("stype", "int");
59 muscle_insert ("ltype", "yyltype");
60
61 /* Default #line formatting. */
62 muscle_insert ("linef", "#line %d %s\n");
63
64 /* Stack parameters. */
65 muscle_insert ("maxdepth", "10000");
66 muscle_insert ("initdepth", "200");
67
68 /* C++ macros. */
69 muscle_insert ("name", "Parser");
70 }
71
72 void
73 muscle_insert (const char *key, const char *value)
74 {
75 muscle_entry_t pair;
76 pair.key = key;
77 muscle_entry_t *entry = hash_lookup (muscle_table, &pair);
78
79 if (!entry)
80 {
81 /* First insertion in the hash. */
82 entry = XMALLOC (muscle_entry_t, 1);
83 entry->key = key;
84 hash_insert (muscle_table, entry);
85 }
86 entry->value = value;
87 }
88
89 const char*
90 muscle_find (const char *key)
91 {
92 muscle_entry_t pair;
93 pair.key = key;
94 muscle_entry_t *result = hash_lookup (muscle_table, &pair);
95 return result ? result->value : NULL;
96 }
97
98
99 /* Output the definition of all the current muscles into a list of
100 m4_defines. */
101
102 static int
103 muscle_m4_output (muscle_entry_t *entry, FILE *out)
104 {
105 fprintf (out, "m4_define([b4_%s],\n", entry->key);
106 fprintf (out, " [[%s]])\n\n\n", entry->value);
107 return 1;
108 }
109
110
111 /* Output the definition of all the current muscles into a list of
112 m4_defines. */
113
114 void
115 muscles_m4_output (FILE *out)
116 {
117 hash_do_for_each (muscle_table,
118 (Hash_processor) muscle_m4_output,
119 out);
120 }