Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
9e0551a2
Commit
9e0551a2
authored
Sep 06, 2006
by
Christian Würdig
Browse files
added plist constructor with foreign obstack
made code more firm style [r8176]
parent
4b230c15
Changes
2
Hide whitespace changes
Inline
Side-by-side
ir/adt/plist.c
View file @
9e0551a2
...
...
@@ -21,25 +21,26 @@
* @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
)
{
plist_element_t
*
new
E
lement
;
static
plist_element_t
*
allocate_element
(
plist_t
*
list
)
{
plist_element_t
*
new
_e
lement
;
if
(
list
->
first_free_element
!=
NULL
)
{
new
E
lement
=
list
->
first_free_element
;
list
->
first_free_element
=
new
E
lement
->
next
;
new
E
lement
->
next
=
NULL
;
new
_e
lement
=
list
->
first_free_element
;
list
->
first_free_element
=
new
_e
lement
->
next
;
new
_e
lement
->
next
=
NULL
;
}
else
{
new
E
lement
=
obstack_alloc
(
&
list
->
obst
,
sizeof
(
*
new
E
lement
));
new
_e
lement
=
obstack_alloc
(
list
->
obst
,
sizeof
(
*
new
_e
lement
));
}
return
new
E
lement
;
return
new
_e
lement
;
}
plist_t
*
plist_new
(
void
)
{
plist_t
*
list
=
xmalloc
(
sizeof
(
*
list
));
obstack_init
(
&
list
->
obst
);
obstack_init
(
list
->
obst
);
list
->
foreign_obstack
=
0
;
list
->
first_element
=
NULL
;
list
->
last_element
=
NULL
;
list
->
first_free_element
=
NULL
;
...
...
@@ -48,14 +49,29 @@ plist_t* plist_new(void) {
return
list
;
}
void
plist_
free
(
plist_
t
*
li
st
)
{
obstack_free
(
&
list
->
obst
,
NULL
);
plist_
t
*
plist_
obstack_new
(
struct
obstack
*
ob
st
)
{
plist_t
*
list
=
obstack_alloc
(
obst
,
sizeof
(
*
list
)
);
list
->
obst
=
obst
;
list
->
foreign_obstack
=
1
;
list
->
first_element
=
NULL
;
list
->
last_element
=
NULL
;
list
->
first_free_element
=
NULL
;
list
->
element_count
=
0
;
xfree
(
list
);
return
list
;
}
void
plist_free
(
plist_t
*
list
)
{
list
->
first_element
=
NULL
;
list
->
last_element
=
NULL
;
list
->
first_free_element
=
NULL
;
list
->
element_count
=
0
;
if
(
!
list
->
foreign_obstack
)
{
obstack_free
(
list
->
obst
,
NULL
);
xfree
(
list
);
}
}
void
plist_insert_back
(
plist_t
*
list
,
void
*
value
)
{
...
...
@@ -128,22 +144,22 @@ void plist_insert_after(plist_t* list, plist_element_t* element, void* value) {
++
list
->
element_count
;
}
void
plist_erase
(
plist_t
*
list
,
plist_element_t
*
element
)
{
plist_element_t
*
next
E
lement
=
element
->
next
;
plist_element_t
*
prev
E
lement
=
element
->
prev
;
void
plist_erase
(
plist_t
*
list
,
plist_element_t
*
element
)
{
plist_element_t
*
next
_e
lement
=
element
->
next
;
plist_element_t
*
prev
_e
lement
=
element
->
prev
;
if
(
next
E
lement
!=
NULL
)
{
next
E
lement
->
prev
=
prev
E
lement
;
if
(
next
_e
lement
!=
NULL
)
{
next
_e
lement
->
prev
=
prev
_e
lement
;
}
else
{
list
->
last_element
=
prev
E
lement
;
list
->
last_element
=
prev
_e
lement
;
}
if
(
prev
E
lement
!=
NULL
)
{
prev
E
lement
->
next
=
next
E
lement
;
if
(
prev
_e
lement
!=
NULL
)
{
prev
_e
lement
->
next
=
next
_e
lement
;
}
else
{
list
->
first_element
=
next
E
lement
;
list
->
first_element
=
next
_e
lement
;
}
--
list
->
element_count
;
...
...
@@ -154,18 +170,18 @@ void plist_erase(plist_t* list, plist_element_t* element) {
list
->
first_free_element
=
element
;
}
void
plist_clear
(
plist_t
*
list
)
{
plist_element_t
*
curre
ntE
lement
=
list
->
first_element
;
void
plist_clear
(
plist_t
*
list
)
{
plist_element_t
*
curr
_
element
=
list
->
first_element
;
while
(
curre
ntE
lement
!=
NULL
)
{
curre
ntE
lement
->
prev
=
NULL
;
curre
ntE
lement
=
curre
ntE
lement
->
next
;
while
(
curr
_
element
!=
NULL
)
{
curr
_
element
->
prev
=
NULL
;
curr
_
element
=
curr
_
element
->
next
;
}
curre
ntE
lement
=
list
->
last_element
;
curr
_
element
=
list
->
last_element
;
if
(
curre
ntE
lement
!=
NULL
)
{
curre
ntE
lement
->
next
=
list
->
first_free_element
;
if
(
curr
_
element
!=
NULL
)
{
curr
_
element
->
next
=
list
->
first_free_element
;
}
list
->
first_free_element
=
list
->
first_element
;
...
...
ir/adt/plist.h
View file @
9e0551a2
...
...
@@ -26,19 +26,26 @@ struct _plist {
/**
* The obstack used for all allocations.
*/
struct
obstack
obst
;
struct
obstack
*
obst
;
/* Set to 1 if plist uses a foreign obstack */
unsigned
foreign_obstack
:
1
;
/**
* First element in the list.
*/
plist_element_t
*
first_element
;
/**
* Last element in the list.
*/
plist_element_t
*
last_element
;
/**
* Current number of elements in the list.
*/
int
element_count
;
/**
* First element in the free list.
* Please note that the free list is a single linked list and all back
...
...
@@ -51,23 +58,31 @@ struct _plist {
* An element in the pointer list.
*/
struct
_plist_element
{
plist_element_t
*
next
;
plist_element_t
*
prev
;
void
*
data
;
plist_element_t
*
next
;
plist_element_t
*
prev
;
void
*
data
;
};
/**
* Creates a new pointer list and initializes it.
* @return The newly created pointer list.
*/
plist_t
*
plist_new
(
void
);
plist_t
*
plist_new
(
void
);
/**
* Creates a new pointer list and initializes it.
* Uses the given obstack instead of creating one.
* @param obst The obstack to use
* @return The newly created pointer list.
*/
plist_t
*
plist_obstack_new
(
struct
obstack
*
obst
);
/**
* Frees the passed pointer list.
* After a call to this function all references to the list and any of
* its elements are invalid.
*/
void
plist_free
(
plist_t
*
list
);
void
plist_free
(
plist_t
*
list
);
/**
* Returns the number of elements in a pointer list.
...
...
@@ -82,14 +97,14 @@ void plist_free(plist_t* list);
* @param list the pointer list to append the new element to.
* @param value the element value to append.
*/
void
plist_insert_back
(
plist_t
*
list
,
void
*
value
);
void
plist_insert_back
(
plist_t
*
list
,
void
*
value
);
/**
* Inserts an element at the front of a pointer list.
* @param list the pointer list to prepend the new element to.
* @param value the element value to prepend.
*/
void
plist_insert_front
(
plist_t
*
list
,
void
*
value
);
void
plist_insert_front
(
plist_t
*
list
,
void
*
value
);
/**
* Inserts an element into a pointer list before the specified element,
...
...
@@ -99,7 +114,7 @@ void plist_insert_front(plist_t* list, void* value);
* be inserted. This element must be a part of @p list.
* @param value the element value to insert.
*/
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
);
/**
* Inserts an element into a pointer list after the specified element,
...
...
@@ -109,21 +124,21 @@ void plist_insert_before(plist_t* list, plist_element_t* element, void* value);
* be inserted. This element must be a part of @p list.
* @param value the element value to insert.
*/
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
);
/**
* Erases the specified element from the pointer list.
* @param list the pointer list from which the lement should be erased.
* @param list the pointer list from which the
e
lement should be erased.
* @param element the list element to erase. This element must be a part
* of @p list.
*/
void
plist_erase
(
plist_t
*
list
,
plist_element_t
*
element
);
void
plist_erase
(
plist_t
*
list
,
plist_element_t
*
element
);
/**
* Erases all elements from the specified pointer list.
* @param list the pointer list that should be cleard.
* @param list the pointer list that should be clear
e
d.
*/
void
plist_clear
(
plist_t
*
list
);
void
plist_clear
(
plist_t
*
list
);
/**
* Returns the first element of a pointer list.
...
...
@@ -143,7 +158,7 @@ void plist_clear(plist_t* list);
/**
* Checks whether a pointer list element has a successor or not.
* @param element the list element that should be queried for exist
a
nce
* @param element the list element that should be queried for exist
e
nce
* of a successor.
* @return TRUE if @p element has a successor, otherwise FALSE.
*/
...
...
@@ -152,7 +167,7 @@ void plist_clear(plist_t* list);
/**
* Checks whether a pointer list element has a predecessor or not.
* @param element the list element that should be queried for exist
a
nce
* @param element the list element that should be queried for exist
e
nce
* of a predecessor.
* @return TRUE if @p element has a successor, otherwise FALSE.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment