aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplex.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r--gcc/cpplex.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index 9912aac559c..6131b3db5a1 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -667,6 +667,46 @@ next_tokenrun (tokenrun *run)
return run->next;
}
+/* APPLE LOCAL begin AltiVec */
+/* Look ahead in the input stream. */
+const cpp_token *
+_cpp_peek_token (cpp_reader *pfile, int index)
+{
+ cpp_context *context = pfile->context;
+ const cpp_token *peektok;
+ int count, saved_keep_tokens;
+
+ /* First, scan through any pending cpp_context objects. */
+ while (context->prev)
+ {
+ ptrdiff_t sz = LAST (context).token - FIRST (context).token;
+
+ if (index < (int) sz)
+ return (context->direct_p
+ ? FIRST (context).token + index
+ : *(FIRST (context).ptoken + index));
+
+ index -= (int) sz;
+ context = context->prev;
+ }
+
+ /* We will have to read some new tokens after all (and do so
+ without invalidating preceding tokens). */
+ count = index;
+ saved_keep_tokens = pfile->keep_tokens;
+ pfile->keep_tokens = 1;
+
+ do
+ peektok = _cpp_lex_token (pfile);
+ while (index--);
+
+ _cpp_backup_tokens_direct (pfile, count + 1);
+ pfile->keep_tokens = saved_keep_tokens;
+
+ return peektok;
+}
+/* APPLE LOCAL end AltiVec */
+
/* Allocate a single token that is invalidated at the same time as the
rest of the tokens on the line. Has its line and col set to the
same as the last lexed token, so that diagnostics appear in the
@@ -675,9 +715,34 @@ cpp_token *
_cpp_temp_token (cpp_reader *pfile)
{
cpp_token *old, *result;
+ /* APPLE LOCAL begin AltiVec */
+ ptrdiff_t sz = pfile->cur_run->limit - pfile->cur_token;
+ ptrdiff_t la = (ptrdiff_t) pfile->lookaheads;
+ /* APPLE LOCAL end AltiVec */
old = pfile->cur_token - 1;
- if (pfile->cur_token == pfile->cur_run->limit)
+ /* APPLE LOCAL begin AltiVec */
+ /* Any pre-existing lookaheads must not be clobbered. */
+ if (la)
+ {
+ if (sz <= la)
+ {
+ tokenrun *next = next_tokenrun (pfile->cur_run);
+
+ if (sz < la)
+ memmove (next->base + 1, next->base,
+ (la - sz) * sizeof (cpp_token));
+
+ next->base[0] = pfile->cur_run->limit[-1];
+ }
+
+ if (sz > 1)
+ memmove (pfile->cur_token + 1, pfile->cur_token,
+ MIN (la, sz - 1) * sizeof (cpp_token));
+ }
+
+ if (!sz)
+ /* APPLE LOCAL end AltiVec */
{
pfile->cur_run = next_tokenrun (pfile->cur_run);
pfile->cur_token = pfile->cur_run->base;
@@ -760,6 +825,12 @@ _cpp_get_fresh_line (cpp_reader *pfile)
if (!buffer->need_line)
return true;
+ /* APPLE LOCAL begin predictive compilation */
+ if (CPP_OPTION (pfile, predictive_compilation)
+ && buffer->next_line >= buffer->rlimit)
+ read_from_stdin (pfile);
+ /* APPLE LOCAL end predictive compilation */
+
if (buffer->next_line < buffer->rlimit)
{
_cpp_clean_line (pfile);