1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
4  *
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.
9  *
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.
14  *
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
18  * 02111-1307, USA.
19  */
20 #include <config.h>
21 
22 #include "entitymap_t.h"
23 
24 static entitymap_entry_t null_entitymap_entry = { NULL, NULL };
25 
hash_ptr(const void * ptr)26 static unsigned hash_ptr(const void *ptr)
27 {
28 	unsigned ptr_int = ((char*) ptr - (char*) NULL);
29 	return ptr_int >> 3;
30 }
31 
32 #define DO_REHASH
33 #define HashSet                   entitymap_t
34 #define ValueType                 entitymap_entry_t
35 #define NullValue                 null_entitymap_entry
36 #define KeyType                   symbol_t*
37 #define ConstKeyType              const symbol_t*
38 #define GetKey(value)             (value).symbol
39 #define InitData(self,value,key)  (value).symbol = (key)
40 #define Hash(self,key)            hash_ptr(key)
41 #define KeysEqual(self,key1,key2) (key1) == (key2)
42 #define SetRangeEmpty(ptr,size)   memset(ptr, 0, (size) * sizeof((ptr)[0]))
43 #define EntrySetEmpty(value)      (value).symbol = NULL
44 #define EntrySetDeleted(value)    (value).symbol = (symbol_t*) -1
45 #define EntryIsEmpty(value)       ((value).symbol == NULL)
46 #define EntryIsDeleted(value)     ((value).symbol == (symbol_t*)-1)
47 
48 #define hashset_init            entitymap_init
49 #define hashset_destroy         entitymap_destroy
50 entitymap_entry_t *_entitymap_insert(entitymap_t *map, symbol_t *symbol);
51 #define hashset_insert          _entitymap_insert
52 entitymap_entry_t *_entitymap_find(const entitymap_t *map, const symbol_t *symbol);
53 #define hashset_find            _entitymap_find
54 
55 #include "adt/hashset.c.inl"
56 
entitymap_get(const entitymap_t * map,symbol_t * symbol)57 ir_entity *entitymap_get(const entitymap_t *map, symbol_t *symbol)
58 {
59 	entitymap_entry_t *entry = _entitymap_find(map, symbol);
60 	return entry->entity;
61 }
62 
entitymap_insert(entitymap_t * map,symbol_t * symbol,ir_entity * entity)63 void entitymap_insert(entitymap_t *map, symbol_t *symbol, ir_entity *entity)
64 {
65 	entitymap_entry_t *entry = _entitymap_insert(map, symbol);
66 	entry->entity = entity;
67 }
68