]> git.saurik.com Git - bison.git/blame - src/muscle_tab.c
Have Bison grammars parsed by a Bison grammar.
[bison.git] / src / muscle_tab.c
CommitLineData
f753cd62 1/* Macro table manager for Bison,
beda758b 2 Copyright (C) 2001, 2002 Free Software Foundation, Inc.
f753cd62
MA
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
f753cd62
MA
21#include "system.h"
22#include "hash.h"
23#include "files.h"
24#include "muscle_tab.h"
f508cb0a 25#include "getargs.h"
f753cd62 26
beda758b
AD
27/* Initial capacity of muscles hash table. */
28#define HT_INITIAL_CAPACITY 257
f753cd62 29
beda758b 30struct hash_table *muscle_table = NULL;
f753cd62 31
beda758b
AD
32static bool
33hash_compare_muscles (void const *x, void const *y)
f753cd62 34{
beda758b
AD
35 const muscle_entry_t *m1 = x;
36 const muscle_entry_t *m2 = y;
37 return strcmp (m1->key, m2->key) ? FALSE : TRUE;
f753cd62
MA
38}
39
beda758b
AD
40static unsigned int
41hash_muscle (const void *x, unsigned int tablesize)
f753cd62 42{
beda758b
AD
43 const muscle_entry_t *m = x;
44 return hash_string (m->key, tablesize);
f753cd62
MA
45}
46
47void
48muscle_init (void)
49{
beda758b
AD
50 muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
51 hash_compare_muscles, NULL);
f753cd62
MA
52
53 /* Version and input file. */
54 muscle_insert ("version", VERSION);
55 muscle_insert ("filename", infile);
56
57 /* Types. */
f753cd62
MA
58 muscle_insert ("ltype", "yyltype");
59
25b222fa
MA
60 /* Default #line formatting. */
61 muscle_insert ("linef", "#line %d %s\n");
f753cd62 62
f753cd62
MA
63 /* Stack parameters. */
64 muscle_insert ("maxdepth", "10000");
65 muscle_insert ("initdepth", "200");
66
67 /* C++ macros. */
68 muscle_insert ("name", "Parser");
69}
70
a870c567 71void
f753cd62
MA
72muscle_insert (const char *key, const char *value)
73{
86eff183 74 muscle_entry_t pair;
e9bca3ad
AD
75 muscle_entry_t *entry = NULL;
76
86eff183 77 pair.key = key;
e9bca3ad 78 entry = hash_lookup (muscle_table, &pair);
beda758b
AD
79
80 if (!entry)
81 {
82 /* First insertion in the hash. */
83 entry = XMALLOC (muscle_entry_t, 1);
84 entry->key = key;
85 hash_insert (muscle_table, entry);
86 }
87 entry->value = value;
f753cd62
MA
88}
89
90const char*
91muscle_find (const char *key)
92{
86eff183 93 muscle_entry_t pair;
e9bca3ad
AD
94 muscle_entry_t *result = NULL;
95
86eff183 96 pair.key = key;
e9bca3ad 97 result = hash_lookup (muscle_table, &pair);
beda758b 98 return result ? result->value : NULL;
f753cd62 99}
be2a1a68
AD
100
101
102/* Output the definition of all the current muscles into a list of
103 m4_defines. */
104
cfaee611 105static int
be2a1a68
AD
106muscle_m4_output (muscle_entry_t *entry, FILE *out)
107{
108 fprintf (out, "m4_define([b4_%s],\n", entry->key);
109 fprintf (out, " [[%s]])\n\n\n", entry->value);
cfaee611 110 return 1;
be2a1a68
AD
111}
112
113
114/* Output the definition of all the current muscles into a list of
115 m4_defines. */
116
117void
118muscles_m4_output (FILE *out)
119{
120 hash_do_for_each (muscle_table,
121 (Hash_processor) muscle_m4_output,
122 out);
123}