js/src/jsclist.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jsclist.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef jsclist_h
    1.11 +#define jsclist_h
    1.12 +
    1.13 +#include "jstypes.h"
    1.14 +
    1.15 +/*
    1.16 +** Circular linked list
    1.17 +*/
    1.18 +typedef struct JSCListStr {
    1.19 +    struct JSCListStr *next;
    1.20 +    struct JSCListStr *prev;
    1.21 +} JSCList;
    1.22 +
    1.23 +/*
    1.24 +** Insert element "_e" into the list, before "_l".
    1.25 +*/
    1.26 +#define JS_INSERT_BEFORE(_e,_l)  \
    1.27 +    JS_BEGIN_MACRO               \
    1.28 +        (_e)->next = (_l);       \
    1.29 +        (_e)->prev = (_l)->prev; \
    1.30 +        (_l)->prev->next = (_e); \
    1.31 +        (_l)->prev = (_e);       \
    1.32 +    JS_END_MACRO
    1.33 +
    1.34 +/*
    1.35 +** Insert element "_e" into the list, after "_l".
    1.36 +*/
    1.37 +#define JS_INSERT_AFTER(_e,_l)   \
    1.38 +    JS_BEGIN_MACRO               \
    1.39 +        (_e)->next = (_l)->next; \
    1.40 +        (_e)->prev = (_l);       \
    1.41 +        (_l)->next->prev = (_e); \
    1.42 +        (_l)->next = (_e);       \
    1.43 +    JS_END_MACRO
    1.44 +
    1.45 +/*
    1.46 +** Return the element following element "_e"
    1.47 +*/
    1.48 +#define JS_NEXT_LINK(_e)         \
    1.49 +        ((_e)->next)
    1.50 +/*
    1.51 +** Return the element preceding element "_e"
    1.52 +*/
    1.53 +#define JS_PREV_LINK(_e)         \
    1.54 +        ((_e)->prev)
    1.55 +
    1.56 +/*
    1.57 +** Append an element "_e" to the end of the list "_l"
    1.58 +*/
    1.59 +#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
    1.60 +
    1.61 +/*
    1.62 +** Insert an element "_e" at the head of the list "_l"
    1.63 +*/
    1.64 +#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
    1.65 +
    1.66 +/* Return the head/tail of the list */
    1.67 +#define JS_LIST_HEAD(_l) (_l)->next
    1.68 +#define JS_LIST_TAIL(_l) (_l)->prev
    1.69 +
    1.70 +/*
    1.71 +** Remove the element "_e" from it's circular list.
    1.72 +*/
    1.73 +#define JS_REMOVE_LINK(_e)             \
    1.74 +    JS_BEGIN_MACRO                     \
    1.75 +        (_e)->prev->next = (_e)->next; \
    1.76 +        (_e)->next->prev = (_e)->prev; \
    1.77 +    JS_END_MACRO
    1.78 +
    1.79 +/*
    1.80 +** Remove the element "_e" from it's circular list. Also initializes the
    1.81 +** linkage.
    1.82 +*/
    1.83 +#define JS_REMOVE_AND_INIT_LINK(_e)    \
    1.84 +    JS_BEGIN_MACRO                     \
    1.85 +        (_e)->prev->next = (_e)->next; \
    1.86 +        (_e)->next->prev = (_e)->prev; \
    1.87 +        (_e)->next = (_e);             \
    1.88 +        (_e)->prev = (_e);             \
    1.89 +    JS_END_MACRO
    1.90 +
    1.91 +/*
    1.92 +** Return non-zero if the given circular list "_l" is empty, zero if the
    1.93 +** circular list is not empty
    1.94 +*/
    1.95 +#define JS_CLIST_IS_EMPTY(_l) \
    1.96 +    ((_l)->next == (_l))
    1.97 +
    1.98 +/*
    1.99 +** Initialize a circular list
   1.100 +*/
   1.101 +#define JS_INIT_CLIST(_l)  \
   1.102 +    JS_BEGIN_MACRO         \
   1.103 +        (_l)->next = (_l); \
   1.104 +        (_l)->prev = (_l); \
   1.105 +    JS_END_MACRO
   1.106 +
   1.107 +#define JS_INIT_STATIC_CLIST(_l) \
   1.108 +    {(_l), (_l)}
   1.109 +
   1.110 +#endif /* jsclist_h */

mercurial