29 |
struct hash_table macro_table; |
struct hash_table macro_table; |
30 |
|
|
31 |
static unsigned long |
static unsigned long |
32 |
mhash1 (const void* item) |
mhash1 (const void *item) |
33 |
{ |
{ |
34 |
return_STRING_HASH_1 (((macro_entry_t*) item)->key); |
return_STRING_HASH_1 (((macro_entry_t *) item)->key); |
35 |
} |
} |
36 |
|
|
37 |
static unsigned long |
static unsigned long |
38 |
mhash2 (const void* item) |
mhash2 (const void *item) |
39 |
{ |
{ |
40 |
return_STRING_HASH_2 (((macro_entry_t*) item)->key); |
return_STRING_HASH_2 (((macro_entry_t *) item)->key); |
41 |
} |
} |
42 |
|
|
43 |
static int |
static int |
44 |
mcmp (const void* x, const void* y) |
mcmp (const void *x, const void *y) |
45 |
{ |
{ |
46 |
return strcmp (((macro_entry_t*) x)->key, ((macro_entry_t*) y)->key); |
return strcmp (((macro_entry_t*) x)->key, ((macro_entry_t *) y)->key); |
47 |
} |
} |
48 |
|
|
49 |
void |
void |
51 |
{ |
{ |
52 |
hash_init (¯o_table, MTABSIZE, &mhash1, &mhash2, &mcmp); |
hash_init (¯o_table, MTABSIZE, &mhash1, &mhash2, &mcmp); |
53 |
|
|
54 |
/* Version and input file. */ |
/* Version and input file. */ |
55 |
macro_insert ("version", VERSION); |
macro_insert ("version", VERSION); |
56 |
macro_insert ("filename", "a.y"); |
macro_insert ("filename", "a.y"); |
57 |
|
|
58 |
/* Types. */ |
/* Types. */ |
59 |
macro_insert ("stype", "int"); |
macro_insert ("stype", "int"); |
60 |
macro_insert ("ltype", "yyltype"); |
macro_insert ("ltype", "yyltype"); |
61 |
|
|
62 |
/* Tokens. */ |
/* Tokens. */ |
63 |
macro_insert ("tokendef", ""); |
macro_insert ("tokendef", ""); |
64 |
|
|
65 |
/* Tables. */ |
/* Tables. */ |
66 |
macro_insert ("rhs", "0"); |
macro_insert ("rhs", "0"); |
67 |
macro_insert ("pact", "0"); |
macro_insert ("pact", "0"); |
68 |
macro_insert ("prhs", "0"); |
macro_insert ("prhs", "0"); |
76 |
macro_insert ("defgoto", "0"); |
macro_insert ("defgoto", "0"); |
77 |
macro_insert ("translate", "0"); |
macro_insert ("translate", "0"); |
78 |
|
|
79 |
/* Various macros. */ |
/* Various macros. */ |
80 |
macro_insert ("flag", "0"); |
macro_insert ("flag", "0"); |
81 |
macro_insert ("last", "0"); |
macro_insert ("last", "0"); |
82 |
macro_insert ("pure", "0"); |
macro_insert ("pure", "0"); |
87 |
macro_insert ("ntbase", "0"); |
macro_insert ("ntbase", "0"); |
88 |
macro_insert ("verbose", "0"); |
macro_insert ("verbose", "0"); |
89 |
|
|
90 |
/* Variable prefix names. */ |
/* Variable prefix names. */ |
91 |
macro_insert ("yyparse", "yyparse"); |
macro_insert ("yyparse", "yyparse"); |
92 |
macro_insert ("yylex", "yylex"); |
macro_insert ("yylex", "yylex"); |
93 |
macro_insert ("yyerror", "yyerror"); |
macro_insert ("yyerror", "yyerror"); |
96 |
macro_insert ("yydebug", "yydebug"); |
macro_insert ("yydebug", "yydebug"); |
97 |
macro_insert ("yynerrs", "yynerrs"); |
macro_insert ("yynerrs", "yynerrs"); |
98 |
|
|
99 |
/* No parser macros. */ |
/* No parser macros. */ |
100 |
macro_insert ("nnts", "0"); |
macro_insert ("nnts", "0"); |
101 |
macro_insert ("nrules", "0"); |
macro_insert ("nrules", "0"); |
102 |
macro_insert ("nstates", "0"); |
macro_insert ("nstates", "0"); |
103 |
macro_insert ("ntokens", "0"); |
macro_insert ("ntokens", "0"); |
104 |
|
|
105 |
/* Stack parameters. */ |
/* Stack parameters. */ |
106 |
macro_insert ("maxdepth", "10000"); |
macro_insert ("maxdepth", "10000"); |
107 |
macro_insert ("initdepth", "200"); |
macro_insert ("initdepth", "200"); |
108 |
|
|
109 |
/* C++ macros. */ |
/* C++ macros. */ |
110 |
macro_insert ("name", "Parser"); |
macro_insert ("name", "Parser"); |
111 |
} |
} |
112 |
|
|
113 |
void |
void |
114 |
macro_insert (const char *key, const char *value) |
macro_insert (const char *key, const char *value) |
115 |
{ |
{ |
116 |
macro_entry_t* pair = XMALLOC (macro_entry_t, 1); |
macro_entry_t *pair = XMALLOC (macro_entry_t, 1); |
117 |
pair->key = key; |
pair->key = key; |
118 |
pair->value = value; |
pair->value = value; |
119 |
hash_insert (¯o_table, pair); |
hash_insert (¯o_table, pair); |
123 |
macro_find (const char *key) |
macro_find (const char *key) |
124 |
{ |
{ |
125 |
macro_entry_t pair = { key, 0 }; |
macro_entry_t pair = { key, 0 }; |
126 |
macro_entry_t* result = hash_find_item (¯o_table, &pair); |
macro_entry_t *result = hash_find_item (¯o_table, &pair); |
127 |
return result ? result->value : 0; |
return result ? result->value : 0; |
128 |
} |
} |