From c1cc71ca2c79b3f2a9afe2be86a678c544ff6e62 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 16 Jul 2012 16:40:15 +0200 Subject: [PATCH] provide our own hashset implementation We want to be independent of libfirms containertypes (as they may get deprecated at some point). The implementation we use is a copy of libfirm :) --- adt/hashset.c | 243 ++++++++++++++++++++--------------------- adt/hashset.h | 4 +- adt/pset_new.c | 51 +++++++++ adt/pset_new.h | 149 +++++++++++++++++++++++++ entitymap.c | 9 +- entitymap_t.h | 2 - libfirm | 2 +- symbol_table.c | 11 +- symbol_table_t.h | 2 - type_hash.c | 13 +-- type_hash.h | 1 - wrappergen/write_jna.c | 2 +- 12 files changed, 330 insertions(+), 159 deletions(-) create mode 100644 adt/pset_new.c create mode 100644 adt/pset_new.h diff --git a/adt/hashset.c b/adt/hashset.c index 330e680..e0cf70c 100644 --- a/adt/hashset.c +++ b/adt/hashset.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2009 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2012 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -46,7 +46,7 @@ *
  • GetKey(value) Extracts the key from a data value
  • *
  • KeysEqual(hashset,key1,key2) Tests wether 2 keys are equal
  • *
  • DO_REHASH Instead of storing the hash-values, recalculate - * them on demand from the datavalues. (usefull if + * them on demand from the datavalues. (useful if * calculating the hash-values takes less time than * a memory access)
  • * @@ -94,26 +94,31 @@ #ifndef Alloc #include "xmalloc.h" -#define Alloc(size) (HashSetEntry*) xmalloc((size) * sizeof(HashSetEntry)) +#define Alloc(size) XMALLOCN(HashSetEntry, (size)) #define Free(ptr) free(ptr) #endif /* Alloc */ #ifdef ID_HASH -#define InsertReturnValue int -#define GetInsertReturnValue(entry,found) (found) -#define NullReturnValue 0 +#define FindReturnValue bool +#define GetFindReturnValue(entry,found) (found) +#define NullReturnValue false +#define InsertReturnValue(findreturn) !(findreturn) #else /* ! ID_HASH */ #ifdef SCALAR_RETURN -#define InsertReturnValue ValueType -#define GetInsertReturnValue(entry,found) EntryGetValue(entry) -#define NullReturnValue NullValue +#define FindReturnValue ValueType +#define GetFindReturnValue(entry,found) EntryGetValue(entry) +#define NullReturnValue NullValue #else -#define InsertReturnValue ValueType* -#define GetInsertReturnValue(entry,found) & EntryGetValue(entry) -#define NullReturnValue & NullValue +#define FindReturnValue ValueType* +#define GetFindReturnValue(entry,found) & EntryGetValue(entry) +#define NullReturnValue & NullValue #endif #endif /* ID_HASH */ +#ifndef InsertReturnValue +#define InsertReturnValue(findreturn) findreturn +#endif + #ifndef KeyType #define KeyType ValueType #define GetKey(value) (value) @@ -142,7 +147,7 @@ size_t _i; \ size_t _size = (size); \ HashSetEntry *entries = (ptr); \ - for(_i = 0; _i < _size; ++_i) { \ + for (_i = 0; _i < _size; ++_i) { \ HashSetEntry *entry = & entries[_i]; \ EntrySetEmpty(*entry); \ } \ @@ -169,50 +174,7 @@ #define ILLEGAL_POS ((size_t)-1) -/* check that all needed functions are defined */ -#ifndef hashset_init -#error You have to redefine hashset_init -#endif -#ifndef hashset_init_size -#error You have to redefine hashset_init_size -#endif -#ifndef hashset_destroy -#error You have to redefine hashset_destroy -#endif -#ifndef hashset_insert -#error You have to redefine hashset_insert -#endif -#ifndef hashset_remove -#error You have to redefine hashset_remove -#endif -#ifndef hashset_find -#error You have to redefine hashset_find -#endif -#ifndef hashset_size -#error You have to redefine hashset_size -#endif -#ifndef hashset_iterator_init -#error You have to redefine hashset_iterator_init -#endif -#ifndef hashset_iterator_next -#error You have to redefine hashset_iterator_next -#endif -#ifndef hashset_remove_iterator -#error You have to redefine hashset_remove_iterator -#endif - -/* prototypes to avoid warnings */ -void hashset_init(HashSet *self); -void hashset_destroy(HashSet *self); -size_t hashset_size(const HashSet *self); -InsertReturnValue hashset_insert(HashSet *self, KeyType key); -InsertReturnValue hashset_find(const HashSet *self, ConstKeyType key); -void hashset_remove(HashSet *self, ConstKeyType key); -void hashset_init_size(HashSet *self, size_t expected_elements); -void hashset_iterator_init(HashSetIterator *self, const HashSet *hashset); -ValueType hashset_iterator_next(HashSetIterator *self); -void hashset_remove_iterator(HashSet *self, const HashSetIterator *iter); - +#ifdef hashset_size /** * Returns the number of elements in the hashset */ @@ -220,15 +182,21 @@ size_t hashset_size(const HashSet *self) { return self->num_elements - self->num_deleted; } +#else +static inline size_t hashset_size(const HashSet *self) +{ + return self->num_elements - self->num_deleted; +} +#endif /** * Inserts an element into a hashset without growing the set (you have to make * sure there's enough room for that. + * @returns previous value if found, NullValue otherwise * @note also see comments for hashset_insert() * @internal */ -static inline -InsertReturnValue insert_nogrow(HashSet *self, KeyType key) +static inline FindReturnValue insert_nogrow(HashSet *self, KeyType key) { size_t num_probes = 0; size_t num_buckets = self->num_buckets; @@ -239,14 +207,14 @@ InsertReturnValue insert_nogrow(HashSet *self, KeyType key) assert((num_buckets & (num_buckets - 1)) == 0); - while(1) { + for (;;) { HashSetEntry *entry = & self->entries[bucknum]; - if(EntryIsEmpty(*entry)) { + if (EntryIsEmpty(*entry)) { size_t p; HashSetEntry *nentry; - if(insert_pos != ILLEGAL_POS) { + if (insert_pos != ILLEGAL_POS) { p = insert_pos; } else { p = bucknum; @@ -256,15 +224,15 @@ InsertReturnValue insert_nogrow(HashSet *self, KeyType key) InitData(self, EntryGetValue(*nentry), key); EntrySetHash(*nentry, hash); self->num_elements++; - return GetInsertReturnValue(*nentry, 0); + return GetFindReturnValue(*nentry, false); } - if(EntryIsDeleted(*entry)) { - if(insert_pos == ILLEGAL_POS) + if (EntryIsDeleted(*entry)) { + if (insert_pos == ILLEGAL_POS) insert_pos = bucknum; - } else if(EntryGetHash(self, *entry) == hash) { - if(KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) { + } else if (EntryGetHash(self, *entry) == hash) { + if (KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) { // Value already in the set, return it - return GetInsertReturnValue(*entry, 1); + return GetFindReturnValue(*entry, true); } } @@ -274,13 +242,24 @@ InsertReturnValue insert_nogrow(HashSet *self, KeyType key) } } +/** + * calculate shrink and enlarge limits + * @internal + */ +static inline void reset_thresholds(HashSet *self) +{ + self->enlarge_threshold = (size_t) HT_OCCUPANCY_FLT(self->num_buckets); + self->shrink_threshold = (size_t) HT_EMPTY_FLT(self->num_buckets); + self->consider_shrink = 0; +} + +#ifndef HAVE_OWN_RESIZE /** * Inserts an element into a hashset under the assumption that the hashset * contains no deleted entries and the element doesn't exist in the hashset yet. * @internal */ -static -void insert_new(HashSet *self, unsigned hash, ValueType value) +static void insert_new(HashSet *self, unsigned hash, ValueType value) { size_t num_probes = 0; size_t num_buckets = self->num_buckets; @@ -290,14 +269,14 @@ void insert_new(HashSet *self, unsigned hash, ValueType value) //assert(value != NullValue); - while(1) { + for (;;) { HashSetEntry *entry = & self->entries[bucknum]; - if(EntryIsEmpty(*entry)) { + if (EntryIsEmpty(*entry)) { size_t p; HashSetEntry *nentry; - if(insert_pos != ILLEGAL_POS) { + if (insert_pos != ILLEGAL_POS) { p = insert_pos; } else { p = bucknum; @@ -317,24 +296,11 @@ void insert_new(HashSet *self, unsigned hash, ValueType value) } } -/** - * calculate shrink and enlarge limits - * @internal - */ -static inline -void reset_thresholds(HashSet *self) -{ - self->enlarge_threshold = (size_t) HT_OCCUPANCY_FLT(self->num_buckets); - self->shrink_threshold = (size_t) HT_EMPTY_FLT(self->num_buckets); - self->consider_shrink = 0; -} - /** * Resize the hashset * @internal */ -static inline -void resize(HashSet *self, size_t new_size) +static inline void resize(HashSet *self, size_t new_size) { size_t num_buckets = self->num_buckets; size_t i; @@ -356,9 +322,9 @@ void resize(HashSet *self, size_t new_size) reset_thresholds(self); /* reinsert all elements */ - for(i = 0; i < num_buckets; ++i) { + for (i = 0; i < num_buckets; ++i) { HashSetEntry *entry = & old_entries[i]; - if(EntryIsEmpty(*entry) || EntryIsDeleted(*entry)) + if (EntryIsEmpty(*entry) || EntryIsDeleted(*entry)) continue; insert_new(self, EntryGetHash(self, *entry), EntryGetValue(*entry)); @@ -367,17 +333,22 @@ void resize(HashSet *self, size_t new_size) /* now we can free the old array */ Free(old_entries); } +#else + +/* resize must be defined outside */ +static inline void resize(HashSet *self, size_t new_size); + +#endif /** * grow the hashset if adding 1 more elements would make it too crowded * @internal */ -static inline -void maybe_grow(HashSet *self) +static inline void maybe_grow(HashSet *self) { size_t resize_to; - if(LIKELY(self->num_elements + 1 <= self->enlarge_threshold)) + if (LIKELY(self->num_elements + 1 <= self->enlarge_threshold)) return; /* double table size */ @@ -389,42 +360,42 @@ void maybe_grow(HashSet *self) * shrink the hashset if it is only sparsely filled * @internal */ -static inline -void maybe_shrink(HashSet *self) +static inline void maybe_shrink(HashSet *self) { size_t size; size_t resize_to; - if(!self->consider_shrink) + if (!self->consider_shrink) return; self->consider_shrink = 0; size = hashset_size(self); - if(size <= HT_MIN_BUCKETS) + if (size <= HT_MIN_BUCKETS) return; - if(LIKELY(size > self->shrink_threshold)) + if (LIKELY(size > self->shrink_threshold)) return; resize_to = ceil_po2(size); - if(resize_to < 4) + if (resize_to < 4) resize_to = 4; resize(self, resize_to); } +#ifdef hashset_insert /** - * Insert an element into the hashset. If no element with key key exists yet, + * Insert an element into the hashset. If no element with the given key exists yet, * then a new one is created and initialized with the InitData function. - * Otherwise the exisiting element is returned (for hashs where key is equal to + * Otherwise the existing element is returned (for hashs where key is equal to * value, nothing is returned.) * * @param self the hashset * @param key the key that identifies the data * @returns the existing or newly created data element (or nothing in case of hashs where keys are the while value) */ -InsertReturnValue hashset_insert(HashSet *self, KeyType key) +FindReturnValue hashset_insert(HashSet *self, KeyType key) { #ifndef NDEBUG self->entries_version++; @@ -432,17 +403,19 @@ InsertReturnValue hashset_insert(HashSet *self, KeyType key) maybe_shrink(self); maybe_grow(self); - return insert_nogrow(self, key); + return InsertReturnValue(insert_nogrow(self, key)); } +#endif +#ifdef hashset_find /** - * Searchs for an element with key @p key. + * Searches for an element with key @p key. * * @param self the hashset * @param key the key to search for * @returns the found value or NullValue if nothing was found */ -InsertReturnValue hashset_find(const HashSet *self, ConstKeyType key) +FindReturnValue hashset_find(const HashSet *self, ConstKeyType key) { size_t num_probes = 0; size_t num_buckets = self->num_buckets; @@ -450,18 +423,18 @@ InsertReturnValue hashset_find(const HashSet *self, ConstKeyType key) unsigned hash = Hash(self, key); size_t bucknum = hash & hashmask; - while(1) { + for (;;) { HashSetEntry *entry = & self->entries[bucknum]; - if(EntryIsEmpty(*entry)) { + if (EntryIsEmpty(*entry)) { return NullReturnValue; } - if(EntryIsDeleted(*entry)) { + if (EntryIsDeleted(*entry)) { // value is deleted - } else if(EntryGetHash(self, *entry) == hash) { - if(KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) { + } else if (EntryGetHash(self, *entry) == hash) { + if (KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) { // found the value - return GetInsertReturnValue(*entry, 1); + return GetFindReturnValue(*entry, true); } } @@ -470,7 +443,9 @@ InsertReturnValue hashset_find(const HashSet *self, ConstKeyType key) assert(num_probes < num_buckets); } } +#endif +#ifdef hashset_remove /** * Removes an element from a hashset. Does nothing if the set doesn't contain * the element. @@ -490,16 +465,16 @@ void hashset_remove(HashSet *self, ConstKeyType key) self->entries_version++; #endif - while(1) { + for (;;) { HashSetEntry *entry = & self->entries[bucknum]; - if(EntryIsEmpty(*entry)) { + if (EntryIsEmpty(*entry)) { return; } - if(EntryIsDeleted(*entry)) { + if (EntryIsDeleted(*entry)) { // entry is deleted - } else if(EntryGetHash(self, *entry) == hash) { - if(KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) { + } else if (EntryGetHash(self, *entry) == hash) { + if (KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) { EntrySetDeleted(*entry); self->num_deleted++; self->consider_shrink = 1; @@ -512,15 +487,15 @@ void hashset_remove(HashSet *self, ConstKeyType key) assert(num_probes < num_buckets); } } +#endif /** * Initializes hashset with a specific size * @internal */ -static inline -void init_size(HashSet *self, size_t initial_size) +static inline void init_size(HashSet *self, size_t initial_size) { - if(initial_size < 4) + if (initial_size < 4) initial_size = 4; self->entries = Alloc(initial_size); @@ -532,40 +507,51 @@ void init_size(HashSet *self, size_t initial_size) #ifndef NDEBUG self->entries_version = 0; #endif +#ifdef ADDITIONAL_INIT + ADDITIONAL_INIT +#endif reset_thresholds(self); } +#ifdef hashset_init /** - * Initialializes a hashset with the default size. The memory for the set has to + * Initializes a hashset with the default size. The memory for the set has to * already allocated. */ void hashset_init(HashSet *self) { init_size(self, HT_MIN_BUCKETS); } +#endif +#ifdef hashset_destroy /** * Destroys a hashset, freeing all used memory (except the memory for the * HashSet struct itself). */ void hashset_destroy(HashSet *self) { +#ifdef ADDITIONAL_TERM + ADDITIONAL_TERM +#endif Free(self->entries); #ifndef NDEBUG self->entries = NULL; #endif } +#endif +#ifdef hashset_init_size /** - * Initializes a hashset expecting expected_element size + * Initializes a hashset expecting expected_element size. */ void hashset_init_size(HashSet *self, size_t expected_elements) { size_t needed_size; size_t po2size; - if(expected_elements >= UINT_MAX/2) { + if (expected_elements >= UINT_MAX/2) { abort(); } @@ -573,7 +559,9 @@ void hashset_init_size(HashSet *self, size_t expected_elements) po2size = ceil_po2(needed_size); init_size(self, po2size); } +#endif +#ifdef hashset_iterator_init /** * Initializes a hashset iterator. The memory for the allocator has to be * already allocated. @@ -588,7 +576,9 @@ void hashset_iterator_init(HashSetIterator *self, const HashSet *hashset) self->entries_version = hashset->entries_version; #endif } +#endif +#ifdef hashset_iterator_next /** * Returns the next value in the iterator or NULL if no value is left * in the hashset. @@ -604,14 +594,16 @@ ValueType hashset_iterator_next(HashSetIterator *self) do { current_bucket++; - if(current_bucket >= end) + if (current_bucket >= end) return NullValue; - } while(EntryIsEmpty(*current_bucket) || EntryIsDeleted(*current_bucket)); + } while (EntryIsEmpty(*current_bucket) || EntryIsDeleted(*current_bucket)); self->current_bucket = current_bucket; return EntryGetValue(*current_bucket); } +#endif +#ifdef hashset_remove_iterator /** * Removes the element the iterator points to. Removing an element a second time * has no result. @@ -625,14 +617,13 @@ void hashset_remove_iterator(HashSet *self, const HashSetIterator *iter) /* needs to be on a valid element */ assert(entry < self->entries + self->num_buckets); - if(EntryIsDeleted(*entry)) + if (EntryIsDeleted(*entry)) return; EntrySetDeleted(*entry); self->num_deleted++; self->consider_shrink = 1; } +#endif -#else -__attribute__((unused)) static int dummy; #endif diff --git a/adt/hashset.h b/adt/hashset.h index 79fe62a..a254a49 100644 --- a/adt/hashset.h +++ b/adt/hashset.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2009 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2012 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -55,6 +55,7 @@ struct HashSet { #endif }; +#ifdef HashSetIterator struct HashSetIterator { HashSetEntry *current_bucket; HashSetEntry *end; @@ -63,6 +64,7 @@ struct HashSetIterator { unsigned entries_version; #endif }; +#endif #ifdef DO_REHASH #undef HashSetEntry diff --git a/adt/pset_new.c b/adt/pset_new.c new file mode 100644 index 0000000..6a49c39 --- /dev/null +++ b/adt/pset_new.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @brief implementation of pset_new + * @author Matthias Braun + */ +#include "config.h" + +#include "pset_new.h" + +/** probing method: quadratic probing */ +#define DO_REHASH +#define ID_HASH +#define HashSet pset_new_t +#define HashSetIterator pset_new_iterator_t +#define ValueType void* +#define NullValue NULL +#define DeletedValue ((void*)-1) +#define KeysEqual(this,key1,key2) 1 +#define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof(HashSetEntry)) + +#define hashset_init pset_new_init +#define hashset_init_size pset_new_init_size +#define hashset_destroy pset_new_destroy +#define hashset_insert pset_new_insert +#define hashset_remove pset_new_remove +#define hashset_find pset_new_contains +#define hashset_size pset_new_size +#define hashset_iterator_init pset_new_iterator_init +#define hashset_iterator_next pset_new_iterator_next +#define hashset_remove_iterator pset_new_remove_iterator + +#include "hashset.c" diff --git a/adt/pset_new.h b/adt/pset_new.h new file mode 100644 index 0000000..77feb7c --- /dev/null +++ b/adt/pset_new.h @@ -0,0 +1,149 @@ +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @date 17.03.2007 + * @brief hashset containing pointers + * @author Matthias Braun + * + * @note This has been named pset_new_new for now until all code has been + * changed to use this instead of the old deprecated pset_new functions! + * This version performs better than pset in terms of speed and memory + * usage and allows multiple iterators over the set + */ +#ifndef FIRM_ADT_PSET_NEW_H +#define FIRM_ADT_PSET_NEW_H + +#include + +/** @cond PRIVATE */ + +#define HashSet pset_new_t +#define HashSetIterator pset_new_iterator_t +#define ValueType void* +#define DO_REHASH +#include "hashset.h" +#undef DO_REHASH +#undef HashSet +#undef HashSetIterator +#undef ValueType + +/** @endcond */ + +/** a pointer (hash)set */ +typedef struct pset_new_t pset_new_t; +/** iterator over a pointer set. + * @see #pset_new_t */ +typedef struct pset_new_iterator_t pset_new_iterator_t; + +/** + * Initializes a pset_new + * + * @param pset_new Pointer to allocated space for the pset_new + */ +void pset_new_init(pset_new_t *pset_new); + +/** + * Initializes a pset_new + * + * @param pset_new Pointer to allocated space for the pset_new + * @param expected_elements Number of elements expected in the pset_new (roughly) + */ +void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements); + +/** + * Destroys a pset_new and frees the memory allocated for hashtable. The memory of + * the pset_new itself is not freed. + * + * @param pset_new Pointer to the pset_new + */ +void pset_new_destroy(pset_new_t *pset_new); + +/** + * Inserts an element into a pset_new. + * + * @param pset_new Pointer to the pset_new + * @param ptr Pointer to insert into the pset_new + * @returns true if the pointer was inserted, false if it was already there + */ +bool pset_new_insert(pset_new_t *pset_new, void *ptr); + +/** + * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the + * element. + * + * @param pset_new Pointer to the pset_new + * @param ptr Pointer to remove from the pset_new + */ +void pset_new_remove(pset_new_t *pset_new, const void *ptr); + +/** + * Tests whether a pset_new contains a pointer + * + * @param pset_new Pointer to the pset_new + * @param ptr The pointer to test + */ +bool pset_new_contains(const pset_new_t *pset_new, const void *ptr); + +/** + * Returns the number of pointers contained in the pset_new + * + * @param pset_new Pointer to the pset_new + * @returns Number of pointers contained in the pset_new + */ +size_t pset_new_size(const pset_new_t *pset_new); + +/** + * Initializes a pset_new iterator. Sets the iterator before the first element in + * the pset_new. + * + * @param iterator Pointer to already allocated iterator memory + * @param pset_new Pointer to the pset_new + */ +void pset_new_iterator_init(pset_new_iterator_t *iterator, const pset_new_t *pset_new); + +/** + * Advances the iterator and returns the current element or NULL if all elements + * in the pset_new have been processed. + * @attention It is not allowed to use pset_new_insert or pset_new_remove while + * iterating over a pset_new; pset_new_remove_iter is allowed. + * + * @param iterator Pointer to the pset_new iterator. + * @returns Next element in the pset_new or NULL + */ +void* pset_new_iterator_next(pset_new_iterator_t *iterator); + +/** + * Removes the element that the iterator currently points to from the hashset. + * + * @param pset_new Pointer to the pset_new + * @param iterator Pointer to the iterator + */ +void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator); + +/** + * Convenience macro for iterating over a pset_new. + */ +#define foreach_pset_new(pset_new, type, ptr, iter) \ + for(pset_new_iterator_init(&iter, pset_new), \ + ptr = (type) pset_new_iterator_next(&iter); \ + ptr != NULL; ptr = (type) pset_new_iterator_next(&iter)) + +#endif diff --git a/entitymap.c b/entitymap.c index 4d2921b..8ab5d50 100644 --- a/entitymap.c +++ b/entitymap.c @@ -31,7 +31,6 @@ static unsigned hash_ptr(const void *ptr) #define DO_REHASH #define HashSet entitymap_t -#define HashSetIterator entitymap_iterator_t #define ValueType entitymap_entry_t #define NullValue null_entitymap_entry #define KeyType symbol_t* @@ -47,15 +46,11 @@ static unsigned hash_ptr(const void *ptr) #define EntryIsDeleted(value) ((value).symbol == (symbol_t*)-1) #define hashset_init entitymap_init -#define hashset_init_size _entitymap_init_size #define hashset_destroy entitymap_destroy +entitymap_entry_t *_entitymap_insert(entitymap_t *map, symbol_t *symbol); #define hashset_insert _entitymap_insert -#define hashset_remove entitymap_remove +entitymap_entry_t *_entitymap_find(const entitymap_t *map, const symbol_t *symbol); #define hashset_find _entitymap_find -#define hashset_size _entitymap_size -#define hashset_iterator_init _entitymap_iterator_init -#define hashset_iterator_next _entitymap_iterator_next -#define hashset_remove_iterator _entitymap_remove_iterator #include "adt/hashset.c" diff --git a/entitymap_t.h b/entitymap_t.h index 1c84188..77deb6f 100644 --- a/entitymap_t.h +++ b/entitymap_t.h @@ -29,13 +29,11 @@ typedef struct entitymap_entry_t { } entitymap_entry_t; #define HashSet entitymap_t -#define HashSetIterator entitymap_iterator_t #define ValueType entitymap_entry_t #define DO_REHASH #include "adt/hashset.h" #undef DO_REHASH #undef HashSetEntry -#undef HashSetIterator #undef HashSet typedef struct entitymap_iterator_t entitymap_iterator_t; diff --git a/libfirm b/libfirm index 78b94dd..f2ad275 160000 --- a/libfirm +++ b/libfirm @@ -1 +1 @@ -Subproject commit 78b94dd9a1d6aee17e0dfb4218a49ef17531d680 +Subproject commit f2ad275bb3619165357b369ac083ae2f73d5a543 diff --git a/symbol_table.c b/symbol_table.c index f43b220..b0c0bb6 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -39,7 +39,6 @@ void init_symbol_table_entry(symbol_t *entry, const char *string) } #define HashSet symbol_table_t -#define HashSetIterator symbol_table_iterator_t #define HashSetEntry symbol_table_hash_entry_t #define ValueType symbol_t* #define NullValue NULL @@ -53,16 +52,12 @@ void init_symbol_table_entry(symbol_t *entry, const char *string) #define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof(symbol_table_hash_entry_t)) #define SCALAR_RETURN +void _symbol_table_init(symbol_table_t *symbol_table); #define hashset_init _symbol_table_init -#define hashset_init_size _symbol_table_init_size +void _symbol_table_destroy(symbol_table_t *symbol_table); #define hashset_destroy _symbol_table_destroy +symbol_t *_symbol_table_insert(symbol_table_t *symbol_table, const char *key); #define hashset_insert _symbol_table_insert -#define hashset_remove _symbol_table_remove -#define hashset_find _symbol_table_find -#define hashset_size _symbol_table_size -#define hashset_iterator_init _symbol_table_iterator_init -#define hashset_iterator_next _symbol_table_iterator_next -#define hashset_remove_iterator _symbol_table_remove_iterator #include "adt/hashset.c" diff --git a/symbol_table_t.h b/symbol_table_t.h index 0124706..d1fc621 100644 --- a/symbol_table_t.h +++ b/symbol_table_t.h @@ -24,13 +24,11 @@ #include "symbol.h" #define HashSet symbol_table_t -#define HashSetIterator symbol_table_iterator_t #define HashSetEntry symbol_table_hash_entry_t #define ValueType symbol_t* #include "adt/hashset.h" #undef ValueType #undef HashSetEntry -#undef HashSetIterator #undef HashSet typedef struct symbol_table_iterator_t symbol_table_iterator_t; diff --git a/type_hash.c b/type_hash.c index e6e487a..ac2385e 100644 --- a/type_hash.c +++ b/type_hash.c @@ -29,11 +29,9 @@ #include #define HashSet type_hash_t -#define HashSetIterator type_hash_iterator_t #define ValueType type_t* #include "adt/hashset.h" #undef ValueType -#undef HashSetIterator #undef HashSet typedef struct type_hash_iterator_t type_hash_iterator_t; @@ -292,7 +290,6 @@ static bool types_equal(const type_t *type1, const type_t *type2) } #define HashSet type_hash_t -#define HashSetIterator type_hash_iterator_t #define ValueType type_t* #define NullValue NULL #define DeletedValue ((type_t*)-1) @@ -300,16 +297,12 @@ static bool types_equal(const type_t *type1, const type_t *type2) #define KeysEqual(this,key1,key2) types_equal(key1, key2) #define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof(*(ptr))) +void _typehash_init(type_hash_t *hash); #define hashset_init _typehash_init -#define hashset_init_size _typehash_init_size +void _typehash_destroy(type_hash_t *hash); #define hashset_destroy _typehash_destroy +type_t *_typehash_insert(type_hash_t *hash, type_t *type); #define hashset_insert _typehash_insert -#define hashset_remove typehash_remove -#define hashset_find typehash_find -#define hashset_size typehash_size -#define hashset_iterator_init typehash_iterator_init -#define hashset_iterator_next typehash_iterator_next -#define hashset_remove_iterator typehash_remove_iterator #define SCALAR_RETURN #include "adt/hashset.c" diff --git a/type_hash.h b/type_hash.h index 85c0159..cd1ff4f 100644 --- a/type_hash.h +++ b/type_hash.h @@ -26,6 +26,5 @@ void init_typehash(void); void exit_typehash(void); type_t *typehash_insert(type_t *type); -int typehash_contains(type_t *type); #endif diff --git a/wrappergen/write_jna.c b/wrappergen/write_jna.c index d681f47..b209042 100644 --- a/wrappergen/write_jna.c +++ b/wrappergen/write_jna.c @@ -32,7 +32,7 @@ #include "printer.h" #include "adt/error.h" #include "adt/xmalloc.h" -#include +#include "adt/pset_new.h" typedef struct output_limit { const char *filename; -- 2.20.1