summaryrefslogtreecommitdiff
path: root/gcc/cpplex.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-09-30 10:03:11 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-09-30 10:03:11 +0000
commit8c3b269309f3b3651362697d48a3ade54bbddb55 (patch)
tree78d68f969b236c6a6934656003c802393ecd85b7 /gcc/cpplex.c
parent218e1e912d74b89f0a6bd7c694bdc89c4515610b (diff)
downloadgcc-8c3b269309f3b3651362697d48a3ade54bbddb55.tar.gz
cpphash.h (POOL_ALIGN, [...]): Remove.
* cpphash.h (POOL_ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_ROOM, POOL_COMMIT, struct cpp_chunk, struct cpp_pool, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk): Remove. (_cpp_extend_buff, BUFF_ROOM): Update. (_cpp_append_extend_buff): New. (struct cpp_reader): Remove macro_pool, add a_buff. * cppinit.c (cpp_create_reader): Initialize a_buff, instead of macro_pool. (cpp_destroy): Free a_buff instead of macro_pool. * cpplex.c (new_chunk, chunk_suitable, _cpp_next_chunk, new_chunk, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, ): Remove. (parse_number, parse_string): Update use of _cpp_extend_buff. (_cpp_extend_buff): Update. (_cpp_append_extend_buff, cpp_aligned_alloc): New. * cpplib.c (glue_header_name, parse_answer): Update use of _cpp_extend_buff. (cpp_register_pragma, cpp_register_pragma_space): Use _cpp_aligned_alloc. (do_assert, do_unassert): Check for EOL, update. * cppmacro.c (stringify_arg, collect_args): Update to use _cpp_extend_buff and _cpp_append_extend_buff. (save_parameter, parse_params, alloc_expansion_token, _cpp_create_definition): Rework memory management. * gcc.dg/cpp/redef2.c: Add test. From-SVN: r45899
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r--gcc/cpplex.c165
1 files changed, 44 insertions, 121 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index 26bda3605fb..4a6c483a2ec 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -104,8 +104,6 @@ static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **,
const unsigned char *, unsigned int *));
static tokenrun *next_tokenrun PARAMS ((tokenrun *));
-static cpp_chunk *new_chunk PARAMS ((unsigned int));
-static int chunk_suitable PARAMS ((cpp_chunk *, unsigned int));
static unsigned int hex_digit_value PARAMS ((unsigned int));
static _cpp_buff *new_buff PARAMS ((size_t));
@@ -609,7 +607,7 @@ parse_number (pfile, number, c, leading_period)
{
if (dest == limit)
{
- pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, 1);
+ _cpp_extend_buff (pfile, &pfile->u_buff, 1);
dest = BUFF_FRONT (pfile->u_buff);
limit = BUFF_LIMIT (pfile->u_buff);
}
@@ -624,7 +622,7 @@ parse_number (pfile, number, c, leading_period)
if ((size_t) (limit - dest) < 2)
{
size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
- pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, 2);
+ _cpp_extend_buff (pfile, &pfile->u_buff, 2);
dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
limit = BUFF_LIMIT (pfile->u_buff);
}
@@ -726,7 +724,7 @@ parse_string (pfile, token, terminator)
if ((size_t) (limit - dest) < 1)
{
size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
- pfile->u_buff = _cpp_extend_buff (pfile, pfile->u_buff, 2);
+ _cpp_extend_buff (pfile, &pfile->u_buff, 2);
dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
limit = BUFF_LIMIT (pfile->u_buff);
}
@@ -2112,20 +2110,42 @@ _cpp_get_buff (pfile, min_size)
return result;
}
-/* Return a buffer chained on the end of BUFF. Copy to it the
- uncommitted remaining bytes of BUFF, with at least MIN_EXTRA more
- bytes. */
+/* Creates a new buffer with enough space to hold the the uncommitted
+ remaining bytes of BUFF, and at least MIN_EXTRA more bytes. Copies
+ the excess bytes to the new buffer. Chains the new buffer after
+ BUFF, and returns the new buffer. */
_cpp_buff *
-_cpp_extend_buff (pfile, buff, min_extra)
+_cpp_append_extend_buff (pfile, buff, min_extra)
cpp_reader *pfile;
_cpp_buff *buff;
size_t min_extra;
{
size_t size = EXTENDED_BUFF_SIZE (buff, min_extra);
+ _cpp_buff *new_buff = _cpp_get_buff (pfile, size);
- buff->next = _cpp_get_buff (pfile, size);
- memcpy (buff->next->base, buff->cur, buff->limit - buff->cur);
- return buff->next;
+ buff->next = new_buff;
+ memcpy (new_buff->base, buff->cur, BUFF_ROOM (buff));
+ return new_buff;
+}
+
+/* Creates a new buffer with enough space to hold the the uncommitted
+ remaining bytes of the buffer pointed to by BUFF, and at least
+ MIN_EXTRA more bytes. Copies the excess bytes to the new buffer.
+ Chains the new buffer before the buffer pointed to by BUFF, and
+ updates the pointer to point to the new buffer. */
+void
+_cpp_extend_buff (pfile, pbuff, min_extra)
+ cpp_reader *pfile;
+ _cpp_buff **pbuff;
+ size_t min_extra;
+{
+ _cpp_buff *new_buff, *old_buff = *pbuff;
+ size_t size = EXTENDED_BUFF_SIZE (old_buff, min_extra);
+
+ new_buff = _cpp_get_buff (pfile, size);
+ memcpy (new_buff->base, old_buff->cur, BUFF_ROOM (old_buff));
+ new_buff->next = old_buff;
+ *pbuff = new_buff;
}
/* Free a chain of buffers starting at BUFF. */
@@ -2163,120 +2183,23 @@ _cpp_unaligned_alloc (pfile, len)
return result;
}
-static int
-chunk_suitable (chunk, size)
- cpp_chunk *chunk;
- unsigned int size;
-{
- /* Being at least twice SIZE means we can use memcpy in
- _cpp_next_chunk rather than memmove. Besides, it's a good idea
- anyway. */
- return (chunk && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
-}
-
-/* Returns the end of the new pool. PTR points to a char in the old
- pool, and is updated to point to the same char in the new pool. */
+/* Allocate permanent, unaligned storage of length LEN. */
unsigned char *
-_cpp_next_chunk (pool, len, ptr)
- cpp_pool *pool;
- unsigned int len;
- unsigned char **ptr;
-{
- cpp_chunk *chunk = pool->cur->next;
-
- /* LEN is the minimum size we want in the new pool. */
- len += POOL_ROOM (pool);
- if (! chunk_suitable (chunk, len))
- {
- chunk = new_chunk (POOL_SIZE (pool) * 2 + len);
-
- chunk->next = pool->cur->next;
- pool->cur->next = chunk;
- }
-
- /* Update the pointer before changing chunk's front. */
- if (ptr)
- *ptr += chunk->base - POOL_FRONT (pool);
-
- memcpy (chunk->base, POOL_FRONT (pool), POOL_ROOM (pool));
- chunk->front = chunk->base;
-
- pool->cur = chunk;
- return POOL_LIMIT (pool);
-}
-
-static cpp_chunk *
-new_chunk (size)
- unsigned int size;
-{
- unsigned char *base;
- cpp_chunk *result;
-
- size = POOL_ALIGN (size, DEFAULT_ALIGNMENT);
- base = (unsigned char *) xmalloc (size + sizeof (cpp_chunk));
- /* Put the chunk descriptor at the end. Then chunk overruns will
- cause obvious chaos. */
- result = (cpp_chunk *) (base + size);
- result->base = base;
- result->front = base;
- result->limit = base + size;
- result->next = 0;
-
- return result;
-}
-
-void
-_cpp_init_pool (pool, size, align, temp)
- cpp_pool *pool;
- unsigned int size, align, temp;
-{
- if (align == 0)
- align = DEFAULT_ALIGNMENT;
- if (align & (align - 1))
- abort ();
- pool->align = align;
- pool->first = new_chunk (size);
- pool->cur = pool->first;
- if (temp)
- pool->cur->next = pool->cur;
-}
-
-void
-_cpp_free_pool (pool)
- cpp_pool *pool;
+_cpp_aligned_alloc (pfile, len)
+ cpp_reader *pfile;
+ size_t len;
{
- cpp_chunk *chunk = pool->first, *next;
+ _cpp_buff *buff = pfile->a_buff;
+ unsigned char *result = buff->cur;
- do
+ if (len > (size_t) (buff->limit - result))
{
- next = chunk->next;
- free (chunk->base);
- chunk = next;
+ buff = _cpp_get_buff (pfile, len);
+ buff->next = pfile->a_buff;
+ pfile->a_buff = buff;
+ result = buff->cur;
}
- while (chunk && chunk != pool->first);
-}
-
-/* Reserve LEN bytes from a memory pool. */
-unsigned char *
-_cpp_pool_reserve (pool, len)
- cpp_pool *pool;
- unsigned int len;
-{
- len = POOL_ALIGN (len, pool->align);
- if (len > (unsigned int) POOL_ROOM (pool))
- _cpp_next_chunk (pool, len, 0);
- return POOL_FRONT (pool);
-}
-
-/* Allocate LEN bytes from a memory pool. */
-unsigned char *
-_cpp_pool_alloc (pool, len)
- cpp_pool *pool;
- unsigned int len;
-{
- unsigned char *result = _cpp_pool_reserve (pool, len);
-
- POOL_COMMIT (pool, len);
+ buff->cur = result + len;
return result;
}