00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 #ifndef _OBSTACK_H
00111 #define _OBSTACK_H 1
00112
00113 #ifdef __cplusplus
00114 extern "C" {
00115 #endif
00116
00117
00118
00119
00120
00121 #ifndef __PTR_TO_INT
00122 # define __PTR_TO_INT(P) ((P) - (char *) 0)
00123 #endif
00124
00125 #ifndef __INT_TO_PTR
00126 # define __INT_TO_PTR(P) ((P) + (char *) 0)
00127 #endif
00128
00129
00130
00131
00132
00133
00134
00135 #ifdef __PTRDIFF_TYPE__
00136 # define PTR_INT_TYPE __PTRDIFF_TYPE__
00137 #else
00138 # ifdef HAVE_STDDEF_H
00139 # include <stddef.h>
00140 # define PTR_INT_TYPE ptrdiff_t
00141 # else
00142 # define PTR_INT_TYPE long
00143 # endif
00144 #endif
00145
00146 #if defined _LIBC || defined HAVE_STRING_H
00147 # include <string.h>
00148 # define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
00149 #else
00150 # ifdef memcpy
00151 # define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N))
00152 # else
00153 # define _obstack_memcpy(To, From, N) bcopy ((char *)(From), (To), (N))
00154 # endif
00155 #endif
00156
00157 struct _obstack_chunk
00158 {
00159 char *limit;
00160 struct _obstack_chunk *prev;
00161 char contents[4];
00162 };
00163
00164 struct obstack
00165 {
00166 long chunk_size;
00167 struct _obstack_chunk *chunk;
00168 char *object_base;
00169 char *next_free;
00170 char *chunk_limit;
00171 PTR_INT_TYPE temp;
00172 int alignment_mask;
00173
00174
00175
00176 struct _obstack_chunk *(*chunkfun) (void *, long);
00177 void (*freefun) (void *, struct _obstack_chunk *);
00178 void *extra_arg;
00179 unsigned use_extra_arg:1;
00180 unsigned maybe_empty_object:1;
00181
00182
00183
00184 unsigned alloc_failed:1;
00185
00186
00187 };
00188
00189
00190
00191 extern void _obstack_newchunk (struct obstack *, int);
00192 extern void _obstack_free (struct obstack *, void *);
00193 extern int _obstack_begin (struct obstack *, int, int,
00194 void *(*) (long), void (*) (void *));
00195 extern int _obstack_begin_1 (struct obstack *, int, int,
00196 void *(*) (void *, long),
00197 void (*) (void *, void *), void *);
00198 extern int _obstack_memory_used (struct obstack *);
00199
00200
00201
00202
00203 void obstack_init (struct obstack *obstack);
00204
00205 void * obstack_alloc (struct obstack *obstack, int size);
00206
00207 void * obstack_copy (struct obstack *obstack, void *address, int size);
00208 void * obstack_copy0 (struct obstack *obstack, void *address, int size);
00209
00210 void obstack_free (struct obstack *obstack, void *block);
00211
00212 void obstack_blank (struct obstack *obstack, int size);
00213
00214 void obstack_grow (struct obstack *obstack, void *data, int size);
00215 void obstack_grow0 (struct obstack *obstack, void *data, int size);
00216
00217 void obstack_1grow (struct obstack *obstack, int data_char);
00218 void obstack_ptr_grow (struct obstack *obstack, void *data);
00219 void obstack_int_grow (struct obstack *obstack, int data);
00220
00221 void * obstack_finish (struct obstack *obstack);
00222
00223 int obstack_object_size (struct obstack *obstack);
00224
00225 int obstack_room (struct obstack *obstack);
00226 void obstack_make_room (struct obstack *obstack, int size);
00227 void obstack_1grow_fast (struct obstack *obstack, int data_char);
00228 void obstack_ptr_grow_fast (struct obstack *obstack, void *data);
00229 void obstack_int_grow_fast (struct obstack *obstack, int data);
00230 void obstack_blank_fast (struct obstack *obstack, int size);
00231
00232 void * obstack_base (struct obstack *obstack);
00233 void * obstack_next_free (struct obstack *obstack);
00234 int obstack_alignment_mask (struct obstack *obstack);
00235 int obstack_chunk_size (struct obstack *obstack);
00236 int obstack_memory_used (struct obstack *obstack);
00237
00238
00239
00240
00241 extern void (*obstack_alloc_failed_handler) (void);
00242
00243
00244 extern int obstack_exit_failure;
00245
00246
00247
00248
00249
00250 #define obstack_base(h) ((h)->object_base)
00251
00252
00253
00254 #define obstack_chunk_size(h) ((h)->chunk_size)
00255
00256
00257
00258 #define obstack_next_free(h) ((h)->next_free)
00259
00260
00261
00262 #define obstack_alignment_mask(h) ((h)->alignment_mask)
00263
00264
00265
00266 # define obstack_init(h) \
00267 _obstack_begin ((h), 0, 0, \
00268 (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
00269
00270 # define obstack_begin(h, size) \
00271 _obstack_begin ((h), (size), 0, \
00272 (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
00273
00274 # define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
00275 _obstack_begin ((h), (size), (alignment), \
00276 (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun))
00277
00278 # define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
00279 _obstack_begin_1 ((h), (size), (alignment), \
00280 (void *(*) (void *, long)) (chunkfun), \
00281 (void (*) (void *, void *)) (freefun), (arg))
00282
00283 # define obstack_chunkfun(h, newchunkfun) \
00284 ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
00285
00286 # define obstack_freefun(h, newfreefun) \
00287 ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
00288
00289 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
00290
00291 #define obstack_blank_fast(h,n) ((h)->next_free += (n))
00292
00293 #define obstack_memory_used(h) _obstack_memory_used (h)
00294
00295 #if defined __GNUC__ && defined __STDC__ && __STDC__
00296
00297
00298
00299 # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
00300 # define __extension__
00301 # endif
00302
00303
00304
00305
00306
00307
00308 # define obstack_object_size(OBSTACK) \
00309 __extension__ \
00310 ({ struct obstack *__o = (OBSTACK); \
00311 (unsigned) (__o->next_free - __o->object_base); })
00312
00313 # define obstack_room(OBSTACK) \
00314 __extension__ \
00315 ({ struct obstack *__o = (OBSTACK); \
00316 (unsigned) (__o->chunk_limit - __o->next_free); })
00317
00318 # define obstack_make_room(OBSTACK,length) \
00319 __extension__ \
00320 ({ struct obstack *__o = (OBSTACK); \
00321 int __len = (length); \
00322 if (__o->chunk_limit - __o->next_free < __len) \
00323 _obstack_newchunk (__o, __len); \
00324 (void) 0; })
00325
00326 # define obstack_empty_p(OBSTACK) \
00327 __extension__ \
00328 ({ struct obstack *__o = (OBSTACK); \
00329 (__o->chunk->prev == 0 && __o->next_free - __o->chunk->contents == 0); })
00330
00331 # define obstack_grow(OBSTACK,where,length) \
00332 __extension__ \
00333 ({ struct obstack *__o = (OBSTACK); \
00334 int __len = (length); \
00335 if (__o->next_free + __len > __o->chunk_limit) \
00336 _obstack_newchunk (__o, __len); \
00337 _obstack_memcpy (__o->next_free, (where), __len); \
00338 __o->next_free += __len; \
00339 (void) 0; })
00340
00341 # define obstack_grow0(OBSTACK,where,length) \
00342 __extension__ \
00343 ({ struct obstack *__o = (OBSTACK); \
00344 int __len = (length); \
00345 if (__o->next_free + __len + 1 > __o->chunk_limit) \
00346 _obstack_newchunk (__o, __len + 1); \
00347 _obstack_memcpy (__o->next_free, (where), __len); \
00348 __o->next_free += __len; \
00349 *(__o->next_free)++ = 0; \
00350 (void) 0; })
00351
00352 # define obstack_1grow(OBSTACK,datum) \
00353 __extension__ \
00354 ({ struct obstack *__o = (OBSTACK); \
00355 if (__o->next_free + 1 > __o->chunk_limit) \
00356 _obstack_newchunk (__o, 1); \
00357 obstack_1grow_fast (__o, datum); \
00358 (void) 0; })
00359
00360
00361
00362
00363
00364 # define obstack_ptr_grow(OBSTACK,datum) \
00365 __extension__ \
00366 ({ struct obstack *__o = (OBSTACK); \
00367 if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
00368 _obstack_newchunk (__o, sizeof (void *)); \
00369 obstack_ptr_grow_fast (__o, datum); })
00370
00371 # define obstack_int_grow(OBSTACK,datum) \
00372 __extension__ \
00373 ({ struct obstack *__o = (OBSTACK); \
00374 if (__o->next_free + sizeof (int) > __o->chunk_limit) \
00375 _obstack_newchunk (__o, sizeof (int)); \
00376 obstack_int_grow_fast (__o, datum); })
00377
00378 # define obstack_ptr_grow_fast(OBSTACK,aptr) \
00379 __extension__ \
00380 ({ struct obstack *__o1 = (OBSTACK); \
00381 *(const void **) __o1->next_free = (aptr); \
00382 __o1->next_free += sizeof (const void *); \
00383 (void) 0; })
00384
00385 # define obstack_int_grow_fast(OBSTACK,aint) \
00386 __extension__ \
00387 ({ struct obstack *__o1 = (OBSTACK); \
00388 *(int *) __o1->next_free = (aint); \
00389 __o1->next_free += sizeof (int); \
00390 (void) 0; })
00391
00392 # define obstack_blank(OBSTACK,length) \
00393 __extension__ \
00394 ({ struct obstack *__o = (OBSTACK); \
00395 int __len = (length); \
00396 if (__o->chunk_limit - __o->next_free < __len) \
00397 _obstack_newchunk (__o, __len); \
00398 obstack_blank_fast (__o, __len); \
00399 (void) 0; })
00400
00401 # define obstack_alloc(OBSTACK,length) \
00402 __extension__ \
00403 ({ struct obstack *__h = (OBSTACK); \
00404 obstack_blank (__h, (length)); \
00405 obstack_finish (__h); })
00406
00407 # define obstack_copy(OBSTACK,where,length) \
00408 __extension__ \
00409 ({ struct obstack *__h = (OBSTACK); \
00410 obstack_grow (__h, (where), (length)); \
00411 obstack_finish (__h); })
00412
00413 # define obstack_copy0(OBSTACK,where,length) \
00414 __extension__ \
00415 ({ struct obstack *__h = (OBSTACK); \
00416 obstack_grow0 (__h, (where), (length)); \
00417 obstack_finish (__h); })
00418
00419
00420
00421 # define obstack_finish(OBSTACK) \
00422 __extension__ \
00423 ({ struct obstack *__o1 = (OBSTACK); \
00424 void *value; \
00425 value = (void *) __o1->object_base; \
00426 if (__o1->next_free == value) \
00427 __o1->maybe_empty_object = 1; \
00428 __o1->next_free \
00429 = __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\
00430 & ~ (__o1->alignment_mask)); \
00431 if (__o1->next_free - (char *)__o1->chunk \
00432 > __o1->chunk_limit - (char *)__o1->chunk) \
00433 __o1->next_free = __o1->chunk_limit; \
00434 __o1->object_base = __o1->next_free; \
00435 value; })
00436
00437 # define obstack_free(OBSTACK, OBJ) \
00438 __extension__ \
00439 ({ struct obstack *__o = (OBSTACK); \
00440 void *__obj = (void *) (OBJ); \
00441 if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
00442 __o->next_free = __o->object_base = (char *) __obj; \
00443 else (obstack_free) (__o, __obj); })
00444
00445 #else
00446
00447 # define obstack_object_size(h) \
00448 (unsigned) ((h)->next_free - (h)->object_base)
00449
00450 # define obstack_room(h) \
00451 (unsigned) ((h)->chunk_limit - (h)->next_free)
00452
00453 # define obstack_empty_p(h) \
00454 ((h)->chunk->prev == 0 && (h)->next_free - (h)->chunk->contents == 0)
00455
00456
00457
00458
00459
00460
00461
00462 # define obstack_make_room(h,length) \
00463 ( (h)->temp = (length), \
00464 (((h)->next_free + (h)->temp > (h)->chunk_limit) \
00465 ? (_obstack_newchunk ((h), (h)->temp), 0) : 0))
00466
00467 # define obstack_grow(h,where,length) \
00468 ( (h)->temp = (length), \
00469 (((h)->next_free + (h)->temp > (h)->chunk_limit) \
00470 ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
00471 _obstack_memcpy ((h)->next_free, (where), (h)->temp), \
00472 (h)->next_free += (h)->temp)
00473
00474 # define obstack_grow0(h,where,length) \
00475 ( (h)->temp = (length), \
00476 (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \
00477 ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \
00478 _obstack_memcpy ((h)->next_free, (where), (h)->temp), \
00479 (h)->next_free += (h)->temp, \
00480 *((h)->next_free)++ = 0)
00481
00482 # define obstack_1grow(h,datum) \
00483 ( (((h)->next_free + 1 > (h)->chunk_limit) \
00484 ? (_obstack_newchunk ((h), 1), 0) : 0), \
00485 obstack_1grow_fast (h, datum))
00486
00487 # define obstack_ptr_grow(h,datum) \
00488 ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
00489 ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
00490 obstack_ptr_grow_fast (h, datum))
00491
00492 # define obstack_int_grow(h,datum) \
00493 ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
00494 ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
00495 obstack_int_grow_fast (h, datum))
00496
00497 # define obstack_ptr_grow_fast(h,aptr) \
00498 (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
00499
00500 # define obstack_int_grow_fast(h,aint) \
00501 (((int *) ((h)->next_free += sizeof (int)))[-1] = (aptr))
00502
00503 # define obstack_blank(h,length) \
00504 ( (h)->temp = (length), \
00505 (((h)->chunk_limit - (h)->next_free < (h)->temp) \
00506 ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
00507 obstack_blank_fast (h, (h)->temp))
00508
00509 # define obstack_alloc(h,length) \
00510 (obstack_blank ((h), (length)), obstack_finish ((h)))
00511
00512 # define obstack_copy(h,where,length) \
00513 (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
00514
00515 # define obstack_copy0(h,where,length) \
00516 (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
00517
00518 # define obstack_finish(h) \
00519 ( ((h)->next_free == (h)->object_base \
00520 ? (((h)->maybe_empty_object = 1), 0) \
00521 : 0), \
00522 (h)->temp = __PTR_TO_INT ((h)->object_base), \
00523 (h)->next_free \
00524 = __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \
00525 & ~ ((h)->alignment_mask)), \
00526 (((h)->next_free - (char *) (h)->chunk \
00527 > (h)->chunk_limit - (char *) (h)->chunk) \
00528 ? ((h)->next_free = (h)->chunk_limit) : 0), \
00529 (h)->object_base = (h)->next_free, \
00530 __INT_TO_PTR ((h)->temp))
00531
00532 # define obstack_free(h,obj) \
00533 ( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \
00534 (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
00535 ? (int) ((h)->next_free = (h)->object_base \
00536 = (h)->temp + (char *) (h)->chunk) \
00537 : (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0)))
00538
00539 #endif
00540
00541 #ifdef __cplusplus
00542 }
00543 #endif
00544
00545 #endif