X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnodeset.h;h=2c298aa9b6794f6c4965363e98cbd1e720a3432b;hb=3c3425a50a1d721b74a015c6812257e32feeac85;hp=6e5a51e6a9d86e0d9eaffcf8eea56c52061384b4;hpb=eb08138c6b80c169945568e4414f491a9bc20388;p=libfirm diff --git a/ir/ir/irnodeset.h b/ir/ir/irnodeset.h index 6e5a51e6a..2c298aa9b 100644 --- a/ir/ir/irnodeset.h +++ b/ir/ir/irnodeset.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -23,24 +23,31 @@ * @date 30.03.2007 * @brief A nodeset. This should be prefered over a simple pset, because it * tries to guarantee deterministic behavior. (and is faster) - * @version $Id$ + * @note Actually the bits to make the behaviour deterministic are not + * implemented yet... */ #ifndef _FIRM_IRNODESET_H_ #define _FIRM_IRNODESET_H_ -#include "irnode.h" +#include +#include "firm_types.h" #include "xmalloc.h" #define HashSet ir_nodeset_t #define HashSetIterator ir_nodeset_iterator_t #define ValueType ir_node* #define DO_REHASH + #include "hashset.h" + #undef DO_REHASH #undef ValueType #undef HashSetIterator #undef HashSet +typedef struct ir_nodeset_t ir_nodeset_t; +typedef struct ir_nodeset_iterator_t ir_nodeset_iterator_t; + /** * Initializes a nodeset with default size. * @@ -70,8 +77,8 @@ void ir_nodeset_destroy(ir_nodeset_t *nodeset); * @param expected_elements Number of elements expected in the nodeset (roughly) * @return The initialized nodeset */ -static INLINE ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { - ir_nodeset_t *res = xmalloc(sizeof(*res)); +static inline ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { + ir_nodeset_t *res = XMALLOC(ir_nodeset_t); ir_nodeset_init_size(res, expected_elements); return res; } @@ -79,7 +86,7 @@ static INLINE ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { /** * Destroys a nodeset and frees the memory of the nodeset itself. */ -static INLINE void ir_nodeset_del(ir_nodeset_t *nodeset) { +static inline void ir_nodeset_del(ir_nodeset_t *nodeset) { ir_nodeset_destroy(nodeset); xfree(nodeset); } @@ -89,10 +96,11 @@ static INLINE void ir_nodeset_del(ir_nodeset_t *nodeset) { * * @param nodeset Pointer to the nodeset * @param node node to insert into the nodeset - * @returns 1 if the element has been inserted, - * 0 if it was already there + * @returns true if the element has been inserted, + * false if it was already there */ -int ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node); +bool ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node); + /** * Removes a node from a nodeset. Does nothing if the nodeset doesn't contain @@ -108,9 +116,8 @@ void ir_nodeset_remove(ir_nodeset_t *nodeset, const ir_node *node); * * @param nodeset Pointer to the nodeset * @param node The pointer to find - * @returns 1 if nodeset contains the node, 0 else */ -int ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node); +bool ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node); /** * Returns the number of pointers contained in the nodeset @@ -150,9 +157,17 @@ ir_node *ir_nodeset_iterator_next(ir_nodeset_iterator_t *iterator); void ir_nodeset_remove_iterator(ir_nodeset_t *nodeset, const ir_nodeset_iterator_t *iterator); +static inline ir_node *ir_nodeset_first(ir_nodeset_t const *const nodeset) +{ + ir_nodeset_iterator_t iter; + ir_nodeset_iterator_init(&iter, nodeset); + return ir_nodeset_iterator_next(&iter); +} + #define foreach_ir_nodeset(nodeset, irn, iter) \ - for(ir_nodeset_iterator_init(&iter, nodeset), \ - irn = ir_nodeset_iterator_next(&iter); \ - irn != NULL; irn = ir_nodeset_iterator_next(&iter)) + for (bool irn##__once = true; irn##__once;) \ + for (ir_nodeset_iterator_t iter; irn##__once;) \ + for (ir_node *irn; irn##__once; irn##__once = false) \ + for (ir_nodeset_iterator_init(&iter, nodeset); (irn = ir_nodeset_iterator_next(&iter));) #endif