2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 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 "entitymap_t.h"
24 static entitymap_entry_t null_entitymap_entry = { NULL, NULL };
26 static unsigned hash_ptr(const void *ptr)
28 unsigned ptr_int = ((char*) ptr - (char*) NULL);
33 #define HashSet entitymap_t
34 #define HashSetIterator entitymap_iterator_t
35 #define ValueType entitymap_entry_t
36 #define NullValue null_entitymap_entry
37 #define KeyType symbol_t*
38 #define ConstKeyType const symbol_t*
39 #define GetKey(value) (value).symbol
40 #define InitData(self,value,key) (value).symbol = (key)
41 #define Hash(self,key) hash_ptr(key)
42 #define KeysEqual(self,key1,key2) (key1) == (key2)
43 #define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof((ptr)[0]))
44 #define EntrySetEmpty(value) (value).symbol = NULL
45 #define EntrySetDeleted(value) (value).symbol = (symbol_t*) -1
46 #define EntryIsEmpty(value) ((value).symbol == NULL)
47 #define EntryIsDeleted(value) ((value).symbol == (symbol_t*)-1)
49 #define hashset_init entitymap_init
50 #define hashset_init_size _entitymap_init_size
51 #define hashset_destroy entitymap_destroy
52 #define hashset_insert _entitymap_insert
53 #define hashset_remove entitymap_remove
54 #define hashset_find _entitymap_find
55 #define hashset_size _entitymap_size
56 #define hashset_iterator_init _entitymap_iterator_init
57 #define hashset_iterator_next _entitymap_iterator_next
58 #define hashset_remove_iterator _entitymap_remove_iterator
60 #include "adt/hashset.c"
62 ir_entity *entitymap_get(const entitymap_t *map, symbol_t *symbol)
64 entitymap_entry_t *entry = _entitymap_find(map, symbol);
68 void entitymap_insert(entitymap_t *map, symbol_t *symbol, ir_entity *entity)
70 entitymap_entry_t *entry = _entitymap_insert(map, symbol);
71 entry->entity = entity;