- return VARRAY_ACTIVE_SIZE (lexer->saved_tokens) != 0;
-}
-
-/* Return a pointer to the token that is N tokens beyond TOKEN in the
- buffer. */
-
-static cp_token *
-cp_lexer_advance_token (cp_lexer *lexer, cp_token *token, ptrdiff_t n)
-{
- token += n;
- if (token >= lexer->buffer_end)
- token = lexer->buffer + (token - lexer->buffer_end);
- return token;
-}
-
-/* Returns the number of times that START would have to be incremented
- to reach FINISH. If START and FINISH are the same, returns zero. */
-
-static ptrdiff_t
-cp_lexer_token_difference (cp_lexer* lexer, cp_token* start, cp_token* finish)
-{
- if (finish >= start)
- return finish - start;
- else
- return ((lexer->buffer_end - lexer->buffer)
- - (start - finish));
-}
-
-/* Obtain another token from the C preprocessor and add it to the
- token buffer. Returns the newly read token. */
-
-static cp_token *
-cp_lexer_read_token (cp_lexer* lexer)
-{
- cp_token *token;
-
- /* Make sure there is room in the buffer. */
- cp_lexer_maybe_grow_buffer (lexer);
-
- /* If there weren't any tokens, then this one will be the first. */
- if (!lexer->first_token)
- lexer->first_token = lexer->last_token;
- /* Similarly, if there were no available tokens, there is one now. */
- if (!lexer->next_token)
- lexer->next_token = lexer->last_token;
-
- /* Figure out where we're going to store the new token. */
- token = lexer->last_token;
-
- /* Get a new token from the preprocessor. */
- cp_lexer_get_preprocessor_token (lexer, token);
-
- /* Increment LAST_TOKEN. */
- lexer->last_token = cp_lexer_next_token (lexer, token);
-
- /* Strings should have type `const char []'. Right now, we will
- have an ARRAY_TYPE that is constant rather than an array of
- constant elements.
- FIXME: Make fix_string_type get this right in the first place. */
- if ((token->type == CPP_STRING || token->type == CPP_WSTRING)
- && flag_const_strings)
- {
- if (c_lex_string_translate)
- {
- tree value = token->value;
- tree type;
-
- /* We might as well go ahead and release the chained
- translated string such that we can reuse its memory. */
- if (TREE_CHAIN (value))
- value = TREE_CHAIN (token->value);
-
- /* Get the current type. It will be an ARRAY_TYPE. */
- type = TREE_TYPE (value);
- /* Use build_cplus_array_type to rebuild the array, thereby
- getting the right type. */
- type = build_cplus_array_type (TREE_TYPE (type),
- TYPE_DOMAIN (type));
- /* Reset the type of the token. */
- TREE_TYPE (value) = type;
- }
- }
-
- return token;
-}
-
-/* If the circular buffer is full, make it bigger. */
-
-static void
-cp_lexer_maybe_grow_buffer (cp_lexer* lexer)
-{
- /* If the buffer is full, enlarge it. */
- if (lexer->last_token == lexer->first_token)
- {
- cp_token *new_buffer;
- cp_token *old_buffer;
- cp_token *new_first_token;
- ptrdiff_t buffer_length;
- size_t num_tokens_to_copy;
-
- /* Remember the current buffer pointer. It will become invalid,
- but we will need to do pointer arithmetic involving this
- value. */
- old_buffer = lexer->buffer;
- /* Compute the current buffer size. */
- buffer_length = lexer->buffer_end - lexer->buffer;
- /* Allocate a buffer twice as big. */
- new_buffer = ggc_realloc (lexer->buffer,
- 2 * buffer_length * sizeof (cp_token));
-
- /* Because the buffer is circular, logically consecutive tokens
- are not necessarily placed consecutively in memory.
- Therefore, we must keep move the tokens that were before
- FIRST_TOKEN to the second half of the newly allocated
- buffer. */
- num_tokens_to_copy = (lexer->first_token - old_buffer);
- memcpy (new_buffer + buffer_length,
- new_buffer,
- num_tokens_to_copy * sizeof (cp_token));
- /* Clear the rest of the buffer. We never look at this storage,
- but the garbage collector may. */
- memset (new_buffer + buffer_length + num_tokens_to_copy, 0,
- (buffer_length - num_tokens_to_copy) * sizeof (cp_token));
-
- /* Now recompute all of the buffer pointers. */
- new_first_token
- = new_buffer + (lexer->first_token - old_buffer);
- if (lexer->next_token != NULL)
- {
- ptrdiff_t next_token_delta;
-
- if (lexer->next_token > lexer->first_token)
- next_token_delta = lexer->next_token - lexer->first_token;
- else
- next_token_delta =
- buffer_length - (lexer->first_token - lexer->next_token);
- lexer->next_token = new_first_token + next_token_delta;
- }
- lexer->last_token = new_first_token + buffer_length;
- lexer->buffer = new_buffer;
- lexer->buffer_end = new_buffer + buffer_length * 2;
- lexer->first_token = new_first_token;
- }