becopyheur2: Remove unnecessary indirection.
[libfirm] / ir / ir / irnodeset.h
index b97b042..09b99a8 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * 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.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
@@ -29,6 +15,7 @@
 #ifndef _FIRM_IRNODESET_H_
 #define _FIRM_IRNODESET_H_
 
+#include <stdbool.h>
 #include "firm_types.h"
 #include "xmalloc.h"
 
@@ -95,10 +82,10 @@ 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);
 
 
 /**
@@ -115,9 +102,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
@@ -157,9 +143,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