aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-lex.c')
-rw-r--r--gcc/c-lex.c126
1 files changed, 116 insertions, 10 deletions
diff --git a/gcc/c-lex.c b/gcc/c-lex.c
index 3986b2771bb..db2533d961e 100644
--- a/gcc/c-lex.c
+++ b/gcc/c-lex.c
@@ -41,6 +41,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "tm_p.h"
#include "splay-tree.h"
#include "debug.h"
+/* APPLE LOCAL begin AltiVec */
+#include "target.h"
+#include "cpphash.h"
+/* APPLE LOCAL end AltiVec */
/* We may keep statistics about how long which files took to compile. */
static int header_time, body_time;
@@ -106,6 +110,24 @@ init_c_lex (void)
cb->define = cb_define;
cb->undef = cb_undef;
}
+
+ /* APPLE LOCAL begin Symbol Separation */
+ /* Set up call back routines. These routines are used when separate symbol
+ repositories are used. */
+ if (write_symbols != NO_DEBUG)
+ {
+ cb->restore_write_symbols = cb_restore_write_symbols;
+ cb->clear_write_symbols = cb_clear_write_symbols;
+ cb->is_builtin_identifier = cb_is_builtin_identifier;
+ cb->start_symbol_repository = cb_start_symbol_repository;
+ cb->end_symbol_repository = cb_end_symbol_repository;
+ if (flag_grepository)
+ {
+ cpp_options *options = cpp_get_options (parse_in);
+ options->use_ss = 1;
+ }
+ }
+ /* APPLE LOCAL end Symbol Separation */
}
struct c_fileinfo *
@@ -298,19 +320,72 @@ cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location loc,
(const char *) NODE_NAME (node));
}
+/* APPLE LOCAL begin AltiVec */
+/* We need a small circular buffer for lookaheads (and lookbacks). */
+
+#define C_LEX_BUFCAPACITY 16
+#define C_LEX_OFFS_BOUND(OFFS) \
+ ((OFFS) >= 0 \
+ ? (OFFS) % C_LEX_BUFCAPACITY \
+ : (OFFS) + C_LEX_BUFCAPACITY)
+
+static int c_lex_buf_beg = 0, c_lex_buf_end = 0;
+static const cpp_token *c_lex_buf[C_LEX_BUFCAPACITY];
+
static inline const cpp_token *
-get_nonpadding_token (void)
+get_nonpadding_token (int from_buffer)
{
const cpp_token *tok;
+
timevar_push (TV_CPP);
- do
- tok = cpp_get_token (parse_in);
- while (tok->type == CPP_PADDING);
+ if (from_buffer && c_lex_buf_beg != c_lex_buf_end)
+ {
+ tok = c_lex_buf[c_lex_buf_beg++];
+ c_lex_buf_beg = C_LEX_OFFS_BOUND (c_lex_buf_beg);
+ }
+ else
+ {
+ do
+ tok = cpp_get_token (parse_in);
+ while (tok->type == CPP_PADDING);
+ c_lex_buf[c_lex_buf_end++] = tok;
+ c_lex_buf_end = C_LEX_OFFS_BOUND (c_lex_buf_end);
+ if (from_buffer)
+ c_lex_buf_beg = c_lex_buf_end;
+ }
timevar_pop (TV_CPP);
+ return tok;
+}
+
+const cpp_token *
+c_lex_peek (int offset)
+{
+ const cpp_token *tok;
+
+ if (offset >= 0)
+ {
+ while (C_LEX_OFFS_BOUND (c_lex_buf_end - c_lex_buf_beg) < offset + 1)
+ get_nonpadding_token (0);
+ tok = c_lex_buf[C_LEX_OFFS_BOUND (c_lex_buf_beg + offset)];
+ }
+ else
+ tok = c_lex_buf[C_LEX_OFFS_BOUND (c_lex_buf_end + offset)];
return tok;
}
+void
+c_lex_prepend (const cpp_token *tok_array, int size)
+{
+ while (size--)
+ {
+ --c_lex_buf_beg;
+ c_lex_buf_beg = C_LEX_OFFS_BOUND (c_lex_buf_beg);
+ c_lex_buf[c_lex_buf_beg] = &tok_array[size];
+ }
+}
+/* APPLE LOCAL end AltiVec */
+
int
c_lex_with_flags (tree *value, unsigned char *cpp_flags)
{
@@ -319,12 +394,24 @@ c_lex_with_flags (tree *value, unsigned char *cpp_flags)
static bool no_more_pch;
retry:
- tok = get_nonpadding_token ();
+ tok = get_nonpadding_token (1);
retry_after_at:
switch (tok->type)
{
case CPP_NAME:
+ /* APPLE LOCAL begin AltiVec */
+ /* Conditional macros are expanded whenever a call-back predicate
+ says they should be. */
+ if ((tok->val.node->flags & NODE_DISABLED)
+ && (*targetm.expand_macro_p) (tok))
+ {
+ c_lex_prepend (tok->val.node->value.macro->exp.tokens,
+ tok->val.node->value.macro->count);
+ goto retry;
+ }
+ /* APPLE LOCAL end AltiVec */
+
*value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node));
break;
@@ -356,7 +443,8 @@ c_lex_with_flags (tree *value, unsigned char *cpp_flags)
case CPP_ATSIGN:
/* An @ may give the next token special significance in Objective-C. */
atloc = input_location;
- tok = get_nonpadding_token ();
+ /* APPLE LOCAL AltiVec */
+ tok = get_nonpadding_token (1);
if (c_dialect_objc ())
{
tree val;
@@ -659,11 +747,13 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string)
if (tok->type == CPP_WSTRING)
wide = true;
- tok = get_nonpadding_token ();
+ /* APPLE LOCAL AltiVec */
+ tok = get_nonpadding_token (1);
if (c_dialect_objc () && tok->type == CPP_ATSIGN)
{
objc_string = true;
- tok = get_nonpadding_token ();
+ /* APPLE LOCAL AltiVec */
+ tok = get_nonpadding_token (1);
}
if (tok->type == CPP_STRING || tok->type == CPP_WSTRING)
{
@@ -677,11 +767,13 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string)
wide = true;
obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
- tok = get_nonpadding_token ();
+ /* APPLE LOCAL ALtiVec */
+ tok = get_nonpadding_token (1);
if (c_dialect_objc () && tok->type == CPP_ATSIGN)
{
objc_string = true;
- tok = get_nonpadding_token ();
+ /* APPLE LOCAL AltiVec */
+ tok = get_nonpadding_token (1);
}
}
while (tok->type == CPP_STRING || tok->type == CPP_WSTRING);
@@ -755,3 +847,17 @@ lex_charconst (const cpp_token *token)
TREE_TYPE (value) = type;
return value;
}
+
+/* APPLE LOCAL begin Symbol Separation */
+
+/* Write context information in .cinfo file.
+ Use PCH routines directly. But set and restore cinfo_state before using them. */
+void
+c_common_write_context (void)
+{
+ /* MERGE FIXME: This used to say 'lineno', not '0', but now we don't
+ have a 'lineno' variable (and it was probably always wrong). */
+ (*debug_hooks->end_symbol_repository) (0);
+ cpp_write_symbol_deps (parse_in);
+}
+/* APPLE LOCAL end Symbol Separation */