X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Fplist.c;h=fae710a9c1c69aa257dc1b62c11faea2f56189a8;hb=52f5575dc678a5f7f1b3a078dcc46b1cdbaf5182;hp=4fbe0f6ee8d71cd8e3a741797328b4f12ba631a3;hpb=863d31d7a5c8210432fef88b30fc3e8353131538;p=libfirm diff --git a/ir/adt/plist.c b/ir/adt/plist.c index 4fbe0f6ee..fae710a9c 100644 --- a/ir/adt/plist.c +++ b/ir/adt/plist.c @@ -1,14 +1,32 @@ +/* + * 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. + */ + /** - * Simple, non circular, double linked pointer list. - * Created because the properties of the standard circular list were not - * very well suited for the interference graph implementation. - * This list uses an obstack and a free-list to efficiently manage its - * elements. - * @author Kimon Hoffmann - * @date 14.07.2005 - * @cvs-id $Id$ - * @note Until now the code is entirely untested so it probably contains - * plenty of errors. + * @file + * @brief Simple, non circular, double linked pointer list. + * @note Created because the properties of the standard circular list were not + * very well suited for the interference graph implementation. + * This list uses an obstack and a free-list to efficiently manage its + * elements. + * @author Kimon Hoffmann + * @date 14.07.2005 + * @version $Id$ */ #include @@ -21,7 +39,8 @@ * @param list the list for which to allocate the element. * @return the newly allocated, uninitialized element. */ -static plist_element_t *allocate_element(plist_t* list) { +static plist_element_t *allocate_element(plist_t* list) +{ plist_element_t *new_element; if (list->first_free_element != NULL) { @@ -30,14 +49,15 @@ static plist_element_t *allocate_element(plist_t* list) { new_element->next = NULL; } else { - new_element = obstack_alloc(list->obst, sizeof(*new_element)); + new_element = OALLOC(list->obst, plist_element_t); } return new_element; } -plist_t *plist_new(void) { - plist_t *list = xmalloc(sizeof(*list) + sizeof(*list->obst)); +plist_t *plist_new(void) +{ + plist_t *list = (plist_t*) xmalloc(sizeof(*list) + sizeof(*list->obst)); list->obst = (struct obstack *)&list[1]; list->foreign_obstack = 0; @@ -50,8 +70,9 @@ plist_t *plist_new(void) { return list; } -plist_t *plist_obstack_new(struct obstack *obst) { - plist_t *list = obstack_alloc(obst, sizeof(*list)); +plist_t *plist_obstack_new(struct obstack *obst) +{ + plist_t *list = OALLOC(obst, plist_t); list->obst = obst; list->foreign_obstack = 1; @@ -63,7 +84,8 @@ plist_t *plist_obstack_new(struct obstack *obst) { return list; } -void plist_free(plist_t *list) { +void plist_free(plist_t *list) +{ list->first_element = NULL; list->last_element = NULL; list->first_free_element = NULL; @@ -75,7 +97,8 @@ void plist_free(plist_t *list) { } } -void plist_insert_back(plist_t *list, void *value) { +void plist_insert_back(plist_t *list, void *value) +{ if (list->last_element != NULL) { plist_insert_after(list, list->last_element, value); } @@ -90,7 +113,8 @@ void plist_insert_back(plist_t *list, void *value) { } } -void plist_insert_front(plist_t *list, void *value) { +void plist_insert_front(plist_t *list, void *value) +{ if (list->first_element != NULL) { plist_insert_before(list, list->first_element, value); } @@ -105,7 +129,8 @@ void plist_insert_front(plist_t *list, void *value) { } } -void plist_insert_before(plist_t *list, plist_element_t *element, void *value) { +void plist_insert_before(plist_t *list, plist_element_t *element, void *value) +{ plist_element_t *prevElement; plist_element_t *newElement = allocate_element(list); @@ -121,11 +146,12 @@ void plist_insert_before(plist_t *list, plist_element_t *element, void *value) { list->first_element = newElement; } - element->prev = newElement; + element->prev = newElement; ++list->element_count; } -void plist_insert_after(plist_t* list, plist_element_t* element, void* value) { +void plist_insert_after(plist_t* list, plist_element_t* element, void* value) +{ plist_element_t *nextElement; plist_element_t *newElement = allocate_element(list); @@ -145,7 +171,8 @@ void plist_insert_after(plist_t* list, plist_element_t* element, void* value) { ++list->element_count; } -int plist_has_value(plist_t *list, void *value) { +int plist_has_value(plist_t *list, void *value) +{ plist_element_t *iter; for (iter = plist_first(list); iter; iter = plist_element_get_next(iter)) { @@ -156,7 +183,8 @@ int plist_has_value(plist_t *list, void *value) { return 0; } -plist_element_t *plist_find_value(plist_t *list, void *value) { +plist_element_t *plist_find_value(plist_t *list, void *value) +{ plist_element_t *iter; for (iter = plist_first(list); iter; iter = plist_element_get_next(iter)) { @@ -167,7 +195,8 @@ plist_element_t *plist_find_value(plist_t *list, void *value) { return NULL; } -void plist_erase(plist_t *list, plist_element_t *element) { +void plist_erase(plist_t *list, plist_element_t *element) +{ plist_element_t *next_element = element->next; plist_element_t *prev_element = element->prev; @@ -193,7 +222,8 @@ void plist_erase(plist_t *list, plist_element_t *element) { list->first_free_element = element; } -void plist_clear(plist_t *list) { +void plist_clear(plist_t *list) +{ plist_element_t *curr_element = list->first_element; while (curr_element != NULL) {