+
+ copy = copy_name (yylval.tsym.stoken);
+ new_type = cp_lookup_nested_type (yylval.tsym.type, copy, block);
+
+ if (new_type == NULL)
+ /* We know the caller won't expect us to update yylval. */
+ return NAME;
+
+ yylval.tsym.type = new_type;
+ return TYPENAME;
+}
+
+/* The outer level of a two-level lexer. This calls the inner lexer
+ to return tokens. It then either returns these tokens, or
+ aggregates them into a larger token. This lets us work around a
+ problem in our parsing approach, where the parser could not
+ distinguish between qualified names and qualified types at the
+ right point.
+
+ This approach is still not ideal, because it mishandles template
+ types. See the comment in lex_one_token for an example. However,
+ this is still an improvement over the earlier approach, and will
+ suffice until we move to better parsing technology. */
+static int
+yylex (void)
+{
+ token_and_value current;
+ int first_was_coloncolon, last_was_coloncolon, first_iter;
+
+ if (popping && !VEC_empty (token_and_value, token_fifo))
+ {
+ token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
+ VEC_ordered_remove (token_and_value, token_fifo, 0);
+ yylval = tv.value;
+ return tv.token;
+ }
+ popping = 0;
+
+ current.token = lex_one_token ();
+ if (current.token == NAME)
+ current.token = classify_name (expression_context_block);
+ if (parse_language->la_language != language_cplus
+ || (current.token != TYPENAME && current.token != COLONCOLON))
+ return current.token;
+
+ first_was_coloncolon = current.token == COLONCOLON;
+ last_was_coloncolon = first_was_coloncolon;
+ obstack_free (&name_obstack, obstack_base (&name_obstack));
+ if (!last_was_coloncolon)
+ obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
+ current.value = yylval;
+ first_iter = 1;
+ while (1)
+ {
+ token_and_value next;
+
+ next.token = lex_one_token ();
+ next.value = yylval;
+
+ if (next.token == NAME && last_was_coloncolon)
+ {
+ int classification;
+
+ classification = classify_inner_name (first_was_coloncolon
+ ? NULL
+ : expression_context_block,
+ first_iter);
+ /* We keep going until we either run out of names, or until
+ we have a qualified name which is not a type. */
+ if (classification != TYPENAME)
+ {
+ /* Push the final component and leave the loop. */
+ VEC_safe_push (token_and_value, token_fifo, &next);
+ break;
+ }
+
+ /* Update the partial name we are constructing. */
+ if (!first_iter)
+ {
+ /* We don't want to put a leading "::" into the name. */
+ obstack_grow_str (&name_obstack, "::");
+ }
+ obstack_grow (&name_obstack, next.value.sval.ptr,
+ next.value.sval.length);
+
+ yylval.sval.ptr = obstack_base (&name_obstack);
+ yylval.sval.length = obstack_object_size (&name_obstack);
+ current.value = yylval;
+ current.token = classification;
+
+ last_was_coloncolon = 0;
+ }
+ else if (next.token == COLONCOLON && !last_was_coloncolon)
+ last_was_coloncolon = 1;
+ else
+ {
+ /* We've reached the end of the name. */
+ VEC_safe_push (token_and_value, token_fifo, &next);
+ break;
+ }
+
+ first_iter = 0;
+ }
+
+ popping = 1;
+
+ /* If we ended with a "::", insert it too. */
+ if (last_was_coloncolon)
+ {
+ token_and_value cc;
+ memset (&cc, 0, sizeof (token_and_value));
+ if (first_was_coloncolon && first_iter)
+ {
+ yylval = cc.value;
+ return COLONCOLON;
+ }
+ cc.token = COLONCOLON;
+ VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
+ }
+
+ yylval = current.value;
+ yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
+ yylval.sval.ptr,
+ yylval.sval.length);
+ return current.token;