2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
4 Written by Mark Mitchell <mark@codesourcery.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
27 #include "dyn-string.h"
35 #include "diagnostic.h"
43 /* The cp_lexer_* routines mediate between the lexer proper (in libcpp
44 and c-lex.c) and the C++ parser. */
48 typedef struct cp_token GTY (())
50 /* The kind of token. */
51 ENUM_BITFIELD (cpp_ttype) type : 8;
52 /* If this token is a keyword, this value indicates which keyword.
53 Otherwise, this value is RID_MAX. */
54 ENUM_BITFIELD (rid) keyword : 8;
57 /* True if this token is from a system header. */
58 BOOL_BITFIELD in_system_header : 1;
59 /* True if this token is from a context where it is implicitly extern "C" */
60 BOOL_BITFIELD implicit_extern_c : 1;
61 /* The value associated with this token, if any. */
63 /* The location at which this token was found. */
67 /* We use a stack of token pointer for saving token sets. */
68 typedef struct cp_token *cp_token_position;
69 DEF_VEC_MALLOC_P (cp_token_position);
71 static const cp_token eof_token =
73 CPP_EOF, RID_MAX, 0, 0, 0, NULL_TREE,
74 #if USE_MAPPED_LOCATION
81 /* The cp_lexer structure represents the C++ lexer. It is responsible
82 for managing the token stream from the preprocessor and supplying
83 it to the parser. Tokens are never added to the cp_lexer after
86 typedef struct cp_lexer GTY (())
88 /* The memory allocated for the buffer. NULL if this lexer does not
89 own the token buffer. */
90 cp_token * GTY ((length ("%h.buffer_length"))) buffer;
91 /* If the lexer owns the buffer, this is the number of tokens in the
95 /* A pointer just past the last available token. The tokens
96 in this lexer are [buffer, last_token). */
97 cp_token_position GTY ((skip)) last_token;
99 /* The next available token. If NEXT_TOKEN is &eof_token, then there are
100 no more available tokens. */
101 cp_token_position GTY ((skip)) next_token;
103 /* A stack indicating positions at which cp_lexer_save_tokens was
104 called. The top entry is the most recent position at which we
105 began saving tokens. If the stack is non-empty, we are saving
107 VEC (cp_token_position) *GTY ((skip)) saved_tokens;
109 /* True if we should output debugging information. */
112 /* The next lexer in a linked list of lexers. */
113 struct cp_lexer *next;
116 /* cp_token_cache is a range of tokens. There is no need to represent
117 allocate heap memory for it, since tokens are never removed from the
118 lexer's array. There is also no need for the GC to walk through
119 a cp_token_cache, since everything in here is referenced through
122 typedef struct cp_token_cache GTY(())
124 /* The beginning of the token range. */
125 cp_token * GTY((skip)) first;
127 /* Points immediately after the last token in the range. */
128 cp_token * GTY ((skip)) last;
133 static cp_lexer *cp_lexer_new_main
135 static cp_lexer *cp_lexer_new_from_tokens
136 (cp_token_cache *tokens);
137 static void cp_lexer_destroy
139 static int cp_lexer_saving_tokens
141 static cp_token_position cp_lexer_token_position
143 static cp_token *cp_lexer_token_at
144 (cp_lexer *, cp_token_position);
145 static void cp_lexer_get_preprocessor_token
146 (cp_lexer *, cp_token *);
147 static inline cp_token *cp_lexer_peek_token
149 static cp_token *cp_lexer_peek_nth_token
150 (cp_lexer *, size_t);
151 static inline bool cp_lexer_next_token_is
152 (cp_lexer *, enum cpp_ttype);
153 static bool cp_lexer_next_token_is_not
154 (cp_lexer *, enum cpp_ttype);
155 static bool cp_lexer_next_token_is_keyword
156 (cp_lexer *, enum rid);
157 static cp_token *cp_lexer_consume_token
159 static void cp_lexer_purge_token
161 static void cp_lexer_purge_tokens_after
162 (cp_lexer *, cp_token_position);
163 static void cp_lexer_handle_pragma
165 static void cp_lexer_save_tokens
167 static void cp_lexer_commit_tokens
169 static void cp_lexer_rollback_tokens
171 #ifdef ENABLE_CHECKING
172 static void cp_lexer_print_token
173 (FILE *, cp_token *);
174 static inline bool cp_lexer_debugging_p
176 static void cp_lexer_start_debugging
177 (cp_lexer *) ATTRIBUTE_UNUSED;
178 static void cp_lexer_stop_debugging
179 (cp_lexer *) ATTRIBUTE_UNUSED;
181 /* If we define cp_lexer_debug_stream to NULL it will provoke warnings
182 about passing NULL to functions that require non-NULL arguments
183 (fputs, fprintf). It will never be used, so all we need is a value
184 of the right type that's guaranteed not to be NULL. */
185 #define cp_lexer_debug_stream stdout
186 #define cp_lexer_print_token(str, tok) (void) 0
187 #define cp_lexer_debugging_p(lexer) 0
188 #endif /* ENABLE_CHECKING */
190 static cp_token_cache *cp_token_cache_new
191 (cp_token *, cp_token *);
193 /* Manifest constants. */
194 #define CP_LEXER_BUFFER_SIZE 10000
195 #define CP_SAVED_TOKEN_STACK 5
197 /* A token type for keywords, as opposed to ordinary identifiers. */
198 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
200 /* A token type for template-ids. If a template-id is processed while
201 parsing tentatively, it is replaced with a CPP_TEMPLATE_ID token;
202 the value of the CPP_TEMPLATE_ID is whatever was returned by
203 cp_parser_template_id. */
204 #define CPP_TEMPLATE_ID ((enum cpp_ttype) (CPP_KEYWORD + 1))
206 /* A token type for nested-name-specifiers. If a
207 nested-name-specifier is processed while parsing tentatively, it is
208 replaced with a CPP_NESTED_NAME_SPECIFIER token; the value of the
209 CPP_NESTED_NAME_SPECIFIER is whatever was returned by
210 cp_parser_nested_name_specifier_opt. */
211 #define CPP_NESTED_NAME_SPECIFIER ((enum cpp_ttype) (CPP_TEMPLATE_ID + 1))
213 /* A token type for tokens that are not tokens at all; these are used
214 to represent slots in the array where there used to be a token
215 that has now been deleted. */
216 #define CPP_PURGED ((enum cpp_ttype) (CPP_NESTED_NAME_SPECIFIER + 1))
218 /* The number of token types, including C++-specific ones. */
219 #define N_CP_TTYPES ((int) (CPP_PURGED + 1))
223 #ifdef ENABLE_CHECKING
224 /* The stream to which debugging output should be written. */
225 static FILE *cp_lexer_debug_stream;
226 #endif /* ENABLE_CHECKING */
228 /* Create a new main C++ lexer, the lexer that gets tokens from the
232 cp_lexer_new_main (void)
234 cp_token first_token;
241 /* Tell cpplib we want CPP_PRAGMA tokens. */
242 cpp_get_options (parse_in)->defer_pragmas = true;
244 /* Tell c_lex not to merge string constants. */
245 c_lex_return_raw_strings = true;
247 /* It's possible that lexing the first token will load a PCH file,
248 which is a GC collection point. So we have to grab the first
249 token before allocating any memory. */
250 cp_lexer_get_preprocessor_token (NULL, &first_token);
251 c_common_no_more_pch ();
253 /* Allocate the memory. */
254 lexer = GGC_CNEW (cp_lexer);
256 #ifdef ENABLE_CHECKING
257 /* Initially we are not debugging. */
258 lexer->debugging_p = false;
259 #endif /* ENABLE_CHECKING */
260 lexer->saved_tokens = VEC_alloc (cp_token_position, CP_SAVED_TOKEN_STACK);
262 /* Create the buffer. */
263 alloc = CP_LEXER_BUFFER_SIZE;
264 buffer = ggc_alloc (alloc * sizeof (cp_token));
266 /* Put the first token in the buffer. */
271 /* Get the remaining tokens from the preprocessor. */
272 while (pos->type != CPP_EOF)
279 buffer = ggc_realloc (buffer, alloc * sizeof (cp_token));
280 pos = buffer + space;
282 cp_lexer_get_preprocessor_token (lexer, pos);
284 lexer->buffer = buffer;
285 lexer->buffer_length = alloc - space;
286 lexer->last_token = pos;
287 lexer->next_token = lexer->buffer_length ? buffer : (cp_token *)&eof_token;
289 /* Pragma processing (via cpp_handle_deferred_pragma) may result in
290 direct calls to c_lex. Those callers all expect c_lex to do
291 string constant concatenation. */
292 c_lex_return_raw_strings = false;
294 gcc_assert (lexer->next_token->type != CPP_PURGED);
298 /* Create a new lexer whose token stream is primed with the tokens in
299 CACHE. When these tokens are exhausted, no new tokens will be read. */
302 cp_lexer_new_from_tokens (cp_token_cache *cache)
304 cp_token *first = cache->first;
305 cp_token *last = cache->last;
306 cp_lexer *lexer = GGC_CNEW (cp_lexer);
308 /* We do not own the buffer. */
309 lexer->buffer = NULL;
310 lexer->buffer_length = 0;
311 lexer->next_token = first == last ? (cp_token *)&eof_token : first;
312 lexer->last_token = last;
314 lexer->saved_tokens = VEC_alloc (cp_token_position, CP_SAVED_TOKEN_STACK);
316 #ifdef ENABLE_CHECKING
317 /* Initially we are not debugging. */
318 lexer->debugging_p = false;
321 gcc_assert (lexer->next_token->type != CPP_PURGED);
325 /* Frees all resources associated with LEXER. */
328 cp_lexer_destroy (cp_lexer *lexer)
331 ggc_free (lexer->buffer);
332 VEC_free (cp_token_position, lexer->saved_tokens);
336 /* Returns nonzero if debugging information should be output. */
338 #ifdef ENABLE_CHECKING
341 cp_lexer_debugging_p (cp_lexer *lexer)
343 return lexer->debugging_p;
346 #endif /* ENABLE_CHECKING */
348 static inline cp_token_position
349 cp_lexer_token_position (cp_lexer *lexer, bool previous_p)
351 gcc_assert (!previous_p || lexer->next_token != &eof_token);
353 return lexer->next_token - previous_p;
356 static inline cp_token *
357 cp_lexer_token_at (cp_lexer *lexer ATTRIBUTE_UNUSED, cp_token_position pos)
362 /* nonzero if we are presently saving tokens. */
365 cp_lexer_saving_tokens (const cp_lexer* lexer)
367 return VEC_length (cp_token_position, lexer->saved_tokens) != 0;
370 /* Store the next token from the preprocessor in *TOKEN. Return true
374 cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED ,
377 static int is_extern_c = 0;
379 /* Get a new token from the preprocessor. */
380 token->type = c_lex_with_flags (&token->value, &token->flags);
381 token->location = input_location;
382 token->in_system_header = in_system_header;
384 /* On some systems, some header files are surrounded by an
385 implicit extern "C" block. Set a flag in the token if it
386 comes from such a header. */
387 is_extern_c += pending_lang_change;
388 pending_lang_change = 0;
389 token->implicit_extern_c = is_extern_c > 0;
391 /* Check to see if this token is a keyword. */
392 if (token->type == CPP_NAME
393 && C_IS_RESERVED_WORD (token->value))
395 /* Mark this token as a keyword. */
396 token->type = CPP_KEYWORD;
397 /* Record which keyword. */
398 token->keyword = C_RID_CODE (token->value);
399 /* Update the value. Some keywords are mapped to particular
400 entities, rather than simply having the value of the
401 corresponding IDENTIFIER_NODE. For example, `__const' is
402 mapped to `const'. */
403 token->value = ridpointers[token->keyword];
406 token->keyword = RID_MAX;
409 /* Update the globals input_location and in_system_header from TOKEN. */
411 cp_lexer_set_source_position_from_token (cp_token *token)
413 if (token->type != CPP_EOF)
415 input_location = token->location;
416 in_system_header = token->in_system_header;
420 /* Return a pointer to the next token in the token stream, but do not
423 static inline cp_token *
424 cp_lexer_peek_token (cp_lexer *lexer)
426 if (cp_lexer_debugging_p (lexer))
428 fputs ("cp_lexer: peeking at token: ", cp_lexer_debug_stream);
429 cp_lexer_print_token (cp_lexer_debug_stream, lexer->next_token);
430 putc ('\n', cp_lexer_debug_stream);
432 return lexer->next_token;
435 /* Return true if the next token has the indicated TYPE. */
438 cp_lexer_next_token_is (cp_lexer* lexer, enum cpp_ttype type)
440 return cp_lexer_peek_token (lexer)->type == type;
443 /* Return true if the next token does not have the indicated TYPE. */
446 cp_lexer_next_token_is_not (cp_lexer* lexer, enum cpp_ttype type)
448 return !cp_lexer_next_token_is (lexer, type);
451 /* Return true if the next token is the indicated KEYWORD. */
454 cp_lexer_next_token_is_keyword (cp_lexer* lexer, enum rid keyword)
458 /* Peek at the next token. */
459 token = cp_lexer_peek_token (lexer);
460 /* Check to see if it is the indicated keyword. */
461 return token->keyword == keyword;
464 /* Return a pointer to the Nth token in the token stream. If N is 1,
465 then this is precisely equivalent to cp_lexer_peek_token (except
466 that it is not inline). One would like to disallow that case, but
467 there is one case (cp_parser_nth_token_starts_template_id) where
468 the caller passes a variable for N and it might be 1. */
471 cp_lexer_peek_nth_token (cp_lexer* lexer, size_t n)
475 /* N is 1-based, not zero-based. */
476 gcc_assert (n > 0 && lexer->next_token != &eof_token);
478 if (cp_lexer_debugging_p (lexer))
479 fprintf (cp_lexer_debug_stream,
480 "cp_lexer: peeking ahead %ld at token: ", (long)n);
483 token = lexer->next_token;
487 if (token == lexer->last_token)
489 token = (cp_token *)&eof_token;
493 if (token->type != CPP_PURGED)
497 if (cp_lexer_debugging_p (lexer))
499 cp_lexer_print_token (cp_lexer_debug_stream, token);
500 putc ('\n', cp_lexer_debug_stream);
506 /* Return the next token, and advance the lexer's next_token pointer
507 to point to the next non-purged token. */
510 cp_lexer_consume_token (cp_lexer* lexer)
512 cp_token *token = lexer->next_token;
514 gcc_assert (token != &eof_token);
519 if (lexer->next_token == lexer->last_token)
521 lexer->next_token = (cp_token *)&eof_token;
526 while (lexer->next_token->type == CPP_PURGED);
528 cp_lexer_set_source_position_from_token (token);
530 /* Provide debugging output. */
531 if (cp_lexer_debugging_p (lexer))
533 fputs ("cp_lexer: consuming token: ", cp_lexer_debug_stream);
534 cp_lexer_print_token (cp_lexer_debug_stream, token);
535 putc ('\n', cp_lexer_debug_stream);
541 /* Permanently remove the next token from the token stream, and
542 advance the next_token pointer to refer to the next non-purged
546 cp_lexer_purge_token (cp_lexer *lexer)
548 cp_token *tok = lexer->next_token;
550 gcc_assert (tok != &eof_token);
551 tok->type = CPP_PURGED;
552 tok->location = UNKNOWN_LOCATION;
553 tok->value = NULL_TREE;
554 tok->keyword = RID_MAX;
559 if (tok == lexer->last_token)
561 tok = (cp_token *)&eof_token;
565 while (tok->type == CPP_PURGED);
566 lexer->next_token = tok;
569 /* Permanently remove all tokens after TOK, up to, but not
570 including, the token that will be returned next by
571 cp_lexer_peek_token. */
574 cp_lexer_purge_tokens_after (cp_lexer *lexer, cp_token *tok)
576 cp_token *peek = lexer->next_token;
578 if (peek == &eof_token)
579 peek = lexer->last_token;
581 gcc_assert (tok < peek);
583 for ( tok += 1; tok != peek; tok += 1)
585 tok->type = CPP_PURGED;
586 tok->location = UNKNOWN_LOCATION;
587 tok->value = NULL_TREE;
588 tok->keyword = RID_MAX;
592 /* Consume and handle a pragma token. */
594 cp_lexer_handle_pragma (cp_lexer *lexer)
597 cp_token *token = cp_lexer_consume_token (lexer);
598 gcc_assert (token->type == CPP_PRAGMA);
599 gcc_assert (token->value);
601 s.len = TREE_STRING_LENGTH (token->value);
602 s.text = (const unsigned char *) TREE_STRING_POINTER (token->value);
604 cpp_handle_deferred_pragma (parse_in, &s);
606 /* Clearing token->value here means that we will get an ICE if we
607 try to process this #pragma again (which should be impossible). */
611 /* Begin saving tokens. All tokens consumed after this point will be
615 cp_lexer_save_tokens (cp_lexer* lexer)
617 /* Provide debugging output. */
618 if (cp_lexer_debugging_p (lexer))
619 fprintf (cp_lexer_debug_stream, "cp_lexer: saving tokens\n");
621 VEC_safe_push (cp_token_position, lexer->saved_tokens, lexer->next_token);
624 /* Commit to the portion of the token stream most recently saved. */
627 cp_lexer_commit_tokens (cp_lexer* lexer)
629 /* Provide debugging output. */
630 if (cp_lexer_debugging_p (lexer))
631 fprintf (cp_lexer_debug_stream, "cp_lexer: committing tokens\n");
633 VEC_pop (cp_token_position, lexer->saved_tokens);
636 /* Return all tokens saved since the last call to cp_lexer_save_tokens
637 to the token stream. Stop saving tokens. */
640 cp_lexer_rollback_tokens (cp_lexer* lexer)
642 /* Provide debugging output. */
643 if (cp_lexer_debugging_p (lexer))
644 fprintf (cp_lexer_debug_stream, "cp_lexer: restoring tokens\n");
646 lexer->next_token = VEC_pop (cp_token_position, lexer->saved_tokens);
649 /* Print a representation of the TOKEN on the STREAM. */
651 #ifdef ENABLE_CHECKING
654 cp_lexer_print_token (FILE * stream, cp_token *token)
656 /* We don't use cpp_type2name here because the parser defines
657 a few tokens of its own. */
658 static const char *const token_names[] = {
659 /* cpplib-defined token types */
665 /* C++ parser token types - see "Manifest constants", above. */
668 "NESTED_NAME_SPECIFIER",
672 /* If we have a name for the token, print it out. Otherwise, we
673 simply give the numeric code. */
674 gcc_assert (token->type < ARRAY_SIZE(token_names));
675 fputs (token_names[token->type], stream);
677 /* For some tokens, print the associated data. */
681 /* Some keywords have a value that is not an IDENTIFIER_NODE.
682 For example, `struct' is mapped to an INTEGER_CST. */
683 if (TREE_CODE (token->value) != IDENTIFIER_NODE)
685 /* else fall through */
687 fputs (IDENTIFIER_POINTER (token->value), stream);
693 fprintf (stream, " \"%s\"", TREE_STRING_POINTER (token->value));
701 /* Start emitting debugging information. */
704 cp_lexer_start_debugging (cp_lexer* lexer)
706 ++lexer->debugging_p;
709 /* Stop emitting debugging information. */
712 cp_lexer_stop_debugging (cp_lexer* lexer)
714 --lexer->debugging_p;
717 #endif /* ENABLE_CHECKING */
719 /* Create a new cp_token_cache, representing a range of tokens. */
721 static cp_token_cache *
722 cp_token_cache_new (cp_token *first, cp_token *last)
724 cp_token_cache *cache = GGC_NEW (cp_token_cache);
725 cache->first = first;
731 /* Decl-specifiers. */
733 static void clear_decl_specs
734 (cp_decl_specifier_seq *);
736 /* Set *DECL_SPECS to represent an empty decl-specifier-seq. */
739 clear_decl_specs (cp_decl_specifier_seq *decl_specs)
741 memset (decl_specs, 0, sizeof (cp_decl_specifier_seq));
746 /* Nothing other than the parser should be creating declarators;
747 declarators are a semi-syntactic representation of C++ entities.
748 Other parts of the front end that need to create entities (like
749 VAR_DECLs or FUNCTION_DECLs) should do that directly. */
751 static cp_declarator *make_call_declarator
752 (cp_declarator *, cp_parameter_declarator *, cp_cv_quals, tree);
753 static cp_declarator *make_array_declarator
754 (cp_declarator *, tree);
755 static cp_declarator *make_pointer_declarator
756 (cp_cv_quals, cp_declarator *);
757 static cp_declarator *make_reference_declarator
758 (cp_cv_quals, cp_declarator *);
759 static cp_parameter_declarator *make_parameter_declarator
760 (cp_decl_specifier_seq *, cp_declarator *, tree);
761 static cp_declarator *make_ptrmem_declarator
762 (cp_cv_quals, tree, cp_declarator *);
764 cp_declarator *cp_error_declarator;
766 /* The obstack on which declarators and related data structures are
768 static struct obstack declarator_obstack;
770 /* Alloc BYTES from the declarator memory pool. */
773 alloc_declarator (size_t bytes)
775 return obstack_alloc (&declarator_obstack, bytes);
778 /* Allocate a declarator of the indicated KIND. Clear fields that are
779 common to all declarators. */
781 static cp_declarator *
782 make_declarator (cp_declarator_kind kind)
784 cp_declarator *declarator;
786 declarator = (cp_declarator *) alloc_declarator (sizeof (cp_declarator));
787 declarator->kind = kind;
788 declarator->attributes = NULL_TREE;
789 declarator->declarator = NULL;
794 /* Make a declarator for a generalized identifier. If non-NULL, the
795 identifier is QUALIFYING_SCOPE::UNQUALIFIED_NAME; otherwise, it is
796 just UNQUALIFIED_NAME. */
798 static cp_declarator *
799 make_id_declarator (tree qualifying_scope, tree unqualified_name)
801 cp_declarator *declarator;
803 /* It is valid to write:
805 class C { void f(); };
809 The standard is not clear about whether `typedef const C D' is
810 legal; as of 2002-09-15 the committee is considering that
811 question. EDG 3.0 allows that syntax. Therefore, we do as
813 if (qualifying_scope && TYPE_P (qualifying_scope))
814 qualifying_scope = TYPE_MAIN_VARIANT (qualifying_scope);
816 declarator = make_declarator (cdk_id);
817 declarator->u.id.qualifying_scope = qualifying_scope;
818 declarator->u.id.unqualified_name = unqualified_name;
819 declarator->u.id.sfk = sfk_none;
824 /* Make a declarator for a pointer to TARGET. CV_QUALIFIERS is a list
825 of modifiers such as const or volatile to apply to the pointer
826 type, represented as identifiers. */
829 make_pointer_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
831 cp_declarator *declarator;
833 declarator = make_declarator (cdk_pointer);
834 declarator->declarator = target;
835 declarator->u.pointer.qualifiers = cv_qualifiers;
836 declarator->u.pointer.class_type = NULL_TREE;
841 /* Like make_pointer_declarator -- but for references. */
844 make_reference_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
846 cp_declarator *declarator;
848 declarator = make_declarator (cdk_reference);
849 declarator->declarator = target;
850 declarator->u.pointer.qualifiers = cv_qualifiers;
851 declarator->u.pointer.class_type = NULL_TREE;
856 /* Like make_pointer_declarator -- but for a pointer to a non-static
857 member of CLASS_TYPE. */
860 make_ptrmem_declarator (cp_cv_quals cv_qualifiers, tree class_type,
861 cp_declarator *pointee)
863 cp_declarator *declarator;
865 declarator = make_declarator (cdk_ptrmem);
866 declarator->declarator = pointee;
867 declarator->u.pointer.qualifiers = cv_qualifiers;
868 declarator->u.pointer.class_type = class_type;
873 /* Make a declarator for the function given by TARGET, with the
874 indicated PARMS. The CV_QUALIFIERS aply to the function, as in
875 "const"-qualified member function. The EXCEPTION_SPECIFICATION
876 indicates what exceptions can be thrown. */
879 make_call_declarator (cp_declarator *target,
880 cp_parameter_declarator *parms,
881 cp_cv_quals cv_qualifiers,
882 tree exception_specification)
884 cp_declarator *declarator;
886 declarator = make_declarator (cdk_function);
887 declarator->declarator = target;
888 declarator->u.function.parameters = parms;
889 declarator->u.function.qualifiers = cv_qualifiers;
890 declarator->u.function.exception_specification = exception_specification;
895 /* Make a declarator for an array of BOUNDS elements, each of which is
896 defined by ELEMENT. */
899 make_array_declarator (cp_declarator *element, tree bounds)
901 cp_declarator *declarator;
903 declarator = make_declarator (cdk_array);
904 declarator->declarator = element;
905 declarator->u.array.bounds = bounds;
910 cp_parameter_declarator *no_parameters;
912 /* Create a parameter declarator with the indicated DECL_SPECIFIERS,
913 DECLARATOR and DEFAULT_ARGUMENT. */
915 cp_parameter_declarator *
916 make_parameter_declarator (cp_decl_specifier_seq *decl_specifiers,
917 cp_declarator *declarator,
918 tree default_argument)
920 cp_parameter_declarator *parameter;
922 parameter = ((cp_parameter_declarator *)
923 alloc_declarator (sizeof (cp_parameter_declarator)));
924 parameter->next = NULL;
926 parameter->decl_specifiers = *decl_specifiers;
928 clear_decl_specs (¶meter->decl_specifiers);
929 parameter->declarator = declarator;
930 parameter->default_argument = default_argument;
931 parameter->ellipsis_p = false;
941 A cp_parser parses the token stream as specified by the C++
942 grammar. Its job is purely parsing, not semantic analysis. For
943 example, the parser breaks the token stream into declarators,
944 expressions, statements, and other similar syntactic constructs.
945 It does not check that the types of the expressions on either side
946 of an assignment-statement are compatible, or that a function is
947 not declared with a parameter of type `void'.
949 The parser invokes routines elsewhere in the compiler to perform
950 semantic analysis and to build up the abstract syntax tree for the
953 The parser (and the template instantiation code, which is, in a
954 way, a close relative of parsing) are the only parts of the
955 compiler that should be calling push_scope and pop_scope, or
956 related functions. The parser (and template instantiation code)
957 keeps track of what scope is presently active; everything else
958 should simply honor that. (The code that generates static
959 initializers may also need to set the scope, in order to check
960 access control correctly when emitting the initializers.)
965 The parser is of the standard recursive-descent variety. Upcoming
966 tokens in the token stream are examined in order to determine which
967 production to use when parsing a non-terminal. Some C++ constructs
968 require arbitrary look ahead to disambiguate. For example, it is
969 impossible, in the general case, to tell whether a statement is an
970 expression or declaration without scanning the entire statement.
971 Therefore, the parser is capable of "parsing tentatively." When the
972 parser is not sure what construct comes next, it enters this mode.
973 Then, while we attempt to parse the construct, the parser queues up
974 error messages, rather than issuing them immediately, and saves the
975 tokens it consumes. If the construct is parsed successfully, the
976 parser "commits", i.e., it issues any queued error messages and
977 the tokens that were being preserved are permanently discarded.
978 If, however, the construct is not parsed successfully, the parser
979 rolls back its state completely so that it can resume parsing using
980 a different alternative.
985 The performance of the parser could probably be improved substantially.
986 We could often eliminate the need to parse tentatively by looking ahead
987 a little bit. In some places, this approach might not entirely eliminate
988 the need to parse tentatively, but it might still speed up the average
991 /* Flags that are passed to some parsing functions. These values can
992 be bitwise-ored together. */
994 typedef enum cp_parser_flags
997 CP_PARSER_FLAGS_NONE = 0x0,
998 /* The construct is optional. If it is not present, then no error
1000 CP_PARSER_FLAGS_OPTIONAL = 0x1,
1001 /* When parsing a type-specifier, do not allow user-defined types. */
1002 CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES = 0x2
1005 /* The different kinds of declarators we want to parse. */
1007 typedef enum cp_parser_declarator_kind
1009 /* We want an abstract declarator. */
1010 CP_PARSER_DECLARATOR_ABSTRACT,
1011 /* We want a named declarator. */
1012 CP_PARSER_DECLARATOR_NAMED,
1013 /* We don't mind, but the name must be an unqualified-id. */
1014 CP_PARSER_DECLARATOR_EITHER
1015 } cp_parser_declarator_kind;
1017 /* The precedence values used to parse binary expressions. The minimum value
1018 of PREC must be 1, because zero is reserved to quickly discriminate
1019 binary operators from other tokens. */
1024 PREC_LOGICAL_OR_EXPRESSION,
1025 PREC_LOGICAL_AND_EXPRESSION,
1026 PREC_INCLUSIVE_OR_EXPRESSION,
1027 PREC_EXCLUSIVE_OR_EXPRESSION,
1028 PREC_AND_EXPRESSION,
1029 PREC_EQUALITY_EXPRESSION,
1030 PREC_RELATIONAL_EXPRESSION,
1031 PREC_SHIFT_EXPRESSION,
1032 PREC_ADDITIVE_EXPRESSION,
1033 PREC_MULTIPLICATIVE_EXPRESSION,
1035 NUM_PREC_VALUES = PREC_PM_EXPRESSION
1038 /* A mapping from a token type to a corresponding tree node type, with a
1039 precedence value. */
1041 typedef struct cp_parser_binary_operations_map_node
1043 /* The token type. */
1044 enum cpp_ttype token_type;
1045 /* The corresponding tree code. */
1046 enum tree_code tree_type;
1047 /* The precedence of this operator. */
1048 enum cp_parser_prec prec;
1049 } cp_parser_binary_operations_map_node;
1051 /* The status of a tentative parse. */
1053 typedef enum cp_parser_status_kind
1055 /* No errors have occurred. */
1056 CP_PARSER_STATUS_KIND_NO_ERROR,
1057 /* An error has occurred. */
1058 CP_PARSER_STATUS_KIND_ERROR,
1059 /* We are committed to this tentative parse, whether or not an error
1061 CP_PARSER_STATUS_KIND_COMMITTED
1062 } cp_parser_status_kind;
1064 typedef struct cp_parser_expression_stack_entry
1067 enum tree_code tree_type;
1069 } cp_parser_expression_stack_entry;
1071 /* The stack for storing partial expressions. We only need NUM_PREC_VALUES
1072 entries because precedence levels on the stack are monotonically
1074 typedef struct cp_parser_expression_stack_entry
1075 cp_parser_expression_stack[NUM_PREC_VALUES];
1077 /* Context that is saved and restored when parsing tentatively. */
1078 typedef struct cp_parser_context GTY (())
1080 /* If this is a tentative parsing context, the status of the
1082 enum cp_parser_status_kind status;
1083 /* If non-NULL, we have just seen a `x->' or `x.' expression. Names
1084 that are looked up in this context must be looked up both in the
1085 scope given by OBJECT_TYPE (the type of `x' or `*x') and also in
1086 the context of the containing expression. */
1089 /* The next parsing context in the stack. */
1090 struct cp_parser_context *next;
1091 } cp_parser_context;
1095 /* Constructors and destructors. */
1097 static cp_parser_context *cp_parser_context_new
1098 (cp_parser_context *);
1100 /* Class variables. */
1102 static GTY((deletable)) cp_parser_context* cp_parser_context_free_list;
1104 /* The operator-precedence table used by cp_parser_binary_expression.
1105 Transformed into an associative array (binops_by_token) by
1108 static const cp_parser_binary_operations_map_node binops[] = {
1109 { CPP_DEREF_STAR, MEMBER_REF, PREC_PM_EXPRESSION },
1110 { CPP_DOT_STAR, DOTSTAR_EXPR, PREC_PM_EXPRESSION },
1112 { CPP_MULT, MULT_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
1113 { CPP_DIV, TRUNC_DIV_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
1114 { CPP_MOD, TRUNC_MOD_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
1116 { CPP_PLUS, PLUS_EXPR, PREC_ADDITIVE_EXPRESSION },
1117 { CPP_MINUS, MINUS_EXPR, PREC_ADDITIVE_EXPRESSION },
1119 { CPP_LSHIFT, LSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
1120 { CPP_RSHIFT, RSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
1122 { CPP_LESS, LT_EXPR, PREC_RELATIONAL_EXPRESSION },
1123 { CPP_GREATER, GT_EXPR, PREC_RELATIONAL_EXPRESSION },
1124 { CPP_LESS_EQ, LE_EXPR, PREC_RELATIONAL_EXPRESSION },
1125 { CPP_GREATER_EQ, GE_EXPR, PREC_RELATIONAL_EXPRESSION },
1126 { CPP_MIN, MIN_EXPR, PREC_RELATIONAL_EXPRESSION },
1127 { CPP_MAX, MAX_EXPR, PREC_RELATIONAL_EXPRESSION },
1129 { CPP_EQ_EQ, EQ_EXPR, PREC_EQUALITY_EXPRESSION },
1130 { CPP_NOT_EQ, NE_EXPR, PREC_EQUALITY_EXPRESSION },
1132 { CPP_AND, BIT_AND_EXPR, PREC_AND_EXPRESSION },
1134 { CPP_XOR, BIT_XOR_EXPR, PREC_EXCLUSIVE_OR_EXPRESSION },
1136 { CPP_OR, BIT_IOR_EXPR, PREC_INCLUSIVE_OR_EXPRESSION },
1138 { CPP_AND_AND, TRUTH_ANDIF_EXPR, PREC_LOGICAL_AND_EXPRESSION },
1140 { CPP_OR_OR, TRUTH_ORIF_EXPR, PREC_LOGICAL_OR_EXPRESSION }
1143 /* The same as binops, but initialized by cp_parser_new so that
1144 binops_by_token[N].token_type == N. Used in cp_parser_binary_expression
1146 static cp_parser_binary_operations_map_node binops_by_token[N_CP_TTYPES];
1148 /* Constructors and destructors. */
1150 /* Construct a new context. The context below this one on the stack
1151 is given by NEXT. */
1153 static cp_parser_context *
1154 cp_parser_context_new (cp_parser_context* next)
1156 cp_parser_context *context;
1158 /* Allocate the storage. */
1159 if (cp_parser_context_free_list != NULL)
1161 /* Pull the first entry from the free list. */
1162 context = cp_parser_context_free_list;
1163 cp_parser_context_free_list = context->next;
1164 memset (context, 0, sizeof (*context));
1167 context = GGC_CNEW (cp_parser_context);
1169 /* No errors have occurred yet in this context. */
1170 context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
1171 /* If this is not the bottomost context, copy information that we
1172 need from the previous context. */
1175 /* If, in the NEXT context, we are parsing an `x->' or `x.'
1176 expression, then we are parsing one in this context, too. */
1177 context->object_type = next->object_type;
1178 /* Thread the stack. */
1179 context->next = next;
1185 /* The cp_parser structure represents the C++ parser. */
1187 typedef struct cp_parser GTY(())
1189 /* The lexer from which we are obtaining tokens. */
1192 /* The scope in which names should be looked up. If NULL_TREE, then
1193 we look up names in the scope that is currently open in the
1194 source program. If non-NULL, this is either a TYPE or
1195 NAMESPACE_DECL for the scope in which we should look.
1197 This value is not cleared automatically after a name is looked
1198 up, so we must be careful to clear it before starting a new look
1199 up sequence. (If it is not cleared, then `X::Y' followed by `Z'
1200 will look up `Z' in the scope of `X', rather than the current
1201 scope.) Unfortunately, it is difficult to tell when name lookup
1202 is complete, because we sometimes peek at a token, look it up,
1203 and then decide not to consume it. */
1206 /* OBJECT_SCOPE and QUALIFYING_SCOPE give the scopes in which the
1207 last lookup took place. OBJECT_SCOPE is used if an expression
1208 like "x->y" or "x.y" was used; it gives the type of "*x" or "x",
1209 respectively. QUALIFYING_SCOPE is used for an expression of the
1210 form "X::Y"; it refers to X. */
1212 tree qualifying_scope;
1214 /* A stack of parsing contexts. All but the bottom entry on the
1215 stack will be tentative contexts.
1217 We parse tentatively in order to determine which construct is in
1218 use in some situations. For example, in order to determine
1219 whether a statement is an expression-statement or a
1220 declaration-statement we parse it tentatively as a
1221 declaration-statement. If that fails, we then reparse the same
1222 token stream as an expression-statement. */
1223 cp_parser_context *context;
1225 /* True if we are parsing GNU C++. If this flag is not set, then
1226 GNU extensions are not recognized. */
1227 bool allow_gnu_extensions_p;
1229 /* TRUE if the `>' token should be interpreted as the greater-than
1230 operator. FALSE if it is the end of a template-id or
1231 template-parameter-list. */
1232 bool greater_than_is_operator_p;
1234 /* TRUE if default arguments are allowed within a parameter list
1235 that starts at this point. FALSE if only a gnu extension makes
1236 them permissible. */
1237 bool default_arg_ok_p;
1239 /* TRUE if we are parsing an integral constant-expression. See
1240 [expr.const] for a precise definition. */
1241 bool integral_constant_expression_p;
1243 /* TRUE if we are parsing an integral constant-expression -- but a
1244 non-constant expression should be permitted as well. This flag
1245 is used when parsing an array bound so that GNU variable-length
1246 arrays are tolerated. */
1247 bool allow_non_integral_constant_expression_p;
1249 /* TRUE if ALLOW_NON_CONSTANT_EXPRESSION_P is TRUE and something has
1250 been seen that makes the expression non-constant. */
1251 bool non_integral_constant_expression_p;
1253 /* TRUE if local variable names and `this' are forbidden in the
1255 bool local_variables_forbidden_p;
1257 /* TRUE if the declaration we are parsing is part of a
1258 linkage-specification of the form `extern string-literal
1260 bool in_unbraced_linkage_specification_p;
1262 /* TRUE if we are presently parsing a declarator, after the
1263 direct-declarator. */
1264 bool in_declarator_p;
1266 /* TRUE if we are presently parsing a template-argument-list. */
1267 bool in_template_argument_list_p;
1269 /* TRUE if we are presently parsing the body of an
1270 iteration-statement. */
1271 bool in_iteration_statement_p;
1273 /* TRUE if we are presently parsing the body of a switch
1275 bool in_switch_statement_p;
1277 /* TRUE if we are parsing a type-id in an expression context. In
1278 such a situation, both "type (expr)" and "type (type)" are valid
1280 bool in_type_id_in_expr_p;
1282 /* TRUE if we are currently in a header file where declarations are
1283 implicitly extern "C". */
1284 bool implicit_extern_c;
1286 /* TRUE if strings in expressions should be translated to the execution
1288 bool translate_strings_p;
1290 /* If non-NULL, then we are parsing a construct where new type
1291 definitions are not permitted. The string stored here will be
1292 issued as an error message if a type is defined. */
1293 const char *type_definition_forbidden_message;
1295 /* A list of lists. The outer list is a stack, used for member
1296 functions of local classes. At each level there are two sub-list,
1297 one on TREE_VALUE and one on TREE_PURPOSE. Each of those
1298 sub-lists has a FUNCTION_DECL or TEMPLATE_DECL on their
1299 TREE_VALUE's. The functions are chained in reverse declaration
1302 The TREE_PURPOSE sublist contains those functions with default
1303 arguments that need post processing, and the TREE_VALUE sublist
1304 contains those functions with definitions that need post
1307 These lists can only be processed once the outermost class being
1308 defined is complete. */
1309 tree unparsed_functions_queues;
1311 /* The number of classes whose definitions are currently in
1313 unsigned num_classes_being_defined;
1315 /* The number of template parameter lists that apply directly to the
1316 current declaration. */
1317 unsigned num_template_parameter_lists;
1320 /* The type of a function that parses some kind of expression. */
1321 typedef tree (*cp_parser_expression_fn) (cp_parser *);
1325 /* Constructors and destructors. */
1327 static cp_parser *cp_parser_new
1330 /* Routines to parse various constructs.
1332 Those that return `tree' will return the error_mark_node (rather
1333 than NULL_TREE) if a parse error occurs, unless otherwise noted.
1334 Sometimes, they will return an ordinary node if error-recovery was
1335 attempted, even though a parse error occurred. So, to check
1336 whether or not a parse error occurred, you should always use
1337 cp_parser_error_occurred. If the construct is optional (indicated
1338 either by an `_opt' in the name of the function that does the
1339 parsing or via a FLAGS parameter), then NULL_TREE is returned if
1340 the construct is not present. */
1342 /* Lexical conventions [gram.lex] */
1344 static tree cp_parser_identifier
1346 static tree cp_parser_string_literal
1347 (cp_parser *, bool, bool);
1349 /* Basic concepts [gram.basic] */
1351 static bool cp_parser_translation_unit
1354 /* Expressions [gram.expr] */
1356 static tree cp_parser_primary_expression
1357 (cp_parser *, cp_id_kind *, tree *);
1358 static tree cp_parser_id_expression
1359 (cp_parser *, bool, bool, bool *, bool);
1360 static tree cp_parser_unqualified_id
1361 (cp_parser *, bool, bool, bool);
1362 static tree cp_parser_nested_name_specifier_opt
1363 (cp_parser *, bool, bool, bool, bool);
1364 static tree cp_parser_nested_name_specifier
1365 (cp_parser *, bool, bool, bool, bool);
1366 static tree cp_parser_class_or_namespace_name
1367 (cp_parser *, bool, bool, bool, bool, bool);
1368 static tree cp_parser_postfix_expression
1369 (cp_parser *, bool);
1370 static tree cp_parser_postfix_open_square_expression
1371 (cp_parser *, tree, bool);
1372 static tree cp_parser_postfix_dot_deref_expression
1373 (cp_parser *, enum cpp_ttype, tree, bool, cp_id_kind *);
1374 static tree cp_parser_parenthesized_expression_list
1375 (cp_parser *, bool, bool *);
1376 static void cp_parser_pseudo_destructor_name
1377 (cp_parser *, tree *, tree *);
1378 static tree cp_parser_unary_expression
1379 (cp_parser *, bool);
1380 static enum tree_code cp_parser_unary_operator
1382 static tree cp_parser_new_expression
1384 static tree cp_parser_new_placement
1386 static tree cp_parser_new_type_id
1387 (cp_parser *, tree *);
1388 static cp_declarator *cp_parser_new_declarator_opt
1390 static cp_declarator *cp_parser_direct_new_declarator
1392 static tree cp_parser_new_initializer
1394 static tree cp_parser_delete_expression
1396 static tree cp_parser_cast_expression
1397 (cp_parser *, bool);
1398 static tree cp_parser_binary_expression
1400 static tree cp_parser_question_colon_clause
1401 (cp_parser *, tree);
1402 static tree cp_parser_assignment_expression
1404 static enum tree_code cp_parser_assignment_operator_opt
1406 static tree cp_parser_expression
1408 static tree cp_parser_constant_expression
1409 (cp_parser *, bool, bool *);
1410 static tree cp_parser_builtin_offsetof
1413 /* Statements [gram.stmt.stmt] */
1415 static void cp_parser_statement
1416 (cp_parser *, tree);
1417 static tree cp_parser_labeled_statement
1418 (cp_parser *, tree);
1419 static tree cp_parser_expression_statement
1420 (cp_parser *, tree);
1421 static tree cp_parser_compound_statement
1422 (cp_parser *, tree, bool);
1423 static void cp_parser_statement_seq_opt
1424 (cp_parser *, tree);
1425 static tree cp_parser_selection_statement
1427 static tree cp_parser_condition
1429 static tree cp_parser_iteration_statement
1431 static void cp_parser_for_init_statement
1433 static tree cp_parser_jump_statement
1435 static void cp_parser_declaration_statement
1438 static tree cp_parser_implicitly_scoped_statement
1440 static void cp_parser_already_scoped_statement
1443 /* Declarations [gram.dcl.dcl] */
1445 static void cp_parser_declaration_seq_opt
1447 static void cp_parser_declaration
1449 static void cp_parser_block_declaration
1450 (cp_parser *, bool);
1451 static void cp_parser_simple_declaration
1452 (cp_parser *, bool);
1453 static void cp_parser_decl_specifier_seq
1454 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, int *);
1455 static tree cp_parser_storage_class_specifier_opt
1457 static tree cp_parser_function_specifier_opt
1458 (cp_parser *, cp_decl_specifier_seq *);
1459 static tree cp_parser_type_specifier
1460 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, bool,
1462 static tree cp_parser_simple_type_specifier
1463 (cp_parser *, cp_decl_specifier_seq *, cp_parser_flags);
1464 static tree cp_parser_type_name
1466 static tree cp_parser_elaborated_type_specifier
1467 (cp_parser *, bool, bool);
1468 static tree cp_parser_enum_specifier
1470 static void cp_parser_enumerator_list
1471 (cp_parser *, tree);
1472 static void cp_parser_enumerator_definition
1473 (cp_parser *, tree);
1474 static tree cp_parser_namespace_name
1476 static void cp_parser_namespace_definition
1478 static void cp_parser_namespace_body
1480 static tree cp_parser_qualified_namespace_specifier
1482 static void cp_parser_namespace_alias_definition
1484 static void cp_parser_using_declaration
1486 static void cp_parser_using_directive
1488 static void cp_parser_asm_definition
1490 static void cp_parser_linkage_specification
1493 /* Declarators [gram.dcl.decl] */
1495 static tree cp_parser_init_declarator
1496 (cp_parser *, cp_decl_specifier_seq *, bool, bool, int, bool *);
1497 static cp_declarator *cp_parser_declarator
1498 (cp_parser *, cp_parser_declarator_kind, int *, bool *, bool);
1499 static cp_declarator *cp_parser_direct_declarator
1500 (cp_parser *, cp_parser_declarator_kind, int *, bool);
1501 static enum tree_code cp_parser_ptr_operator
1502 (cp_parser *, tree *, cp_cv_quals *);
1503 static cp_cv_quals cp_parser_cv_qualifier_seq_opt
1505 static tree cp_parser_declarator_id
1507 static tree cp_parser_type_id
1509 static void cp_parser_type_specifier_seq
1510 (cp_parser *, cp_decl_specifier_seq *);
1511 static cp_parameter_declarator *cp_parser_parameter_declaration_clause
1513 static cp_parameter_declarator *cp_parser_parameter_declaration_list
1514 (cp_parser *, bool *);
1515 static cp_parameter_declarator *cp_parser_parameter_declaration
1516 (cp_parser *, bool, bool *);
1517 static void cp_parser_function_body
1519 static tree cp_parser_initializer
1520 (cp_parser *, bool *, bool *);
1521 static tree cp_parser_initializer_clause
1522 (cp_parser *, bool *);
1523 static tree cp_parser_initializer_list
1524 (cp_parser *, bool *);
1526 static bool cp_parser_ctor_initializer_opt_and_function_body
1529 /* Classes [gram.class] */
1531 static tree cp_parser_class_name
1532 (cp_parser *, bool, bool, enum tag_types, bool, bool, bool);
1533 static tree cp_parser_class_specifier
1535 static tree cp_parser_class_head
1536 (cp_parser *, bool *, tree *);
1537 static enum tag_types cp_parser_class_key
1539 static void cp_parser_member_specification_opt
1541 static void cp_parser_member_declaration
1543 static tree cp_parser_pure_specifier
1545 static tree cp_parser_constant_initializer
1548 /* Derived classes [gram.class.derived] */
1550 static tree cp_parser_base_clause
1552 static tree cp_parser_base_specifier
1555 /* Special member functions [gram.special] */
1557 static tree cp_parser_conversion_function_id
1559 static tree cp_parser_conversion_type_id
1561 static cp_declarator *cp_parser_conversion_declarator_opt
1563 static bool cp_parser_ctor_initializer_opt
1565 static void cp_parser_mem_initializer_list
1567 static tree cp_parser_mem_initializer
1569 static tree cp_parser_mem_initializer_id
1572 /* Overloading [gram.over] */
1574 static tree cp_parser_operator_function_id
1576 static tree cp_parser_operator
1579 /* Templates [gram.temp] */
1581 static void cp_parser_template_declaration
1582 (cp_parser *, bool);
1583 static tree cp_parser_template_parameter_list
1585 static tree cp_parser_template_parameter
1586 (cp_parser *, bool *);
1587 static tree cp_parser_type_parameter
1589 static tree cp_parser_template_id
1590 (cp_parser *, bool, bool, bool);
1591 static tree cp_parser_template_name
1592 (cp_parser *, bool, bool, bool, bool *);
1593 static tree cp_parser_template_argument_list
1595 static tree cp_parser_template_argument
1597 static void cp_parser_explicit_instantiation
1599 static void cp_parser_explicit_specialization
1602 /* Exception handling [gram.exception] */
1604 static tree cp_parser_try_block
1606 static bool cp_parser_function_try_block
1608 static void cp_parser_handler_seq
1610 static void cp_parser_handler
1612 static tree cp_parser_exception_declaration
1614 static tree cp_parser_throw_expression
1616 static tree cp_parser_exception_specification_opt
1618 static tree cp_parser_type_id_list
1621 /* GNU Extensions */
1623 static tree cp_parser_asm_specification_opt
1625 static tree cp_parser_asm_operand_list
1627 static tree cp_parser_asm_clobber_list
1629 static tree cp_parser_attributes_opt
1631 static tree cp_parser_attribute_list
1633 static bool cp_parser_extension_opt
1634 (cp_parser *, int *);
1635 static void cp_parser_label_declaration
1638 /* Utility Routines */
1640 static tree cp_parser_lookup_name
1641 (cp_parser *, tree, enum tag_types, bool, bool, bool, bool *);
1642 static tree cp_parser_lookup_name_simple
1643 (cp_parser *, tree);
1644 static tree cp_parser_maybe_treat_template_as_class
1646 static bool cp_parser_check_declarator_template_parameters
1647 (cp_parser *, cp_declarator *);
1648 static bool cp_parser_check_template_parameters
1649 (cp_parser *, unsigned);
1650 static tree cp_parser_simple_cast_expression
1652 static tree cp_parser_global_scope_opt
1653 (cp_parser *, bool);
1654 static bool cp_parser_constructor_declarator_p
1655 (cp_parser *, bool);
1656 static tree cp_parser_function_definition_from_specifiers_and_declarator
1657 (cp_parser *, cp_decl_specifier_seq *, tree, const cp_declarator *);
1658 static tree cp_parser_function_definition_after_declarator
1659 (cp_parser *, bool);
1660 static void cp_parser_template_declaration_after_export
1661 (cp_parser *, bool);
1662 static tree cp_parser_single_declaration
1663 (cp_parser *, bool, bool *);
1664 static tree cp_parser_functional_cast
1665 (cp_parser *, tree);
1666 static tree cp_parser_save_member_function_body
1667 (cp_parser *, cp_decl_specifier_seq *, cp_declarator *, tree);
1668 static tree cp_parser_enclosed_template_argument_list
1670 static void cp_parser_save_default_args
1671 (cp_parser *, tree);
1672 static void cp_parser_late_parsing_for_member
1673 (cp_parser *, tree);
1674 static void cp_parser_late_parsing_default_args
1675 (cp_parser *, tree);
1676 static tree cp_parser_sizeof_operand
1677 (cp_parser *, enum rid);
1678 static bool cp_parser_declares_only_class_p
1680 static void cp_parser_set_storage_class
1681 (cp_decl_specifier_seq *, cp_storage_class);
1682 static void cp_parser_set_decl_spec_type
1683 (cp_decl_specifier_seq *, tree, bool);
1684 static bool cp_parser_friend_p
1685 (const cp_decl_specifier_seq *);
1686 static cp_token *cp_parser_require
1687 (cp_parser *, enum cpp_ttype, const char *);
1688 static cp_token *cp_parser_require_keyword
1689 (cp_parser *, enum rid, const char *);
1690 static bool cp_parser_token_starts_function_definition_p
1692 static bool cp_parser_next_token_starts_class_definition_p
1694 static bool cp_parser_next_token_ends_template_argument_p
1696 static bool cp_parser_nth_token_starts_template_argument_list_p
1697 (cp_parser *, size_t);
1698 static enum tag_types cp_parser_token_is_class_key
1700 static void cp_parser_check_class_key
1701 (enum tag_types, tree type);
1702 static void cp_parser_check_access_in_redeclaration
1704 static bool cp_parser_optional_template_keyword
1706 static void cp_parser_pre_parsed_nested_name_specifier
1708 static void cp_parser_cache_group
1709 (cp_parser *, enum cpp_ttype, unsigned);
1710 static void cp_parser_parse_tentatively
1712 static void cp_parser_commit_to_tentative_parse
1714 static void cp_parser_abort_tentative_parse
1716 static bool cp_parser_parse_definitely
1718 static inline bool cp_parser_parsing_tentatively
1720 static bool cp_parser_uncommitted_to_tentative_parse_p
1722 static void cp_parser_error
1723 (cp_parser *, const char *);
1724 static void cp_parser_name_lookup_error
1725 (cp_parser *, tree, tree, const char *);
1726 static bool cp_parser_simulate_error
1728 static void cp_parser_check_type_definition
1730 static void cp_parser_check_for_definition_in_return_type
1731 (cp_declarator *, tree);
1732 static void cp_parser_check_for_invalid_template_id
1733 (cp_parser *, tree);
1734 static bool cp_parser_non_integral_constant_expression
1735 (cp_parser *, const char *);
1736 static void cp_parser_diagnose_invalid_type_name
1737 (cp_parser *, tree, tree);
1738 static bool cp_parser_parse_and_diagnose_invalid_type_name
1740 static int cp_parser_skip_to_closing_parenthesis
1741 (cp_parser *, bool, bool, bool);
1742 static void cp_parser_skip_to_end_of_statement
1744 static void cp_parser_consume_semicolon_at_end_of_statement
1746 static void cp_parser_skip_to_end_of_block_or_statement
1748 static void cp_parser_skip_to_closing_brace
1750 static void cp_parser_skip_until_found
1751 (cp_parser *, enum cpp_ttype, const char *);
1752 static bool cp_parser_error_occurred
1754 static bool cp_parser_allow_gnu_extensions_p
1756 static bool cp_parser_is_string_literal
1758 static bool cp_parser_is_keyword
1759 (cp_token *, enum rid);
1760 static tree cp_parser_make_typename_type
1761 (cp_parser *, tree, tree);
1763 /* Returns nonzero if we are parsing tentatively. */
1766 cp_parser_parsing_tentatively (cp_parser* parser)
1768 return parser->context->next != NULL;
1771 /* Returns nonzero if TOKEN is a string literal. */
1774 cp_parser_is_string_literal (cp_token* token)
1776 return (token->type == CPP_STRING || token->type == CPP_WSTRING);
1779 /* Returns nonzero if TOKEN is the indicated KEYWORD. */
1782 cp_parser_is_keyword (cp_token* token, enum rid keyword)
1784 return token->keyword == keyword;
1787 /* If not parsing tentatively, issue a diagnostic of the form
1788 FILE:LINE: MESSAGE before TOKEN
1789 where TOKEN is the next token in the input stream. MESSAGE
1790 (specified by the caller) is usually of the form "expected
1794 cp_parser_error (cp_parser* parser, const char* message)
1796 if (!cp_parser_simulate_error (parser))
1798 cp_token *token = cp_lexer_peek_token (parser->lexer);
1799 /* This diagnostic makes more sense if it is tagged to the line
1800 of the token we just peeked at. */
1801 cp_lexer_set_source_position_from_token (token);
1802 if (token->type == CPP_PRAGMA)
1804 error ("%<#pragma%> is not allowed here");
1805 cp_lexer_purge_token (parser->lexer);
1808 c_parse_error (message,
1809 /* Because c_parser_error does not understand
1810 CPP_KEYWORD, keywords are treated like
1812 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
1817 /* Issue an error about name-lookup failing. NAME is the
1818 IDENTIFIER_NODE DECL is the result of
1819 the lookup (as returned from cp_parser_lookup_name). DESIRED is
1820 the thing that we hoped to find. */
1823 cp_parser_name_lookup_error (cp_parser* parser,
1826 const char* desired)
1828 /* If name lookup completely failed, tell the user that NAME was not
1830 if (decl == error_mark_node)
1832 if (parser->scope && parser->scope != global_namespace)
1833 error ("%<%D::%D%> has not been declared",
1834 parser->scope, name);
1835 else if (parser->scope == global_namespace)
1836 error ("%<::%D%> has not been declared", name);
1837 else if (parser->object_scope
1838 && !CLASS_TYPE_P (parser->object_scope))
1839 error ("request for member %qD in non-class type %qT",
1840 name, parser->object_scope);
1841 else if (parser->object_scope)
1842 error ("%<%T::%D%> has not been declared",
1843 parser->object_scope, name);
1845 error ("%qD has not been declared", name);
1847 else if (parser->scope && parser->scope != global_namespace)
1848 error ("%<%D::%D%> %s", parser->scope, name, desired);
1849 else if (parser->scope == global_namespace)
1850 error ("%<::%D%> %s", name, desired);
1852 error ("%qD %s", name, desired);
1855 /* If we are parsing tentatively, remember that an error has occurred
1856 during this tentative parse. Returns true if the error was
1857 simulated; false if a message should be issued by the caller. */
1860 cp_parser_simulate_error (cp_parser* parser)
1862 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
1864 parser->context->status = CP_PARSER_STATUS_KIND_ERROR;
1870 /* This function is called when a type is defined. If type
1871 definitions are forbidden at this point, an error message is
1875 cp_parser_check_type_definition (cp_parser* parser)
1877 /* If types are forbidden here, issue a message. */
1878 if (parser->type_definition_forbidden_message)
1879 /* Use `%s' to print the string in case there are any escape
1880 characters in the message. */
1881 error ("%s", parser->type_definition_forbidden_message);
1884 /* This function is called when the DECLARATOR is processed. The TYPE
1885 was a type defined in the decl-specifiers. If it is invalid to
1886 define a type in the decl-specifiers for DECLARATOR, an error is
1890 cp_parser_check_for_definition_in_return_type (cp_declarator *declarator,
1893 /* [dcl.fct] forbids type definitions in return types.
1894 Unfortunately, it's not easy to know whether or not we are
1895 processing a return type until after the fact. */
1897 && (declarator->kind == cdk_pointer
1898 || declarator->kind == cdk_reference
1899 || declarator->kind == cdk_ptrmem))
1900 declarator = declarator->declarator;
1902 && declarator->kind == cdk_function)
1904 error ("new types may not be defined in a return type");
1905 inform ("(perhaps a semicolon is missing after the definition of %qT)",
1910 /* A type-specifier (TYPE) has been parsed which cannot be followed by
1911 "<" in any valid C++ program. If the next token is indeed "<",
1912 issue a message warning the user about what appears to be an
1913 invalid attempt to form a template-id. */
1916 cp_parser_check_for_invalid_template_id (cp_parser* parser,
1919 cp_token_position start = 0;
1921 if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
1924 error ("%qT is not a template", type);
1925 else if (TREE_CODE (type) == IDENTIFIER_NODE)
1926 error ("%qE is not a template", type);
1928 error ("invalid template-id");
1929 /* Remember the location of the invalid "<". */
1930 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
1931 start = cp_lexer_token_position (parser->lexer, true);
1932 /* Consume the "<". */
1933 cp_lexer_consume_token (parser->lexer);
1934 /* Parse the template arguments. */
1935 cp_parser_enclosed_template_argument_list (parser);
1936 /* Permanently remove the invalid template arguments so that
1937 this error message is not issued again. */
1939 cp_lexer_purge_tokens_after (parser->lexer, start);
1943 /* If parsing an integral constant-expression, issue an error message
1944 about the fact that THING appeared and return true. Otherwise,
1945 return false, marking the current expression as non-constant. */
1948 cp_parser_non_integral_constant_expression (cp_parser *parser,
1951 if (parser->integral_constant_expression_p)
1953 if (!parser->allow_non_integral_constant_expression_p)
1955 error ("%s cannot appear in a constant-expression", thing);
1958 parser->non_integral_constant_expression_p = true;
1963 /* Emit a diagnostic for an invalid type name. SCOPE is the
1964 qualifying scope (or NULL, if none) for ID. */
1967 cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
1969 tree decl, old_scope;
1970 /* Try to lookup the identifier. */
1971 old_scope = parser->scope;
1972 parser->scope = scope;
1973 decl = cp_parser_lookup_name_simple (parser, id);
1974 parser->scope = old_scope;
1975 /* If the lookup found a template-name, it means that the user forgot
1976 to specify an argument list. Emit an useful error message. */
1977 if (TREE_CODE (decl) == TEMPLATE_DECL)
1978 error ("invalid use of template-name %qE without an argument list",
1980 else if (!parser->scope)
1982 /* Issue an error message. */
1983 error ("%qE does not name a type", id);
1984 /* If we're in a template class, it's possible that the user was
1985 referring to a type from a base class. For example:
1987 template <typename T> struct A { typedef T X; };
1988 template <typename T> struct B : public A<T> { X x; };
1990 The user should have said "typename A<T>::X". */
1991 if (processing_template_decl && current_class_type)
1995 for (b = TREE_CHAIN (TYPE_BINFO (current_class_type));
1999 tree base_type = BINFO_TYPE (b);
2000 if (CLASS_TYPE_P (base_type)
2001 && dependent_type_p (base_type))
2004 /* Go from a particular instantiation of the
2005 template (which will have an empty TYPE_FIELDs),
2006 to the main version. */
2007 base_type = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (base_type);
2008 for (field = TYPE_FIELDS (base_type);
2010 field = TREE_CHAIN (field))
2011 if (TREE_CODE (field) == TYPE_DECL
2012 && DECL_NAME (field) == id)
2014 inform ("(perhaps %<typename %T::%E%> was intended)",
2015 BINFO_TYPE (b), id);
2024 /* Here we diagnose qualified-ids where the scope is actually correct,
2025 but the identifier does not resolve to a valid type name. */
2028 if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
2029 error ("%qE in namespace %qE does not name a type",
2031 else if (TYPE_P (parser->scope))
2032 error ("%qE in class %qT does not name a type", id, parser->scope);
2038 /* Check for a common situation where a type-name should be present,
2039 but is not, and issue a sensible error message. Returns true if an
2040 invalid type-name was detected.
2042 The situation handled by this function are variable declarations of the
2043 form `ID a', where `ID' is an id-expression and `a' is a plain identifier.
2044 Usually, `ID' should name a type, but if we got here it means that it
2045 does not. We try to emit the best possible error message depending on
2046 how exactly the id-expression looks like.
2050 cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
2054 cp_parser_parse_tentatively (parser);
2055 id = cp_parser_id_expression (parser,
2056 /*template_keyword_p=*/false,
2057 /*check_dependency_p=*/true,
2058 /*template_p=*/NULL,
2059 /*declarator_p=*/true);
2060 /* After the id-expression, there should be a plain identifier,
2061 otherwise this is not a simple variable declaration. Also, if
2062 the scope is dependent, we cannot do much. */
2063 if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)
2064 || (parser->scope && TYPE_P (parser->scope)
2065 && dependent_type_p (parser->scope)))
2067 cp_parser_abort_tentative_parse (parser);
2070 if (!cp_parser_parse_definitely (parser)
2071 || TREE_CODE (id) != IDENTIFIER_NODE)
2074 /* Emit a diagnostic for the invalid type. */
2075 cp_parser_diagnose_invalid_type_name (parser, parser->scope, id);
2076 /* Skip to the end of the declaration; there's no point in
2077 trying to process it. */
2078 cp_parser_skip_to_end_of_block_or_statement (parser);
2082 /* Consume tokens up to, and including, the next non-nested closing `)'.
2083 Returns 1 iff we found a closing `)'. RECOVERING is true, if we
2084 are doing error recovery. Returns -1 if OR_COMMA is true and we
2085 found an unnested comma. */
2088 cp_parser_skip_to_closing_parenthesis (cp_parser *parser,
2093 unsigned paren_depth = 0;
2094 unsigned brace_depth = 0;
2097 if (recovering && !or_comma
2098 && cp_parser_uncommitted_to_tentative_parse_p (parser))
2105 /* If we've run out of tokens, then there is no closing `)'. */
2106 if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
2112 token = cp_lexer_peek_token (parser->lexer);
2114 /* This matches the processing in skip_to_end_of_statement. */
2115 if (token->type == CPP_SEMICOLON && !brace_depth)
2120 if (token->type == CPP_OPEN_BRACE)
2122 if (token->type == CPP_CLOSE_BRACE)
2130 if (recovering && or_comma && token->type == CPP_COMMA
2131 && !brace_depth && !paren_depth)
2139 /* If it is an `(', we have entered another level of nesting. */
2140 if (token->type == CPP_OPEN_PAREN)
2142 /* If it is a `)', then we might be done. */
2143 else if (token->type == CPP_CLOSE_PAREN && !paren_depth--)
2146 cp_lexer_consume_token (parser->lexer);
2154 /* Consume the token. */
2155 cp_lexer_consume_token (parser->lexer);
2161 /* Consume tokens until we reach the end of the current statement.
2162 Normally, that will be just before consuming a `;'. However, if a
2163 non-nested `}' comes first, then we stop before consuming that. */
2166 cp_parser_skip_to_end_of_statement (cp_parser* parser)
2168 unsigned nesting_depth = 0;
2174 /* Peek at the next token. */
2175 token = cp_lexer_peek_token (parser->lexer);
2176 /* If we've run out of tokens, stop. */
2177 if (token->type == CPP_EOF)
2179 /* If the next token is a `;', we have reached the end of the
2181 if (token->type == CPP_SEMICOLON && !nesting_depth)
2183 /* If the next token is a non-nested `}', then we have reached
2184 the end of the current block. */
2185 if (token->type == CPP_CLOSE_BRACE)
2187 /* If this is a non-nested `}', stop before consuming it.
2188 That way, when confronted with something like:
2192 we stop before consuming the closing `}', even though we
2193 have not yet reached a `;'. */
2194 if (nesting_depth == 0)
2196 /* If it is the closing `}' for a block that we have
2197 scanned, stop -- but only after consuming the token.
2203 we will stop after the body of the erroneously declared
2204 function, but before consuming the following `typedef'
2206 if (--nesting_depth == 0)
2208 cp_lexer_consume_token (parser->lexer);
2212 /* If it the next token is a `{', then we are entering a new
2213 block. Consume the entire block. */
2214 else if (token->type == CPP_OPEN_BRACE)
2216 /* Consume the token. */
2217 cp_lexer_consume_token (parser->lexer);
2221 /* This function is called at the end of a statement or declaration.
2222 If the next token is a semicolon, it is consumed; otherwise, error
2223 recovery is attempted. */
2226 cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser)
2228 /* Look for the trailing `;'. */
2229 if (!cp_parser_require (parser, CPP_SEMICOLON, "`;'"))
2231 /* If there is additional (erroneous) input, skip to the end of
2233 cp_parser_skip_to_end_of_statement (parser);
2234 /* If the next token is now a `;', consume it. */
2235 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
2236 cp_lexer_consume_token (parser->lexer);
2240 /* Skip tokens until we have consumed an entire block, or until we
2241 have consumed a non-nested `;'. */
2244 cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
2246 unsigned nesting_depth = 0;
2252 /* Peek at the next token. */
2253 token = cp_lexer_peek_token (parser->lexer);
2254 /* If we've run out of tokens, stop. */
2255 if (token->type == CPP_EOF)
2257 /* If the next token is a `;', we have reached the end of the
2259 if (token->type == CPP_SEMICOLON && !nesting_depth)
2261 /* Consume the `;'. */
2262 cp_lexer_consume_token (parser->lexer);
2265 /* Consume the token. */
2266 token = cp_lexer_consume_token (parser->lexer);
2267 /* If the next token is a non-nested `}', then we have reached
2268 the end of the current block. */
2269 if (token->type == CPP_CLOSE_BRACE
2270 && (nesting_depth == 0 || --nesting_depth == 0))
2272 /* If it the next token is a `{', then we are entering a new
2273 block. Consume the entire block. */
2274 if (token->type == CPP_OPEN_BRACE)
2279 /* Skip tokens until a non-nested closing curly brace is the next
2283 cp_parser_skip_to_closing_brace (cp_parser *parser)
2285 unsigned nesting_depth = 0;
2291 /* Peek at the next token. */
2292 token = cp_lexer_peek_token (parser->lexer);
2293 /* If we've run out of tokens, stop. */
2294 if (token->type == CPP_EOF)
2296 /* If the next token is a non-nested `}', then we have reached
2297 the end of the current block. */
2298 if (token->type == CPP_CLOSE_BRACE && nesting_depth-- == 0)
2300 /* If it the next token is a `{', then we are entering a new
2301 block. Consume the entire block. */
2302 else if (token->type == CPP_OPEN_BRACE)
2304 /* Consume the token. */
2305 cp_lexer_consume_token (parser->lexer);
2309 /* This is a simple wrapper around make_typename_type. When the id is
2310 an unresolved identifier node, we can provide a superior diagnostic
2311 using cp_parser_diagnose_invalid_type_name. */
2314 cp_parser_make_typename_type (cp_parser *parser, tree scope, tree id)
2317 if (TREE_CODE (id) == IDENTIFIER_NODE)
2319 result = make_typename_type (scope, id, typename_type,
2321 if (result == error_mark_node)
2322 cp_parser_diagnose_invalid_type_name (parser, scope, id);
2325 return make_typename_type (scope, id, typename_type, tf_error);
2329 /* Create a new C++ parser. */
2332 cp_parser_new (void)
2338 /* cp_lexer_new_main is called before calling ggc_alloc because
2339 cp_lexer_new_main might load a PCH file. */
2340 lexer = cp_lexer_new_main ();
2342 /* Initialize the binops_by_token so that we can get the tree
2343 directly from the token. */
2344 for (i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
2345 binops_by_token[binops[i].token_type] = binops[i];
2347 parser = GGC_CNEW (cp_parser);
2348 parser->lexer = lexer;
2349 parser->context = cp_parser_context_new (NULL);
2351 /* For now, we always accept GNU extensions. */
2352 parser->allow_gnu_extensions_p = 1;
2354 /* The `>' token is a greater-than operator, not the end of a
2356 parser->greater_than_is_operator_p = true;
2358 parser->default_arg_ok_p = true;
2360 /* We are not parsing a constant-expression. */
2361 parser->integral_constant_expression_p = false;
2362 parser->allow_non_integral_constant_expression_p = false;
2363 parser->non_integral_constant_expression_p = false;
2365 /* Local variable names are not forbidden. */
2366 parser->local_variables_forbidden_p = false;
2368 /* We are not processing an `extern "C"' declaration. */
2369 parser->in_unbraced_linkage_specification_p = false;
2371 /* We are not processing a declarator. */
2372 parser->in_declarator_p = false;
2374 /* We are not processing a template-argument-list. */
2375 parser->in_template_argument_list_p = false;
2377 /* We are not in an iteration statement. */
2378 parser->in_iteration_statement_p = false;
2380 /* We are not in a switch statement. */
2381 parser->in_switch_statement_p = false;
2383 /* We are not parsing a type-id inside an expression. */
2384 parser->in_type_id_in_expr_p = false;
2386 /* Declarations aren't implicitly extern "C". */
2387 parser->implicit_extern_c = false;
2389 /* String literals should be translated to the execution character set. */
2390 parser->translate_strings_p = true;
2392 /* The unparsed function queue is empty. */
2393 parser->unparsed_functions_queues = build_tree_list (NULL_TREE, NULL_TREE);
2395 /* There are no classes being defined. */
2396 parser->num_classes_being_defined = 0;
2398 /* No template parameters apply. */
2399 parser->num_template_parameter_lists = 0;
2404 /* Create a cp_lexer structure which will emit the tokens in CACHE
2405 and push it onto the parser's lexer stack. This is used for delayed
2406 parsing of in-class method bodies and default arguments, and should
2407 not be confused with tentative parsing. */
2409 cp_parser_push_lexer_for_tokens (cp_parser *parser, cp_token_cache *cache)
2411 cp_lexer *lexer = cp_lexer_new_from_tokens (cache);
2412 lexer->next = parser->lexer;
2413 parser->lexer = lexer;
2415 /* Move the current source position to that of the first token in the
2417 cp_lexer_set_source_position_from_token (lexer->next_token);
2420 /* Pop the top lexer off the parser stack. This is never used for the
2421 "main" lexer, only for those pushed by cp_parser_push_lexer_for_tokens. */
2423 cp_parser_pop_lexer (cp_parser *parser)
2425 cp_lexer *lexer = parser->lexer;
2426 parser->lexer = lexer->next;
2427 cp_lexer_destroy (lexer);
2429 /* Put the current source position back where it was before this
2430 lexer was pushed. */
2431 cp_lexer_set_source_position_from_token (parser->lexer->next_token);
2434 /* Lexical conventions [gram.lex] */
2436 /* Parse an identifier. Returns an IDENTIFIER_NODE representing the
2440 cp_parser_identifier (cp_parser* parser)
2444 /* Look for the identifier. */
2445 token = cp_parser_require (parser, CPP_NAME, "identifier");
2446 /* Return the value. */
2447 return token ? token->value : error_mark_node;
2450 /* Parse a sequence of adjacent string constants. Returns a
2451 TREE_STRING representing the combined, nul-terminated string
2452 constant. If TRANSLATE is true, translate the string to the
2453 execution character set. If WIDE_OK is true, a wide string is
2456 C++98 [lex.string] says that if a narrow string literal token is
2457 adjacent to a wide string literal token, the behavior is undefined.
2458 However, C99 6.4.5p4 says that this results in a wide string literal.
2459 We follow C99 here, for consistency with the C front end.
2461 This code is largely lifted from lex_string() in c-lex.c.
2463 FUTURE: ObjC++ will need to handle @-strings here. */
2465 cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
2470 struct obstack str_ob;
2471 cpp_string str, istr, *strs;
2474 tok = cp_lexer_peek_token (parser->lexer);
2475 if (!cp_parser_is_string_literal (tok))
2477 cp_parser_error (parser, "expected string-literal");
2478 return error_mark_node;
2481 /* Try to avoid the overhead of creating and destroying an obstack
2482 for the common case of just one string. */
2483 if (!cp_parser_is_string_literal
2484 (cp_lexer_peek_nth_token (parser->lexer, 2)))
2486 cp_lexer_consume_token (parser->lexer);
2488 str.text = (const unsigned char *)TREE_STRING_POINTER (tok->value);
2489 str.len = TREE_STRING_LENGTH (tok->value);
2491 if (tok->type == CPP_WSTRING)
2498 gcc_obstack_init (&str_ob);
2503 cp_lexer_consume_token (parser->lexer);
2505 str.text = (unsigned char *)TREE_STRING_POINTER (tok->value);
2506 str.len = TREE_STRING_LENGTH (tok->value);
2507 if (tok->type == CPP_WSTRING)
2510 obstack_grow (&str_ob, &str, sizeof (cpp_string));
2512 tok = cp_lexer_peek_token (parser->lexer);
2514 while (cp_parser_is_string_literal (tok));
2516 strs = (cpp_string *) obstack_finish (&str_ob);
2519 if (wide && !wide_ok)
2521 cp_parser_error (parser, "a wide string is invalid in this context");
2525 if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
2526 (parse_in, strs, count, &istr, wide))
2528 value = build_string (istr.len, (char *)istr.text);
2529 free ((void *)istr.text);
2531 TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node;
2532 value = fix_string_type (value);
2535 /* cpp_interpret_string has issued an error. */
2536 value = error_mark_node;
2539 obstack_free (&str_ob, 0);
2545 /* Basic concepts [gram.basic] */
2547 /* Parse a translation-unit.
2550 declaration-seq [opt]
2552 Returns TRUE if all went well. */
2555 cp_parser_translation_unit (cp_parser* parser)
2557 /* The address of the first non-permanent object on the declarator
2559 static void *declarator_obstack_base;
2563 /* Create the declarator obstack, if necessary. */
2564 if (!cp_error_declarator)
2566 gcc_obstack_init (&declarator_obstack);
2567 /* Create the error declarator. */
2568 cp_error_declarator = make_declarator (cdk_error);
2569 /* Create the empty parameter list. */
2570 no_parameters = make_parameter_declarator (NULL, NULL, NULL_TREE);
2571 /* Remember where the base of the declarator obstack lies. */
2572 declarator_obstack_base = obstack_next_free (&declarator_obstack);
2577 cp_parser_declaration_seq_opt (parser);
2579 /* If there are no tokens left then all went well. */
2580 if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
2582 /* Get rid of the token array; we don't need it any more. */
2583 cp_lexer_destroy (parser->lexer);
2584 parser->lexer = NULL;
2586 /* This file might have been a context that's implicitly extern
2587 "C". If so, pop the lang context. (Only relevant for PCH.) */
2588 if (parser->implicit_extern_c)
2590 pop_lang_context ();
2591 parser->implicit_extern_c = false;
2595 finish_translation_unit ();
2602 cp_parser_error (parser, "expected declaration");
2608 /* Make sure the declarator obstack was fully cleaned up. */
2609 gcc_assert (obstack_next_free (&declarator_obstack)
2610 == declarator_obstack_base);
2612 /* All went well. */
2616 /* Expressions [gram.expr] */
2618 /* Parse a primary-expression.
2629 ( compound-statement )
2630 __builtin_va_arg ( assignment-expression , type-id )
2635 Returns a representation of the expression.
2637 *IDK indicates what kind of id-expression (if any) was present.
2639 *QUALIFYING_CLASS is set to a non-NULL value if the id-expression can be
2640 used as the operand of a pointer-to-member. In that case,
2641 *QUALIFYING_CLASS gives the class that is used as the qualifying
2642 class in the pointer-to-member. */
2645 cp_parser_primary_expression (cp_parser *parser,
2647 tree *qualifying_class)
2651 /* Assume the primary expression is not an id-expression. */
2652 *idk = CP_ID_KIND_NONE;
2653 /* And that it cannot be used as pointer-to-member. */
2654 *qualifying_class = NULL_TREE;
2656 /* Peek at the next token. */
2657 token = cp_lexer_peek_token (parser->lexer);
2658 switch (token->type)
2669 token = cp_lexer_consume_token (parser->lexer);
2670 return token->value;
2674 /* ??? Should wide strings be allowed when parser->translate_strings_p
2675 is false (i.e. in attributes)? If not, we can kill the third
2676 argument to cp_parser_string_literal. */
2677 return cp_parser_string_literal (parser,
2678 parser->translate_strings_p,
2681 case CPP_OPEN_PAREN:
2684 bool saved_greater_than_is_operator_p;
2686 /* Consume the `('. */
2687 cp_lexer_consume_token (parser->lexer);
2688 /* Within a parenthesized expression, a `>' token is always
2689 the greater-than operator. */
2690 saved_greater_than_is_operator_p
2691 = parser->greater_than_is_operator_p;
2692 parser->greater_than_is_operator_p = true;
2693 /* If we see `( { ' then we are looking at the beginning of
2694 a GNU statement-expression. */
2695 if (cp_parser_allow_gnu_extensions_p (parser)
2696 && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
2698 /* Statement-expressions are not allowed by the standard. */
2700 pedwarn ("ISO C++ forbids braced-groups within expressions");
2702 /* And they're not allowed outside of a function-body; you
2703 cannot, for example, write:
2705 int i = ({ int j = 3; j + 1; });
2707 at class or namespace scope. */
2708 if (!at_function_scope_p ())
2709 error ("statement-expressions are allowed only inside functions");
2710 /* Start the statement-expression. */
2711 expr = begin_stmt_expr ();
2712 /* Parse the compound-statement. */
2713 cp_parser_compound_statement (parser, expr, false);
2715 expr = finish_stmt_expr (expr, false);
2719 /* Parse the parenthesized expression. */
2720 expr = cp_parser_expression (parser);
2721 /* Let the front end know that this expression was
2722 enclosed in parentheses. This matters in case, for
2723 example, the expression is of the form `A::B', since
2724 `&A::B' might be a pointer-to-member, but `&(A::B)' is
2726 finish_parenthesized_expr (expr);
2728 /* The `>' token might be the end of a template-id or
2729 template-parameter-list now. */
2730 parser->greater_than_is_operator_p
2731 = saved_greater_than_is_operator_p;
2732 /* Consume the `)'. */
2733 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
2734 cp_parser_skip_to_end_of_statement (parser);
2740 switch (token->keyword)
2742 /* These two are the boolean literals. */
2744 cp_lexer_consume_token (parser->lexer);
2745 return boolean_true_node;
2747 cp_lexer_consume_token (parser->lexer);
2748 return boolean_false_node;
2750 /* The `__null' literal. */
2752 cp_lexer_consume_token (parser->lexer);
2755 /* Recognize the `this' keyword. */
2757 cp_lexer_consume_token (parser->lexer);
2758 if (parser->local_variables_forbidden_p)
2760 error ("%<this%> may not be used in this context");
2761 return error_mark_node;
2763 /* Pointers cannot appear in constant-expressions. */
2764 if (cp_parser_non_integral_constant_expression (parser,
2766 return error_mark_node;
2767 return finish_this_expr ();
2769 /* The `operator' keyword can be the beginning of an
2774 case RID_FUNCTION_NAME:
2775 case RID_PRETTY_FUNCTION_NAME:
2776 case RID_C99_FUNCTION_NAME:
2777 /* The symbols __FUNCTION__, __PRETTY_FUNCTION__, and
2778 __func__ are the names of variables -- but they are
2779 treated specially. Therefore, they are handled here,
2780 rather than relying on the generic id-expression logic
2781 below. Grammatically, these names are id-expressions.
2783 Consume the token. */
2784 token = cp_lexer_consume_token (parser->lexer);
2785 /* Look up the name. */
2786 return finish_fname (token->value);
2793 /* The `__builtin_va_arg' construct is used to handle
2794 `va_arg'. Consume the `__builtin_va_arg' token. */
2795 cp_lexer_consume_token (parser->lexer);
2796 /* Look for the opening `('. */
2797 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
2798 /* Now, parse the assignment-expression. */
2799 expression = cp_parser_assignment_expression (parser);
2800 /* Look for the `,'. */
2801 cp_parser_require (parser, CPP_COMMA, "`,'");
2802 /* Parse the type-id. */
2803 type = cp_parser_type_id (parser);
2804 /* Look for the closing `)'. */
2805 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
2806 /* Using `va_arg' in a constant-expression is not
2808 if (cp_parser_non_integral_constant_expression (parser,
2810 return error_mark_node;
2811 return build_x_va_arg (expression, type);
2815 return cp_parser_builtin_offsetof (parser);
2818 cp_parser_error (parser, "expected primary-expression");
2819 return error_mark_node;
2822 /* An id-expression can start with either an identifier, a
2823 `::' as the beginning of a qualified-id, or the "operator"
2827 case CPP_TEMPLATE_ID:
2828 case CPP_NESTED_NAME_SPECIFIER:
2832 const char *error_msg;
2835 /* Parse the id-expression. */
2837 = cp_parser_id_expression (parser,
2838 /*template_keyword_p=*/false,
2839 /*check_dependency_p=*/true,
2840 /*template_p=*/NULL,
2841 /*declarator_p=*/false);
2842 if (id_expression == error_mark_node)
2843 return error_mark_node;
2844 /* If we have a template-id, then no further lookup is
2845 required. If the template-id was for a template-class, we
2846 will sometimes have a TYPE_DECL at this point. */
2847 else if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR
2848 || TREE_CODE (id_expression) == TYPE_DECL)
2849 decl = id_expression;
2850 /* Look up the name. */
2855 decl = cp_parser_lookup_name (parser, id_expression,
2857 /*is_template=*/false,
2858 /*is_namespace=*/false,
2859 /*check_dependency=*/true,
2861 /* If the lookup was ambiguous, an error will already have
2864 return error_mark_node;
2865 /* If name lookup gives us a SCOPE_REF, then the
2866 qualifying scope was dependent. Just propagate the
2868 if (TREE_CODE (decl) == SCOPE_REF)
2870 if (TYPE_P (TREE_OPERAND (decl, 0)))
2871 *qualifying_class = TREE_OPERAND (decl, 0);
2874 /* Check to see if DECL is a local variable in a context
2875 where that is forbidden. */
2876 if (parser->local_variables_forbidden_p
2877 && local_variable_p (decl))
2879 /* It might be that we only found DECL because we are
2880 trying to be generous with pre-ISO scoping rules.
2881 For example, consider:
2885 for (int i = 0; i < 10; ++i) {}
2886 extern void f(int j = i);
2889 Here, name look up will originally find the out
2890 of scope `i'. We need to issue a warning message,
2891 but then use the global `i'. */
2892 decl = check_for_out_of_scope_variable (decl);
2893 if (local_variable_p (decl))
2895 error ("local variable %qD may not appear in this context",
2897 return error_mark_node;
2902 decl = finish_id_expression (id_expression, decl, parser->scope,
2903 idk, qualifying_class,
2904 parser->integral_constant_expression_p,
2905 parser->allow_non_integral_constant_expression_p,
2906 &parser->non_integral_constant_expression_p,
2909 cp_parser_error (parser, error_msg);
2913 /* Anything else is an error. */
2915 cp_parser_error (parser, "expected primary-expression");
2916 return error_mark_node;
2920 /* Parse an id-expression.
2927 :: [opt] nested-name-specifier template [opt] unqualified-id
2929 :: operator-function-id
2932 Return a representation of the unqualified portion of the
2933 identifier. Sets PARSER->SCOPE to the qualifying scope if there is
2934 a `::' or nested-name-specifier.
2936 Often, if the id-expression was a qualified-id, the caller will
2937 want to make a SCOPE_REF to represent the qualified-id. This
2938 function does not do this in order to avoid wastefully creating
2939 SCOPE_REFs when they are not required.
2941 If TEMPLATE_KEYWORD_P is true, then we have just seen the
2944 If CHECK_DEPENDENCY_P is false, then names are looked up inside
2945 uninstantiated templates.
2947 If *TEMPLATE_P is non-NULL, it is set to true iff the
2948 `template' keyword is used to explicitly indicate that the entity
2949 named is a template.
2951 If DECLARATOR_P is true, the id-expression is appearing as part of
2952 a declarator, rather than as part of an expression. */
2955 cp_parser_id_expression (cp_parser *parser,
2956 bool template_keyword_p,
2957 bool check_dependency_p,
2961 bool global_scope_p;
2962 bool nested_name_specifier_p;
2964 /* Assume the `template' keyword was not used. */
2966 *template_p = false;
2968 /* Look for the optional `::' operator. */
2970 = (cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/false)
2972 /* Look for the optional nested-name-specifier. */
2973 nested_name_specifier_p
2974 = (cp_parser_nested_name_specifier_opt (parser,
2975 /*typename_keyword_p=*/false,
2980 /* If there is a nested-name-specifier, then we are looking at
2981 the first qualified-id production. */
2982 if (nested_name_specifier_p)
2985 tree saved_object_scope;
2986 tree saved_qualifying_scope;
2987 tree unqualified_id;
2990 /* See if the next token is the `template' keyword. */
2992 template_p = &is_template;
2993 *template_p = cp_parser_optional_template_keyword (parser);
2994 /* Name lookup we do during the processing of the
2995 unqualified-id might obliterate SCOPE. */
2996 saved_scope = parser->scope;
2997 saved_object_scope = parser->object_scope;
2998 saved_qualifying_scope = parser->qualifying_scope;
2999 /* Process the final unqualified-id. */
3000 unqualified_id = cp_parser_unqualified_id (parser, *template_p,
3003 /* Restore the SAVED_SCOPE for our caller. */
3004 parser->scope = saved_scope;
3005 parser->object_scope = saved_object_scope;
3006 parser->qualifying_scope = saved_qualifying_scope;
3008 return unqualified_id;
3010 /* Otherwise, if we are in global scope, then we are looking at one
3011 of the other qualified-id productions. */
3012 else if (global_scope_p)
3017 /* Peek at the next token. */
3018 token = cp_lexer_peek_token (parser->lexer);
3020 /* If it's an identifier, and the next token is not a "<", then
3021 we can avoid the template-id case. This is an optimization
3022 for this common case. */
3023 if (token->type == CPP_NAME
3024 && !cp_parser_nth_token_starts_template_argument_list_p
3026 return cp_parser_identifier (parser);
3028 cp_parser_parse_tentatively (parser);
3029 /* Try a template-id. */
3030 id = cp_parser_template_id (parser,
3031 /*template_keyword_p=*/false,
3032 /*check_dependency_p=*/true,
3034 /* If that worked, we're done. */
3035 if (cp_parser_parse_definitely (parser))
3038 /* Peek at the next token. (Changes in the token buffer may
3039 have invalidated the pointer obtained above.) */
3040 token = cp_lexer_peek_token (parser->lexer);
3042 switch (token->type)
3045 return cp_parser_identifier (parser);
3048 if (token->keyword == RID_OPERATOR)
3049 return cp_parser_operator_function_id (parser);
3053 cp_parser_error (parser, "expected id-expression");
3054 return error_mark_node;
3058 return cp_parser_unqualified_id (parser, template_keyword_p,
3059 /*check_dependency_p=*/true,
3063 /* Parse an unqualified-id.
3067 operator-function-id
3068 conversion-function-id
3072 If TEMPLATE_KEYWORD_P is TRUE, we have just seen the `template'
3073 keyword, in a construct like `A::template ...'.
3075 Returns a representation of unqualified-id. For the `identifier'
3076 production, an IDENTIFIER_NODE is returned. For the `~ class-name'
3077 production a BIT_NOT_EXPR is returned; the operand of the
3078 BIT_NOT_EXPR is an IDENTIFIER_NODE for the class-name. For the
3079 other productions, see the documentation accompanying the
3080 corresponding parsing functions. If CHECK_DEPENDENCY_P is false,
3081 names are looked up in uninstantiated templates. If DECLARATOR_P
3082 is true, the unqualified-id is appearing as part of a declarator,
3083 rather than as part of an expression. */
3086 cp_parser_unqualified_id (cp_parser* parser,
3087 bool template_keyword_p,
3088 bool check_dependency_p,
3093 /* Peek at the next token. */
3094 token = cp_lexer_peek_token (parser->lexer);
3096 switch (token->type)
3102 /* We don't know yet whether or not this will be a
3104 cp_parser_parse_tentatively (parser);
3105 /* Try a template-id. */
3106 id = cp_parser_template_id (parser, template_keyword_p,
3109 /* If it worked, we're done. */
3110 if (cp_parser_parse_definitely (parser))
3112 /* Otherwise, it's an ordinary identifier. */
3113 return cp_parser_identifier (parser);
3116 case CPP_TEMPLATE_ID:
3117 return cp_parser_template_id (parser, template_keyword_p,
3124 tree qualifying_scope;
3128 /* Consume the `~' token. */
3129 cp_lexer_consume_token (parser->lexer);
3130 /* Parse the class-name. The standard, as written, seems to
3133 template <typename T> struct S { ~S (); };
3134 template <typename T> S<T>::~S() {}
3136 is invalid, since `~' must be followed by a class-name, but
3137 `S<T>' is dependent, and so not known to be a class.
3138 That's not right; we need to look in uninstantiated
3139 templates. A further complication arises from:
3141 template <typename T> void f(T t) {
3145 Here, it is not possible to look up `T' in the scope of `T'
3146 itself. We must look in both the current scope, and the
3147 scope of the containing complete expression.
3149 Yet another issue is:
3158 The standard does not seem to say that the `S' in `~S'
3159 should refer to the type `S' and not the data member
3162 /* DR 244 says that we look up the name after the "~" in the
3163 same scope as we looked up the qualifying name. That idea
3164 isn't fully worked out; it's more complicated than that. */
3165 scope = parser->scope;
3166 object_scope = parser->object_scope;
3167 qualifying_scope = parser->qualifying_scope;
3169 /* If the name is of the form "X::~X" it's OK. */
3170 if (scope && TYPE_P (scope)
3171 && cp_lexer_next_token_is (parser->lexer, CPP_NAME)
3172 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
3174 && (cp_lexer_peek_token (parser->lexer)->value
3175 == TYPE_IDENTIFIER (scope)))
3177 cp_lexer_consume_token (parser->lexer);
3178 return build_nt (BIT_NOT_EXPR, scope);
3181 /* If there was an explicit qualification (S::~T), first look
3182 in the scope given by the qualification (i.e., S). */
3185 cp_parser_parse_tentatively (parser);
3186 type_decl = cp_parser_class_name (parser,
3187 /*typename_keyword_p=*/false,
3188 /*template_keyword_p=*/false,
3190 /*check_dependency=*/false,
3191 /*class_head_p=*/false,
3193 if (cp_parser_parse_definitely (parser))
3194 return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
3196 /* In "N::S::~S", look in "N" as well. */
3197 if (scope && qualifying_scope)
3199 cp_parser_parse_tentatively (parser);
3200 parser->scope = qualifying_scope;
3201 parser->object_scope = NULL_TREE;
3202 parser->qualifying_scope = NULL_TREE;
3204 = cp_parser_class_name (parser,
3205 /*typename_keyword_p=*/false,
3206 /*template_keyword_p=*/false,
3208 /*check_dependency=*/false,
3209 /*class_head_p=*/false,
3211 if (cp_parser_parse_definitely (parser))
3212 return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
3214 /* In "p->S::~T", look in the scope given by "*p" as well. */
3215 else if (object_scope)
3217 cp_parser_parse_tentatively (parser);
3218 parser->scope = object_scope;
3219 parser->object_scope = NULL_TREE;
3220 parser->qualifying_scope = NULL_TREE;
3222 = cp_parser_class_name (parser,
3223 /*typename_keyword_p=*/false,
3224 /*template_keyword_p=*/false,
3226 /*check_dependency=*/false,
3227 /*class_head_p=*/false,
3229 if (cp_parser_parse_definitely (parser))
3230 return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
3232 /* Look in the surrounding context. */
3233 parser->scope = NULL_TREE;
3234 parser->object_scope = NULL_TREE;
3235 parser->qualifying_scope = NULL_TREE;
3237 = cp_parser_class_name (parser,
3238 /*typename_keyword_p=*/false,
3239 /*template_keyword_p=*/false,
3241 /*check_dependency=*/false,
3242 /*class_head_p=*/false,
3244 /* If an error occurred, assume that the name of the
3245 destructor is the same as the name of the qualifying
3246 class. That allows us to keep parsing after running
3247 into ill-formed destructor names. */
3248 if (type_decl == error_mark_node && scope && TYPE_P (scope))
3249 return build_nt (BIT_NOT_EXPR, scope);
3250 else if (type_decl == error_mark_node)
3251 return error_mark_node;
3255 A typedef-name that names a class shall not be used as the
3256 identifier in the declarator for a destructor declaration. */
3258 && !DECL_IMPLICIT_TYPEDEF_P (type_decl)
3259 && !DECL_SELF_REFERENCE_P (type_decl)
3260 && !cp_parser_uncommitted_to_tentative_parse_p (parser))
3261 error ("typedef-name %qD used as destructor declarator",
3264 return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
3268 if (token->keyword == RID_OPERATOR)
3272 /* This could be a template-id, so we try that first. */
3273 cp_parser_parse_tentatively (parser);
3274 /* Try a template-id. */
3275 id = cp_parser_template_id (parser, template_keyword_p,
3276 /*check_dependency_p=*/true,
3278 /* If that worked, we're done. */
3279 if (cp_parser_parse_definitely (parser))
3281 /* We still don't know whether we're looking at an
3282 operator-function-id or a conversion-function-id. */
3283 cp_parser_parse_tentatively (parser);
3284 /* Try an operator-function-id. */
3285 id = cp_parser_operator_function_id (parser);
3286 /* If that didn't work, try a conversion-function-id. */
3287 if (!cp_parser_parse_definitely (parser))
3288 id = cp_parser_conversion_function_id (parser);
3295 cp_parser_error (parser, "expected unqualified-id");
3296 return error_mark_node;
3300 /* Parse an (optional) nested-name-specifier.
3302 nested-name-specifier:
3303 class-or-namespace-name :: nested-name-specifier [opt]
3304 class-or-namespace-name :: template nested-name-specifier [opt]
3306 PARSER->SCOPE should be set appropriately before this function is
3307 called. TYPENAME_KEYWORD_P is TRUE if the `typename' keyword is in
3308 effect. TYPE_P is TRUE if we non-type bindings should be ignored
3311 Sets PARSER->SCOPE to the class (TYPE) or namespace
3312 (NAMESPACE_DECL) specified by the nested-name-specifier, or leaves
3313 it unchanged if there is no nested-name-specifier. Returns the new
3314 scope iff there is a nested-name-specifier, or NULL_TREE otherwise.
3316 If IS_DECLARATION is TRUE, the nested-name-specifier is known to be
3317 part of a declaration and/or decl-specifier. */
3320 cp_parser_nested_name_specifier_opt (cp_parser *parser,
3321 bool typename_keyword_p,
3322 bool check_dependency_p,
3324 bool is_declaration)
3326 bool success = false;
3327 tree access_check = NULL_TREE;
3328 cp_token_position start = 0;
3331 /* If the next token corresponds to a nested name specifier, there
3332 is no need to reparse it. However, if CHECK_DEPENDENCY_P is
3333 false, it may have been true before, in which case something
3334 like `A<X>::B<Y>::C' may have resulted in a nested-name-specifier
3335 of `A<X>::', where it should now be `A<X>::B<Y>::'. So, when
3336 CHECK_DEPENDENCY_P is false, we have to fall through into the
3338 if (check_dependency_p
3339 && cp_lexer_next_token_is (parser->lexer, CPP_NESTED_NAME_SPECIFIER))
3341 cp_parser_pre_parsed_nested_name_specifier (parser);
3342 return parser->scope;
3345 /* Remember where the nested-name-specifier starts. */
3346 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
3347 start = cp_lexer_token_position (parser->lexer, false);
3349 push_deferring_access_checks (dk_deferred);
3355 tree saved_qualifying_scope;
3356 bool template_keyword_p;
3358 /* Spot cases that cannot be the beginning of a
3359 nested-name-specifier. */
3360 token = cp_lexer_peek_token (parser->lexer);
3362 /* If the next token is CPP_NESTED_NAME_SPECIFIER, just process
3363 the already parsed nested-name-specifier. */
3364 if (token->type == CPP_NESTED_NAME_SPECIFIER)
3366 /* Grab the nested-name-specifier and continue the loop. */
3367 cp_parser_pre_parsed_nested_name_specifier (parser);
3372 /* Spot cases that cannot be the beginning of a
3373 nested-name-specifier. On the second and subsequent times
3374 through the loop, we look for the `template' keyword. */
3375 if (success && token->keyword == RID_TEMPLATE)
3377 /* A template-id can start a nested-name-specifier. */
3378 else if (token->type == CPP_TEMPLATE_ID)
3382 /* If the next token is not an identifier, then it is
3383 definitely not a class-or-namespace-name. */
3384 if (token->type != CPP_NAME)
3386 /* If the following token is neither a `<' (to begin a
3387 template-id), nor a `::', then we are not looking at a
3388 nested-name-specifier. */
3389 token = cp_lexer_peek_nth_token (parser->lexer, 2);
3390 if (token->type != CPP_SCOPE
3391 && !cp_parser_nth_token_starts_template_argument_list_p
3396 /* The nested-name-specifier is optional, so we parse
3398 cp_parser_parse_tentatively (parser);
3400 /* Look for the optional `template' keyword, if this isn't the
3401 first time through the loop. */
3403 template_keyword_p = cp_parser_optional_template_keyword (parser);
3405 template_keyword_p = false;
3407 /* Save the old scope since the name lookup we are about to do
3408 might destroy it. */
3409 old_scope = parser->scope;
3410 saved_qualifying_scope = parser->qualifying_scope;
3411 /* In a declarator-id like "X<T>::I::Y<T>" we must be able to
3412 look up names in "X<T>::I" in order to determine that "Y" is
3413 a template. So, if we have a typename at this point, we make
3414 an effort to look through it. */
3416 && !typename_keyword_p
3418 && TREE_CODE (parser->scope) == TYPENAME_TYPE)
3419 parser->scope = resolve_typename_type (parser->scope,
3420 /*only_current_p=*/false);
3421 /* Parse the qualifying entity. */
3423 = cp_parser_class_or_namespace_name (parser,
3429 /* Look for the `::' token. */
3430 cp_parser_require (parser, CPP_SCOPE, "`::'");
3432 /* If we found what we wanted, we keep going; otherwise, we're
3434 if (!cp_parser_parse_definitely (parser))
3436 bool error_p = false;
3438 /* Restore the OLD_SCOPE since it was valid before the
3439 failed attempt at finding the last
3440 class-or-namespace-name. */
3441 parser->scope = old_scope;
3442 parser->qualifying_scope = saved_qualifying_scope;
3443 /* If the next token is an identifier, and the one after
3444 that is a `::', then any valid interpretation would have
3445 found a class-or-namespace-name. */
3446 while (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
3447 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
3449 && (cp_lexer_peek_nth_token (parser->lexer, 3)->type
3452 token = cp_lexer_consume_token (parser->lexer);
3457 decl = cp_parser_lookup_name_simple (parser, token->value);
3458 if (TREE_CODE (decl) == TEMPLATE_DECL)
3459 error ("%qD used without template parameters", decl);
3461 cp_parser_name_lookup_error
3462 (parser, token->value, decl,
3463 "is not a class or namespace");
3464 parser->scope = NULL_TREE;
3466 /* Treat this as a successful nested-name-specifier
3471 If the name found is not a class-name (clause
3472 _class_) or namespace-name (_namespace.def_), the
3473 program is ill-formed. */
3476 cp_lexer_consume_token (parser->lexer);
3481 /* We've found one valid nested-name-specifier. */
3483 /* Make sure we look in the right scope the next time through
3485 parser->scope = (TREE_CODE (new_scope) == TYPE_DECL
3486 ? TREE_TYPE (new_scope)
3488 /* If it is a class scope, try to complete it; we are about to
3489 be looking up names inside the class. */
3490 if (TYPE_P (parser->scope)
3491 /* Since checking types for dependency can be expensive,
3492 avoid doing it if the type is already complete. */
3493 && !COMPLETE_TYPE_P (parser->scope)
3494 /* Do not try to complete dependent types. */
3495 && !dependent_type_p (parser->scope))
3496 complete_type (parser->scope);
3499 /* Retrieve any deferred checks. Do not pop this access checks yet
3500 so the memory will not be reclaimed during token replacing below. */
3501 access_check = get_deferred_access_checks ();
3503 /* If parsing tentatively, replace the sequence of tokens that makes
3504 up the nested-name-specifier with a CPP_NESTED_NAME_SPECIFIER
3505 token. That way, should we re-parse the token stream, we will
3506 not have to repeat the effort required to do the parse, nor will
3507 we issue duplicate error messages. */
3508 if (success && start)
3510 cp_token *token = cp_lexer_token_at (parser->lexer, start);
3512 /* Reset the contents of the START token. */
3513 token->type = CPP_NESTED_NAME_SPECIFIER;
3514 token->value = build_tree_list (access_check, parser->scope);
3515 TREE_TYPE (token->value) = parser->qualifying_scope;
3516 token->keyword = RID_MAX;
3518 /* Purge all subsequent tokens. */
3519 cp_lexer_purge_tokens_after (parser->lexer, start);
3522 pop_deferring_access_checks ();
3523 return success ? parser->scope : NULL_TREE;
3526 /* Parse a nested-name-specifier. See
3527 cp_parser_nested_name_specifier_opt for details. This function
3528 behaves identically, except that it will an issue an error if no
3529 nested-name-specifier is present, and it will return
3530 ERROR_MARK_NODE, rather than NULL_TREE, if no nested-name-specifier
3534 cp_parser_nested_name_specifier (cp_parser *parser,
3535 bool typename_keyword_p,
3536 bool check_dependency_p,
3538 bool is_declaration)
3542 /* Look for the nested-name-specifier. */
3543 scope = cp_parser_nested_name_specifier_opt (parser,
3548 /* If it was not present, issue an error message. */
3551 cp_parser_error (parser, "expected nested-name-specifier");
3552 parser->scope = NULL_TREE;
3553 return error_mark_node;
3559 /* Parse a class-or-namespace-name.
3561 class-or-namespace-name:
3565 TYPENAME_KEYWORD_P is TRUE iff the `typename' keyword is in effect.
3566 TEMPLATE_KEYWORD_P is TRUE iff the `template' keyword is in effect.
3567 CHECK_DEPENDENCY_P is FALSE iff dependent names should be looked up.
3568 TYPE_P is TRUE iff the next name should be taken as a class-name,
3569 even the same name is declared to be another entity in the same
3572 Returns the class (TYPE_DECL) or namespace (NAMESPACE_DECL)
3573 specified by the class-or-namespace-name. If neither is found the
3574 ERROR_MARK_NODE is returned. */
3577 cp_parser_class_or_namespace_name (cp_parser *parser,
3578 bool typename_keyword_p,
3579 bool template_keyword_p,
3580 bool check_dependency_p,
3582 bool is_declaration)
3585 tree saved_qualifying_scope;
3586 tree saved_object_scope;
3590 /* Before we try to parse the class-name, we must save away the
3591 current PARSER->SCOPE since cp_parser_class_name will destroy
3593 saved_scope = parser->scope;
3594 saved_qualifying_scope = parser->qualifying_scope;
3595 saved_object_scope = parser->object_scope;
3596 /* Try for a class-name first. If the SAVED_SCOPE is a type, then
3597 there is no need to look for a namespace-name. */
3598 only_class_p = template_keyword_p || (saved_scope && TYPE_P (saved_scope));
3600 cp_parser_parse_tentatively (parser);
3601 scope = cp_parser_class_name (parser,
3604 type_p ? class_type : none_type,
3606 /*class_head_p=*/false,
3608 /* If that didn't work, try for a namespace-name. */
3609 if (!only_class_p && !cp_parser_parse_definitely (parser))
3611 /* Restore the saved scope. */
3612 parser->scope = saved_scope;
3613 parser->qualifying_scope = saved_qualifying_scope;
3614 parser->object_scope = saved_object_scope;
3615 /* If we are not looking at an identifier followed by the scope
3616 resolution operator, then this is not part of a
3617 nested-name-specifier. (Note that this function is only used
3618 to parse the components of a nested-name-specifier.) */
3619 if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)
3620 || cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
3621 return error_mark_node;
3622 scope = cp_parser_namespace_name (parser);
3628 /* Parse a postfix-expression.
3632 postfix-expression [ expression ]
3633 postfix-expression ( expression-list [opt] )
3634 simple-type-specifier ( expression-list [opt] )
3635 typename :: [opt] nested-name-specifier identifier
3636 ( expression-list [opt] )
3637 typename :: [opt] nested-name-specifier template [opt] template-id
3638 ( expression-list [opt] )
3639 postfix-expression . template [opt] id-expression
3640 postfix-expression -> template [opt] id-expression
3641 postfix-expression . pseudo-destructor-name
3642 postfix-expression -> pseudo-destructor-name
3643 postfix-expression ++
3644 postfix-expression --
3645 dynamic_cast < type-id > ( expression )
3646 static_cast < type-id > ( expression )
3647 reinterpret_cast < type-id > ( expression )
3648 const_cast < type-id > ( expression )
3649 typeid ( expression )
3655 ( type-id ) { initializer-list , [opt] }
3657 This extension is a GNU version of the C99 compound-literal
3658 construct. (The C99 grammar uses `type-name' instead of `type-id',
3659 but they are essentially the same concept.)
3661 If ADDRESS_P is true, the postfix expression is the operand of the
3664 Returns a representation of the expression. */
3667 cp_parser_postfix_expression (cp_parser *parser, bool address_p)
3671 cp_id_kind idk = CP_ID_KIND_NONE;
3672 tree postfix_expression = NULL_TREE;
3673 /* Non-NULL only if the current postfix-expression can be used to
3674 form a pointer-to-member. In that case, QUALIFYING_CLASS is the
3675 class used to qualify the member. */
3676 tree qualifying_class = NULL_TREE;
3678 /* Peek at the next token. */
3679 token = cp_lexer_peek_token (parser->lexer);
3680 /* Some of the productions are determined by keywords. */
3681 keyword = token->keyword;
3691 const char *saved_message;
3693 /* All of these can be handled in the same way from the point
3694 of view of parsing. Begin by consuming the token
3695 identifying the cast. */
3696 cp_lexer_consume_token (parser->lexer);
3698 /* New types cannot be defined in the cast. */
3699 saved_message = parser->type_definition_forbidden_message;
3700 parser->type_definition_forbidden_message
3701 = "types may not be defined in casts";
3703 /* Look for the opening `<'. */
3704 cp_parser_require (parser, CPP_LESS, "`<'");
3705 /* Parse the type to which we are casting. */
3706 type = cp_parser_type_id (parser);
3707 /* Look for the closing `>'. */
3708 cp_parser_require (parser, CPP_GREATER, "`>'");
3709 /* Restore the old message. */
3710 parser->type_definition_forbidden_message = saved_message;
3712 /* And the expression which is being cast. */
3713 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
3714 expression = cp_parser_expression (parser);
3715 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
3717 /* Only type conversions to integral or enumeration types
3718 can be used in constant-expressions. */
3719 if (parser->integral_constant_expression_p
3720 && !dependent_type_p (type)
3721 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type)
3722 && (cp_parser_non_integral_constant_expression
3724 "a cast to a type other than an integral or "
3725 "enumeration type")))
3726 return error_mark_node;
3732 = build_dynamic_cast (type, expression);
3736 = build_static_cast (type, expression);
3740 = build_reinterpret_cast (type, expression);
3744 = build_const_cast (type, expression);
3755 const char *saved_message;
3756 bool saved_in_type_id_in_expr_p;
3758 /* Consume the `typeid' token. */
3759 cp_lexer_consume_token (parser->lexer);
3760 /* Look for the `(' token. */
3761 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
3762 /* Types cannot be defined in a `typeid' expression. */
3763 saved_message = parser->type_definition_forbidden_message;
3764 parser->type_definition_forbidden_message
3765 = "types may not be defined in a `typeid\' expression";
3766 /* We can't be sure yet whether we're looking at a type-id or an
3768 cp_parser_parse_tentatively (parser);
3769 /* Try a type-id first. */
3770 saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
3771 parser->in_type_id_in_expr_p = true;
3772 type = cp_parser_type_id (parser);
3773 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
3774 /* Look for the `)' token. Otherwise, we can't be sure that
3775 we're not looking at an expression: consider `typeid (int
3776 (3))', for example. */
3777 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
3778 /* If all went well, simply lookup the type-id. */
3779 if (cp_parser_parse_definitely (parser))
3780 postfix_expression = get_typeid (type);
3781 /* Otherwise, fall back to the expression variant. */
3786 /* Look for an expression. */
3787 expression = cp_parser_expression (parser);
3788 /* Compute its typeid. */
3789 postfix_expression = build_typeid (expression);
3790 /* Look for the `)' token. */
3791 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
3793 /* `typeid' may not appear in an integral constant expression. */
3794 if (cp_parser_non_integral_constant_expression(parser,
3795 "`typeid' operator"))
3796 return error_mark_node;
3797 /* Restore the saved message. */
3798 parser->type_definition_forbidden_message = saved_message;
3804 bool template_p = false;
3808 /* Consume the `typename' token. */
3809 cp_lexer_consume_token (parser->lexer);
3810 /* Look for the optional `::' operator. */
3811 cp_parser_global_scope_opt (parser,
3812 /*current_scope_valid_p=*/false);
3813 /* Look for the nested-name-specifier. */
3814 cp_parser_nested_name_specifier (parser,
3815 /*typename_keyword_p=*/true,
3816 /*check_dependency_p=*/true,
3818 /*is_declaration=*/true);
3819 /* Look for the optional `template' keyword. */
3820 template_p = cp_parser_optional_template_keyword (parser);
3821 /* We don't know whether we're looking at a template-id or an
3823 cp_parser_parse_tentatively (parser);
3824 /* Try a template-id. */
3825 id = cp_parser_template_id (parser, template_p,
3826 /*check_dependency_p=*/true,
3827 /*is_declaration=*/true);
3828 /* If that didn't work, try an identifier. */
3829 if (!cp_parser_parse_definitely (parser))
3830 id = cp_parser_identifier (parser);
3831 /* If we look up a template-id in a non-dependent qualifying
3832 scope, there's no need to create a dependent type. */
3833 if (TREE_CODE (id) == TYPE_DECL
3834 && !dependent_type_p (parser->scope))
3835 type = TREE_TYPE (id);
3836 /* Create a TYPENAME_TYPE to represent the type to which the
3837 functional cast is being performed. */
3839 type = make_typename_type (parser->scope, id,
3843 postfix_expression = cp_parser_functional_cast (parser, type);
3851 /* If the next thing is a simple-type-specifier, we may be
3852 looking at a functional cast. We could also be looking at
3853 an id-expression. So, we try the functional cast, and if
3854 that doesn't work we fall back to the primary-expression. */
3855 cp_parser_parse_tentatively (parser);
3856 /* Look for the simple-type-specifier. */
3857 type = cp_parser_simple_type_specifier (parser,
3858 /*decl_specs=*/NULL,
3859 CP_PARSER_FLAGS_NONE);
3860 /* Parse the cast itself. */
3861 if (!cp_parser_error_occurred (parser))
3863 = cp_parser_functional_cast (parser, type);
3864 /* If that worked, we're done. */
3865 if (cp_parser_parse_definitely (parser))
3868 /* If the functional-cast didn't work out, try a
3869 compound-literal. */
3870 if (cp_parser_allow_gnu_extensions_p (parser)
3871 && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
3873 tree initializer_list = NULL_TREE;
3874 bool saved_in_type_id_in_expr_p;
3876 cp_parser_parse_tentatively (parser);
3877 /* Consume the `('. */
3878 cp_lexer_consume_token (parser->lexer);
3879 /* Parse the type. */
3880 saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
3881 parser->in_type_id_in_expr_p = true;
3882 type = cp_parser_type_id (parser);
3883 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
3884 /* Look for the `)'. */
3885 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
3886 /* Look for the `{'. */
3887 cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
3888 /* If things aren't going well, there's no need to
3890 if (!cp_parser_error_occurred (parser))
3892 bool non_constant_p;
3893 /* Parse the initializer-list. */
3895 = cp_parser_initializer_list (parser, &non_constant_p);
3896 /* Allow a trailing `,'. */
3897 if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
3898 cp_lexer_consume_token (parser->lexer);
3899 /* Look for the final `}'. */
3900 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
3902 /* If that worked, we're definitely looking at a
3903 compound-literal expression. */
3904 if (cp_parser_parse_definitely (parser))
3906 /* Warn the user that a compound literal is not
3907 allowed in standard C++. */
3909 pedwarn ("ISO C++ forbids compound-literals");
3910 /* Form the representation of the compound-literal. */
3912 = finish_compound_literal (type, initializer_list);
3917 /* It must be a primary-expression. */
3918 postfix_expression = cp_parser_primary_expression (parser,
3925 /* If we were avoiding committing to the processing of a
3926 qualified-id until we knew whether or not we had a
3927 pointer-to-member, we now know. */
3928 if (qualifying_class)
3932 /* Peek at the next token. */
3933 token = cp_lexer_peek_token (parser->lexer);
3934 done = (token->type != CPP_OPEN_SQUARE
3935 && token->type != CPP_OPEN_PAREN
3936 && token->type != CPP_DOT
3937 && token->type != CPP_DEREF
3938 && token->type != CPP_PLUS_PLUS
3939 && token->type != CPP_MINUS_MINUS);
3941 postfix_expression = finish_qualified_id_expr (qualifying_class,
3946 return postfix_expression;
3949 /* Keep looping until the postfix-expression is complete. */
3952 if (idk == CP_ID_KIND_UNQUALIFIED
3953 && TREE_CODE (postfix_expression) == IDENTIFIER_NODE
3954 && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
3955 /* It is not a Koenig lookup function call. */
3957 = unqualified_name_lookup_error (postfix_expression);
3959 /* Peek at the next token. */
3960 token = cp_lexer_peek_token (parser->lexer);
3962 switch (token->type)
3964 case CPP_OPEN_SQUARE:
3966 = cp_parser_postfix_open_square_expression (parser,
3969 idk = CP_ID_KIND_NONE;
3972 case CPP_OPEN_PAREN:
3973 /* postfix-expression ( expression-list [opt] ) */
3976 tree args = (cp_parser_parenthesized_expression_list
3977 (parser, false, /*non_constant_p=*/NULL));
3979 if (args == error_mark_node)
3981 postfix_expression = error_mark_node;
3985 /* Function calls are not permitted in
3986 constant-expressions. */
3987 if (cp_parser_non_integral_constant_expression (parser,
3990 postfix_expression = error_mark_node;
3995 if (idk == CP_ID_KIND_UNQUALIFIED)
3997 if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
4003 = perform_koenig_lookup (postfix_expression, args);
4007 = unqualified_fn_lookup_error (postfix_expression);
4009 /* We do not perform argument-dependent lookup if
4010 normal lookup finds a non-function, in accordance
4011 with the expected resolution of DR 218. */
4012 else if (args && is_overloaded_fn (postfix_expression))
4014 tree fn = get_first_fn (postfix_expression);
4016 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
4017 fn = OVL_CURRENT (TREE_OPERAND (fn, 0));
4019 /* Only do argument dependent lookup if regular
4020 lookup does not find a set of member functions.
4021 [basic.lookup.koenig]/2a */
4022 if (!DECL_FUNCTION_MEMBER_P (fn))
4026 = perform_koenig_lookup (postfix_expression, args);
4031 if (TREE_CODE (postfix_expression) == COMPONENT_REF)
4033 tree instance = TREE_OPERAND (postfix_expression, 0);
4034 tree fn = TREE_OPERAND (postfix_expression, 1);
4036 if (processing_template_decl
4037 && (type_dependent_expression_p (instance)
4038 || (!BASELINK_P (fn)
4039 && TREE_CODE (fn) != FIELD_DECL)
4040 || type_dependent_expression_p (fn)
4041 || any_type_dependent_arguments_p (args)))
4044 = build_min_nt (CALL_EXPR, postfix_expression,
4049 if (BASELINK_P (fn))
4051 = (build_new_method_call
4052 (instance, fn, args, NULL_TREE,
4053 (idk == CP_ID_KIND_QUALIFIED
4054 ? LOOKUP_NONVIRTUAL : LOOKUP_NORMAL)));
4057 = finish_call_expr (postfix_expression, args,
4058 /*disallow_virtual=*/false,
4059 /*koenig_p=*/false);
4061 else if (TREE_CODE (postfix_expression) == OFFSET_REF
4062 || TREE_CODE (postfix_expression) == MEMBER_REF
4063 || TREE_CODE (postfix_expression) == DOTSTAR_EXPR)
4064 postfix_expression = (build_offset_ref_call_from_tree
4065 (postfix_expression, args));
4066 else if (idk == CP_ID_KIND_QUALIFIED)
4067 /* A call to a static class member, or a namespace-scope
4070 = finish_call_expr (postfix_expression, args,
4071 /*disallow_virtual=*/true,
4074 /* All other function calls. */
4076 = finish_call_expr (postfix_expression, args,
4077 /*disallow_virtual=*/false,
4080 /* The POSTFIX_EXPRESSION is certainly no longer an id. */
4081 idk = CP_ID_KIND_NONE;
4087 /* postfix-expression . template [opt] id-expression
4088 postfix-expression . pseudo-destructor-name
4089 postfix-expression -> template [opt] id-expression
4090 postfix-expression -> pseudo-destructor-name */
4092 /* Consume the `.' or `->' operator. */
4093 cp_lexer_consume_token (parser->lexer);
4096 = cp_parser_postfix_dot_deref_expression (parser, token->type,
4102 /* postfix-expression ++ */
4103 /* Consume the `++' token. */
4104 cp_lexer_consume_token (parser->lexer);
4105 /* Generate a representation for the complete expression. */
4107 = finish_increment_expr (postfix_expression,
4108 POSTINCREMENT_EXPR);
4109 /* Increments may not appear in constant-expressions. */
4110 if (cp_parser_non_integral_constant_expression (parser,
4112 postfix_expression = error_mark_node;
4113 idk = CP_ID_KIND_NONE;
4116 case CPP_MINUS_MINUS:
4117 /* postfix-expression -- */
4118 /* Consume the `--' token. */
4119 cp_lexer_consume_token (parser->lexer);