]>
Commit | Line | Data |
---|---|---|
83cd972a RA |
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 "system.h" | |
24 | #include "hash.h" | |
25 | #include "files.h" | |
26 | #include "macrotab.h" | |
27 | ||
28 | struct hash_table macro_table; | |
29 | ||
30 | static unsigned long | |
31 | mhash1 (const void* item) | |
32 | { | |
33 | return_STRING_HASH_1 (((macro_entry_t*) item)->key); | |
34 | } | |
35 | ||
36 | static unsigned long | |
37 | mhash2 (const void* item) | |
38 | { | |
39 | return_STRING_HASH_2 (((macro_entry_t*) item)->key); | |
40 | } | |
41 | ||
42 | static int | |
43 | mcmp (const void* x, const void* y) | |
44 | { | |
45 | return strcmp (((macro_entry_t*) x)->key, ((macro_entry_t*) y)->key); | |
46 | } | |
47 | ||
48 | void | |
49 | macro_init (void) | |
50 | { | |
51 | hash_init (¯o_table, MTABSIZE, &mhash1, &mhash2, &mcmp); | |
52 | ||
53 | /* Version and input file. */ | |
54 | macro_insert ("version", VERSION); | |
55 | macro_insert ("filename", "a.y"); | |
56 | ||
57 | /* Types. */ | |
58 | macro_insert ("stype", "int"); | |
59 | macro_insert ("ltype", "yyltype"); | |
60 | ||
61 | /* Tokens. */ | |
62 | macro_insert ("tokendef", ""); | |
63 | ||
64 | /* Tables. */ | |
65 | macro_insert ("rhs", "0"); | |
66 | macro_insert ("pact", "0"); | |
67 | macro_insert ("prhs", "0"); | |
68 | macro_insert ("stos", "0"); | |
69 | macro_insert ("check", "0"); | |
70 | macro_insert ("pgoto", "0"); | |
71 | macro_insert ("table", "0"); | |
72 | macro_insert ("tname", "0"); | |
73 | macro_insert ("defact", "0"); | |
74 | macro_insert ("toknum", "0"); | |
75 | macro_insert ("defgoto", "0"); | |
76 | macro_insert ("translate", "0"); | |
77 | ||
78 | /* Various macros. */ | |
79 | macro_insert ("flag", "0"); | |
80 | macro_insert ("last", "0"); | |
81 | macro_insert ("pure", "0"); | |
82 | macro_insert ("nsym", "0"); | |
83 | macro_insert ("debug", "0"); | |
84 | macro_insert ("final", "0"); | |
85 | macro_insert ("maxtok", "0"); | |
86 | macro_insert ("ntbase", "0"); | |
87 | macro_insert ("verbose", "0"); | |
88 | ||
89 | /* Variable prefix names. */ | |
90 | macro_insert ("yyparse", "yyparse"); | |
91 | macro_insert ("yylex", "yylex"); | |
92 | macro_insert ("yyerror", "yyerror"); | |
93 | macro_insert ("yylval", "yylval"); | |
94 | macro_insert ("yychar", "yychar"); | |
95 | macro_insert ("yydebug", "yydebug"); | |
96 | macro_insert ("yynerrs", "yynerrs"); | |
97 | ||
98 | /* No parser macros. */ | |
99 | macro_insert ("nnts", "0"); | |
100 | macro_insert ("nrules", "0"); | |
101 | macro_insert ("nstates", "0"); | |
102 | macro_insert ("ntokens", "0"); | |
103 | ||
104 | /* Stack parameters. */ | |
105 | macro_insert ("maxdepth", "10000"); | |
106 | macro_insert ("initdepth", "200"); | |
107 | ||
108 | /* C++ macros. */ | |
109 | macro_insert ("name", "Parser"); | |
110 | } | |
111 | ||
112 | void | |
113 | macro_insert (char* key, char* value) | |
114 | { | |
115 | macro_entry_t* pair = (macro_entry_t*) xmalloc (sizeof (macro_entry_t)); | |
116 | pair->key = key; | |
117 | pair->value = value; | |
118 | hash_insert (¯o_table, pair); | |
119 | } | |
120 | ||
121 | char* | |
122 | macro_find (char* key) | |
123 | { | |
124 | macro_entry_t pair = { key, 0 }; | |
125 | macro_entry_t* result = hash_find_item (¯o_table, &pair); | |
126 | return result ? result->value : 0; | |
127 | } |