2 * This file is part of cparser.
3 * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include "adt/strutil.h"
23 #include "symbol_table_t.h"
26 #include "adt/hash_string.h"
29 struct obstack symbol_obstack;
32 void init_symbol_table_entry(symbol_t *entry, const char *string)
34 entry->string = string;
35 entry->ID = T_IDENTIFIER;
36 entry->pp_ID = TP_NULL;
38 entry->pp_definition = NULL;
41 #define HashSet symbol_table_t
42 #define HashSetEntry symbol_table_hash_entry_t
43 #define ValueType symbol_t*
44 #define NullValue NULL
45 #define DeletedValue ((symbol_t*)-1)
46 #define KeyType const char *
47 #define ConstKeyType const char *
48 #define GetKey(value) (value)->string
49 #define InitData(this,value,key) ((void)((value) = (ValueType)obstack_alloc(&symbol_obstack, sizeof(symbol_t)), init_symbol_table_entry((value), key)))
50 #define Hash(this, key) hash_string(key)
51 #define KeysEqual(this,key1,key2) (streq(key1, key2))
52 #define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof(symbol_table_hash_entry_t))
55 void _symbol_table_init(symbol_table_t *symbol_table);
56 #define hashset_init _symbol_table_init
57 void _symbol_table_destroy(symbol_table_t *symbol_table);
58 #define hashset_destroy _symbol_table_destroy
59 symbol_t *_symbol_table_insert(symbol_table_t *symbol_table, const char *key);
60 #define hashset_insert _symbol_table_insert
62 #include "adt/hashset.c.inl"
64 static symbol_table_t symbol_table;
66 symbol_t *sym_anonymous;
68 symbol_t *symbol_table_insert(const char *string)
70 return _symbol_table_insert(&symbol_table, string);
73 void init_symbol_table(void)
75 obstack_init(&symbol_obstack);
76 _symbol_table_init(&symbol_table);
77 sym_anonymous = symbol_table_insert("<anonymous>");
80 void exit_symbol_table(void)
82 _symbol_table_destroy(&symbol_table);
83 obstack_free(&symbol_obstack, NULL);