aboutsummaryrefslogtreecommitdiff
path: root/libcpp/lex.c
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@redhat.com>2011-10-22 17:49:18 +0000
committerDodji Seketeli <dodji@gcc.gnu.org>2011-10-22 19:49:18 +0200
commitad2305adb4957005096c0fd019a1cb7071879abd (patch)
tree06c0096adb2e891ed006c895e4c785b4ad2b1133 /libcpp/lex.c
parent94bf1a5fb73fc9c6a9bf9810c56b3f1678667f20 (diff)
downloadgcc-ad2305adb4957005096c0fd019a1cb7071879abd.zip
gcc-ad2305adb4957005096c0fd019a1cb7071879abd.tar.gz
gcc-ad2305adb4957005096c0fd019a1cb7071879abd.tar.bz2
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
Diffstat (limited to 'libcpp/lex.c')
-rw-r--r--libcpp/lex.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 527368b..896a3be 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1703,12 +1703,11 @@ next_tokenrun (tokenrun *run)
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. */
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)
return (LAST (context).token - FIRST (context).token);
else if (context->tokens_kind == TOKENS_KIND_INDIRECT
@@ -1718,12 +1717,11 @@ _cpp_remaining_tokens_num_in_context (cpp_reader *pfile)
abort ();
}
-/* Returns the token present at index INDEX in the current context.
- If INDEX is zero, the next token to be processed is returned. */
+/* Returns the token present at index INDEX in a given context. If
+ INDEX is zero, the next token to be processed is returned. */
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)
return &(FIRST (context).token[index]);
else if (context->tokens_kind == TOKENS_KIND_INDIRECT
@@ -1744,10 +1742,10 @@ cpp_peek_token (cpp_reader *pfile, int index)
/* First, scan through any pending cpp_context objects. */
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)
- return _cpp_token_from_context_at (pfile, index);
+ return _cpp_token_from_context_at (context, index);
index -= (int) sz;
context = context->prev;
}