aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/spew.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/spew.c')
-rw-r--r--gcc/cp/spew.c62
1 files changed, 52 insertions, 10 deletions
diff --git a/gcc/cp/spew.c b/gcc/cp/spew.c
index efeae64a711..380d6936b83 100644
--- a/gcc/cp/spew.c
+++ b/gcc/cp/spew.c
@@ -86,7 +86,7 @@ struct unparsed_text GTY(())
struct token_chunk *last_chunk; /* End of the token list. */
short last_pos; /* Number of tokens used in the last chunk of
- TOKENS. */
+ TOKENS. */
short cur_pos; /* Current token in 'cur_chunk', when rescanning. */
struct token_chunk *cur_chunk; /* Current chunk, when rescanning. */
@@ -133,6 +133,7 @@ static struct unparsed_text * alloc_unparsed_text
static void snarf_block PARAMS ((struct unparsed_text *t));
static tree snarf_defarg PARAMS ((void));
+static void snarf_parenthesized_expression (struct unparsed_text *);
static int frob_id PARAMS ((int, int, tree *));
/* The list of inline functions being held off until we reach the end of
@@ -185,7 +186,7 @@ static int first_token;
static GTY(()) tree defarg_fns;
/* current default parameter */
static GTY(()) tree defarg_parm;
-/* list of unprocessed fns met during current fn. */
+/* list of unprocessed fns met during current fn. */
static GTY(()) tree defarg_depfns;
/* list of fns with circular defargs */
static GTY(()) tree defarg_fnsdone;
@@ -476,8 +477,7 @@ next_token (t)
return t->yychar;
}
- memcpy (t, &Teosi, sizeof (struct token));
- return END_OF_SAVED_INPUT;
+ return 0;
}
/* Shift the next token onto the fifo. */
@@ -668,7 +668,7 @@ do_aggr ()
void
see_typename ()
{
- /* Only types expected, not even namespaces. */
+ /* Only types expected, not even namespaces. */
looking_for_typename = 2;
if (yychar < 0)
if ((yychar = yylex ()) < 0) yychar = 0;
@@ -754,7 +754,7 @@ yylex ()
case PTYPENAME:
case PTYPENAME_DEFN:
/* If we see a SCOPE next, restore the old value.
- Otherwise, we got what we want. */
+ Otherwise, we got what we want. */
looking_for_typename = old_looking_for_typename;
looking_for_template = 0;
break;
@@ -832,7 +832,7 @@ yylex ()
}
/* Unget character CH from the input stream.
- If RESCAN is non-zero, then we want to `see' this
+ If RESCAN is nonzero, then we want to `see' this
character as the next input token. */
void
@@ -887,7 +887,7 @@ frob_id (yyc, peek, idp)
case NSNAME:
case PTYPENAME:
/* If this got special lookup, remember it. In these
- cases, we know it can't be a declarator-id. */
+ cases, we know it can't be a declarator-id. */
if (got_scope || got_object)
*idp = trrr;
/* FALLTHROUGH */
@@ -1067,6 +1067,30 @@ alloc_unparsed_text (locus, decl, interface)
return r;
}
+/* Accumulate the tokens that make up a parenthesized expression in T,
+ having already read the opening parenthesis. */
+
+static void
+snarf_parenthesized_expression (struct unparsed_text *t)
+{
+ int yyc;
+ int level = 1;
+
+ while (1)
+ {
+ yyc = next_token (space_for_token (t));
+ if (yyc == '(')
+ ++level;
+ else if (yyc == ')' && --level == 0)
+ break;
+ else if (yyc == 0)
+ {
+ error ("%Hend of file read inside definition", &t->locus);
+ break;
+ }
+ }
+}
+
/* Subroutine of snarf_method, deals with actual absorption of the block. */
static void
@@ -1145,6 +1169,8 @@ snarf_block (t)
else if (look_for_semicolon && blev == 0)
break;
}
+ else if (yyc == '(' && blev == 0)
+ snarf_parenthesized_expression (t);
else if (yyc == 0)
{
error ("%Hend of file read inside definition", &t->locus);
@@ -1168,6 +1194,14 @@ snarf_method (decl)
: (interface_only ? 0 : 2)));
snarf_block (meth);
+ /* Add three END_OF_SAVED_INPUT tokens. We used to provide an
+ infinite stream of END_OF_SAVED_INPUT tokens -- but that can
+ cause the compiler to get stuck in an infinite loop when
+ encountering invalid code. We need more than one because the
+ parser sometimes peeks ahead several tokens. */
+ memcpy (space_for_token (meth), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (meth), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (meth), &Teosi, sizeof (struct token));
/* Happens when we get two declarations of the same function in the
same scope. */
@@ -1226,6 +1260,14 @@ snarf_defarg ()
/* Unget the last token. */
push_token (remove_last_token (buf));
+ /* Add three END_OF_SAVED_INPUT tokens. We used to provide an
+ infinite stream of END_OF_SAVED_INPUT tokens -- but that can
+ cause the compiler to get stuck in an infinite loop when
+ encountering invalid code. We need more than one because the
+ parser sometimes peeks ahead several tokens. */
+ memcpy (space_for_token (buf), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (buf), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (buf), &Teosi, sizeof (struct token));
done:
#ifdef SPEW_DEBUG
@@ -1372,7 +1414,7 @@ do_pending_defargs ()
/* No need to say what else is dependent, as they will be
picked up in another pass. */
- /* Immediately repeat, but marked so that we break the loop. */
+ /* Immediately repeat, but marked so that we break the loop. */
defarg_fns = current;
TREE_PURPOSE (current) = error_mark_node;
}
@@ -1384,7 +1426,7 @@ do_pending_defargs ()
}
/* After parsing all the default arguments, we must clear any that remain,
- which will be part of a circular dependency. */
+ which will be part of a circular dependency. */
void
done_pending_defargs ()
{