Commit ad2305ad by Dodji Seketeli Committed by Dodji Seketeli

Fix cpp_peek_token behaviour (PR bootstrap/50778)

libcpp/

	* include/internal.h (_cpp_remaining_tokens_num_in_context): Take the
	context to act upon.
	* lex.c (_cpp_remaining_tokens_num_in_context): Likewise.  Update
	comment.
	(cpp_token_from_context_at): Likewise.
	(cpp_peek_token): Use the context to peek tokens from.

From-SVN: r180328
parent 94bf1a5f
2011-10-22 Dodji Seketeli <dodji@redhat.com>
PR bootstrap/50778
* include/internal.h (_cpp_remaining_tokens_num_in_context): Take the
context to act upon.
* lex.c (_cpp_remaining_tokens_num_in_context): Likewise. Update
comment.
(cpp_token_from_context_at): Likewise.
(cpp_peek_token): Use the context to peek tokens from.
2011-10-20 Dodji Seketeli <dodji@redhat.com> 2011-10-20 Dodji Seketeli <dodji@redhat.com>
PR bootstrap/50801 PR bootstrap/50801
......
...@@ -652,7 +652,7 @@ extern cpp_token *_cpp_lex_direct (cpp_reader *); ...@@ -652,7 +652,7 @@ extern cpp_token *_cpp_lex_direct (cpp_reader *);
extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *); extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
extern void _cpp_init_tokenrun (tokenrun *, unsigned int); extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *); extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *);
extern int _cpp_remaining_tokens_num_in_context (cpp_reader *); extern int _cpp_remaining_tokens_num_in_context (cpp_context *);
/* In init.c. */ /* In init.c. */
extern void _cpp_maybe_push_include_file (cpp_reader *); extern void _cpp_maybe_push_include_file (cpp_reader *);
......
...@@ -1703,12 +1703,11 @@ next_tokenrun (tokenrun *run) ...@@ -1703,12 +1703,11 @@ next_tokenrun (tokenrun *run)
return run->next; return run->next;
} }
/* Return the number of not yet processed token in the the current /* Return the number of not yet processed token in a given
context. */ context. */
int int
_cpp_remaining_tokens_num_in_context (cpp_reader *pfile) _cpp_remaining_tokens_num_in_context (cpp_context *context)
{ {
cpp_context *context = pfile->context;
if (context->tokens_kind == TOKENS_KIND_DIRECT) if (context->tokens_kind == TOKENS_KIND_DIRECT)
return (LAST (context).token - FIRST (context).token); return (LAST (context).token - FIRST (context).token);
else if (context->tokens_kind == TOKENS_KIND_INDIRECT else if (context->tokens_kind == TOKENS_KIND_INDIRECT
...@@ -1718,12 +1717,11 @@ _cpp_remaining_tokens_num_in_context (cpp_reader *pfile) ...@@ -1718,12 +1717,11 @@ _cpp_remaining_tokens_num_in_context (cpp_reader *pfile)
abort (); abort ();
} }
/* Returns the token present at index INDEX in the current context. /* Returns the token present at index INDEX in a given context. If
If INDEX is zero, the next token to be processed is returned. */ INDEX is zero, the next token to be processed is returned. */
static const cpp_token* static const cpp_token*
_cpp_token_from_context_at (cpp_reader *pfile, int index) _cpp_token_from_context_at (cpp_context *context, int index)
{ {
cpp_context *context = pfile->context;
if (context->tokens_kind == TOKENS_KIND_DIRECT) if (context->tokens_kind == TOKENS_KIND_DIRECT)
return &(FIRST (context).token[index]); return &(FIRST (context).token[index]);
else if (context->tokens_kind == TOKENS_KIND_INDIRECT else if (context->tokens_kind == TOKENS_KIND_INDIRECT
...@@ -1744,10 +1742,10 @@ cpp_peek_token (cpp_reader *pfile, int index) ...@@ -1744,10 +1742,10 @@ cpp_peek_token (cpp_reader *pfile, int index)
/* First, scan through any pending cpp_context objects. */ /* First, scan through any pending cpp_context objects. */
while (context->prev) while (context->prev)
{ {
ptrdiff_t sz = _cpp_remaining_tokens_num_in_context (pfile); ptrdiff_t sz = _cpp_remaining_tokens_num_in_context (context);
if (index < (int) sz) if (index < (int) sz)
return _cpp_token_from_context_at (pfile, index); return _cpp_token_from_context_at (context, index);
index -= (int) sz; index -= (int) sz;
context = context->prev; context = context->prev;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment