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 "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 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)
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
55 #include "adt/hashset.c.inl"
57 ir_entity *entitymap_get(const entitymap_t *map, symbol_t *symbol)
59 entitymap_entry_t *entry = _entitymap_find(map, symbol);
63 void entitymap_insert(entitymap_t *map, symbol_t *symbol, ir_entity *entity)
65 entitymap_entry_t *entry = _entitymap_insert(map, symbol);
66 entry->entity = entity;