1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*******************************************************************************
*
* HEADER: idl.h
*
********************************************************************************
*
* DESCRIPTION: C::B::C identifier lists
*
********************************************************************************
*
* $Project: /Convert-Binary-C $
* $Author: mhx $
* $Date: 2009/03/15 04:10:52 +0100 $
* $Revision: 10 $
* $Source: /cbc/idl.h $
*
********************************************************************************
*
* Copyright (c) 2002-2009 Marcus Holland-Moritz. All rights reserved.
* This program is free software; you can redistribute it and/or modify
* it under the same terms as Perl itself.
*
*******************************************************************************/
#ifndef _CBC_IDL_H
#define _CBC_IDL_H
/*===== GLOBAL INCLUDES ======================================================*/
/*===== LOCAL INCLUDES =======================================================*/
/*===== DEFINES ==============================================================*/
#define IDLIST_GRANULARITY 8
#define IDLIST_INITIAL_SIZE (2*IDLIST_GRANULARITY)
#define IDLIST_GROW(idl, size) \
STMT_START { \
if ((size) > (idl)->max) \
{ \
unsigned grow = ((size)+(IDLIST_GRANULARITY-1))/IDLIST_GRANULARITY;\
grow *= IDLIST_GRANULARITY; \
Renew((idl)->list, grow, struct IDList_list); \
(idl)->max = grow; \
} \
} STMT_END
#define IDLIST_INIT(idl) \
STMT_START { \
(idl)->count = 0; \
(idl)->max = IDLIST_INITIAL_SIZE; \
(idl)->cur = NULL; \
New(0, (idl)->list, (idl)->max, struct IDList_list); \
} STMT_END
#define IDLIST_FREE(idl) \
STMT_START { \
if ((idl)->list) \
Safefree((idl)->list); \
} STMT_END
#define IDLIST_PUSH(idl, what) \
STMT_START { \
IDLIST_GROW(idl, (idl)->count+1); \
(idl)->cur = (idl)->list + (idl)->count++; \
(idl)->cur->choice = IDL_ ## what; \
} STMT_END
#define IDLIST_SET_ID(idl, value) \
(idl)->cur->val.id = value
#define IDLIST_SET_IX(idl, index) \
(idl)->cur->val.ix = index
#define IDLIST_POP(idl) \
STMT_START { \
assert((idl)->count > 0); \
if (--(idl)->count > 0) \
(idl)->cur--; \
else \
(idl)->cur = NULL; \
} STMT_END
/*===== TYPEDEFS =============================================================*/
typedef struct {
unsigned count, max;
struct IDList_list {
enum { IDL_ID, IDL_IX } choice;
union {
const char *id;
long ix;
} val;
} *cur, *list;
} IDList;
/*===== FUNCTION PROTOTYPES ==================================================*/
#define idl_to_str CBC_idl_to_str
const char *idl_to_str(pTHX_ IDList *idl);
#endif
|