1
/* This file is part of KDevelop
2
Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
22
#include "memorypool.h"
26
* @brief An intrusive list of AST nodes.
27
* @note ListNodes inside AST nodes are NOT guarantied to start from the beginning, call toFront.
29
template <typename Tp>
36
mutable const ListNode<Tp> *next;
38
static ListNode *create(const Tp &element, pool *p)
40
ListNode<Tp> *node = new (p->allocate(sizeof(ListNode))) ListNode();
41
node->element = element;
48
static ListNode *create(const ListNode *n1, const Tp &element, pool *p)
50
ListNode<Tp> *n2 = ListNode::create(element, p);
52
n2->index = n1->index + 1;
59
inline const ListNode<Tp> *at(int index) const
61
const ListNode<Tp> *node = this;
62
while (index != node->index)
68
inline bool hasNext() const
69
{ return ( next && index < next->index ); }
71
inline int count() const
72
{ return 1 + toBack()->index; }
74
inline const ListNode<Tp> *toFront() const
75
{ return toBack()->next; }
77
inline const ListNode<Tp> *toBack() const
79
const ListNode<Tp> *node = this;
80
while (node->hasNext())
88
inline const ListNode<Tp> *snoc(const ListNode<Tp> *list,
89
const Tp &element, pool *p)
93
return ListNode<Tp>::create(element, p);
95
return ListNode<Tp>::create(list->toBack(), element, p);