]>
Commit | Line | Data |
---|---|---|
f753cd62 MA |
1 | /* Macro table manager for Bison, |
2 | Copyright 1984, 1989, 2000 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 <string.h> | |
22 | ||
23 | #include "xalloc.h" | |
24 | #include "system.h" | |
25 | #include "hash.h" | |
26 | #include "files.h" | |
27 | #include "muscle_tab.h" | |
f508cb0a | 28 | #include "getargs.h" |
f753cd62 MA |
29 | |
30 | struct hash_table muscle_table; | |
31 | ||
32 | static unsigned long | |
33 | mhash1 (const void *item) | |
34 | { | |
35 | return_STRING_HASH_1 (((muscle_entry_t *) item)->key); | |
36 | } | |
37 | ||
38 | static unsigned long | |
39 | mhash2 (const void *item) | |
40 | { | |
41 | return_STRING_HASH_2 (((muscle_entry_t *) item)->key); | |
42 | } | |
43 | ||
44 | static int | |
45 | mcmp (const void *x, const void *y) | |
46 | { | |
47 | return strcmp (((muscle_entry_t*) x)->key, ((muscle_entry_t *) y)->key); | |
48 | } | |
49 | ||
50 | void | |
51 | muscle_init (void) | |
52 | { | |
53 | hash_init (&muscle_table, MTABSIZE, &mhash1, &mhash2, &mcmp); | |
54 | ||
55 | /* Version and input file. */ | |
56 | muscle_insert ("version", VERSION); | |
57 | muscle_insert ("filename", infile); | |
58 | ||
59 | /* Types. */ | |
60 | muscle_insert ("stype", "int"); | |
61 | muscle_insert ("ltype", "yyltype"); | |
62 | ||
63 | /* Tokens. */ | |
64 | muscle_insert ("tokendef", ""); | |
65 | ||
66 | /* Tables. */ | |
67 | muscle_insert ("rhs", "0"); | |
68 | muscle_insert ("pact", "0"); | |
69 | muscle_insert ("prhs", "0"); | |
70 | muscle_insert ("stos", "0"); | |
71 | muscle_insert ("check", "0"); | |
72 | muscle_insert ("pgoto", "0"); | |
73 | muscle_insert ("table", "0"); | |
74 | muscle_insert ("tname", "0"); | |
75 | muscle_insert ("defact", "0"); | |
76 | muscle_insert ("toknum", "0"); | |
77 | muscle_insert ("defgoto", "0"); | |
78 | muscle_insert ("translate", "0"); | |
79 | ||
80 | /* Various macros. */ | |
81 | muscle_insert ("flag", "0"); | |
82 | muscle_insert ("last", "0"); | |
83 | muscle_insert ("pure", "0"); | |
84 | muscle_insert ("nsym", "0"); | |
85 | muscle_insert ("debug", "0"); | |
86 | muscle_insert ("final", "0"); | |
87 | muscle_insert ("maxtok", "0"); | |
88 | muscle_insert ("ntbase", "0"); | |
5b5d1929 | 89 | muscle_insert ("error-verbose", "0"); |
f753cd62 | 90 | muscle_insert ("prefix", "yy"); |
25b222fa MA |
91 | /* Default #line formatting. */ |
92 | muscle_insert ("linef", "#line %d %s\n"); | |
f753cd62 MA |
93 | |
94 | /* No parser macros. */ | |
95 | muscle_insert ("nnts", "0"); | |
96 | muscle_insert ("nrules", "0"); | |
97 | muscle_insert ("nstates", "0"); | |
98 | muscle_insert ("ntokens", "0"); | |
99 | ||
100 | /* Stack parameters. */ | |
101 | muscle_insert ("maxdepth", "10000"); | |
102 | muscle_insert ("initdepth", "200"); | |
103 | ||
104 | /* C++ macros. */ | |
105 | muscle_insert ("name", "Parser"); | |
106 | } | |
107 | ||
108 | void | |
109 | muscle_insert (const char *key, const char *value) | |
110 | { | |
111 | muscle_entry_t *pair = XMALLOC (muscle_entry_t, 1); | |
112 | pair->key = key; | |
113 | pair->value = value; | |
114 | hash_insert (&muscle_table, pair); | |
115 | } | |
116 | ||
117 | const char* | |
118 | muscle_find (const char *key) | |
119 | { | |
120 | muscle_entry_t pair = { key, 0 }; | |
121 | muscle_entry_t *result = hash_find_item (&muscle_table, &pair); | |
122 | return result ? result->value : 0; | |
123 | } |