1 // This may look like C code, but it is really -*- C++ -*-
3 Copyright (C) 1988 Free Software Foundation
4 written by Doug Lea (dl@rocky.oswego.edu)
6 This file is part of GNU CC.
8 GNU CC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY. No author or distributor
10 accepts responsibility to anyone for the consequences of using it
11 or for whether it serves any particular purpose or works at all,
12 unless he says so in writing. Refer to the GNU CC General Public
13 License for full details.
15 Everyone is granted permission to copy, modify and redistribute
16 GNU CC, but only under the conditions described in the
17 GNU CC General Public License. A copy of this license is
18 supposed to have been given to you along with GNU CC so you
19 can know your rights and responsibilities. It should be in a
20 file named COPYING. Among other things, the copyright notice
21 and this notice must be preserved on all copies.
45 _obstack_chunk
* chunk
;
51 void _free(void* obj
);
52 void newchunk(int size
);
55 Obstack(int size
= 4080, int alignment
= 4); // 4080=4096-mallocslop
65 int contains(void* p
); // does Obstack hold pointer p?
67 void grow(const void* data
, int size
);
68 void grow(const void* data
, int size
, char terminator
);
69 void grow(const char* s
);
71 void grow_fast(char c
);
73 void blank_fast(int size
);
76 void* finish(char terminator
);
78 void* copy(const void* data
, int size
);
79 void* copy(const void* data
, int size
, char terminator
);
80 void* copy(const char* s
);
82 void* alloc(int size
);
85 void shrink(int size
= 1); // suggested by ken@cs.rochester.edu
87 int OK(); // rep invariant
90 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
93 inline Obstack::~Obstack()
98 inline void* Obstack::base()
103 inline void* Obstack::next_free()
108 inline int Obstack::alignment_mask()
110 return alignmentmask
;
113 inline int Obstack::chunk_size()
118 inline int Obstack::size()
120 return nextfree
- objectbase
;
123 inline int Obstack::room()
125 return chunklimit
- nextfree
;
128 inline void Obstack:: grow(const void* data
, int size
)
130 if (nextfree
+size
> chunklimit
)
132 bcopy(data
, nextfree
, size
);
136 inline void Obstack:: grow(const void* data
, int size
, char terminator
)
138 if (nextfree
+size
+1 > chunklimit
)
140 bcopy(data
, nextfree
, size
);
142 *(nextfree
)++ = terminator
;
145 inline void Obstack:: grow(const char* s
)
147 grow((void*)s
, strlen(s
), 0);
150 inline void Obstack:: grow(char c
)
152 if (nextfree
+1 > chunklimit
)
157 inline void Obstack:: blank(int size
)
159 if (nextfree
+size
> chunklimit
)
164 inline void* Obstack::finish(char terminator
)
170 inline void* Obstack::copy(const void* data
, int size
)
176 inline void* Obstack::copy(const void* data
, int size
, char terminator
)
178 grow(data
, size
, terminator
);
182 inline void* Obstack::copy(const char* s
)
184 grow((void*)s
, strlen(s
), 0);
188 inline void* Obstack::copy(char c
)
194 inline void* Obstack::alloc(int size
)
200 inline void Obstack:: free(void* obj
)
202 if (obj
>= (void*)chunk
&& obj
<(void*)chunklimit
)
203 nextfree
= objectbase
= (char *) obj
;
208 inline void Obstack:: grow_fast(char c
)
213 inline void Obstack:: blank_fast(int size
)
218 inline void Obstack:: shrink(int size
) // from ken@cs.rochester.edu
220 if (nextfree
>= objectbase
+ size
)