• Main Page
  • Modules
  • Data Types
  • Files

osprey-gcc-4.2.0/gcc/cp/parser.c

Go to the documentation of this file.
00001 /* C++ Parser.
00002    Copyright (C) 2000, 2001, 2002, 2003, 2004,
00003    2005  Free Software Foundation, Inc.
00004    Written by Mark Mitchell <mark@codesourcery.com>.
00005 
00006    This file is part of GCC.
00007 
00008    GCC is free software; you can redistribute it and/or modify it
00009    under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    GCC is distributed in the hope that it will be useful, but
00014    WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with GCC; see the file COPYING.  If not, write to the Free
00020    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 #include "config.h"
00024 #include "system.h"
00025 #include "coretypes.h"
00026 #include "tm.h"
00027 #include "dyn-string.h"
00028 #include "varray.h"
00029 #include "cpplib.h"
00030 #include "tree.h"
00031 #include "cp-tree.h"
00032 #include "c-pragma.h"
00033 #include "decl.h"
00034 #include "flags.h"
00035 #include "diagnostic.h"
00036 #include "toplev.h"
00037 #include "output.h"
00038 #include "target.h"
00039 #include "cgraph.h"
00040 #include "c-common.h"
00041 
00042 
00043 /* The lexer.  */
00044 
00045 /* The cp_lexer_* routines mediate between the lexer proper (in libcpp
00046    and c-lex.c) and the C++ parser.  */
00047 
00048 /* A token's value and its associated deferred access checks and
00049    qualifying scope.  */
00050 
00051 struct tree_check GTY(())
00052 {
00053   /* The value associated with the token.  */
00054   tree value;
00055   /* The checks that have been associated with value.  */
00056   VEC (deferred_access_check, gc)* checks;
00057   /* The token's qualifying scope (used when it is a
00058      CPP_NESTED_NAME_SPECIFIER).  */
00059   tree qualifying_scope;
00060 };
00061 
00062 /* A C++ token.  */
00063 
00064 typedef struct cp_token GTY (())
00065 {
00066   /* The kind of token.  */
00067   ENUM_BITFIELD (cpp_ttype) type : 8;
00068   /* If this token is a keyword, this value indicates which keyword.
00069      Otherwise, this value is RID_MAX.  */
00070   ENUM_BITFIELD (rid) keyword : 8;
00071   /* Token flags.  */
00072   unsigned char flags;
00073   /* Identifier for the pragma.  */
00074   ENUM_BITFIELD (pragma_kind) pragma_kind : 6;
00075   /* True if this token is from a system header.  */
00076   BOOL_BITFIELD in_system_header : 1;
00077   /* True if this token is from a context where it is implicitly extern "C" */
00078   BOOL_BITFIELD implicit_extern_c : 1;
00079   /* True for a CPP_NAME token that is not a keyword (i.e., for which
00080      KEYWORD is RID_MAX) iff this name was looked up and found to be
00081      ambiguous.  An error has already been reported.  */
00082   BOOL_BITFIELD ambiguous_p : 1;
00083   /* The input file stack index at which this token was found.  */
00084   unsigned input_file_stack_index : INPUT_FILE_STACK_BITS;
00085   /* The value associated with this token, if any.  */
00086   union cp_token_value {
00087     /* Used for CPP_NESTED_NAME_SPECIFIER and CPP_TEMPLATE_ID.  */
00088     struct tree_check* GTY((tag ("1"))) tree_check_value;
00089     /* Use for all other tokens.  */
00090     tree GTY((tag ("0"))) value;
00091   } GTY((desc ("(%1.type == CPP_TEMPLATE_ID) || (%1.type == CPP_NESTED_NAME_SPECIFIER)"))) u;
00092   /* The location at which this token was found.  */
00093   location_t location;
00094 } cp_token;
00095 
00096 /* We use a stack of token pointer for saving token sets.  */
00097 typedef struct cp_token *cp_token_position;
00098 DEF_VEC_P (cp_token_position);
00099 DEF_VEC_ALLOC_P (cp_token_position,heap);
00100 
00101 static const cp_token eof_token =
00102 {
00103   CPP_EOF, RID_MAX, 0, PRAGMA_NONE, 0, 0, false, 0, { NULL },
00104 #if USE_MAPPED_LOCATION
00105   0
00106 #else
00107   {0, 0}
00108 #endif
00109 };
00110 
00111 /* The cp_lexer structure represents the C++ lexer.  It is responsible
00112    for managing the token stream from the preprocessor and supplying
00113    it to the parser.  Tokens are never added to the cp_lexer after
00114    it is created.  */
00115 
00116 typedef struct cp_lexer GTY (())
00117 {
00118   /* The memory allocated for the buffer.  NULL if this lexer does not
00119      own the token buffer.  */
00120   cp_token * GTY ((length ("%h.buffer_length"))) buffer;
00121   /* If the lexer owns the buffer, this is the number of tokens in the
00122      buffer.  */
00123   size_t buffer_length;
00124 
00125   /* A pointer just past the last available token.  The tokens
00126      in this lexer are [buffer, last_token).  */
00127   cp_token_position GTY ((skip)) last_token;
00128 
00129   /* The next available token.  If NEXT_TOKEN is &eof_token, then there are
00130      no more available tokens.  */
00131   cp_token_position GTY ((skip)) next_token;
00132 
00133   /* A stack indicating positions at which cp_lexer_save_tokens was
00134      called.  The top entry is the most recent position at which we
00135      began saving tokens.  If the stack is non-empty, we are saving
00136      tokens.  */
00137   VEC(cp_token_position,heap) *GTY ((skip)) saved_tokens;
00138 
00139   /* The next lexer in a linked list of lexers.  */
00140   struct cp_lexer *next;
00141 
00142   /* True if we should output debugging information.  */
00143   bool debugging_p;
00144 
00145   /* True if we're in the context of parsing a pragma, and should not
00146      increment past the end-of-line marker.  */
00147   bool in_pragma;
00148 } cp_lexer;
00149 
00150 /* cp_token_cache is a range of tokens.  There is no need to represent
00151    allocate heap memory for it, since tokens are never removed from the
00152    lexer's array.  There is also no need for the GC to walk through
00153    a cp_token_cache, since everything in here is referenced through
00154    a lexer.  */
00155 
00156 typedef struct cp_token_cache GTY(())
00157 {
00158   /* The beginning of the token range.  */
00159   cp_token * GTY((skip)) first;
00160 
00161   /* Points immediately after the last token in the range.  */
00162   cp_token * GTY ((skip)) last;
00163 } cp_token_cache;
00164 
00165 /* Prototypes.  */
00166 
00167 static cp_lexer *cp_lexer_new_main
00168   (void);
00169 static cp_lexer *cp_lexer_new_from_tokens
00170   (cp_token_cache *tokens);
00171 static void cp_lexer_destroy
00172   (cp_lexer *);
00173 static int cp_lexer_saving_tokens
00174   (const cp_lexer *);
00175 static cp_token_position cp_lexer_token_position
00176   (cp_lexer *, bool);
00177 static cp_token *cp_lexer_token_at
00178   (cp_lexer *, cp_token_position);
00179 static void cp_lexer_get_preprocessor_token
00180   (cp_lexer *, cp_token *);
00181 static inline cp_token *cp_lexer_peek_token
00182   (cp_lexer *);
00183 static cp_token *cp_lexer_peek_nth_token
00184   (cp_lexer *, size_t);
00185 static inline bool cp_lexer_next_token_is
00186   (cp_lexer *, enum cpp_ttype);
00187 static bool cp_lexer_next_token_is_not
00188   (cp_lexer *, enum cpp_ttype);
00189 static bool cp_lexer_next_token_is_keyword
00190   (cp_lexer *, enum rid);
00191 static cp_token *cp_lexer_consume_token
00192   (cp_lexer *);
00193 static void cp_lexer_purge_token
00194   (cp_lexer *);
00195 static void cp_lexer_purge_tokens_after
00196   (cp_lexer *, cp_token_position);
00197 static void cp_lexer_save_tokens
00198   (cp_lexer *);
00199 static void cp_lexer_commit_tokens
00200   (cp_lexer *);
00201 static void cp_lexer_rollback_tokens
00202   (cp_lexer *);
00203 #ifdef ENABLE_CHECKING
00204 static void cp_lexer_print_token
00205   (FILE *, cp_token *);
00206 static inline bool cp_lexer_debugging_p
00207   (cp_lexer *);
00208 static void cp_lexer_start_debugging
00209   (cp_lexer *) ATTRIBUTE_UNUSED;
00210 static void cp_lexer_stop_debugging
00211   (cp_lexer *) ATTRIBUTE_UNUSED;
00212 #else
00213 /* If we define cp_lexer_debug_stream to NULL it will provoke warnings
00214    about passing NULL to functions that require non-NULL arguments
00215    (fputs, fprintf).  It will never be used, so all we need is a value
00216    of the right type that's guaranteed not to be NULL.  */
00217 #define cp_lexer_debug_stream stdout
00218 #define cp_lexer_print_token(str, tok) (void) 0
00219 #define cp_lexer_debugging_p(lexer) 0
00220 #endif /* ENABLE_CHECKING */
00221 
00222 static cp_token_cache *cp_token_cache_new
00223   (cp_token *, cp_token *);
00224 
00225 static void cp_parser_initial_pragma
00226   (cp_token *);
00227 
00228 /* Manifest constants.  */
00229 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
00230 #define CP_SAVED_TOKEN_STACK 5
00231 
00232 /* A token type for keywords, as opposed to ordinary identifiers.  */
00233 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
00234 
00235 /* A token type for template-ids.  If a template-id is processed while
00236    parsing tentatively, it is replaced with a CPP_TEMPLATE_ID token;
00237    the value of the CPP_TEMPLATE_ID is whatever was returned by
00238    cp_parser_template_id.  */
00239 #define CPP_TEMPLATE_ID ((enum cpp_ttype) (CPP_KEYWORD + 1))
00240 
00241 /* A token type for nested-name-specifiers.  If a
00242    nested-name-specifier is processed while parsing tentatively, it is
00243    replaced with a CPP_NESTED_NAME_SPECIFIER token; the value of the
00244    CPP_NESTED_NAME_SPECIFIER is whatever was returned by
00245    cp_parser_nested_name_specifier_opt.  */
00246 #define CPP_NESTED_NAME_SPECIFIER ((enum cpp_ttype) (CPP_TEMPLATE_ID + 1))
00247 
00248 /* A token type for tokens that are not tokens at all; these are used
00249    to represent slots in the array where there used to be a token
00250    that has now been deleted.  */
00251 #define CPP_PURGED ((enum cpp_ttype) (CPP_NESTED_NAME_SPECIFIER + 1))
00252 
00253 /* The number of token types, including C++-specific ones.  */
00254 #define N_CP_TTYPES ((int) (CPP_PURGED + 1))
00255 
00256 /* Variables.  */
00257 
00258 #ifdef ENABLE_CHECKING
00259 /* The stream to which debugging output should be written.  */
00260 static FILE *cp_lexer_debug_stream;
00261 #endif /* ENABLE_CHECKING */
00262 
00263 /* Create a new main C++ lexer, the lexer that gets tokens from the
00264    preprocessor.  */
00265 
00266 static cp_lexer *
00267 cp_lexer_new_main (void)
00268 {
00269   cp_token first_token;
00270   cp_lexer *lexer;
00271   cp_token *pos;
00272   size_t alloc;
00273   size_t space;
00274   cp_token *buffer;
00275 
00276   /* It's possible that parsing the first pragma will load a PCH file,
00277      which is a GC collection point.  So we have to do that before
00278      allocating any memory.  */
00279   cp_parser_initial_pragma (&first_token);
00280 
00281   /* Tell c_lex_with_flags not to merge string constants.  */
00282   c_lex_return_raw_strings = true;
00283 
00284   c_common_no_more_pch ();
00285 
00286   /* Allocate the memory.  */
00287   lexer = GGC_CNEW (cp_lexer);
00288 
00289 #ifdef ENABLE_CHECKING
00290   /* Initially we are not debugging.  */
00291   lexer->debugging_p = false;
00292 #endif /* ENABLE_CHECKING */
00293   lexer->saved_tokens = VEC_alloc (cp_token_position, heap,
00294            CP_SAVED_TOKEN_STACK);
00295 
00296   /* Create the buffer.  */
00297   alloc = CP_LEXER_BUFFER_SIZE;
00298   buffer = GGC_NEWVEC (cp_token, alloc);
00299 
00300   /* Put the first token in the buffer.  */
00301   space = alloc;
00302   pos = buffer;
00303   *pos = first_token;
00304 
00305   /* Get the remaining tokens from the preprocessor.  */
00306   while (pos->type != CPP_EOF)
00307     {
00308       pos++;
00309       if (!--space)
00310   {
00311     space = alloc;
00312     alloc *= 2;
00313     buffer = GGC_RESIZEVEC (cp_token, buffer, alloc);
00314     pos = buffer + space;
00315   }
00316       cp_lexer_get_preprocessor_token (lexer, pos);
00317     }
00318   lexer->buffer = buffer;
00319   lexer->buffer_length = alloc - space;
00320   lexer->last_token = pos;
00321   lexer->next_token = lexer->buffer_length ? buffer : (cp_token *)&eof_token;
00322 
00323   /* Subsequent preprocessor diagnostics should use compiler
00324      diagnostic functions to get the compiler source location.  */
00325   cpp_get_options (parse_in)->client_diagnostic = true;
00326   cpp_get_callbacks (parse_in)->error = cp_cpp_error;
00327 
00328   gcc_assert (lexer->next_token->type != CPP_PURGED);
00329   return lexer;
00330 }
00331 
00332 /* Create a new lexer whose token stream is primed with the tokens in
00333    CACHE.  When these tokens are exhausted, no new tokens will be read.  */
00334 
00335 static cp_lexer *
00336 cp_lexer_new_from_tokens (cp_token_cache *cache)
00337 {
00338   cp_token *first = cache->first;
00339   cp_token *last = cache->last;
00340   cp_lexer *lexer = GGC_CNEW (cp_lexer);
00341 
00342   /* We do not own the buffer.  */
00343   lexer->buffer = NULL;
00344   lexer->buffer_length = 0;
00345   lexer->next_token = first == last ? (cp_token *)&eof_token : first;
00346   lexer->last_token = last;
00347 
00348   lexer->saved_tokens = VEC_alloc (cp_token_position, heap,
00349            CP_SAVED_TOKEN_STACK);
00350 
00351 #ifdef ENABLE_CHECKING
00352   /* Initially we are not debugging.  */
00353   lexer->debugging_p = false;
00354 #endif
00355 
00356   gcc_assert (lexer->next_token->type != CPP_PURGED);
00357   return lexer;
00358 }
00359 
00360 /* Frees all resources associated with LEXER.  */
00361 
00362 static void
00363 cp_lexer_destroy (cp_lexer *lexer)
00364 {
00365   if (lexer->buffer)
00366     ggc_free (lexer->buffer);
00367   VEC_free (cp_token_position, heap, lexer->saved_tokens);
00368   ggc_free (lexer);
00369 }
00370 
00371 /* Returns nonzero if debugging information should be output.  */
00372 
00373 #ifdef ENABLE_CHECKING
00374 
00375 static inline bool
00376 cp_lexer_debugging_p (cp_lexer *lexer)
00377 {
00378   return lexer->debugging_p;
00379 }
00380 
00381 #endif /* ENABLE_CHECKING */
00382 
00383 static inline cp_token_position
00384 cp_lexer_token_position (cp_lexer *lexer, bool previous_p)
00385 {
00386   gcc_assert (!previous_p || lexer->next_token != &eof_token);
00387 
00388   return lexer->next_token - previous_p;
00389 }
00390 
00391 static inline cp_token *
00392 cp_lexer_token_at (cp_lexer *lexer ATTRIBUTE_UNUSED, cp_token_position pos)
00393 {
00394   return pos;
00395 }
00396 
00397 /* nonzero if we are presently saving tokens.  */
00398 
00399 static inline int
00400 cp_lexer_saving_tokens (const cp_lexer* lexer)
00401 {
00402   return VEC_length (cp_token_position, lexer->saved_tokens) != 0;
00403 }
00404 
00405 /* Store the next token from the preprocessor in *TOKEN.  Return true
00406    if we reach EOF.  */
00407 
00408 static void
00409 cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED ,
00410          cp_token *token)
00411 {
00412   static int is_extern_c = 0;
00413 
00414    /* Get a new token from the preprocessor.  */
00415   token->type
00416     = c_lex_with_flags (&token->u.value, &token->location, &token->flags);
00417   token->input_file_stack_index = input_file_stack_tick;
00418   token->keyword = RID_MAX;
00419   token->pragma_kind = PRAGMA_NONE;
00420   token->in_system_header = in_system_header;
00421 
00422   /* On some systems, some header files are surrounded by an
00423      implicit extern "C" block.  Set a flag in the token if it
00424      comes from such a header.  */
00425   is_extern_c += pending_lang_change;
00426   pending_lang_change = 0;
00427   token->implicit_extern_c = is_extern_c > 0;
00428 
00429   /* Check to see if this token is a keyword.  */
00430   if (token->type == CPP_NAME)
00431     {
00432       if (C_IS_RESERVED_WORD (token->u.value))
00433   {
00434     /* Mark this token as a keyword.  */
00435     token->type = CPP_KEYWORD;
00436     /* Record which keyword.  */
00437     token->keyword = C_RID_CODE (token->u.value);
00438     /* Update the value.  Some keywords are mapped to particular
00439        entities, rather than simply having the value of the
00440        corresponding IDENTIFIER_NODE.  For example, `__const' is
00441        mapped to `const'.  */
00442     token->u.value = ridpointers[token->keyword];
00443   }
00444       else
00445   {
00446     token->ambiguous_p = false;
00447     token->keyword = RID_MAX;
00448   }
00449     }
00450   /* Handle Objective-C++ keywords.  */
00451   else if (token->type == CPP_AT_NAME)
00452     {
00453       token->type = CPP_KEYWORD;
00454       switch (C_RID_CODE (token->u.value))
00455   {
00456   /* Map 'class' to '@class', 'private' to '@private', etc.  */
00457   case RID_CLASS: token->keyword = RID_AT_CLASS; break;
00458   case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
00459   case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
00460   case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
00461   case RID_THROW: token->keyword = RID_AT_THROW; break;
00462   case RID_TRY: token->keyword = RID_AT_TRY; break;
00463   case RID_CATCH: token->keyword = RID_AT_CATCH; break;
00464   default: token->keyword = C_RID_CODE (token->u.value);
00465   }
00466     }
00467   else if (token->type == CPP_PRAGMA)
00468     {
00469       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
00470       token->pragma_kind = TREE_INT_CST_LOW (token->u.value);
00471       token->u.value = NULL_TREE;
00472     }
00473 }
00474 
00475 /* Update the globals input_location and in_system_header and the
00476    input file stack from TOKEN.  */
00477 static inline void
00478 cp_lexer_set_source_position_from_token (cp_token *token)
00479 {
00480   if (token->type != CPP_EOF)
00481     {
00482       input_location = token->location;
00483       in_system_header = token->in_system_header;
00484       restore_input_file_stack (token->input_file_stack_index);
00485     }
00486 }
00487 
00488 /* Return a pointer to the next token in the token stream, but do not
00489    consume it.  */
00490 
00491 static inline cp_token *
00492 cp_lexer_peek_token (cp_lexer *lexer)
00493 {
00494   if (cp_lexer_debugging_p (lexer))
00495     {
00496       fputs ("cp_lexer: peeking at token: ", cp_lexer_debug_stream);
00497       cp_lexer_print_token (cp_lexer_debug_stream, lexer->next_token);
00498       putc ('\n', cp_lexer_debug_stream);
00499     }
00500   return lexer->next_token;
00501 }
00502 
00503 /* Return true if the next token has the indicated TYPE.  */
00504 
00505 static inline bool
00506 cp_lexer_next_token_is (cp_lexer* lexer, enum cpp_ttype type)
00507 {
00508   return cp_lexer_peek_token (lexer)->type == type;
00509 }
00510 
00511 /* Return true if the next token does not have the indicated TYPE.  */
00512 
00513 static inline bool
00514 cp_lexer_next_token_is_not (cp_lexer* lexer, enum cpp_ttype type)
00515 {
00516   return !cp_lexer_next_token_is (lexer, type);
00517 }
00518 
00519 /* Return true if the next token is the indicated KEYWORD.  */
00520 
00521 static inline bool
00522 cp_lexer_next_token_is_keyword (cp_lexer* lexer, enum rid keyword)
00523 {
00524   return cp_lexer_peek_token (lexer)->keyword == keyword;
00525 }
00526 
00527 /* Return true if the next token is a keyword for a decl-specifier.  */
00528 
00529 static bool
00530 cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer)
00531 {
00532   cp_token *token;
00533 
00534   token = cp_lexer_peek_token (lexer);
00535   switch (token->keyword) 
00536     {
00537       /* Storage classes.  */
00538     case RID_AUTO:
00539     case RID_REGISTER:
00540     case RID_STATIC:
00541     case RID_EXTERN:
00542     case RID_MUTABLE:
00543     case RID_THREAD:
00544       /* Elaborated type specifiers.  */
00545     case RID_ENUM:
00546     case RID_CLASS:
00547     case RID_STRUCT:
00548     case RID_UNION:
00549     case RID_TYPENAME:
00550       /* Simple type specifiers.  */
00551     case RID_CHAR:
00552     case RID_WCHAR:
00553     case RID_BOOL:
00554     case RID_SHORT:
00555     case RID_INT:
00556     case RID_LONG:
00557     case RID_SIGNED:
00558     case RID_UNSIGNED:
00559     case RID_FLOAT:
00560     case RID_DOUBLE:
00561     case RID_VOID:
00562       /* GNU extensions.  */ 
00563     case RID_ATTRIBUTE:
00564     case RID_TYPEOF:
00565       return true;
00566 
00567     default:
00568       return false;
00569     }
00570 }
00571 
00572 /* Return a pointer to the Nth token in the token stream.  If N is 1,
00573    then this is precisely equivalent to cp_lexer_peek_token (except
00574    that it is not inline).  One would like to disallow that case, but
00575    there is one case (cp_parser_nth_token_starts_template_id) where
00576    the caller passes a variable for N and it might be 1.  */
00577 
00578 static cp_token *
00579 cp_lexer_peek_nth_token (cp_lexer* lexer, size_t n)
00580 {
00581   cp_token *token;
00582 
00583   /* N is 1-based, not zero-based.  */
00584   gcc_assert (n > 0);
00585 
00586   if (cp_lexer_debugging_p (lexer))
00587     fprintf (cp_lexer_debug_stream,
00588        "cp_lexer: peeking ahead %ld at token: ", (long)n);
00589 
00590   --n;
00591   token = lexer->next_token;
00592   gcc_assert (!n || token != &eof_token);
00593   while (n != 0)
00594     {
00595       ++token;
00596       if (token == lexer->last_token)
00597   {
00598     token = (cp_token *)&eof_token;
00599     break;
00600   }
00601 
00602       if (token->type != CPP_PURGED)
00603   --n;
00604     }
00605 
00606   if (cp_lexer_debugging_p (lexer))
00607     {
00608       cp_lexer_print_token (cp_lexer_debug_stream, token);
00609       putc ('\n', cp_lexer_debug_stream);
00610     }
00611 
00612   return token;
00613 }
00614 
00615 /* Return the next token, and advance the lexer's next_token pointer
00616    to point to the next non-purged token.  */
00617 
00618 static cp_token *
00619 cp_lexer_consume_token (cp_lexer* lexer)
00620 {
00621   cp_token *token = lexer->next_token;
00622 
00623   gcc_assert (token != &eof_token);
00624   gcc_assert (!lexer->in_pragma || token->type != CPP_PRAGMA_EOL);
00625 
00626   do
00627     {
00628       lexer->next_token++;
00629       if (lexer->next_token == lexer->last_token)
00630   {
00631     lexer->next_token = (cp_token *)&eof_token;
00632     break;
00633   }
00634 
00635     }
00636   while (lexer->next_token->type == CPP_PURGED);
00637 
00638   cp_lexer_set_source_position_from_token (token);
00639 
00640   /* Provide debugging output.  */
00641   if (cp_lexer_debugging_p (lexer))
00642     {
00643       fputs ("cp_lexer: consuming token: ", cp_lexer_debug_stream);
00644       cp_lexer_print_token (cp_lexer_debug_stream, token);
00645       putc ('\n', cp_lexer_debug_stream);
00646     }
00647 
00648   return token;
00649 }
00650 
00651 /* Permanently remove the next token from the token stream, and
00652    advance the next_token pointer to refer to the next non-purged
00653    token.  */
00654 
00655 static void
00656 cp_lexer_purge_token (cp_lexer *lexer)
00657 {
00658   cp_token *tok = lexer->next_token;
00659 
00660   gcc_assert (tok != &eof_token);
00661   tok->type = CPP_PURGED;
00662   tok->location = UNKNOWN_LOCATION;
00663   tok->u.value = NULL_TREE;
00664   tok->keyword = RID_MAX;
00665 
00666   do
00667     {
00668       tok++;
00669       if (tok == lexer->last_token)
00670   {
00671     tok = (cp_token *)&eof_token;
00672     break;
00673   }
00674     }
00675   while (tok->type == CPP_PURGED);
00676   lexer->next_token = tok;
00677 }
00678 
00679 /* Permanently remove all tokens after TOK, up to, but not
00680    including, the token that will be returned next by
00681    cp_lexer_peek_token.  */
00682 
00683 static void
00684 cp_lexer_purge_tokens_after (cp_lexer *lexer, cp_token *tok)
00685 {
00686   cp_token *peek = lexer->next_token;
00687 
00688   if (peek == &eof_token)
00689     peek = lexer->last_token;
00690 
00691   gcc_assert (tok < peek);
00692 
00693   for ( tok += 1; tok != peek; tok += 1)
00694     {
00695       tok->type = CPP_PURGED;
00696       tok->location = UNKNOWN_LOCATION;
00697       tok->u.value = NULL_TREE;
00698       tok->keyword = RID_MAX;
00699     }
00700 }
00701 
00702 /* Begin saving tokens.  All tokens consumed after this point will be
00703    preserved.  */
00704 
00705 static void
00706 cp_lexer_save_tokens (cp_lexer* lexer)
00707 {
00708   /* Provide debugging output.  */
00709   if (cp_lexer_debugging_p (lexer))
00710     fprintf (cp_lexer_debug_stream, "cp_lexer: saving tokens\n");
00711 
00712   VEC_safe_push (cp_token_position, heap,
00713      lexer->saved_tokens, lexer->next_token);
00714 }
00715 
00716 /* Commit to the portion of the token stream most recently saved.  */
00717 
00718 static void
00719 cp_lexer_commit_tokens (cp_lexer* lexer)
00720 {
00721   /* Provide debugging output.  */
00722   if (cp_lexer_debugging_p (lexer))
00723     fprintf (cp_lexer_debug_stream, "cp_lexer: committing tokens\n");
00724 
00725   VEC_pop (cp_token_position, lexer->saved_tokens);
00726 }
00727 
00728 /* Return all tokens saved since the last call to cp_lexer_save_tokens
00729    to the token stream.  Stop saving tokens.  */
00730 
00731 static void
00732 cp_lexer_rollback_tokens (cp_lexer* lexer)
00733 {
00734   /* Provide debugging output.  */
00735   if (cp_lexer_debugging_p (lexer))
00736     fprintf (cp_lexer_debug_stream, "cp_lexer: restoring tokens\n");
00737 
00738   lexer->next_token = VEC_pop (cp_token_position, lexer->saved_tokens);
00739 }
00740 
00741 /* Print a representation of the TOKEN on the STREAM.  */
00742 
00743 #ifdef ENABLE_CHECKING
00744 
00745 static void
00746 cp_lexer_print_token (FILE * stream, cp_token *token)
00747 {
00748   /* We don't use cpp_type2name here because the parser defines
00749      a few tokens of its own.  */
00750   static const char *const token_names[] = {
00751     /* cpplib-defined token types */
00752 #define OP(e, s) #e,
00753 #define TK(e, s) #e,
00754     TTYPE_TABLE
00755 #undef OP
00756 #undef TK
00757     /* C++ parser token types - see "Manifest constants", above.  */
00758     "KEYWORD",
00759     "TEMPLATE_ID",
00760     "NESTED_NAME_SPECIFIER",
00761     "PURGED"
00762   };
00763 
00764   /* If we have a name for the token, print it out.  Otherwise, we
00765      simply give the numeric code.  */
00766   gcc_assert (token->type < ARRAY_SIZE(token_names));
00767   fputs (token_names[token->type], stream);
00768 
00769   /* For some tokens, print the associated data.  */
00770   switch (token->type)
00771     {
00772     case CPP_KEYWORD:
00773       /* Some keywords have a value that is not an IDENTIFIER_NODE.
00774    For example, `struct' is mapped to an INTEGER_CST.  */
00775       if (TREE_CODE (token->u.value) != IDENTIFIER_NODE)
00776   break;
00777       /* else fall through */
00778     case CPP_NAME:
00779       fputs (IDENTIFIER_POINTER (token->u.value), stream);
00780       break;
00781 
00782     case CPP_STRING:
00783     case CPP_WSTRING:
00784       fprintf (stream, " \"%s\"", TREE_STRING_POINTER (token->u.value));
00785       break;
00786 
00787     default:
00788       break;
00789     }
00790 }
00791 
00792 /* Start emitting debugging information.  */
00793 
00794 static void
00795 cp_lexer_start_debugging (cp_lexer* lexer)
00796 {
00797   lexer->debugging_p = true;
00798 }
00799 
00800 /* Stop emitting debugging information.  */
00801 
00802 static void
00803 cp_lexer_stop_debugging (cp_lexer* lexer)
00804 {
00805   lexer->debugging_p = false;
00806 }
00807 
00808 #endif /* ENABLE_CHECKING */
00809 
00810 /* Create a new cp_token_cache, representing a range of tokens.  */
00811 
00812 static cp_token_cache *
00813 cp_token_cache_new (cp_token *first, cp_token *last)
00814 {
00815   cp_token_cache *cache = GGC_NEW (cp_token_cache);
00816   cache->first = first;
00817   cache->last = last;
00818   return cache;
00819 }
00820 
00821 
00822 /* Decl-specifiers.  */
00823 
00824 /* Set *DECL_SPECS to represent an empty decl-specifier-seq.  */
00825 
00826 static void
00827 clear_decl_specs (cp_decl_specifier_seq *decl_specs)
00828 {
00829   memset (decl_specs, 0, sizeof (cp_decl_specifier_seq));
00830 }
00831 
00832 /* Declarators.  */
00833 
00834 /* Nothing other than the parser should be creating declarators;
00835    declarators are a semi-syntactic representation of C++ entities.
00836    Other parts of the front end that need to create entities (like
00837    VAR_DECLs or FUNCTION_DECLs) should do that directly.  */
00838 
00839 static cp_declarator *make_call_declarator
00840   (cp_declarator *, cp_parameter_declarator *, cp_cv_quals, tree);
00841 static cp_declarator *make_array_declarator
00842   (cp_declarator *, tree);
00843 static cp_declarator *make_pointer_declarator
00844   (cp_cv_quals, cp_declarator *);
00845 static cp_declarator *make_reference_declarator
00846   (cp_cv_quals, cp_declarator *);
00847 static cp_parameter_declarator *make_parameter_declarator
00848   (cp_decl_specifier_seq *, cp_declarator *, tree);
00849 static cp_declarator *make_ptrmem_declarator
00850   (cp_cv_quals, tree, cp_declarator *);
00851 
00852 /* An erroneous declarator.  */
00853 static cp_declarator *cp_error_declarator;
00854 
00855 /* The obstack on which declarators and related data structures are
00856    allocated.  */
00857 static struct obstack declarator_obstack;
00858 
00859 /* Alloc BYTES from the declarator memory pool.  */
00860 
00861 static inline void *
00862 alloc_declarator (size_t bytes)
00863 {
00864   return obstack_alloc (&declarator_obstack, bytes);
00865 }
00866 
00867 /* Allocate a declarator of the indicated KIND.  Clear fields that are
00868    common to all declarators.  */
00869 
00870 static cp_declarator *
00871 make_declarator (cp_declarator_kind kind)
00872 {
00873   cp_declarator *declarator;
00874 
00875   declarator = (cp_declarator *) alloc_declarator (sizeof (cp_declarator));
00876   declarator->kind = kind;
00877   declarator->attributes = NULL_TREE;
00878   declarator->declarator = NULL;
00879 
00880   return declarator;
00881 }
00882 
00883 /* Make a declarator for a generalized identifier.  If
00884    QUALIFYING_SCOPE is non-NULL, the identifier is
00885    QUALIFYING_SCOPE::UNQUALIFIED_NAME; otherwise, it is just
00886    UNQUALIFIED_NAME.  SFK indicates the kind of special function this
00887    is, if any.   */
00888 
00889 static cp_declarator *
00890 make_id_declarator (tree qualifying_scope, tree unqualified_name,
00891         special_function_kind sfk)
00892 {
00893   cp_declarator *declarator;
00894 
00895   /* It is valid to write:
00896 
00897        class C { void f(); };
00898        typedef C D;
00899        void D::f();
00900 
00901      The standard is not clear about whether `typedef const C D' is
00902      legal; as of 2002-09-15 the committee is considering that
00903      question.  EDG 3.0 allows that syntax.  Therefore, we do as
00904      well.  */
00905   if (qualifying_scope && TYPE_P (qualifying_scope))
00906     qualifying_scope = TYPE_MAIN_VARIANT (qualifying_scope);
00907 
00908   gcc_assert (TREE_CODE (unqualified_name) == IDENTIFIER_NODE
00909         || TREE_CODE (unqualified_name) == BIT_NOT_EXPR
00910         || TREE_CODE (unqualified_name) == TEMPLATE_ID_EXPR);
00911 
00912   declarator = make_declarator (cdk_id);
00913   declarator->u.id.qualifying_scope = qualifying_scope;
00914   declarator->u.id.unqualified_name = unqualified_name;
00915   declarator->u.id.sfk = sfk;
00916 
00917   return declarator;
00918 }
00919 
00920 /* Make a declarator for a pointer to TARGET.  CV_QUALIFIERS is a list
00921    of modifiers such as const or volatile to apply to the pointer
00922    type, represented as identifiers.  */
00923 
00924 cp_declarator *
00925 make_pointer_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
00926 {
00927   cp_declarator *declarator;
00928 
00929   declarator = make_declarator (cdk_pointer);
00930   declarator->declarator = target;
00931   declarator->u.pointer.qualifiers = cv_qualifiers;
00932   declarator->u.pointer.class_type = NULL_TREE;
00933 
00934   return declarator;
00935 }
00936 
00937 /* Like make_pointer_declarator -- but for references.  */
00938 
00939 cp_declarator *
00940 make_reference_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
00941 {
00942   cp_declarator *declarator;
00943 
00944   declarator = make_declarator (cdk_reference);
00945   declarator->declarator = target;
00946   declarator->u.pointer.qualifiers = cv_qualifiers;
00947   declarator->u.pointer.class_type = NULL_TREE;
00948 
00949   return declarator;
00950 }
00951 
00952 /* Like make_pointer_declarator -- but for a pointer to a non-static
00953    member of CLASS_TYPE.  */
00954 
00955 cp_declarator *
00956 make_ptrmem_declarator (cp_cv_quals cv_qualifiers, tree class_type,
00957       cp_declarator *pointee)
00958 {
00959   cp_declarator *declarator;
00960 
00961   declarator = make_declarator (cdk_ptrmem);
00962   declarator->declarator = pointee;
00963   declarator->u.pointer.qualifiers = cv_qualifiers;
00964   declarator->u.pointer.class_type = class_type;
00965 
00966   return declarator;
00967 }
00968 
00969 /* Make a declarator for the function given by TARGET, with the
00970    indicated PARMS.  The CV_QUALIFIERS aply to the function, as in
00971    "const"-qualified member function.  The EXCEPTION_SPECIFICATION
00972    indicates what exceptions can be thrown.  */
00973 
00974 cp_declarator *
00975 make_call_declarator (cp_declarator *target,
00976           cp_parameter_declarator *parms,
00977           cp_cv_quals cv_qualifiers,
00978           tree exception_specification)
00979 {
00980   cp_declarator *declarator;
00981 
00982   declarator = make_declarator (cdk_function);
00983   declarator->declarator = target;
00984   declarator->u.function.parameters = parms;
00985   declarator->u.function.qualifiers = cv_qualifiers;
00986   declarator->u.function.exception_specification = exception_specification;
00987 
00988   return declarator;
00989 }
00990 
00991 /* Make a declarator for an array of BOUNDS elements, each of which is
00992    defined by ELEMENT.  */
00993 
00994 cp_declarator *
00995 make_array_declarator (cp_declarator *element, tree bounds)
00996 {
00997   cp_declarator *declarator;
00998 
00999   declarator = make_declarator (cdk_array);
01000   declarator->declarator = element;
01001   declarator->u.array.bounds = bounds;
01002 
01003   return declarator;
01004 }
01005 
01006 cp_parameter_declarator *no_parameters;
01007 
01008 /* Create a parameter declarator with the indicated DECL_SPECIFIERS,
01009    DECLARATOR and DEFAULT_ARGUMENT.  */
01010 
01011 cp_parameter_declarator *
01012 make_parameter_declarator (cp_decl_specifier_seq *decl_specifiers,
01013          cp_declarator *declarator,
01014          tree default_argument)
01015 {
01016   cp_parameter_declarator *parameter;
01017 
01018   parameter = ((cp_parameter_declarator *)
01019          alloc_declarator (sizeof (cp_parameter_declarator)));
01020   parameter->next = NULL;
01021   if (decl_specifiers)
01022     parameter->decl_specifiers = *decl_specifiers;
01023   else
01024     clear_decl_specs (&parameter->decl_specifiers);
01025   parameter->declarator = declarator;
01026   parameter->default_argument = default_argument;
01027   parameter->ellipsis_p = false;
01028 
01029   return parameter;
01030 }
01031 
01032 /* Returns true iff DECLARATOR  is a declaration for a function.  */
01033 
01034 static bool
01035 function_declarator_p (const cp_declarator *declarator)
01036 {
01037   while (declarator)
01038     {
01039       if (declarator->kind == cdk_function
01040     && declarator->declarator->kind == cdk_id)
01041   return true;
01042       if (declarator->kind == cdk_id
01043     || declarator->kind == cdk_error)
01044   return false;
01045       declarator = declarator->declarator;
01046     }
01047   return false;
01048 }
01049  
01050 /* The parser.  */
01051 
01052 /* Overview
01053    --------
01054 
01055    A cp_parser parses the token stream as specified by the C++
01056    grammar.  Its job is purely parsing, not semantic analysis.  For
01057    example, the parser breaks the token stream into declarators,
01058    expressions, statements, and other similar syntactic constructs.
01059    It does not check that the types of the expressions on either side
01060    of an assignment-statement are compatible, or that a function is
01061    not declared with a parameter of type `void'.
01062 
01063    The parser invokes routines elsewhere in the compiler to perform
01064    semantic analysis and to build up the abstract syntax tree for the
01065    code processed.
01066 
01067    The parser (and the template instantiation code, which is, in a
01068    way, a close relative of parsing) are the only parts of the
01069    compiler that should be calling push_scope and pop_scope, or
01070    related functions.  The parser (and template instantiation code)
01071    keeps track of what scope is presently active; everything else
01072    should simply honor that.  (The code that generates static
01073    initializers may also need to set the scope, in order to check
01074    access control correctly when emitting the initializers.)
01075 
01076    Methodology
01077    -----------
01078 
01079    The parser is of the standard recursive-descent variety.  Upcoming
01080    tokens in the token stream are examined in order to determine which
01081    production to use when parsing a non-terminal.  Some C++ constructs
01082    require arbitrary look ahead to disambiguate.  For example, it is
01083    impossible, in the general case, to tell whether a statement is an
01084    expression or declaration without scanning the entire statement.
01085    Therefore, the parser is capable of "parsing tentatively."  When the
01086    parser is not sure what construct comes next, it enters this mode.
01087    Then, while we attempt to parse the construct, the parser queues up
01088    error messages, rather than issuing them immediately, and saves the
01089    tokens it consumes.  If the construct is parsed successfully, the
01090    parser "commits", i.e., it issues any queued error messages and
01091    the tokens that were being preserved are permanently discarded.
01092    If, however, the construct is not parsed successfully, the parser
01093    rolls back its state completely so that it can resume parsing using
01094    a different alternative.
01095 
01096    Future Improvements
01097    -------------------
01098 
01099    The performance of the parser could probably be improved substantially.
01100    We could often eliminate the need to parse tentatively by looking ahead
01101    a little bit.  In some places, this approach might not entirely eliminate
01102    the need to parse tentatively, but it might still speed up the average
01103    case.  */
01104 
01105 /* Flags that are passed to some parsing functions.  These values can
01106    be bitwise-ored together.  */
01107 
01108 typedef enum cp_parser_flags
01109 {
01110   /* No flags.  */
01111   CP_PARSER_FLAGS_NONE = 0x0,
01112   /* The construct is optional.  If it is not present, then no error
01113      should be issued.  */
01114   CP_PARSER_FLAGS_OPTIONAL = 0x1,
01115   /* When parsing a type-specifier, do not allow user-defined types.  */
01116   CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES = 0x2
01117 } cp_parser_flags;
01118 
01119 /* The different kinds of declarators we want to parse.  */
01120 
01121 typedef enum cp_parser_declarator_kind
01122 {
01123   /* We want an abstract declarator.  */
01124   CP_PARSER_DECLARATOR_ABSTRACT,
01125   /* We want a named declarator.  */
01126   CP_PARSER_DECLARATOR_NAMED,
01127   /* We don't mind, but the name must be an unqualified-id.  */
01128   CP_PARSER_DECLARATOR_EITHER
01129 } cp_parser_declarator_kind;
01130 
01131 /* The precedence values used to parse binary expressions.  The minimum value
01132    of PREC must be 1, because zero is reserved to quickly discriminate
01133    binary operators from other tokens.  */
01134 
01135 enum cp_parser_prec
01136 {
01137   PREC_NOT_OPERATOR,
01138   PREC_LOGICAL_OR_EXPRESSION,
01139   PREC_LOGICAL_AND_EXPRESSION,
01140   PREC_INCLUSIVE_OR_EXPRESSION,
01141   PREC_EXCLUSIVE_OR_EXPRESSION,
01142   PREC_AND_EXPRESSION,
01143   PREC_EQUALITY_EXPRESSION,
01144   PREC_RELATIONAL_EXPRESSION,
01145   PREC_SHIFT_EXPRESSION,
01146   PREC_ADDITIVE_EXPRESSION,
01147   PREC_MULTIPLICATIVE_EXPRESSION,
01148   PREC_PM_EXPRESSION,
01149   NUM_PREC_VALUES = PREC_PM_EXPRESSION
01150 };
01151 
01152 /* A mapping from a token type to a corresponding tree node type, with a
01153    precedence value.  */
01154 
01155 typedef struct cp_parser_binary_operations_map_node
01156 {
01157   /* The token type.  */
01158   enum cpp_ttype token_type;
01159   /* The corresponding tree code.  */
01160   enum tree_code tree_type;
01161   /* The precedence of this operator.  */
01162   enum cp_parser_prec prec;
01163 } cp_parser_binary_operations_map_node;
01164 
01165 /* The status of a tentative parse.  */
01166 
01167 typedef enum cp_parser_status_kind
01168 {
01169   /* No errors have occurred.  */
01170   CP_PARSER_STATUS_KIND_NO_ERROR,
01171   /* An error has occurred.  */
01172   CP_PARSER_STATUS_KIND_ERROR,
01173   /* We are committed to this tentative parse, whether or not an error
01174      has occurred.  */
01175   CP_PARSER_STATUS_KIND_COMMITTED
01176 } cp_parser_status_kind;
01177 
01178 typedef struct cp_parser_expression_stack_entry
01179 {
01180   tree lhs;
01181   enum tree_code tree_type;
01182   int prec;
01183 } cp_parser_expression_stack_entry;
01184 
01185 /* The stack for storing partial expressions.  We only need NUM_PREC_VALUES
01186    entries because precedence levels on the stack are monotonically
01187    increasing.  */
01188 typedef struct cp_parser_expression_stack_entry
01189   cp_parser_expression_stack[NUM_PREC_VALUES];
01190 
01191 /* Context that is saved and restored when parsing tentatively.  */
01192 typedef struct cp_parser_context GTY (())
01193 {
01194   /* If this is a tentative parsing context, the status of the
01195      tentative parse.  */
01196   enum cp_parser_status_kind status;
01197   /* If non-NULL, we have just seen a `x->' or `x.' expression.  Names
01198      that are looked up in this context must be looked up both in the
01199      scope given by OBJECT_TYPE (the type of `x' or `*x') and also in
01200      the context of the containing expression.  */
01201   tree object_type;
01202 
01203   /* The next parsing context in the stack.  */
01204   struct cp_parser_context *next;
01205 } cp_parser_context;
01206 
01207 /* Prototypes.  */
01208 
01209 /* Constructors and destructors.  */
01210 
01211 static cp_parser_context *cp_parser_context_new
01212   (cp_parser_context *);
01213 
01214 /* Class variables.  */
01215 
01216 static GTY((deletable)) cp_parser_context* cp_parser_context_free_list;
01217 
01218 /* The operator-precedence table used by cp_parser_binary_expression.
01219    Transformed into an associative array (binops_by_token) by
01220    cp_parser_new.  */
01221 
01222 static const cp_parser_binary_operations_map_node binops[] = {
01223   { CPP_DEREF_STAR, MEMBER_REF, PREC_PM_EXPRESSION },
01224   { CPP_DOT_STAR, DOTSTAR_EXPR, PREC_PM_EXPRESSION },
01225 
01226   { CPP_MULT, MULT_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
01227   { CPP_DIV, TRUNC_DIV_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
01228   { CPP_MOD, TRUNC_MOD_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
01229 
01230   { CPP_PLUS, PLUS_EXPR, PREC_ADDITIVE_EXPRESSION },
01231   { CPP_MINUS, MINUS_EXPR, PREC_ADDITIVE_EXPRESSION },
01232 
01233   { CPP_LSHIFT, LSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
01234   { CPP_RSHIFT, RSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
01235 
01236   { CPP_LESS, LT_EXPR, PREC_RELATIONAL_EXPRESSION },
01237   { CPP_GREATER, GT_EXPR, PREC_RELATIONAL_EXPRESSION },
01238   { CPP_LESS_EQ, LE_EXPR, PREC_RELATIONAL_EXPRESSION },
01239   { CPP_GREATER_EQ, GE_EXPR, PREC_RELATIONAL_EXPRESSION },
01240 
01241   { CPP_EQ_EQ, EQ_EXPR, PREC_EQUALITY_EXPRESSION },
01242   { CPP_NOT_EQ, NE_EXPR, PREC_EQUALITY_EXPRESSION },
01243 
01244   { CPP_AND, BIT_AND_EXPR, PREC_AND_EXPRESSION },
01245 
01246   { CPP_XOR, BIT_XOR_EXPR, PREC_EXCLUSIVE_OR_EXPRESSION },
01247 
01248   { CPP_OR, BIT_IOR_EXPR, PREC_INCLUSIVE_OR_EXPRESSION },
01249 
01250   { CPP_AND_AND, TRUTH_ANDIF_EXPR, PREC_LOGICAL_AND_EXPRESSION },
01251 
01252   { CPP_OR_OR, TRUTH_ORIF_EXPR, PREC_LOGICAL_OR_EXPRESSION }
01253 };
01254 
01255 /* The same as binops, but initialized by cp_parser_new so that
01256    binops_by_token[N].token_type == N.  Used in cp_parser_binary_expression
01257    for speed.  */
01258 static cp_parser_binary_operations_map_node binops_by_token[N_CP_TTYPES];
01259 
01260 /* Constructors and destructors.  */
01261 
01262 /* Construct a new context.  The context below this one on the stack
01263    is given by NEXT.  */
01264 
01265 static cp_parser_context *
01266 cp_parser_context_new (cp_parser_context* next)
01267 {
01268   cp_parser_context *context;
01269 
01270   /* Allocate the storage.  */
01271   if (cp_parser_context_free_list != NULL)
01272     {
01273       /* Pull the first entry from the free list.  */
01274       context = cp_parser_context_free_list;
01275       cp_parser_context_free_list = context->next;
01276       memset (context, 0, sizeof (*context));
01277     }
01278   else
01279     context = GGC_CNEW (cp_parser_context);
01280 
01281   /* No errors have occurred yet in this context.  */
01282   context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
01283   /* If this is not the bottomost context, copy information that we
01284      need from the previous context.  */
01285   if (next)
01286     {
01287       /* If, in the NEXT context, we are parsing an `x->' or `x.'
01288    expression, then we are parsing one in this context, too.  */
01289       context->object_type = next->object_type;
01290       /* Thread the stack.  */
01291       context->next = next;
01292     }
01293 
01294   return context;
01295 }
01296 
01297 /* The cp_parser structure represents the C++ parser.  */
01298 
01299 typedef struct cp_parser GTY(())
01300 {
01301   /* The lexer from which we are obtaining tokens.  */
01302   cp_lexer *lexer;
01303 
01304   /* The scope in which names should be looked up.  If NULL_TREE, then
01305      we look up names in the scope that is currently open in the
01306      source program.  If non-NULL, this is either a TYPE or
01307      NAMESPACE_DECL for the scope in which we should look.  It can
01308      also be ERROR_MARK, when we've parsed a bogus scope.
01309 
01310      This value is not cleared automatically after a name is looked
01311      up, so we must be careful to clear it before starting a new look
01312      up sequence.  (If it is not cleared, then `X::Y' followed by `Z'
01313      will look up `Z' in the scope of `X', rather than the current
01314      scope.)  Unfortunately, it is difficult to tell when name lookup
01315      is complete, because we sometimes peek at a token, look it up,
01316      and then decide not to consume it.   */
01317   tree scope;
01318 
01319   /* OBJECT_SCOPE and QUALIFYING_SCOPE give the scopes in which the
01320      last lookup took place.  OBJECT_SCOPE is used if an expression
01321      like "x->y" or "x.y" was used; it gives the type of "*x" or "x",
01322      respectively.  QUALIFYING_SCOPE is used for an expression of the
01323      form "X::Y"; it refers to X.  */
01324   tree object_scope;
01325   tree qualifying_scope;
01326 
01327   /* A stack of parsing contexts.  All but the bottom entry on the
01328      stack will be tentative contexts.
01329 
01330      We parse tentatively in order to determine which construct is in
01331      use in some situations.  For example, in order to determine
01332      whether a statement is an expression-statement or a
01333      declaration-statement we parse it tentatively as a
01334      declaration-statement.  If that fails, we then reparse the same
01335      token stream as an expression-statement.  */
01336   cp_parser_context *context;
01337 
01338   /* True if we are parsing GNU C++.  If this flag is not set, then
01339      GNU extensions are not recognized.  */
01340   bool allow_gnu_extensions_p;
01341 
01342   /* TRUE if the `>' token should be interpreted as the greater-than
01343      operator.  FALSE if it is the end of a template-id or
01344      template-parameter-list.  */
01345   bool greater_than_is_operator_p;
01346 
01347   /* TRUE if default arguments are allowed within a parameter list
01348      that starts at this point. FALSE if only a gnu extension makes
01349      them permissible.  */
01350   bool default_arg_ok_p;
01351 
01352   /* TRUE if we are parsing an integral constant-expression.  See
01353      [expr.const] for a precise definition.  */
01354   bool integral_constant_expression_p;
01355 
01356   /* TRUE if we are parsing an integral constant-expression -- but a
01357      non-constant expression should be permitted as well.  This flag
01358      is used when parsing an array bound so that GNU variable-length
01359      arrays are tolerated.  */
01360   bool allow_non_integral_constant_expression_p;
01361 
01362   /* TRUE if ALLOW_NON_CONSTANT_EXPRESSION_P is TRUE and something has
01363      been seen that makes the expression non-constant.  */
01364   bool non_integral_constant_expression_p;
01365 
01366   /* TRUE if local variable names and `this' are forbidden in the
01367      current context.  */
01368   bool local_variables_forbidden_p;
01369 
01370   /* TRUE if the declaration we are parsing is part of a
01371      linkage-specification of the form `extern string-literal
01372      declaration'.  */
01373   bool in_unbraced_linkage_specification_p;
01374 
01375   /* TRUE if we are presently parsing a declarator, after the
01376      direct-declarator.  */
01377   bool in_declarator_p;
01378 
01379   /* TRUE if we are presently parsing a template-argument-list.  */
01380   bool in_template_argument_list_p;
01381 
01382   /* Set to IN_ITERATION_STMT if parsing an iteration-statement,
01383      to IN_OMP_BLOCK if parsing OpenMP structured block and
01384      IN_OMP_FOR if parsing OpenMP loop.  If parsing a switch statement,
01385      this is bitwise ORed with IN_SWITCH_STMT, unless parsing an
01386      iteration-statement, OpenMP block or loop within that switch.  */
01387 #define IN_SWITCH_STMT    1
01388 #define IN_ITERATION_STMT 2
01389 #define IN_OMP_BLOCK    4
01390 #define IN_OMP_FOR    8
01391   unsigned char in_statement;
01392 
01393   /* TRUE if we are presently parsing the body of a switch statement.
01394      Note that this doesn't quite overlap with in_statement above.
01395      The difference relates to giving the right sets of error messages:
01396      "case not in switch" vs "break statement used with OpenMP...".  */
01397   bool in_switch_statement_p;
01398 
01399   /* TRUE if we are parsing a type-id in an expression context.  In
01400      such a situation, both "type (expr)" and "type (type)" are valid
01401      alternatives.  */
01402   bool in_type_id_in_expr_p;
01403 
01404   /* TRUE if we are currently in a header file where declarations are
01405      implicitly extern "C".  */
01406   bool implicit_extern_c;
01407 
01408   /* TRUE if strings in expressions should be translated to the execution
01409      character set.  */
01410   bool translate_strings_p;
01411 
01412   /* TRUE if we are presently parsing the body of a function, but not
01413      a local class.  */
01414   bool in_function_body;
01415 
01416   /* If non-NULL, then we are parsing a construct where new type
01417      definitions are not permitted.  The string stored here will be
01418      issued as an error message if a type is defined.  */
01419   const char *type_definition_forbidden_message;
01420 
01421   /* A list of lists. The outer list is a stack, used for member
01422      functions of local classes. At each level there are two sub-list,
01423      one on TREE_VALUE and one on TREE_PURPOSE. Each of those
01424      sub-lists has a FUNCTION_DECL or TEMPLATE_DECL on their
01425      TREE_VALUE's. The functions are chained in reverse declaration
01426      order.
01427 
01428      The TREE_PURPOSE sublist contains those functions with default
01429      arguments that need post processing, and the TREE_VALUE sublist
01430      contains those functions with definitions that need post
01431      processing.
01432 
01433      These lists can only be processed once the outermost class being
01434      defined is complete.  */
01435   tree unparsed_functions_queues;
01436 
01437   /* The number of classes whose definitions are currently in
01438      progress.  */
01439   unsigned num_classes_being_defined;
01440 
01441   /* The number of template parameter lists that apply directly to the
01442      current declaration.  */
01443   unsigned num_template_parameter_lists;
01444 } cp_parser;
01445 
01446 /* Prototypes.  */
01447 
01448 /* Constructors and destructors.  */
01449 
01450 static cp_parser *cp_parser_new
01451   (void);
01452 
01453 /* Routines to parse various constructs.
01454 
01455    Those that return `tree' will return the error_mark_node (rather
01456    than NULL_TREE) if a parse error occurs, unless otherwise noted.
01457    Sometimes, they will return an ordinary node if error-recovery was
01458    attempted, even though a parse error occurred.  So, to check
01459    whether or not a parse error occurred, you should always use
01460    cp_parser_error_occurred.  If the construct is optional (indicated
01461    either by an `_opt' in the name of the function that does the
01462    parsing or via a FLAGS parameter), then NULL_TREE is returned if
01463    the construct is not present.  */
01464 
01465 /* Lexical conventions [gram.lex]  */
01466 
01467 static tree cp_parser_identifier
01468   (cp_parser *);
01469 static tree cp_parser_string_literal
01470   (cp_parser *, bool, bool);
01471 
01472 /* Basic concepts [gram.basic]  */
01473 
01474 static bool cp_parser_translation_unit
01475   (cp_parser *);
01476 
01477 /* Expressions [gram.expr]  */
01478 
01479 static tree cp_parser_primary_expression
01480   (cp_parser *, bool, bool, bool, cp_id_kind *);
01481 static tree cp_parser_id_expression
01482   (cp_parser *, bool, bool, bool *, bool, bool);
01483 static tree cp_parser_unqualified_id
01484   (cp_parser *, bool, bool, bool, bool);
01485 static tree cp_parser_nested_name_specifier_opt
01486   (cp_parser *, bool, bool, bool, bool);
01487 static tree cp_parser_nested_name_specifier
01488   (cp_parser *, bool, bool, bool, bool);
01489 static tree cp_parser_class_or_namespace_name
01490   (cp_parser *, bool, bool, bool, bool, bool);
01491 static tree cp_parser_postfix_expression
01492   (cp_parser *, bool, bool);
01493 static tree cp_parser_postfix_open_square_expression
01494   (cp_parser *, tree, bool);
01495 static tree cp_parser_postfix_dot_deref_expression
01496   (cp_parser *, enum cpp_ttype, tree, bool, cp_id_kind *);
01497 static tree cp_parser_parenthesized_expression_list
01498   (cp_parser *, bool, bool, bool *);
01499 static void cp_parser_pseudo_destructor_name
01500   (cp_parser *, tree *, tree *);
01501 static tree cp_parser_unary_expression
01502   (cp_parser *, bool, bool);
01503 static enum tree_code cp_parser_unary_operator
01504   (cp_token *);
01505 static tree cp_parser_new_expression
01506   (cp_parser *);
01507 static tree cp_parser_new_placement
01508   (cp_parser *);
01509 static tree cp_parser_new_type_id
01510   (cp_parser *, tree *);
01511 static cp_declarator *cp_parser_new_declarator_opt
01512   (cp_parser *);
01513 static cp_declarator *cp_parser_direct_new_declarator
01514   (cp_parser *);
01515 static tree cp_parser_new_initializer
01516   (cp_parser *);
01517 static tree cp_parser_delete_expression
01518   (cp_parser *);
01519 static tree cp_parser_cast_expression
01520   (cp_parser *, bool, bool);
01521 static tree cp_parser_binary_expression
01522   (cp_parser *, bool);
01523 static tree cp_parser_question_colon_clause
01524   (cp_parser *, tree);
01525 static tree cp_parser_assignment_expression
01526   (cp_parser *, bool);
01527 static enum tree_code cp_parser_assignment_operator_opt
01528   (cp_parser *);
01529 static tree cp_parser_expression
01530   (cp_parser *, bool);
01531 static tree cp_parser_constant_expression
01532   (cp_parser *, bool, bool *);
01533 static tree cp_parser_builtin_offsetof
01534   (cp_parser *);
01535 
01536 /* Statements [gram.stmt.stmt]  */
01537 
01538 static void cp_parser_statement
01539   (cp_parser *, tree, bool);
01540 static void cp_parser_label_for_labeled_statement
01541   (cp_parser *);
01542 static tree cp_parser_expression_statement
01543   (cp_parser *, tree);
01544 static tree cp_parser_compound_statement
01545   (cp_parser *, tree, bool);
01546 static void cp_parser_statement_seq_opt
01547   (cp_parser *, tree);
01548 static tree cp_parser_selection_statement
01549   (cp_parser *);
01550 static tree cp_parser_condition
01551   (cp_parser *);
01552 static tree cp_parser_iteration_statement
01553   (cp_parser *);
01554 static void cp_parser_for_init_statement
01555   (cp_parser *);
01556 static tree cp_parser_jump_statement
01557   (cp_parser *);
01558 static void cp_parser_declaration_statement
01559   (cp_parser *);
01560 
01561 static tree cp_parser_implicitly_scoped_statement
01562   (cp_parser *);
01563 static void cp_parser_already_scoped_statement
01564   (cp_parser *);
01565 
01566 /* Declarations [gram.dcl.dcl] */
01567 
01568 static void cp_parser_declaration_seq_opt
01569   (cp_parser *);
01570 static void cp_parser_declaration
01571   (cp_parser *);
01572 static void cp_parser_block_declaration
01573   (cp_parser *, bool);
01574 static void cp_parser_simple_declaration
01575   (cp_parser *, bool);
01576 static void cp_parser_decl_specifier_seq
01577   (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, int *);
01578 static tree cp_parser_storage_class_specifier_opt
01579   (cp_parser *);
01580 static tree cp_parser_function_specifier_opt
01581   (cp_parser *, cp_decl_specifier_seq *);
01582 static tree cp_parser_type_specifier
01583   (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, bool,
01584    int *, bool *);
01585 static tree cp_parser_simple_type_specifier
01586   (cp_parser *, cp_decl_specifier_seq *, cp_parser_flags);
01587 static tree cp_parser_type_name
01588   (cp_parser *);
01589 static tree cp_parser_elaborated_type_specifier
01590   (cp_parser *, bool, bool);
01591 static tree cp_parser_enum_specifier
01592   (cp_parser *);
01593 static void cp_parser_enumerator_list
01594   (cp_parser *, tree);
01595 static void cp_parser_enumerator_definition
01596   (cp_parser *, tree);
01597 static tree cp_parser_namespace_name
01598   (cp_parser *);
01599 static void cp_parser_namespace_definition
01600   (cp_parser *);
01601 static void cp_parser_namespace_body
01602   (cp_parser *);
01603 static tree cp_parser_qualified_namespace_specifier
01604   (cp_parser *);
01605 static void cp_parser_namespace_alias_definition
01606   (cp_parser *);
01607 static bool cp_parser_using_declaration
01608   (cp_parser *, bool);
01609 static void cp_parser_using_directive
01610   (cp_parser *);
01611 static void cp_parser_asm_definition
01612   (cp_parser *);
01613 static void cp_parser_linkage_specification
01614   (cp_parser *);
01615 
01616 /* Declarators [gram.dcl.decl] */
01617 
01618 static tree cp_parser_init_declarator
01619   (cp_parser *, cp_decl_specifier_seq *, VEC (deferred_access_check,gc)*, bool, bool, int, bool *);
01620 static cp_declarator *cp_parser_declarator
01621   (cp_parser *, cp_parser_declarator_kind, int *, bool *, bool);
01622 static cp_declarator *cp_parser_direct_declarator
01623   (cp_parser *, cp_parser_declarator_kind, int *, bool);
01624 static enum tree_code cp_parser_ptr_operator
01625   (cp_parser *, tree *, cp_cv_quals *);
01626 static cp_cv_quals cp_parser_cv_qualifier_seq_opt
01627   (cp_parser *);
01628 static tree cp_parser_declarator_id
01629   (cp_parser *, bool);
01630 static tree cp_parser_type_id
01631   (cp_parser *);
01632 static void cp_parser_type_specifier_seq
01633   (cp_parser *, bool, cp_decl_specifier_seq *);
01634 static cp_parameter_declarator *cp_parser_parameter_declaration_clause
01635   (cp_parser *);
01636 static cp_parameter_declarator *cp_parser_parameter_declaration_list
01637   (cp_parser *, bool *);
01638 static cp_parameter_declarator *cp_parser_parameter_declaration
01639   (cp_parser *, bool, bool *);
01640 static void cp_parser_function_body
01641   (cp_parser *);
01642 static tree cp_parser_initializer
01643   (cp_parser *, bool *, bool *);
01644 static tree cp_parser_initializer_clause
01645   (cp_parser *, bool *);
01646 static VEC(constructor_elt,gc) *cp_parser_initializer_list
01647   (cp_parser *, bool *);
01648 
01649 static bool cp_parser_ctor_initializer_opt_and_function_body
01650   (cp_parser *);
01651 
01652 /* Classes [gram.class] */
01653 
01654 static tree cp_parser_class_name
01655   (cp_parser *, bool, bool, enum tag_types, bool, bool, bool);
01656 static tree cp_parser_class_specifier
01657   (cp_parser *);
01658 static tree cp_parser_class_head
01659   (cp_parser *, bool *, tree *, tree *);
01660 static enum tag_types cp_parser_class_key
01661   (cp_parser *);
01662 static void cp_parser_member_specification_opt
01663   (cp_parser *);
01664 static void cp_parser_member_declaration
01665   (cp_parser *);
01666 static tree cp_parser_pure_specifier
01667   (cp_parser *);
01668 static tree cp_parser_constant_initializer
01669   (cp_parser *);
01670 
01671 /* Derived classes [gram.class.derived] */
01672 
01673 static tree cp_parser_base_clause
01674   (cp_parser *);
01675 static tree cp_parser_base_specifier
01676   (cp_parser *);
01677 
01678 /* Special member functions [gram.special] */
01679 
01680 static tree cp_parser_conversion_function_id
01681   (cp_parser *);
01682 static tree cp_parser_conversion_type_id
01683   (cp_parser *);
01684 static cp_declarator *cp_parser_conversion_declarator_opt
01685   (cp_parser *);
01686 static bool cp_parser_ctor_initializer_opt
01687   (cp_parser *);
01688 static void cp_parser_mem_initializer_list
01689   (cp_parser *);
01690 static tree cp_parser_mem_initializer
01691   (cp_parser *);
01692 static tree cp_parser_mem_initializer_id
01693   (cp_parser *);
01694 
01695 /* Overloading [gram.over] */
01696 
01697 static tree cp_parser_operator_function_id
01698   (cp_parser *);
01699 static tree cp_parser_operator
01700   (cp_parser *);
01701 
01702 /* Templates [gram.temp] */
01703 
01704 static void cp_parser_template_declaration
01705   (cp_parser *, bool);
01706 static tree cp_parser_template_parameter_list
01707   (cp_parser *);
01708 static tree cp_parser_template_parameter
01709   (cp_parser *, bool *);
01710 static tree cp_parser_type_parameter
01711   (cp_parser *);
01712 static tree cp_parser_template_id
01713   (cp_parser *, bool, bool, bool);
01714 static tree cp_parser_template_name
01715   (cp_parser *, bool, bool, bool, bool *);
01716 static tree cp_parser_template_argument_list
01717   (cp_parser *);
01718 static tree cp_parser_template_argument
01719   (cp_parser *);
01720 static void cp_parser_explicit_instantiation
01721   (cp_parser *);
01722 static void cp_parser_explicit_specialization
01723   (cp_parser *);
01724 
01725 /* Exception handling [gram.exception] */
01726 
01727 static tree cp_parser_try_block
01728   (cp_parser *);
01729 static bool cp_parser_function_try_block
01730   (cp_parser *);
01731 static void cp_parser_handler_seq
01732   (cp_parser *);
01733 static void cp_parser_handler
01734   (cp_parser *);
01735 static tree cp_parser_exception_declaration
01736   (cp_parser *);
01737 static tree cp_parser_throw_expression
01738   (cp_parser *);
01739 static tree cp_parser_exception_specification_opt
01740   (cp_parser *);
01741 static tree cp_parser_type_id_list
01742   (cp_parser *);
01743 
01744 /* GNU Extensions */
01745 
01746 static tree cp_parser_asm_specification_opt
01747   (cp_parser *);
01748 static tree cp_parser_asm_operand_list
01749   (cp_parser *);
01750 static tree cp_parser_asm_clobber_list
01751   (cp_parser *);
01752 static tree cp_parser_attributes_opt
01753   (cp_parser *);
01754 static tree cp_parser_attribute_list
01755   (cp_parser *);
01756 static bool cp_parser_extension_opt
01757   (cp_parser *, int *);
01758 static void cp_parser_label_declaration
01759   (cp_parser *);
01760 
01761 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
01762 static bool cp_parser_pragma
01763   (cp_parser *, enum pragma_context);
01764 
01765 /* Objective-C++ Productions */
01766 
01767 static tree cp_parser_objc_message_receiver
01768   (cp_parser *);
01769 static tree cp_parser_objc_message_args
01770   (cp_parser *);
01771 static tree cp_parser_objc_message_expression
01772   (cp_parser *);
01773 static tree cp_parser_objc_encode_expression
01774   (cp_parser *);
01775 static tree cp_parser_objc_defs_expression
01776   (cp_parser *);
01777 static tree cp_parser_objc_protocol_expression
01778   (cp_parser *);
01779 static tree cp_parser_objc_selector_expression
01780   (cp_parser *);
01781 static tree cp_parser_objc_expression
01782   (cp_parser *);
01783 static bool cp_parser_objc_selector_p
01784   (enum cpp_ttype);
01785 static tree cp_parser_objc_selector
01786   (cp_parser *);
01787 static tree cp_parser_objc_protocol_refs_opt
01788   (cp_parser *);
01789 static void cp_parser_objc_declaration
01790   (cp_parser *);
01791 static tree cp_parser_objc_statement
01792   (cp_parser *);
01793 
01794 /* Utility Routines */
01795 
01796 static tree cp_parser_lookup_name
01797   (cp_parser *, tree, enum tag_types, bool, bool, bool, tree *);
01798 static tree cp_parser_lookup_name_simple
01799   (cp_parser *, tree);
01800 static tree cp_parser_maybe_treat_template_as_class
01801   (tree, bool);
01802 static bool cp_parser_check_declarator_template_parameters
01803   (cp_parser *, cp_declarator *);
01804 static bool cp_parser_check_template_parameters
01805   (cp_parser *, unsigned);
01806 static tree cp_parser_simple_cast_expression
01807   (cp_parser *);
01808 static tree cp_parser_global_scope_opt
01809   (cp_parser *, bool);
01810 static bool cp_parser_constructor_declarator_p
01811   (cp_parser *, bool);
01812 static tree cp_parser_function_definition_from_specifiers_and_declarator
01813   (cp_parser *, cp_decl_specifier_seq *, tree, const cp_declarator *);
01814 static tree cp_parser_function_definition_after_declarator
01815   (cp_parser *, bool);
01816 static void cp_parser_template_declaration_after_export
01817   (cp_parser *, bool);
01818 static void cp_parser_perform_template_parameter_access_checks
01819   (VEC (deferred_access_check,gc)*);
01820 static tree cp_parser_single_declaration
01821   (cp_parser *, VEC (deferred_access_check,gc)*, bool, bool *);
01822 static tree cp_parser_functional_cast
01823   (cp_parser *, tree);
01824 static tree cp_parser_save_member_function_body
01825   (cp_parser *, cp_decl_specifier_seq *, cp_declarator *, tree);
01826 static tree cp_parser_enclosed_template_argument_list
01827   (cp_parser *);
01828 static void cp_parser_save_default_args
01829   (cp_parser *, tree);
01830 static void cp_parser_late_parsing_for_member
01831   (cp_parser *, tree);
01832 static void cp_parser_late_parsing_default_args
01833   (cp_parser *, tree);
01834 static tree cp_parser_sizeof_operand
01835   (cp_parser *, enum rid);
01836 static bool cp_parser_declares_only_class_p
01837   (cp_parser *);
01838 static void cp_parser_set_storage_class
01839   (cp_parser *, cp_decl_specifier_seq *, enum rid);
01840 static void cp_parser_set_decl_spec_type
01841   (cp_decl_specifier_seq *, tree, bool);
01842 static bool cp_parser_friend_p
01843   (const cp_decl_specifier_seq *);
01844 static cp_token *cp_parser_require
01845   (cp_parser *, enum cpp_ttype, const char *);
01846 static cp_token *cp_parser_require_keyword
01847   (cp_parser *, enum rid, const char *);
01848 static bool cp_parser_token_starts_function_definition_p
01849   (cp_token *);
01850 static bool cp_parser_next_token_starts_class_definition_p
01851   (cp_parser *);
01852 static bool cp_parser_next_token_ends_template_argument_p
01853   (cp_parser *);
01854 static bool cp_parser_nth_token_starts_template_argument_list_p
01855   (cp_parser *, size_t);
01856 static enum tag_types cp_parser_token_is_class_key
01857   (cp_token *);
01858 static void cp_parser_check_class_key
01859   (enum tag_types, tree type);
01860 static void cp_parser_check_access_in_redeclaration
01861   (tree type);
01862 static bool cp_parser_optional_template_keyword
01863   (cp_parser *);
01864 static void cp_parser_pre_parsed_nested_name_specifier
01865   (cp_parser *);
01866 static void cp_parser_cache_group
01867   (cp_parser *, enum cpp_ttype, unsigned);
01868 static void cp_parser_parse_tentatively
01869   (cp_parser *);
01870 static void cp_parser_commit_to_tentative_parse
01871   (cp_parser *);
01872 static void cp_parser_abort_tentative_parse
01873   (cp_parser *);
01874 static bool cp_parser_parse_definitely
01875   (cp_parser *);
01876 static inline bool cp_parser_parsing_tentatively
01877   (cp_parser *);
01878 static bool cp_parser_uncommitted_to_tentative_parse_p
01879   (cp_parser *);
01880 static void cp_parser_error
01881   (cp_parser *, const char *);
01882 static void cp_parser_name_lookup_error
01883   (cp_parser *, tree, tree, const char *);
01884 static bool cp_parser_simulate_error
01885   (cp_parser *);
01886 static bool cp_parser_check_type_definition
01887   (cp_parser *);
01888 static void cp_parser_check_for_definition_in_return_type
01889   (cp_declarator *, tree);
01890 static void cp_parser_check_for_invalid_template_id
01891   (cp_parser *, tree);
01892 static bool cp_parser_non_integral_constant_expression
01893   (cp_parser *, const char *);
01894 static void cp_parser_diagnose_invalid_type_name
01895   (cp_parser *, tree, tree);
01896 static bool cp_parser_parse_and_diagnose_invalid_type_name
01897   (cp_parser *);
01898 static int cp_parser_skip_to_closing_parenthesis
01899   (cp_parser *, bool, bool, bool);
01900 static void cp_parser_skip_to_end_of_statement
01901   (cp_parser *);
01902 static void cp_parser_consume_semicolon_at_end_of_statement
01903   (cp_parser *);
01904 static void cp_parser_skip_to_end_of_block_or_statement
01905   (cp_parser *);
01906 static void cp_parser_skip_to_closing_brace
01907   (cp_parser *);
01908 static void cp_parser_skip_to_end_of_template_parameter_list
01909   (cp_parser *);
01910 static void cp_parser_skip_to_pragma_eol
01911   (cp_parser*, cp_token *);
01912 static bool cp_parser_error_occurred
01913   (cp_parser *);
01914 static bool cp_parser_allow_gnu_extensions_p
01915   (cp_parser *);
01916 static bool cp_parser_is_string_literal
01917   (cp_token *);
01918 static bool cp_parser_is_keyword
01919   (cp_token *, enum rid);
01920 static tree cp_parser_make_typename_type
01921   (cp_parser *, tree, tree);
01922 
01923 /* Returns nonzero if we are parsing tentatively.  */
01924 
01925 static inline bool
01926 cp_parser_parsing_tentatively (cp_parser* parser)
01927 {
01928   return parser->context->next != NULL;
01929 }
01930 
01931 /* Returns nonzero if TOKEN is a string literal.  */
01932 
01933 static bool
01934 cp_parser_is_string_literal (cp_token* token)
01935 {
01936   return (token->type == CPP_STRING || token->type == CPP_WSTRING);
01937 }
01938 
01939 /* Returns nonzero if TOKEN is the indicated KEYWORD.  */
01940 
01941 static bool
01942 cp_parser_is_keyword (cp_token* token, enum rid keyword)
01943 {
01944   return token->keyword == keyword;
01945 }
01946 
01947 /* If not parsing tentatively, issue a diagnostic of the form
01948       FILE:LINE: MESSAGE before TOKEN
01949    where TOKEN is the next token in the input stream.  MESSAGE
01950    (specified by the caller) is usually of the form "expected
01951    OTHER-TOKEN".  */
01952 
01953 static void
01954 cp_parser_error (cp_parser* parser, const char* message)
01955 {
01956   if (!cp_parser_simulate_error (parser))
01957     {
01958       cp_token *token = cp_lexer_peek_token (parser->lexer);
01959       /* This diagnostic makes more sense if it is tagged to the line
01960    of the token we just peeked at.  */
01961       cp_lexer_set_source_position_from_token (token);
01962 
01963       if (token->type == CPP_PRAGMA)
01964   {
01965     error ("%<#pragma%> is not allowed here");
01966     cp_parser_skip_to_pragma_eol (parser, token);
01967     return;
01968   }
01969 
01970       c_parse_error (message,
01971          /* Because c_parser_error does not understand
01972       CPP_KEYWORD, keywords are treated like
01973       identifiers.  */
01974          (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
01975          token->u.value);
01976     }
01977 }
01978 
01979 /* Issue an error about name-lookup failing.  NAME is the
01980    IDENTIFIER_NODE DECL is the result of
01981    the lookup (as returned from cp_parser_lookup_name).  DESIRED is
01982    the thing that we hoped to find.  */
01983 
01984 static void
01985 cp_parser_name_lookup_error (cp_parser* parser,
01986            tree name,
01987            tree decl,
01988            const char* desired)
01989 {
01990   /* If name lookup completely failed, tell the user that NAME was not
01991      declared.  */
01992   if (decl == error_mark_node)
01993     {
01994       if (parser->scope && parser->scope != global_namespace)
01995   error ("%<%D::%D%> has not been declared",
01996          parser->scope, name);
01997       else if (parser->scope == global_namespace)
01998   error ("%<::%D%> has not been declared", name);
01999       else if (parser->object_scope
02000          && !CLASS_TYPE_P (parser->object_scope))
02001   error ("request for member %qD in non-class type %qT",
02002          name, parser->object_scope);
02003       else if (parser->object_scope)
02004   error ("%<%T::%D%> has not been declared",
02005          parser->object_scope, name);
02006       else
02007   error ("%qD has not been declared", name);
02008     }
02009   else if (parser->scope && parser->scope != global_namespace)
02010     error ("%<%D::%D%> %s", parser->scope, name, desired);
02011   else if (parser->scope == global_namespace)
02012     error ("%<::%D%> %s", name, desired);
02013   else
02014     error ("%qD %s", name, desired);
02015 }
02016 
02017 /* If we are parsing tentatively, remember that an error has occurred
02018    during this tentative parse.  Returns true if the error was
02019    simulated; false if a message should be issued by the caller.  */
02020 
02021 static bool
02022 cp_parser_simulate_error (cp_parser* parser)
02023 {
02024   if (cp_parser_uncommitted_to_tentative_parse_p (parser))
02025     {
02026       parser->context->status = CP_PARSER_STATUS_KIND_ERROR;
02027       return true;
02028     }
02029   return false;
02030 }
02031 
02032 /* Check for repeated decl-specifiers.  */
02033 
02034 static void
02035 cp_parser_check_decl_spec (cp_decl_specifier_seq *decl_specs)
02036 {
02037   cp_decl_spec ds;
02038 
02039   for (ds = ds_first; ds != ds_last; ++ds)
02040     {
02041       unsigned count = decl_specs->specs[(int)ds];
02042       if (count < 2)
02043   continue;
02044       /* The "long" specifier is a special case because of "long long".  */
02045       if (ds == ds_long)
02046   {
02047     if (count > 2)
02048       error ("%<long long long%> is too long for GCC");
02049     else if (pedantic && !in_system_header && warn_long_long)
02050       pedwarn ("ISO C++ does not support %<long long%>");
02051   }
02052       else if (count > 1)
02053   {
02054     static const char *const decl_spec_names[] = {
02055       "signed",
02056       "unsigned",
02057       "short",
02058       "long",
02059       "const",
02060       "volatile",
02061       "restrict",
02062       "inline",
02063       "virtual",
02064       "explicit",
02065       "friend",
02066       "typedef",
02067       "__complex",
02068       "__thread"
02069     };
02070     error ("duplicate %qs", decl_spec_names[(int)ds]);
02071   }
02072     }
02073 }
02074 
02075 /* This function is called when a type is defined.  If type
02076    definitions are forbidden at this point, an error message is
02077    issued.  */
02078 
02079 static bool
02080 cp_parser_check_type_definition (cp_parser* parser)
02081 {
02082   /* If types are forbidden here, issue a message.  */
02083   if (parser->type_definition_forbidden_message)
02084     {
02085       /* Use `%s' to print the string in case there are any escape
02086    characters in the message.  */
02087       error ("%s", parser->type_definition_forbidden_message);
02088       return false;
02089     }
02090   return true;
02091 }
02092 
02093 /* This function is called when the DECLARATOR is processed.  The TYPE
02094    was a type defined in the decl-specifiers.  If it is invalid to
02095    define a type in the decl-specifiers for DECLARATOR, an error is
02096    issued.  */
02097 
02098 static void
02099 cp_parser_check_for_definition_in_return_type (cp_declarator *declarator,
02100                  tree type)
02101 {
02102   /* [dcl.fct] forbids type definitions in return types.
02103      Unfortunately, it's not easy to know whether or not we are
02104      processing a return type until after the fact.  */
02105   while (declarator
02106    && (declarator->kind == cdk_pointer
02107        || declarator->kind == cdk_reference
02108        || declarator->kind == cdk_ptrmem))
02109     declarator = declarator->declarator;
02110   if (declarator
02111       && declarator->kind == cdk_function)
02112     {
02113       error ("new types may not be defined in a return type");
02114       inform ("(perhaps a semicolon is missing after the definition of %qT)",
02115         type);
02116     }
02117 }
02118 
02119 /* A type-specifier (TYPE) has been parsed which cannot be followed by
02120    "<" in any valid C++ program.  If the next token is indeed "<",
02121    issue a message warning the user about what appears to be an
02122    invalid attempt to form a template-id.  */
02123 
02124 static void
02125 cp_parser_check_for_invalid_template_id (cp_parser* parser,
02126            tree type)
02127 {
02128   cp_token_position start = 0;
02129 
02130   if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
02131     {
02132       if (TYPE_P (type))
02133   error ("%qT is not a template", type);
02134       else if (TREE_CODE (type) == IDENTIFIER_NODE)
02135   error ("%qE is not a template", type);
02136       else
02137   error ("invalid template-id");
02138       /* Remember the location of the invalid "<".  */
02139       if (cp_parser_uncommitted_to_tentative_parse_p (parser))
02140   start = cp_lexer_token_position (parser->lexer, true);
02141       /* Consume the "<".  */
02142       cp_lexer_consume_token (parser->lexer);
02143       /* Parse the template arguments.  */
02144       cp_parser_enclosed_template_argument_list (parser);
02145       /* Permanently remove the invalid template arguments so that
02146    this error message is not issued again.  */
02147       if (start)
02148   cp_lexer_purge_tokens_after (parser->lexer, start);
02149     }
02150 }
02151 
02152 /* If parsing an integral constant-expression, issue an error message
02153    about the fact that THING appeared and return true.  Otherwise,
02154    return false.  In either case, set
02155    PARSER->NON_INTEGRAL_CONSTANT_EXPRESSION_P.  */
02156 
02157 static bool
02158 cp_parser_non_integral_constant_expression (cp_parser  *parser,
02159               const char *thing)
02160 {
02161   parser->non_integral_constant_expression_p = true;
02162   if (parser->integral_constant_expression_p)
02163     {
02164       if (!parser->allow_non_integral_constant_expression_p)
02165   {
02166     error ("%s cannot appear in a constant-expression", thing);
02167     return true;
02168   }
02169     }
02170   return false;
02171 }
02172 
02173 /* Emit a diagnostic for an invalid type name.  SCOPE is the
02174    qualifying scope (or NULL, if none) for ID.  This function commits
02175    to the current active tentative parse, if any.  (Otherwise, the
02176    problematic construct might be encountered again later, resulting
02177    in duplicate error messages.)  */
02178 
02179 static void
02180 cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
02181 {
02182   tree decl, old_scope;
02183   /* Try to lookup the identifier.  */
02184   old_scope = parser->scope;
02185   parser->scope = scope;
02186   decl = cp_parser_lookup_name_simple (parser, id);
02187   parser->scope = old_scope;
02188   /* If the lookup found a template-name, it means that the user forgot
02189   to specify an argument list. Emit a useful error message.  */
02190   if (TREE_CODE (decl) == TEMPLATE_DECL)
02191     error ("invalid use of template-name %qE without an argument list", decl);
02192   else if (TREE_CODE (id) == BIT_NOT_EXPR)
02193     error ("invalid use of destructor %qD as a type", id);
02194   else if (TREE_CODE (decl) == TYPE_DECL)
02195     /* Something like 'unsigned A a;'  */
02196     error ("invalid combination of multiple type-specifiers");
02197   else if (!parser->scope)
02198     {
02199       /* Issue an error message.  */
02200       error ("%qE does not name a type", id);
02201       /* If we're in a template class, it's possible that the user was
02202    referring to a type from a base class.  For example:
02203 
02204      template <typename T> struct A { typedef T X; };
02205      template <typename T> struct B : public A<T> { X x; };
02206 
02207    The user should have said "typename A<T>::X".  */
02208       if (processing_template_decl && current_class_type
02209     && TYPE_BINFO (current_class_type))
02210   {
02211     tree b;
02212 
02213     for (b = TREE_CHAIN (TYPE_BINFO (current_class_type));
02214          b;
02215          b = TREE_CHAIN (b))
02216       {
02217         tree base_type = BINFO_TYPE (b);
02218         if (CLASS_TYPE_P (base_type)
02219       && dependent_type_p (base_type))
02220     {
02221       tree field;
02222       /* Go from a particular instantiation of the
02223          template (which will have an empty TYPE_FIELDs),
02224          to the main version.  */
02225       base_type = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (base_type);
02226       for (field = TYPE_FIELDS (base_type);
02227            field;
02228            field = TREE_CHAIN (field))
02229         if (TREE_CODE (field) == TYPE_DECL
02230       && DECL_NAME (field) == id)
02231           {
02232       inform ("(perhaps %<typename %T::%E%> was intended)",
02233         BINFO_TYPE (b), id);
02234       break;
02235           }
02236       if (field)
02237         break;
02238     }
02239       }
02240   }
02241     }
02242   /* Here we diagnose qualified-ids where the scope is actually correct,
02243      but the identifier does not resolve to a valid type name.  */
02244   else if (parser->scope != error_mark_node)
02245     {
02246       if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
02247   error ("%qE in namespace %qE does not name a type",
02248          id, parser->scope);
02249       else if (TYPE_P (parser->scope))
02250   error ("%qE in class %qT does not name a type", id, parser->scope);
02251       else
02252   gcc_unreachable ();
02253     }
02254   cp_parser_commit_to_tentative_parse (parser);
02255 }
02256 
02257 /* Check for a common situation where a type-name should be present,
02258    but is not, and issue a sensible error message.  Returns true if an
02259    invalid type-name was detected.
02260 
02261    The situation handled by this function are variable declarations of the
02262    form `ID a', where `ID' is an id-expression and `a' is a plain identifier.
02263    Usually, `ID' should name a type, but if we got here it means that it
02264    does not. We try to emit the best possible error message depending on
02265    how exactly the id-expression looks like.  */
02266 
02267 static bool
02268 cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
02269 {
02270   tree id;
02271 
02272   cp_parser_parse_tentatively (parser);
02273   id = cp_parser_id_expression (parser,
02274         /*template_keyword_p=*/false,
02275         /*check_dependency_p=*/true,
02276         /*template_p=*/NULL,
02277         /*declarator_p=*/true,
02278         /*optional_p=*/false);
02279   /* After the id-expression, there should be a plain identifier,
02280      otherwise this is not a simple variable declaration. Also, if
02281      the scope is dependent, we cannot do much.  */
02282   if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)
02283       || (parser->scope && TYPE_P (parser->scope)
02284     && dependent_type_p (parser->scope))
02285       || TREE_CODE (id) == TYPE_DECL)
02286     {
02287       cp_parser_abort_tentative_parse (parser);
02288       return false;
02289     }
02290   if (!cp_parser_parse_definitely (parser))
02291     return false;
02292 
02293   /* Emit a diagnostic for the invalid type.  */
02294   cp_parser_diagnose_invalid_type_name (parser, parser->scope, id);
02295   /* Skip to the end of the declaration; there's no point in
02296      trying to process it.  */
02297   cp_parser_skip_to_end_of_block_or_statement (parser);
02298   return true;
02299 }
02300 
02301 /* Consume tokens up to, and including, the next non-nested closing `)'.
02302    Returns 1 iff we found a closing `)'.  RECOVERING is true, if we
02303    are doing error recovery. Returns -1 if OR_COMMA is true and we
02304    found an unnested comma.  */
02305 
02306 static int
02307 cp_parser_skip_to_closing_parenthesis (cp_parser *parser,
02308                bool recovering,
02309                bool or_comma,
02310                bool consume_paren)
02311 {
02312   unsigned paren_depth = 0;
02313   unsigned brace_depth = 0;
02314 
02315   if (recovering && !or_comma
02316       && cp_parser_uncommitted_to_tentative_parse_p (parser))
02317     return 0;
02318 
02319   while (true)
02320     {
02321       cp_token * token = cp_lexer_peek_token (parser->lexer);
02322 
02323       switch (token->type)
02324   {
02325   case CPP_EOF:
02326   case CPP_PRAGMA_EOL:
02327     /* If we've run out of tokens, then there is no closing `)'.  */
02328     return 0;
02329 
02330   case CPP_SEMICOLON:
02331     /* This matches the processing in skip_to_end_of_statement.  */
02332     if (!brace_depth)
02333       return 0;
02334     break;
02335 
02336   case CPP_OPEN_BRACE:
02337     ++brace_depth;
02338     break;
02339   case CPP_CLOSE_BRACE:
02340     if (!brace_depth--)
02341       return 0;
02342     break;
02343 
02344   case CPP_COMMA:
02345     if (recovering && or_comma && !brace_depth && !paren_depth)
02346       return -1;
02347     break;
02348 
02349   case CPP_OPEN_PAREN:
02350     if (!brace_depth)
02351       ++paren_depth;
02352     break;
02353 
02354   case CPP_CLOSE_PAREN:
02355     if (!brace_depth && !paren_depth--)
02356       {
02357         if (consume_paren)
02358     cp_lexer_consume_token (parser->lexer);
02359         return 1;
02360       }
02361     break;
02362 
02363   default:
02364     break;
02365   }
02366 
02367       /* Consume the token.  */
02368       cp_lexer_consume_token (parser->lexer);
02369     }
02370 }
02371 
02372 /* Consume tokens until we reach the end of the current statement.
02373    Normally, that will be just before consuming a `;'.  However, if a
02374    non-nested `}' comes first, then we stop before consuming that.  */
02375 
02376 static void
02377 cp_parser_skip_to_end_of_statement (cp_parser* parser)
02378 {
02379   unsigned nesting_depth = 0;
02380 
02381   while (true)
02382     {
02383       cp_token *token = cp_lexer_peek_token (parser->lexer);
02384 
02385       switch (token->type)
02386   {
02387   case CPP_EOF:
02388   case CPP_PRAGMA_EOL:
02389     /* If we've run out of tokens, stop.  */
02390     return;
02391 
02392   case CPP_SEMICOLON:
02393     /* If the next token is a `;', we have reached the end of the
02394        statement.  */
02395     if (!nesting_depth)
02396       return;
02397     break;
02398 
02399   case CPP_CLOSE_BRACE:
02400     /* If this is a non-nested '}', stop before consuming it.
02401        That way, when confronted with something like:
02402 
02403          { 3 + }
02404 
02405        we stop before consuming the closing '}', even though we
02406        have not yet reached a `;'.  */
02407     if (nesting_depth == 0)
02408       return;
02409 
02410     /* If it is the closing '}' for a block that we have
02411        scanned, stop -- but only after consuming the token.
02412        That way given:
02413 
02414     void f g () { ... }
02415     typedef int I;
02416 
02417        we will stop after the body of the erroneously declared
02418        function, but before consuming the following `typedef'
02419        declaration.  */
02420     if (--nesting_depth == 0)
02421       {
02422         cp_lexer_consume_token (parser->lexer);
02423         return;
02424       }
02425 
02426   case CPP_OPEN_BRACE:
02427     ++nesting_depth;
02428     break;
02429 
02430   default:
02431     break;
02432   }
02433 
02434       /* Consume the token.  */
02435       cp_lexer_consume_token (parser->lexer);
02436     }
02437 }
02438 
02439 /* This function is called at the end of a statement or declaration.
02440    If the next token is a semicolon, it is consumed; otherwise, error
02441    recovery is attempted.  */
02442 
02443 static void
02444 cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser)
02445 {
02446   /* Look for the trailing `;'.  */
02447   if (!cp_parser_require (parser, CPP_SEMICOLON, "`;'"))
02448     {
02449       /* If there is additional (erroneous) input, skip to the end of
02450    the statement.  */
02451       cp_parser_skip_to_end_of_statement (parser);
02452       /* If the next token is now a `;', consume it.  */
02453       if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
02454   cp_lexer_consume_token (parser->lexer);
02455     }
02456 }
02457 
02458 /* Skip tokens until we have consumed an entire block, or until we
02459    have consumed a non-nested `;'.  */
02460 
02461 static void
02462 cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
02463 {
02464   int nesting_depth = 0;
02465 
02466   while (nesting_depth >= 0)
02467     {
02468       cp_token *token = cp_lexer_peek_token (parser->lexer);
02469 
02470       switch (token->type)
02471   {
02472   case CPP_EOF:
02473   case CPP_PRAGMA_EOL:
02474     /* If we've run out of tokens, stop.  */
02475     return;
02476 
02477   case CPP_SEMICOLON:
02478     /* Stop if this is an unnested ';'. */
02479     if (!nesting_depth)
02480       nesting_depth = -1;
02481     break;
02482 
02483   case CPP_CLOSE_BRACE:
02484     /* Stop if this is an unnested '}', or closes the outermost
02485        nesting level.  */
02486     nesting_depth--;
02487     if (!nesting_depth)
02488       nesting_depth = -1;
02489     break;
02490 
02491   case CPP_OPEN_BRACE:
02492     /* Nest. */
02493     nesting_depth++;
02494     break;
02495 
02496   default:
02497     break;
02498   }
02499 
02500       /* Consume the token.  */
02501       cp_lexer_consume_token (parser->lexer);
02502     }
02503 }
02504 
02505 /* Skip tokens until a non-nested closing curly brace is the next
02506    token.  */
02507 
02508 static void
02509 cp_parser_skip_to_closing_brace (cp_parser *parser)
02510 {
02511   unsigned nesting_depth = 0;
02512 
02513   while (true)
02514     {
02515       cp_token *token = cp_lexer_peek_token (parser->lexer);
02516 
02517       switch (token->type)
02518   {
02519   case CPP_EOF:
02520   case CPP_PRAGMA_EOL:
02521     /* If we've run out of tokens, stop.  */
02522     return;
02523 
02524   case CPP_CLOSE_BRACE:
02525     /* If the next token is a non-nested `}', then we have reached
02526        the end of the current block.  */
02527     if (nesting_depth-- == 0)
02528       return;
02529     break;
02530 
02531   case CPP_OPEN_BRACE:
02532     /* If it the next token is a `{', then we are entering a new
02533        block.  Consume the entire block.  */
02534     ++nesting_depth;
02535     break;
02536 
02537   default:
02538     break;
02539   }
02540 
02541       /* Consume the token.  */
02542       cp_lexer_consume_token (parser->lexer);
02543     }
02544 }
02545 
02546 /* Consume tokens until we reach the end of the pragma.  The PRAGMA_TOK
02547    parameter is the PRAGMA token, allowing us to purge the entire pragma
02548    sequence.  */
02549 
02550 static void
02551 cp_parser_skip_to_pragma_eol (cp_parser* parser, cp_token *pragma_tok)
02552 {
02553   cp_token *token;
02554 
02555   parser->lexer->in_pragma = false;
02556 
02557   do
02558     token = cp_lexer_consume_token (parser->lexer);
02559   while (token->type != CPP_PRAGMA_EOL && token->type != CPP_EOF);
02560 
02561   /* Ensure that the pragma is not parsed again.  */
02562   cp_lexer_purge_tokens_after (parser->lexer, pragma_tok);
02563 }
02564 
02565 /* Require pragma end of line, resyncing with it as necessary.  The
02566    arguments are as for cp_parser_skip_to_pragma_eol.  */
02567 
02568 static void
02569 cp_parser_require_pragma_eol (cp_parser *parser, cp_token *pragma_tok)
02570 {
02571   parser->lexer->in_pragma = false;
02572   if (!cp_parser_require (parser, CPP_PRAGMA_EOL, "end of line"))
02573     cp_parser_skip_to_pragma_eol (parser, pragma_tok);
02574 }
02575 
02576 /* This is a simple wrapper around make_typename_type. When the id is
02577    an unresolved identifier node, we can provide a superior diagnostic
02578    using cp_parser_diagnose_invalid_type_name.  */
02579 
02580 static tree
02581 cp_parser_make_typename_type (cp_parser *parser, tree scope, tree id)
02582 {
02583   tree result;
02584   if (TREE_CODE (id) == IDENTIFIER_NODE)
02585     {
02586       result = make_typename_type (scope, id, typename_type,
02587            /*complain=*/tf_none);
02588       if (result == error_mark_node)
02589   cp_parser_diagnose_invalid_type_name (parser, scope, id);
02590       return result;
02591     }
02592   return make_typename_type (scope, id, typename_type, tf_error);
02593 }
02594 
02595 
02596 /* Create a new C++ parser.  */
02597 
02598 static cp_parser *
02599 cp_parser_new (void)
02600 {
02601   cp_parser *parser;
02602   cp_lexer *lexer;
02603   unsigned i;
02604 
02605   /* cp_lexer_new_main is called before calling ggc_alloc because
02606      cp_lexer_new_main might load a PCH file.  */
02607   lexer = cp_lexer_new_main ();
02608 
02609   /* Initialize the binops_by_token so that we can get the tree
02610      directly from the token.  */
02611   for (i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
02612     binops_by_token[binops[i].token_type] = binops[i];
02613 
02614   parser = GGC_CNEW (cp_parser);
02615   parser->lexer = lexer;
02616   parser->context = cp_parser_context_new (NULL);
02617 
02618   /* For now, we always accept GNU extensions.  */
02619   parser->allow_gnu_extensions_p = 1;
02620 
02621   /* The `>' token is a greater-than operator, not the end of a
02622      template-id.  */
02623   parser->greater_than_is_operator_p = true;
02624 
02625   parser->default_arg_ok_p = true;
02626 
02627   /* We are not parsing a constant-expression.  */
02628   parser->integral_constant_expression_p = false;
02629   parser->allow_non_integral_constant_expression_p = false;
02630   parser->non_integral_constant_expression_p = false;
02631 
02632   /* Local variable names are not forbidden.  */
02633   parser->local_variables_forbidden_p = false;
02634 
02635   /* We are not processing an `extern "C"' declaration.  */
02636   parser->in_unbraced_linkage_specification_p = false;
02637 
02638   /* We are not processing a declarator.  */
02639   parser->in_declarator_p = false;
02640 
02641   /* We are not processing a template-argument-list.  */
02642   parser->in_template_argument_list_p = false;
02643 
02644   /* We are not in an iteration statement.  */
02645   parser->in_statement = 0;
02646 
02647   /* We are not in a switch statement.  */
02648   parser->in_switch_statement_p = false;
02649 
02650   /* We are not parsing a type-id inside an expression.  */
02651   parser->in_type_id_in_expr_p = false;
02652 
02653   /* Declarations aren't implicitly extern "C".  */
02654   parser->implicit_extern_c = false;
02655 
02656   /* String literals should be translated to the execution character set.  */
02657   parser->translate_strings_p = true;
02658 
02659   /* We are not parsing a function body.  */
02660   parser->in_function_body = false;
02661 
02662   /* The unparsed function queue is empty.  */
02663   parser->unparsed_functions_queues = build_tree_list (NULL_TREE, NULL_TREE);
02664 
02665   /* There are no classes being defined.  */
02666   parser->num_classes_being_defined = 0;
02667 
02668   /* No template parameters apply.  */
02669   parser->num_template_parameter_lists = 0;
02670 
02671   return parser;
02672 }
02673 
02674 /* Create a cp_lexer structure which will emit the tokens in CACHE
02675    and push it onto the parser's lexer stack.  This is used for delayed
02676    parsing of in-class method bodies and default arguments, and should
02677    not be confused with tentative parsing.  */
02678 static void
02679 cp_parser_push_lexer_for_tokens (cp_parser *parser, cp_token_cache *cache)
02680 {
02681   cp_lexer *lexer = cp_lexer_new_from_tokens (cache);
02682   lexer->next = parser->lexer;
02683   parser->lexer = lexer;
02684 
02685   /* Move the current source position to that of the first token in the
02686      new lexer.  */
02687   cp_lexer_set_source_position_from_token (lexer->next_token);
02688 }
02689 
02690 /* Pop the top lexer off the parser stack.  This is never used for the
02691    "main" lexer, only for those pushed by cp_parser_push_lexer_for_tokens.  */
02692 static void
02693 cp_parser_pop_lexer (cp_parser *parser)
02694 {
02695   cp_lexer *lexer = parser->lexer;
02696   parser->lexer = lexer->next;
02697   cp_lexer_destroy (lexer);
02698 
02699   /* Put the current source position back where it was before this
02700      lexer was pushed.  */
02701   cp_lexer_set_source_position_from_token (parser->lexer->next_token);
02702 }
02703 
02704 /* Lexical conventions [gram.lex]  */
02705 
02706 /* Parse an identifier.  Returns an IDENTIFIER_NODE representing the
02707    identifier.  */
02708 
02709 static tree
02710 cp_parser_identifier (cp_parser* parser)
02711 {
02712   cp_token *token;
02713 
02714   /* Look for the identifier.  */
02715   token = cp_parser_require (parser, CPP_NAME, "identifier");
02716   /* Return the value.  */
02717   return token ? token->u.value : error_mark_node;
02718 }
02719 
02720 /* Parse a sequence of adjacent string constants.  Returns a
02721    TREE_STRING representing the combined, nul-terminated string
02722    constant.  If TRANSLATE is true, translate the string to the
02723    execution character set.  If WIDE_OK is true, a wide string is
02724    invalid here.
02725 
02726    C++98 [lex.string] says that if a narrow string literal token is
02727    adjacent to a wide string literal token, the behavior is undefined.
02728    However, C99 6.4.5p4 says that this results in a wide string literal.
02729    We follow C99 here, for consistency with the C front end.
02730 
02731    This code is largely lifted from lex_string() in c-lex.c.
02732 
02733    FUTURE: ObjC++ will need to handle @-strings here.  */
02734 static tree
02735 cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
02736 {
02737   tree value;
02738   bool wide = false;
02739   size_t count;
02740   struct obstack str_ob;
02741   cpp_string str, istr, *strs;
02742   cp_token *tok;
02743 
02744   tok = cp_lexer_peek_token (parser->lexer);
02745   if (!cp_parser_is_string_literal (tok))
02746     {
02747       cp_parser_error (parser, "expected string-literal");
02748       return error_mark_node;
02749     }
02750 
02751   /* Try to avoid the overhead of creating and destroying an obstack
02752      for the common case of just one string.  */
02753   if (!cp_parser_is_string_literal
02754       (cp_lexer_peek_nth_token (parser->lexer, 2)))
02755     {
02756       cp_lexer_consume_token (parser->lexer);
02757 
02758       str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
02759       str.len = TREE_STRING_LENGTH (tok->u.value);
02760       count = 1;
02761       if (tok->type == CPP_WSTRING)
02762   wide = true;
02763 
02764       strs = &str;
02765     }
02766   else
02767     {
02768       gcc_obstack_init (&str_ob);
02769       count = 0;
02770 
02771       do
02772   {
02773     cp_lexer_consume_token (parser->lexer);
02774     count++;
02775     str.text = (unsigned char *)TREE_STRING_POINTER (tok->u.value);
02776     str.len = TREE_STRING_LENGTH (tok->u.value);
02777     if (tok->type == CPP_WSTRING)
02778       wide = true;
02779 
02780     obstack_grow (&str_ob, &str, sizeof (cpp_string));
02781 
02782     tok = cp_lexer_peek_token (parser->lexer);
02783   }
02784       while (cp_parser_is_string_literal (tok));
02785 
02786       strs = (cpp_string *) obstack_finish (&str_ob);
02787     }
02788 
02789   if (wide && !wide_ok)
02790     {
02791       cp_parser_error (parser, "a wide string is invalid in this context");
02792       wide = false;
02793     }
02794 
02795   if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
02796       (parse_in, strs, count, &istr, wide))
02797     {
02798       value = build_string (istr.len, (char *)istr.text);
02799       free ((void *)istr.text);
02800 
02801       TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node;
02802       value = fix_string_type (value);
02803     }
02804   else
02805     /* cpp_interpret_string has issued an error.  */
02806     value = error_mark_node;
02807 
02808   if (count > 1)
02809     obstack_free (&str_ob, 0);
02810 
02811   return value;
02812 }
02813 
02814 
02815 /* Basic concepts [gram.basic]  */
02816 
02817 /* Parse a translation-unit.
02818 
02819    translation-unit:
02820      declaration-seq [opt]
02821 
02822    Returns TRUE if all went well.  */
02823 
02824 static bool
02825 cp_parser_translation_unit (cp_parser* parser)
02826 {
02827   /* The address of the first non-permanent object on the declarator
02828      obstack.  */
02829   static void *declarator_obstack_base;
02830 
02831   bool success;
02832 
02833   /* Create the declarator obstack, if necessary.  */
02834   if (!cp_error_declarator)
02835     {
02836       gcc_obstack_init (&declarator_obstack);
02837       /* Create the error declarator.  */
02838       cp_error_declarator = make_declarator (cdk_error);
02839       /* Create the empty parameter list.  */
02840       no_parameters = make_parameter_declarator (NULL, NULL, NULL_TREE);
02841       /* Remember where the base of the declarator obstack lies.  */
02842       declarator_obstack_base = obstack_next_free (&declarator_obstack);
02843     }
02844 
02845   cp_parser_declaration_seq_opt (parser);
02846 
02847   /* If there are no tokens left then all went well.  */
02848   if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
02849     {
02850       /* Get rid of the token array; we don't need it any more.  */
02851       cp_lexer_destroy (parser->lexer);
02852       parser->lexer = NULL;
02853 
02854       /* This file might have been a context that's implicitly extern
02855    "C".  If so, pop the lang context.  (Only relevant for PCH.) */
02856       if (parser->implicit_extern_c)
02857   {
02858     pop_lang_context ();
02859     parser->implicit_extern_c = false;
02860   }
02861 
02862       /* Finish up.  */
02863       finish_translation_unit ();
02864 
02865       success = true;
02866     }
02867   else
02868     {
02869       cp_parser_error (parser, "expected declaration");
02870       success = false;
02871     }
02872 
02873   /* Make sure the declarator obstack was fully cleaned up.  */
02874   gcc_assert (obstack_next_free (&declarator_obstack)
02875         == declarator_obstack_base);
02876 
02877   /* All went well.  */
02878   return success;
02879 }
02880 
02881 /* Expressions [gram.expr] */
02882 
02883 /* Parse a primary-expression.
02884 
02885    primary-expression:
02886      literal
02887      this
02888      ( expression )
02889      id-expression
02890 
02891    GNU Extensions:
02892 
02893    primary-expression:
02894      ( compound-statement )
02895      __builtin_va_arg ( assignment-expression , type-id )
02896      __builtin_offsetof ( type-id , offsetof-expression )
02897 
02898    Objective-C++ Extension:
02899 
02900    primary-expression:
02901      objc-expression
02902 
02903    literal:
02904      __null
02905 
02906    ADDRESS_P is true iff this expression was immediately preceded by
02907    "&" and therefore might denote a pointer-to-member.  CAST_P is true
02908    iff this expression is the target of a cast.  TEMPLATE_ARG_P is
02909    true iff this expression is a template argument.
02910 
02911    Returns a representation of the expression.  Upon return, *IDK
02912    indicates what kind of id-expression (if any) was present.  */
02913 
02914 static tree
02915 cp_parser_primary_expression (cp_parser *parser,
02916             bool address_p,
02917             bool cast_p,
02918             bool template_arg_p,
02919             cp_id_kind *idk)
02920 {
02921   cp_token *token;
02922 
02923   /* Assume the primary expression is not an id-expression.  */
02924   *idk = CP_ID_KIND_NONE;
02925 
02926   /* Peek at the next token.  */
02927   token = cp_lexer_peek_token (parser->lexer);
02928   switch (token->type)
02929     {
02930       /* literal:
02931      integer-literal
02932      character-literal
02933      floating-literal
02934      string-literal
02935      boolean-literal  */
02936     case CPP_CHAR:
02937     case CPP_WCHAR:
02938     case CPP_NUMBER:
02939       token = cp_lexer_consume_token (parser->lexer);
02940       /* Floating-point literals are only allowed in an integral
02941    constant expression if they are cast to an integral or
02942    enumeration type.  */
02943       if (TREE_CODE (token->u.value) == REAL_CST
02944     && parser->integral_constant_expression_p
02945     && pedantic)
02946   {
02947     /* CAST_P will be set even in invalid code like "int(2.7 +
02948        ...)".   Therefore, we have to check that the next token
02949        is sure to end the cast.  */
02950     if (cast_p)
02951       {
02952         cp_token *next_token;
02953 
02954         next_token = cp_lexer_peek_token (parser->lexer);
02955         if (/* The comma at the end of an
02956          enumerator-definition.  */
02957       next_token->type != CPP_COMMA
02958       /* The curly brace at the end of an enum-specifier.  */
02959       && next_token->type != CPP_CLOSE_BRACE
02960       /* The end of a statement.  */
02961       && next_token->type != CPP_SEMICOLON
02962       /* The end of the cast-expression.  */
02963       && next_token->type != CPP_CLOSE_PAREN
02964       /* The end of an array bound.  */
02965       && next_token->type != CPP_CLOSE_SQUARE
02966       /* The closing ">" in a template-argument-list.  */
02967       && (next_token->type != CPP_GREATER
02968           || parser->greater_than_is_operator_p))
02969     cast_p = false;
02970       }
02971 
02972     /* If we are within a cast, then the constraint that the
02973        cast is to an integral or enumeration type will be
02974        checked at that point.  If we are not within a cast, then
02975        this code is invalid.  */
02976     if (!cast_p)
02977       cp_parser_non_integral_constant_expression
02978         (parser, "floating-point literal");
02979   }
02980       return token->u.value;
02981 
02982     case CPP_STRING:
02983     case CPP_WSTRING:
02984       /* ??? Should wide strings be allowed when parser->translate_strings_p
02985    is false (i.e. in attributes)?  If not, we can kill the third
02986    argument to cp_parser_string_literal.  */
02987       return cp_parser_string_literal (parser,
02988                parser->translate_strings_p,
02989                true);
02990 
02991     case CPP_OPEN_PAREN:
02992       {
02993   tree expr;
02994   bool saved_greater_than_is_operator_p;
02995 
02996   /* Consume the `('.  */
02997   cp_lexer_consume_token (parser->lexer);
02998   /* Within a parenthesized expression, a `>' token is always
02999      the greater-than operator.  */
03000   saved_greater_than_is_operator_p
03001     = parser->greater_than_is_operator_p;
03002   parser->greater_than_is_operator_p = true;
03003   /* If we see `( { ' then we are looking at the beginning of
03004      a GNU statement-expression.  */
03005   if (cp_parser_allow_gnu_extensions_p (parser)
03006       && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
03007     {
03008       /* Statement-expressions are not allowed by the standard.  */
03009       if (pedantic)
03010         pedwarn ("ISO C++ forbids braced-groups within expressions");
03011 
03012       /* And they're not allowed outside of a function-body; you
03013          cannot, for example, write:
03014 
03015      int i = ({ int j = 3; j + 1; });
03016 
03017          at class or namespace scope.  */
03018       if (!parser->in_function_body)
03019         error ("statement-expressions are allowed only inside functions");
03020       /* Start the statement-expression.  */
03021       expr = begin_stmt_expr ();
03022       /* Parse the compound-statement.  */
03023       cp_parser_compound_statement (parser, expr, false);
03024       /* Finish up.  */
03025       expr = finish_stmt_expr (expr, false);
03026     }
03027   else
03028     {
03029       /* Parse the parenthesized expression.  */
03030       expr = cp_parser_expression (parser, cast_p);
03031       /* Let the front end know that this expression was
03032          enclosed in parentheses. This matters in case, for
03033          example, the expression is of the form `A::B', since
03034          `&A::B' might be a pointer-to-member, but `&(A::B)' is
03035          not.  */
03036       finish_parenthesized_expr (expr);
03037     }
03038   /* The `>' token might be the end of a template-id or
03039      template-parameter-list now.  */
03040   parser->greater_than_is_operator_p
03041     = saved_greater_than_is_operator_p;
03042   /* Consume the `)'.  */
03043   if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
03044     cp_parser_skip_to_end_of_statement (parser);
03045 
03046   return expr;
03047       }
03048 
03049     case CPP_KEYWORD:
03050       switch (token->keyword)
03051   {
03052     /* These two are the boolean literals.  */
03053   case RID_TRUE:
03054     cp_lexer_consume_token (parser->lexer);
03055     return boolean_true_node;
03056   case RID_FALSE:
03057     cp_lexer_consume_token (parser->lexer);
03058     return boolean_false_node;
03059 
03060     /* The `__null' literal.  */
03061   case RID_NULL:
03062     cp_lexer_consume_token (parser->lexer);
03063     return null_node;
03064 
03065     /* Recognize the `this' keyword.  */
03066   case RID_THIS:
03067     cp_lexer_consume_token (parser->lexer);
03068     if (parser->local_variables_forbidden_p)
03069       {
03070         error ("%<this%> may not be used in this context");
03071         return error_mark_node;
03072       }
03073     /* Pointers cannot appear in constant-expressions.  */
03074     if (cp_parser_non_integral_constant_expression (parser,
03075                 "`this'"))
03076       return error_mark_node;
03077     return finish_this_expr ();
03078 
03079     /* The `operator' keyword can be the beginning of an
03080        id-expression.  */
03081   case RID_OPERATOR:
03082     goto id_expression;
03083 
03084   case RID_FUNCTION_NAME:
03085   case RID_PRETTY_FUNCTION_NAME:
03086   case RID_C99_FUNCTION_NAME:
03087     /* The symbols __FUNCTION__, __PRETTY_FUNCTION__, and
03088        __func__ are the names of variables -- but they are
03089        treated specially.  Therefore, they are handled here,
03090        rather than relying on the generic id-expression logic
03091        below.  Grammatically, these names are id-expressions.
03092 
03093        Consume the token.  */
03094     token = cp_lexer_consume_token (parser->lexer);
03095     /* Look up the name.  */
03096     return finish_fname (token->u.value);
03097 
03098   case RID_VA_ARG:
03099     {
03100       tree expression;
03101       tree type;
03102 
03103       /* The `__builtin_va_arg' construct is used to handle
03104          `va_arg'.  Consume the `__builtin_va_arg' token.  */
03105       cp_lexer_consume_token (parser->lexer);
03106       /* Look for the opening `('.  */
03107       cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
03108       /* Now, parse the assignment-expression.  */
03109       expression = cp_parser_assignment_expression (parser,
03110                 /*cast_p=*/false);
03111       /* Look for the `,'.  */
03112       cp_parser_require (parser, CPP_COMMA, "`,'");
03113       /* Parse the type-id.  */
03114       type = cp_parser_type_id (parser);
03115       /* Look for the closing `)'.  */
03116       cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
03117       /* Using `va_arg' in a constant-expression is not
03118          allowed.  */
03119       if (cp_parser_non_integral_constant_expression (parser,
03120                   "`va_arg'"))
03121         return error_mark_node;
03122       return build_x_va_arg (expression, type);
03123     }
03124 
03125   case RID_OFFSETOF:
03126     return cp_parser_builtin_offsetof (parser);
03127 
03128     /* Objective-C++ expressions.  */
03129   case RID_AT_ENCODE:
03130   case RID_AT_PROTOCOL:
03131   case RID_AT_SELECTOR:
03132     return cp_parser_objc_expression (parser);
03133 
03134   default:
03135     cp_parser_error (parser, "expected primary-expression");
03136     return error_mark_node;
03137   }
03138 
03139       /* An id-expression can start with either an identifier, a
03140    `::' as the beginning of a qualified-id, or the "operator"
03141    keyword.  */
03142     case CPP_NAME:
03143     case CPP_SCOPE:
03144     case CPP_TEMPLATE_ID:
03145     case CPP_NESTED_NAME_SPECIFIER:
03146       {
03147   tree id_expression;
03148   tree decl;
03149   const char *error_msg;
03150   bool template_p;
03151   bool done;
03152 
03153       id_expression:
03154   /* Parse the id-expression.  */
03155   id_expression
03156     = cp_parser_id_expression (parser,
03157              /*template_keyword_p=*/false,
03158              /*check_dependency_p=*/true,
03159              &template_p,
03160              /*declarator_p=*/false,
03161              /*optional_p=*/false);
03162   if (id_expression == error_mark_node)
03163     return error_mark_node;
03164   token = cp_lexer_peek_token (parser->lexer);
03165   done = (token->type != CPP_OPEN_SQUARE
03166     && token->type != CPP_OPEN_PAREN
03167     && token->type != CPP_DOT
03168     && token->type != CPP_DEREF
03169     && token->type != CPP_PLUS_PLUS
03170     && token->type != CPP_MINUS_MINUS);
03171   /* If we have a template-id, then no further lookup is
03172      required.  If the template-id was for a template-class, we
03173      will sometimes have a TYPE_DECL at this point.  */
03174   if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR
03175      || TREE_CODE (id_expression) == TYPE_DECL)
03176     decl = id_expression;
03177   /* Look up the name.  */
03178   else
03179     {
03180       tree ambiguous_decls;
03181 
03182       decl = cp_parser_lookup_name (parser, id_expression,
03183             none_type,
03184             template_p,
03185             /*is_namespace=*/false,
03186             /*check_dependency=*/true,
03187             &ambiguous_decls);
03188       /* If the lookup was ambiguous, an error will already have
03189          been issued.  */
03190       if (ambiguous_decls)
03191         return error_mark_node;
03192 
03193       /* In Objective-C++, an instance variable (ivar) may be preferred
03194          to whatever cp_parser_lookup_name() found.  */
03195       decl = objc_lookup_ivar (decl, id_expression);
03196 
03197       /* If name lookup gives us a SCOPE_REF, then the
03198          qualifying scope was dependent.  */
03199       if (TREE_CODE (decl) == SCOPE_REF)
03200         return decl;
03201       /* Check to see if DECL is a local variable in a context
03202          where that is forbidden.  */
03203       if (parser->local_variables_forbidden_p
03204     && local_variable_p (decl))
03205         {
03206     /* It might be that we only found DECL because we are
03207        trying to be generous with pre-ISO scoping rules.
03208        For example, consider:
03209 
03210          int i;
03211          void g() {
03212            for (int i = 0; i < 10; ++i) {}
03213            extern void f(int j = i);
03214          }
03215 
03216        Here, name look up will originally find the out
03217        of scope `i'.  We need to issue a warning message,
03218        but then use the global `i'.  */
03219     decl = check_for_out_of_scope_variable (decl);
03220     if (local_variable_p (decl))
03221       {
03222         error ("local variable %qD may not appear in this context",
03223          decl);
03224         return error_mark_node;
03225       }
03226         }
03227     }
03228 
03229   decl = (finish_id_expression
03230     (id_expression, decl, parser->scope,
03231      idk,
03232      parser->integral_constant_expression_p,
03233      parser->allow_non_integral_constant_expression_p,
03234      &parser->non_integral_constant_expression_p,
03235      template_p, done, address_p,
03236      template_arg_p,
03237      &error_msg));
03238   if (error_msg)
03239     cp_parser_error (parser, error_msg);
03240   return decl;
03241       }
03242 
03243       /* Anything else is an error.  */
03244     default:
03245       /* ...unless we have an Objective-C++ message or string literal, that is.  */
03246       if (c_dialect_objc ()
03247     && (token->type == CPP_OPEN_SQUARE || token->type == CPP_OBJC_STRING))
03248   return cp_parser_objc_expression (parser);
03249 
03250       cp_parser_error (parser, "expected primary-expression");
03251       return error_mark_node;
03252     }
03253 }
03254 
03255 /* Parse an id-expression.
03256 
03257    id-expression:
03258      unqualified-id
03259      qualified-id
03260 
03261    qualified-id:
03262      :: [opt] nested-name-specifier template [opt] unqualified-id
03263      :: identifier
03264      :: operator-function-id
03265      :: template-id
03266 
03267    Return a representation of the unqualified portion of the
03268    identifier.  Sets PARSER->SCOPE to the qualifying scope if there is
03269    a `::' or nested-name-specifier.
03270 
03271    Often, if the id-expression was a qualified-id, the caller will
03272    want to make a SCOPE_REF to represent the qualified-id.  This
03273    function does not do this in order to avoid wastefully creating
03274    SCOPE_REFs when they are not required.
03275 
03276    If TEMPLATE_KEYWORD_P is true, then we have just seen the
03277    `template' keyword.
03278 
03279    If CHECK_DEPENDENCY_P is false, then names are looked up inside
03280    uninstantiated templates.
03281 
03282    If *TEMPLATE_P is non-NULL, it is set to true iff the
03283    `template' keyword is used to explicitly indicate that the entity
03284    named is a template.
03285 
03286    If DECLARATOR_P is true, the id-expression is appearing as part of
03287    a declarator, rather than as part of an expression.  */
03288 
03289 static tree
03290 cp_parser_id_expression (cp_parser *parser,
03291        bool template_keyword_p,
03292        bool check_dependency_p,
03293        bool *template_p,
03294        bool declarator_p,
03295        bool optional_p)
03296 {
03297   bool global_scope_p;
03298   bool nested_name_specifier_p;
03299 
03300   /* Assume the `template' keyword was not used.  */
03301   if (template_p)
03302     *template_p = template_keyword_p;
03303 
03304   /* Look for the optional `::' operator.  */
03305   global_scope_p
03306     = (cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/false)
03307        != NULL_TREE);
03308   /* Look for the optional nested-name-specifier.  */
03309   nested_name_specifier_p
03310     = (cp_parser_nested_name_specifier_opt (parser,
03311               /*typename_keyword_p=*/false,
03312               check_dependency_p,
03313               /*type_p=*/false,
03314               declarator_p)
03315        != NULL_TREE);
03316   /* If there is a nested-name-specifier, then we are looking at
03317      the first qualified-id production.  */
03318   if (nested_name_specifier_p)
03319     {
03320       tree saved_scope;
03321       tree saved_object_scope;
03322       tree saved_qualifying_scope;
03323       tree unqualified_id;
03324       bool is_template;
03325 
03326       /* See if the next token is the `template' keyword.  */
03327       if (!template_p)
03328   template_p = &is_template;
03329       *template_p = cp_parser_optional_template_keyword (parser);
03330       /* Name lookup we do during the processing of the
03331    unqualified-id might obliterate SCOPE.  */
03332       saved_scope = parser->scope;
03333       saved_object_scope = parser->object_scope;
03334       saved_qualifying_scope = parser->qualifying_scope;
03335       /* Process the final unqualified-id.  */
03336       unqualified_id = cp_parser_unqualified_id (parser, *template_p,
03337              check_dependency_p,
03338              declarator_p,
03339              /*optional_p=*/false);
03340       /* Restore the SAVED_SCOPE for our caller.  */
03341       parser->scope = saved_scope;
03342       parser->object_scope = saved_object_scope;
03343       parser->qualifying_scope = saved_qualifying_scope;
03344 
03345       return unqualified_id;
03346     }
03347   /* Otherwise, if we are in global scope, then we are looking at one
03348      of the other qualified-id productions.  */
03349   else if (global_scope_p)
03350     {
03351       cp_token *token;
03352       tree id;
03353 
03354       /* Peek at the next token.  */
03355       token = cp_lexer_peek_token (parser->lexer);
03356 
03357       /* If it's an identifier, and the next token is not a "<", then
03358    we can avoid the template-id case.  This is an optimization
03359    for this common case.  */
03360       if (token->type == CPP_NAME
03361     && !cp_parser_nth_token_starts_template_argument_list_p
03362          (parser, 2))
03363   return cp_parser_identifier (parser);
03364 
03365       cp_parser_parse_tentatively (parser);
03366       /* Try a template-id.  */
03367       id = cp_parser_template_id (parser,
03368           /*template_keyword_p=*/false,
03369           /*check_dependency_p=*/true,
03370           declarator_p);
03371       /* If that worked, we're done.  */
03372       if (cp_parser_parse_definitely (parser))
03373   return id;
03374 
03375       /* Peek at the next token.  (Changes in the token buffer may
03376    have invalidated the pointer obtained above.)  */
03377       token = cp_lexer_peek_token (parser->lexer);
03378 
03379       switch (token->type)
03380   {
03381   case CPP_NAME:
03382     return cp_parser_identifier (parser);
03383 
03384   case CPP_KEYWORD:
03385     if (token->keyword == RID_OPERATOR)
03386       return cp_parser_operator_function_id (parser);
03387     /* Fall through.  */
03388 
03389   default:
03390     cp_parser_error (parser, "expected id-expression");
03391     return error_mark_node;
03392   }
03393     }
03394   else
03395     return cp_parser_unqualified_id (parser, template_keyword_p,
03396              /*check_dependency_p=*/true,
03397              declarator_p,
03398              optional_p);
03399 }
03400 
03401 /* Parse an unqualified-id.
03402 
03403    unqualified-id:
03404      identifier
03405      operator-function-id
03406      conversion-function-id
03407      ~ class-name
03408      template-id
03409 
03410    If TEMPLATE_KEYWORD_P is TRUE, we have just seen the `template'
03411    keyword, in a construct like `A::template ...'.
03412 
03413    Returns a representation of unqualified-id.  For the `identifier'
03414    production, an IDENTIFIER_NODE is returned.  For the `~ class-name'
03415    production a BIT_NOT_EXPR is returned; the operand of the
03416    BIT_NOT_EXPR is an IDENTIFIER_NODE for the class-name.  For the
03417    other productions, see the documentation accompanying the
03418    corresponding parsing functions.  If CHECK_DEPENDENCY_P is false,
03419    names are looked up in uninstantiated templates.  If DECLARATOR_P
03420    is true, the unqualified-id is appearing as part of a declarator,
03421    rather than as part of an expression.  */
03422 
03423 static tree
03424 cp_parser_unqualified_id (cp_parser* parser,
03425         bool template_keyword_p,
03426         bool check_dependency_p,
03427         bool declarator_p,
03428         bool optional_p)
03429 {
03430   cp_token *token;
03431 
03432   /* Peek at the next token.  */
03433   token = cp_lexer_peek_token (parser->lexer);
03434 
03435   switch (token->type)
03436     {
03437     case CPP_NAME:
03438       {
03439   tree id;
03440 
03441   /* We don't know yet whether or not this will be a
03442      template-id.  */
03443   cp_parser_parse_tentatively (parser);
03444   /* Try a template-id.  */
03445   id = cp_parser_template_id (parser, template_keyword_p,
03446             check_dependency_p,
03447             declarator_p);
03448   /* If it worked, we're done.  */
03449   if (cp_parser_parse_definitely (parser))
03450     return id;
03451   /* Otherwise, it's an ordinary identifier.  */
03452   return cp_parser_identifier (parser);
03453       }
03454 
03455     case CPP_TEMPLATE_ID:
03456       return cp_parser_template_id (parser, template_keyword_p,
03457             check_dependency_p,
03458             declarator_p);
03459 
03460     case CPP_COMPL:
03461       {
03462   tree type_decl;
03463   tree qualifying_scope;
03464   tree object_scope;
03465   tree scope;
03466   bool done;
03467 
03468   /* Consume the `~' token.  */
03469   cp_lexer_consume_token (parser->lexer);
03470   /* Parse the class-name.  The standard, as written, seems to
03471      say that:
03472 
03473        template <typename T> struct S { ~S (); };
03474        template <typename T> S<T>::~S() {}
03475 
03476      is invalid, since `~' must be followed by a class-name, but
03477      `S<T>' is dependent, and so not known to be a class.
03478      That's not right; we need to look in uninstantiated
03479      templates.  A further complication arises from:
03480 
03481        template <typename T> void f(T t) {
03482          t.T::~T();
03483        }
03484 
03485      Here, it is not possible to look up `T' in the scope of `T'
03486      itself.  We must look in both the current scope, and the
03487      scope of the containing complete expression.
03488 
03489      Yet another issue is:
03490 
03491        struct S {
03492          int S;
03493          ~S();
03494        };
03495 
03496        S::~S() {}
03497 
03498      The standard does not seem to say that the `S' in `~S'
03499      should refer to the type `S' and not the data member
03500      `S::S'.  */
03501 
03502   /* DR 244 says that we look up the name after the "~" in the
03503      same scope as we looked up the qualifying name.  That idea
03504      isn't fully worked out; it's more complicated than that.  */
03505   scope = parser->scope;
03506   object_scope = parser->object_scope;
03507   qualifying_scope = parser->qualifying_scope;
03508 
03509   /* Check for invalid scopes.  */
03510   if (scope == error_mark_node)
03511     {
03512       if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
03513         cp_lexer_consume_token (parser->lexer);
03514       return error_mark_node;
03515     }
03516   if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
03517     {
03518       if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
03519         error ("scope %qT before %<~%> is not a class-name", scope);
03520       cp_parser_simulate_error (parser);
03521       if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
03522         cp_lexer_consume_token (parser->lexer);
03523       return error_mark_node;
03524     }
03525   gcc_assert (!scope || TYPE_P (scope));
03526 
03527   /* If the name is of the form "X::~X" it's OK.  */
03528   token = cp_lexer_peek_token (parser->lexer);
03529   if (scope
03530       && token->type == CPP_NAME
03531       && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
03532     == CPP_OPEN_PAREN)
03533       && constructor_name_p (token->u.value, scope))
03534     {
03535       cp_lexer_consume_token (parser->lexer);
03536       return build_nt (BIT_NOT_EXPR, scope);
03537     }
03538 
03539   /* If there was an explicit qualification (S::~T), first look
03540      in the scope given by the qualification (i.e., S).  */
03541   done = false;
03542   type_decl = NULL_TREE;
03543   if (scope)
03544     {
03545       cp_parser_parse_tentatively (parser);
03546       type_decl = cp_parser_class_name (parser,
03547                 /*typename_keyword_p=*/false,
03548                 /*template_keyword_p=*/false,
03549                 none_type,
03550                 /*check_dependency=*/false,
03551                 /*class_head_p=*/false,
03552                 declarator_p);
03553       if (cp_parser_parse_definitely (parser))
03554         done = true;
03555     }
03556   /* In "N::S::~S", look in "N" as well.  */
03557   if (!done && scope && qualifying_scope)
03558     {
03559       cp_parser_parse_tentatively (parser);
03560       parser->scope = qualifying_scope;
03561       parser->object_scope = NULL_TREE;
03562       parser->qualifying_scope = NULL_TREE;
03563       type_decl
03564         = cp_parser_class_name (parser,
03565               /*typename_keyword_p=*/false,
03566               /*template_keyword_p=*/false,
03567               none_type,
03568               /*check_dependency=*/false,
03569               /*class_head_p=*/false,
03570               declarator_p);
03571       if (cp_parser_parse_definitely (parser))
03572         done = true;
03573     }
03574   /* In "p->S::~T", look in the scope given by "*p" as well.  */
03575   else if (!done && object_scope)
03576     {
03577       cp_parser_parse_tentatively (parser);
03578       parser->scope = object_scope;
03579       parser->object_scope = NULL_TREE;
03580       parser->qualifying_scope = NULL_TREE;
03581       type_decl
03582         = cp_parser_class_name (parser,
03583               /*typename_keyword_p=*/false,
03584               /*template_keyword_p=*/false,
03585               none_type,
03586               /*check_dependency=*/false,
03587               /*class_head_p=*/false,
03588               declarator_p);
03589       if (cp_parser_parse_definitely (parser))
03590         done = true;
03591     }
03592   /* Look in the surrounding context.  */
03593   if (!done)
03594     {
03595       parser->scope = NULL_TREE;
03596       parser->object_scope = NULL_TREE;
03597       parser->qualifying_scope = NULL_TREE;
03598       type_decl
03599         = cp_parser_class_name (parser,
03600               /*typename_keyword_p=*/false,
03601               /*template_keyword_p=*/false,
03602               none_type,
03603               /*check_dependency=*/false,
03604               /*class_head_p=*/false,
03605               declarator_p);
03606     }
03607   /* If an error occurred, assume that the name of the
03608      destructor is the same as the name of the qualifying
03609      class.  That allows us to keep parsing after running
03610      into ill-formed destructor names.  */
03611   if (type_decl == error_mark_node && scope)
03612     return build_nt (BIT_NOT_EXPR, scope);
03613   else if (type_decl == error_mark_node)
03614     return error_mark_node;
03615 
03616   /* Check that destructor name and scope match.  */
03617   if (declarator_p && scope && !check_dtor_name (scope, type_decl))
03618     {
03619       if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
03620         error ("declaration of %<~%T%> as member of %qT",
03621          type_decl, scope);
03622       cp_parser_simulate_error (parser);
03623       return error_mark_node;
03624     }
03625 
03626   /* [class.dtor]
03627 
03628      A typedef-name that names a class shall not be used as the
03629      identifier in the declarator for a destructor declaration.  */
03630   if (declarator_p
03631       && !DECL_IMPLICIT_TYPEDEF_P (type_decl)
03632       && !DECL_SELF_REFERENCE_P (type_decl)
03633       && !cp_parser_uncommitted_to_tentative_parse_p (parser))
03634     error ("typedef-name %qD used as destructor declarator",
03635      type_decl);
03636 
03637   return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
03638       }
03639 
03640     case CPP_KEYWORD:
03641       if (token->keyword == RID_OPERATOR)
03642   {
03643     tree id;
03644 
03645     /* This could be a template-id, so we try that first.  */
03646     cp_parser_parse_tentatively (parser);
03647     /* Try a template-id.  */
03648     id = cp_parser_template_id (parser, template_keyword_p,
03649               /*check_dependency_p=*/true,
03650               declarator_p);
03651     /* If that worked, we're done.  */
03652     if (cp_parser_parse_definitely (parser))
03653       return id;
03654     /* We still don't know whether we're looking at an
03655        operator-function-id or a conversion-function-id.  */
03656     cp_parser_parse_tentatively (parser);
03657     /* Try an operator-function-id.  */
03658     id = cp_parser_operator_function_id (parser);
03659     /* If that didn't work, try a conversion-function-id.  */
03660     if (!cp_parser_parse_definitely (parser))
03661       id = cp_parser_conversion_function_id (parser);
03662 
03663     return id;
03664   }
03665       /* Fall through.  */
03666 
03667     default:
03668       if (optional_p)
03669   return NULL_TREE;
03670       cp_parser_error (parser, "expected unqualified-id");
03671       return error_mark_node;
03672     }
03673 }
03674 
03675 /* Parse an (optional) nested-name-specifier.
03676 
03677    nested-name-specifier:
03678      class-or-namespace-name :: nested-name-specifier [opt]
03679      class-or-namespace-name :: template nested-name-specifier [opt]
03680 
03681    PARSER->SCOPE should be set appropriately before this function is
03682    called.  TYPENAME_KEYWORD_P is TRUE if the `typename' keyword is in
03683    effect.  TYPE_P is TRUE if we non-type bindings should be ignored
03684    in name lookups.
03685 
03686    Sets PARSER->SCOPE to the class (TYPE) or namespace
03687    (NAMESPACE_DECL) specified by the nested-name-specifier, or leaves
03688    it unchanged if there is no nested-name-specifier.  Returns the new
03689    scope iff there is a nested-name-specifier, or NULL_TREE otherwise.
03690 
03691    If IS_DECLARATION is TRUE, the nested-name-specifier is known to be
03692    part of a declaration and/or decl-specifier.  */
03693 
03694 static tree
03695 cp_parser_nested_name_specifier_opt (cp_parser *parser,
03696              bool typename_keyword_p,
03697              bool check_dependency_p,
03698              bool type_p,
03699              bool is_declaration)
03700 {
03701   bool success = false;
03702   cp_token_position start = 0;
03703   cp_token *token;
03704 
03705   /* Remember where the nested-name-specifier starts.  */
03706   if (cp_parser_uncommitted_to_tentative_parse_p (parser))
03707     {
03708       start = cp_lexer_token_position (parser->lexer, false);
03709       push_deferring_access_checks (dk_deferred);
03710     }
03711 
03712   while (true)
03713     {
03714       tree new_scope;
03715       tree old_scope;
03716       tree saved_qualifying_scope;
03717       bool template_keyword_p;
03718 
03719       /* Spot cases that cannot be the beginning of a
03720    nested-name-specifier.  */
03721       token = cp_lexer_peek_token (parser->lexer);
03722 
03723       /* If the next token is CPP_NESTED_NAME_SPECIFIER, just process
03724    the already parsed nested-name-specifier.  */
03725       if (token->type == CPP_NESTED_NAME_SPECIFIER)
03726   {
03727     /* Grab the nested-name-specifier and continue the loop.  */
03728     cp_parser_pre_parsed_nested_name_specifier (parser);
03729     /* If we originally encountered this nested-name-specifier
03730        with IS_DECLARATION set to false, we will not have
03731        resolved TYPENAME_TYPEs, so we must do so here.  */
03732     if (is_declaration
03733         && TREE_CODE (parser->scope) == TYPENAME_TYPE)
03734       {
03735         new_scope = resolve_typename_type (parser->scope,
03736              /*only_current_p=*/false);
03737         if (new_scope != error_mark_node)
03738     parser->scope = new_scope;
03739       }
03740     success = true;
03741     continue;
03742   }
03743 
03744       /* Spot cases that cannot be the beginning of a
03745    nested-name-specifier.  On the second and subsequent times
03746    through the loop, we look for the `template' keyword.  */
03747       if (success && token->keyword == RID_TEMPLATE)
03748   ;
03749       /* A template-id can start a nested-name-specifier.  */
03750       else if (token->type == CPP_TEMPLATE_ID)
03751   ;
03752       else
03753   {
03754     /* If the next token is not an identifier, then it is
03755        definitely not a class-or-namespace-name.  */
03756     if (token->type != CPP_NAME)
03757       break;
03758     /* If the following token is neither a `<' (to begin a
03759        template-id), nor a `::', then we are not looking at a
03760        nested-name-specifier.  */
03761     token = cp_lexer_peek_nth_token (parser->lexer, 2);
03762     if (token->type != CPP_SCOPE
03763         && !cp_parser_nth_token_starts_template_argument_list_p
03764       (parser, 2))
03765       break;
03766   }
03767 
03768       /* The nested-name-specifier is optional, so we parse
03769    tentatively.  */
03770       cp_parser_parse_tentatively (parser);
03771 
03772       /* Look for the optional `template' keyword, if this isn't the
03773    first time through the loop.  */
03774       if (success)
03775   template_keyword_p = cp_parser_optional_template_keyword (parser);
03776       else
03777   template_keyword_p = false;
03778 
03779       /* Save the old scope since the name lookup we are about to do
03780    might destroy it.  */
03781       old_scope = parser->scope;
03782       saved_qualifying_scope = parser->qualifying_scope;
03783       /* In a declarator-id like "X<T>::I::Y<T>" we must be able to
03784    look up names in "X<T>::I" in order to determine that "Y" is
03785    a template.  So, if we have a typename at this point, we make
03786    an effort to look through it.  */
03787       if (is_declaration
03788     && !typename_keyword_p
03789     && parser->scope
03790     && TREE_CODE (parser->scope) == TYPENAME_TYPE)
03791   parser->scope = resolve_typename_type (parser->scope,
03792                  /*only_current_p=*/false);
03793       /* Parse the qualifying entity.  */
03794       new_scope
03795   = cp_parser_class_or_namespace_name (parser,
03796                typename_keyword_p,
03797                template_keyword_p,
03798                check_dependency_p,
03799                type_p,
03800                is_declaration);
03801       /* Look for the `::' token.  */
03802       cp_parser_require (parser, CPP_SCOPE, "`::'");
03803 
03804       /* If we found what we wanted, we keep going; otherwise, we're
03805    done.  */
03806       if (!cp_parser_parse_definitely (parser))
03807   {
03808     bool error_p = false;
03809 
03810     /* Restore the OLD_SCOPE since it was valid before the
03811        failed attempt at finding the last
03812        class-or-namespace-name.  */
03813     parser->scope = old_scope;
03814     parser->qualifying_scope = saved_qualifying_scope;
03815     if (cp_parser_uncommitted_to_tentative_parse_p (parser))
03816       break;
03817     /* If the next token is an identifier, and the one after
03818        that is a `::', then any valid interpretation would have
03819        found a class-or-namespace-name.  */
03820     while (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
03821      && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
03822          == CPP_SCOPE)
03823      && (cp_lexer_peek_nth_token (parser->lexer, 3)->type
03824          != CPP_COMPL))
03825       {
03826         token = cp_lexer_consume_token (parser->lexer);
03827         if (!error_p)
03828     {
03829       if (!token->ambiguous_p)
03830         {
03831           tree decl;
03832           tree ambiguous_decls;
03833 
03834           decl = cp_parser_lookup_name (parser, token->u.value,
03835                 none_type,
03836                 /*is_template=*/false,
03837                 /*is_namespace=*/false,
03838                 /*check_dependency=*/true,
03839                 &ambiguous_decls);
03840           if (TREE_CODE (decl) == TEMPLATE_DECL)
03841       error ("%qD used without template parameters", decl);
03842           else if (ambiguous_decls)
03843       {
03844         error ("reference to %qD is ambiguous",
03845          token->u.value);
03846         print_candidates (ambiguous_decls);
03847         decl = error_mark_node;
03848       }
03849           else
03850       cp_parser_name_lookup_error
03851         (parser, token->u.value, decl,
03852          "is not a class or namespace");
03853         }
03854       parser->scope = error_mark_node;
03855       error_p = true;
03856       /* Treat this as a successful nested-name-specifier
03857          due to:
03858 
03859          [basic.lookup.qual]
03860 
03861          If the name found is not a class-name (clause
03862          _class_) or namespace-name (_namespace.def_), the
03863          program is ill-formed.  */
03864       success = true;
03865     }
03866         cp_lexer_consume_token (parser->lexer);
03867       }
03868     break;
03869   }
03870       /* We've found one valid nested-name-specifier.  */
03871       success = true;
03872       /* Name lookup always gives us a DECL.  */
03873       if (TREE_CODE (new_scope) == TYPE_DECL)
03874   new_scope = TREE_TYPE (new_scope);
03875       /* Uses of "template" must be followed by actual templates.  */
03876       if (template_keyword_p
03877     && !(CLASS_TYPE_P (new_scope)
03878          && ((CLASSTYPE_USE_TEMPLATE (new_scope)
03879         && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (new_scope)))
03880        || CLASSTYPE_IS_TEMPLATE (new_scope)))
03881     && !(TREE_CODE (new_scope) == TYPENAME_TYPE
03882          && (TREE_CODE (TYPENAME_TYPE_FULLNAME (new_scope))
03883        == TEMPLATE_ID_EXPR)))
03884   pedwarn (TYPE_P (new_scope)
03885      ? "%qT is not a template"
03886      : "%qD is not a template",
03887      new_scope);
03888       /* If it is a class scope, try to complete it; we are about to
03889    be looking up names inside the class.  */
03890       if (TYPE_P (new_scope)
03891     /* Since checking types for dependency can be expensive,
03892        avoid doing it if the type is already complete.  */
03893     && !COMPLETE_TYPE_P (new_scope)
03894     /* Do not try to complete dependent types.  */
03895     && !dependent_type_p (new_scope))
03896   new_scope = complete_type (new_scope);
03897       /* Make sure we look in the right scope the next time through
03898    the loop.  */
03899       parser->scope = new_scope;
03900     }
03901 
03902   /* If parsing tentatively, replace the sequence of tokens that makes
03903      up the nested-name-specifier with a CPP_NESTED_NAME_SPECIFIER
03904      token.  That way, should we re-parse the token stream, we will
03905      not have to repeat the effort required to do the parse, nor will
03906      we issue duplicate error messages.  */
03907   if (success && start)
03908     {
03909       cp_token *token;
03910 
03911       token = cp_lexer_token_at (parser->lexer, start);
03912       /* Reset the contents of the START token.  */
03913       token->type = CPP_NESTED_NAME_SPECIFIER;
03914       /* Retrieve any deferred checks.  Do not pop this access checks yet
03915    so the memory will not be reclaimed during token replacing below.  */
03916       token->u.tree_check_value = GGC_CNEW (struct tree_check);
03917       token->u.tree_check_value->value = parser->scope;
03918       token->u.tree_check_value->checks = get_deferred_access_checks ();
03919       token->u.tree_check_value->qualifying_scope =
03920   parser->qualifying_scope;
03921       token->keyword = RID_MAX;
03922 
03923       /* Purge all subsequent tokens.  */
03924       cp_lexer_purge_tokens_after (parser->lexer, start);
03925     }
03926 
03927   if (start)
03928     pop_to_parent_deferring_access_checks ();
03929 
03930   return success ? parser->scope : NULL_TREE;
03931 }
03932 
03933 /* Parse a nested-name-specifier.  See
03934    cp_parser_nested_name_specifier_opt for details.  This function
03935    behaves identically, except that it will an issue an error if no
03936    nested-name-specifier is present.  */
03937 
03938 static tree
03939 cp_parser_nested_name_specifier (cp_parser *parser,
03940          bool typename_keyword_p,
03941          bool check_dependency_p,
03942          bool type_p,
03943          bool is_declaration)
03944 {
03945   tree scope;
03946 
03947   /* Look for the nested-name-specifier.  */
03948   scope = cp_parser_nested_name_specifier_opt (parser,
03949                  typename_keyword_p,
03950                  check_dependency_p,
03951                  type_p,
03952                  is_declaration);
03953   /* If it was not present, issue an error message.  */
03954   if (!scope)
03955     {
03956       cp_parser_error (parser, "expected nested-name-specifier");
03957       parser->scope = NULL_TREE;
03958     }
03959 
03960   return scope;
03961 }
03962 
03963 /* Parse a class-or-namespace-name.
03964 
03965    class-or-namespace-name:
03966      class-name
03967      namespace-name
03968 
03969    TYPENAME_KEYWORD_P is TRUE iff the `typename' keyword is in effect.
03970    TEMPLATE_KEYWORD_P is TRUE iff the `template' keyword is in effect.
03971    CHECK_DEPENDENCY_P is FALSE iff dependent names should be looked up.
03972    TYPE_P is TRUE iff the next name should be taken as a class-name,
03973    even the same name is declared to be another entity in the same
03974    scope.
03975 
03976    Returns the class (TYPE_DECL) or namespace (NAMESPACE_DECL)
03977    specified by the class-or-namespace-name.  If neither is found the
03978    ERROR_MARK_NODE is returned.  */
03979 
03980 static tree
03981 cp_parser_class_or_namespace_name (cp_parser *parser,
03982            bool typename_keyword_p,
03983            bool template_keyword_p,
03984            bool check_dependency_p,
03985            bool type_p,
03986            bool is_declaration)
03987 {
03988   tree saved_scope;
03989   tree saved_qualifying_scope;
03990   tree saved_object_scope;
03991   tree scope;
03992   bool only_class_p;
03993 
03994   /* Before we try to parse the class-name, we must save away the
03995      current PARSER->SCOPE since cp_parser_class_name will destroy
03996      it.  */
03997   saved_scope = parser->scope;
03998   saved_qualifying_scope = parser->qualifying_scope;
03999   saved_object_scope = parser->object_scope;
04000   /* Try for a class-name first.  If the SAVED_SCOPE is a type, then
04001      there is no need to look for a namespace-name.  */
04002   only_class_p = template_keyword_p || (saved_scope && TYPE_P (saved_scope));
04003   if (!only_class_p)
04004     cp_parser_parse_tentatively (parser);
04005   scope = cp_parser_class_name (parser,
04006         typename_keyword_p,
04007         template_keyword_p,
04008         type_p ? class_type : none_type,
04009         check_dependency_p,
04010         /*class_head_p=*/false,
04011         is_declaration);
04012   /* If that didn't work, try for a namespace-name.  */
04013   if (!only_class_p && !cp_parser_parse_definitely (parser))
04014     {
04015       /* Restore the saved scope.  */
04016       parser->scope = saved_scope;
04017       parser->qualifying_scope = saved_qualifying_scope;
04018       parser->object_scope = saved_object_scope;
04019       /* If we are not looking at an identifier followed by the scope
04020    resolution operator, then this is not part of a
04021    nested-name-specifier.  (Note that this function is only used
04022    to parse the components of a nested-name-specifier.)  */
04023       if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)
04024     || cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
04025   return error_mark_node;
04026       scope = cp_parser_namespace_name (parser);
04027     }
04028 
04029   return scope;
04030 }
04031 
04032 /* Parse a postfix-expression.
04033 
04034    postfix-expression:
04035      primary-expression
04036      postfix-expression [ expression ]
04037      postfix-expression ( expression-list [opt] )
04038      simple-type-specifier ( expression-list [opt] )
04039      typename :: [opt] nested-name-specifier identifier
04040        ( expression-list [opt] )
04041      typename :: [opt] nested-name-specifier template [opt] template-id
04042        ( expression-list [opt] )
04043      postfix-expression . template [opt] id-expression
04044      postfix-expression -> template [opt] id-expression
04045      postfix-expression . pseudo-destructor-name
04046      postfix-expression -> pseudo-destructor-name
04047      postfix-expression ++
04048      postfix-expression --
04049      dynamic_cast < type-id > ( expression )
04050      static_cast < type-id > ( expression )
04051      reinterpret_cast < type-id > ( expression )
04052      const_cast < type-id > ( expression )
04053      typeid ( expression )
04054      typeid ( type-id )
04055 
04056    GNU Extension:
04057 
04058    postfix-expression:
04059      ( type-id ) { initializer-list , [opt] }
04060 
04061    This extension is a GNU version of the C99 compound-literal
04062    construct.  (The C99 grammar uses `type-name' instead of `type-id',
04063    but they are essentially the same concept.)
04064 
04065    If ADDRESS_P is true, the postfix expression is the operand of the
04066    `&' operator.  CAST_P is true if this expression is the target of a
04067    cast.
04068 
04069    Returns a representation of the expression.  */
04070 
04071 static tree
04072 cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p)
04073 {
04074   cp_token *token;
04075   enum rid keyword;
04076   cp_id_kind idk = CP_ID_KIND_NONE;
04077   tree postfix_expression = NULL_TREE;
04078 
04079   /* Peek at the next token.  */
04080   token = cp_lexer_peek_token (parser->lexer);
04081   /* Some of the productions are determined by keywords.  */
04082   keyword = token->keyword;
04083   switch (keyword)
04084     {
04085     case RID_DYNCAST:
04086     case RID_STATCAST:
04087     case RID_REINTCAST:
04088     case RID_CONSTCAST:
04089       {
04090   tree type;
04091   tree expression;
04092   const char *saved_message;
04093 
04094   /* All of these can be handled in the same way from the point
04095      of view of parsing.  Begin by consuming the token
04096      identifying the cast.  */
04097   cp_lexer_consume_token (parser->lexer);
04098 
04099   /* New types cannot be defined in the cast.  */
04100   saved_message = parser->type_definition_forbidden_message;
04101   parser->type_definition_forbidden_message
04102     = "types may not be defined in casts";
04103 
04104   /* Look for the opening `<'.  */
04105   cp_parser_require (parser, CPP_LESS, "`<'");
04106   /* Parse the type to which we are casting.  */
04107   type = cp_parser_type_id (parser);
04108   /* Look for the closing `>'.  */
04109   cp_parser_require (parser, CPP_GREATER, "`>'");
04110   /* Restore the old message.  */
04111   parser->type_definition_forbidden_message = saved_message;
04112 
04113   /* And the expression which is being cast.  */
04114   cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
04115   expression = cp_parser_expression (parser, /*cast_p=*/true);
04116   cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04117 
04118   /* Only type conversions to integral or enumeration types
04119      can be used in constant-expressions.  */
04120   if (!cast_valid_in_integral_constant_expression_p (type)
04121       && (cp_parser_non_integral_constant_expression
04122     (parser,
04123      "a cast to a type other than an integral or "
04124      "enumeration type")))
04125     return error_mark_node;
04126 
04127   switch (keyword)
04128     {
04129     case RID_DYNCAST:
04130       postfix_expression
04131         = build_dynamic_cast (type, expression);
04132       break;
04133     case RID_STATCAST:
04134       postfix_expression
04135         = build_static_cast (type, expression);
04136       break;
04137     case RID_REINTCAST:
04138       postfix_expression
04139         = build_reinterpret_cast (type, expression);
04140       break;
04141     case RID_CONSTCAST:
04142       postfix_expression
04143         = build_const_cast (type, expression);
04144       break;
04145     default:
04146       gcc_unreachable ();
04147     }
04148       }
04149       break;
04150 
04151     case RID_TYPEID:
04152       {
04153   tree type;
04154   const char *saved_message;
04155   bool saved_in_type_id_in_expr_p;
04156 
04157   /* Consume the `typeid' token.  */
04158   cp_lexer_consume_token (parser->lexer);
04159   /* Look for the `(' token.  */
04160   cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
04161   /* Types cannot be defined in a `typeid' expression.  */
04162   saved_message = parser->type_definition_forbidden_message;
04163   parser->type_definition_forbidden_message
04164     = "types may not be defined in a `typeid\' expression";
04165   /* We can't be sure yet whether we're looking at a type-id or an
04166      expression.  */
04167   cp_parser_parse_tentatively (parser);
04168   /* Try a type-id first.  */
04169   saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
04170   parser->in_type_id_in_expr_p = true;
04171   type = cp_parser_type_id (parser);
04172   parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
04173   /* Look for the `)' token.  Otherwise, we can't be sure that
04174      we're not looking at an expression: consider `typeid (int
04175      (3))', for example.  */
04176   cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04177   /* If all went well, simply lookup the type-id.  */
04178   if (cp_parser_parse_definitely (parser))
04179     postfix_expression = get_typeid (type);
04180   /* Otherwise, fall back to the expression variant.  */
04181   else
04182     {
04183       tree expression;
04184 
04185       /* Look for an expression.  */
04186       expression = cp_parser_expression (parser, /*cast_p=*/false);
04187       /* Compute its typeid.  */
04188       postfix_expression = build_typeid (expression);
04189       /* Look for the `)' token.  */
04190       cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04191     }
04192   /* Restore the saved message.  */
04193   parser->type_definition_forbidden_message = saved_message;
04194   /* `typeid' may not appear in an integral constant expression.  */
04195   if (cp_parser_non_integral_constant_expression(parser,
04196                    "`typeid' operator"))
04197     return error_mark_node;
04198       }
04199       break;
04200 
04201     case RID_TYPENAME:
04202       {
04203   tree type;
04204   /* The syntax permitted here is the same permitted for an
04205      elaborated-type-specifier.  */
04206   type = cp_parser_elaborated_type_specifier (parser,
04207                 /*is_friend=*/false,
04208                 /*is_declaration=*/false);
04209   postfix_expression = cp_parser_functional_cast (parser, type);
04210       }
04211       break;
04212 
04213     default:
04214       {
04215   tree type;
04216 
04217   /* If the next thing is a simple-type-specifier, we may be
04218      looking at a functional cast.  We could also be looking at
04219      an id-expression.  So, we try the functional cast, and if
04220      that doesn't work we fall back to the primary-expression.  */
04221   cp_parser_parse_tentatively (parser);
04222   /* Look for the simple-type-specifier.  */
04223   type = cp_parser_simple_type_specifier (parser,
04224             /*decl_specs=*/NULL,
04225             CP_PARSER_FLAGS_NONE);
04226   /* Parse the cast itself.  */
04227   if (!cp_parser_error_occurred (parser))
04228     postfix_expression
04229       = cp_parser_functional_cast (parser, type);
04230   /* If that worked, we're done.  */
04231   if (cp_parser_parse_definitely (parser))
04232     break;
04233 
04234   /* If the functional-cast didn't work out, try a
04235      compound-literal.  */
04236   if (cp_parser_allow_gnu_extensions_p (parser)
04237       && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
04238     {
04239       VEC(constructor_elt,gc) *initializer_list = NULL;
04240       bool saved_in_type_id_in_expr_p;
04241 
04242       cp_parser_parse_tentatively (parser);
04243       /* Consume the `('.  */
04244       cp_lexer_consume_token (parser->lexer);
04245       /* Parse the type.  */
04246       saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
04247       parser->in_type_id_in_expr_p = true;
04248       type = cp_parser_type_id (parser);
04249       parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
04250       /* Look for the `)'.  */
04251       cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04252       /* Look for the `{'.  */
04253       cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
04254       /* If things aren't going well, there's no need to
04255          keep going.  */
04256       if (!cp_parser_error_occurred (parser))
04257         {
04258     bool non_constant_p;
04259     /* Parse the initializer-list.  */
04260     initializer_list
04261       = cp_parser_initializer_list (parser, &non_constant_p);
04262     /* Allow a trailing `,'.  */
04263     if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
04264       cp_lexer_consume_token (parser->lexer);
04265     /* Look for the final `}'.  */
04266     cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
04267         }
04268       /* If that worked, we're definitely looking at a
04269          compound-literal expression.  */
04270       if (cp_parser_parse_definitely (parser))
04271         {
04272     /* Warn the user that a compound literal is not
04273        allowed in standard C++.  */
04274     if (pedantic)
04275       pedwarn ("ISO C++ forbids compound-literals");
04276     /* For simplicitly, we disallow compound literals in
04277        constant-expressions for simpliicitly.  We could
04278        allow compound literals of integer type, whose
04279        initializer was a constant, in constant
04280        expressions.  Permitting that usage, as a further
04281        extension, would not change the meaning of any
04282        currently accepted programs.  (Of course, as
04283        compound literals are not part of ISO C++, the
04284        standard has nothing to say.)  */
04285     if (cp_parser_non_integral_constant_expression 
04286         (parser, "non-constant compound literals"))
04287       {
04288         postfix_expression = error_mark_node;
04289         break;
04290       }
04291     /* Form the representation of the compound-literal.  */
04292     postfix_expression
04293       = finish_compound_literal (type, initializer_list);
04294     break;
04295         }
04296     }
04297 
04298   /* It must be a primary-expression.  */
04299   postfix_expression
04300     = cp_parser_primary_expression (parser, address_p, cast_p,
04301             /*template_arg_p=*/false,
04302             &idk);
04303       }
04304       break;
04305     }
04306 
04307   /* Keep looping until the postfix-expression is complete.  */
04308   while (true)
04309     {
04310       if (idk == CP_ID_KIND_UNQUALIFIED
04311     && TREE_CODE (postfix_expression) == IDENTIFIER_NODE
04312     && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
04313   /* It is not a Koenig lookup function call.  */
04314   postfix_expression
04315     = unqualified_name_lookup_error (postfix_expression);
04316 
04317       /* Peek at the next token.  */
04318       token = cp_lexer_peek_token (parser->lexer);
04319 
04320       switch (token->type)
04321   {
04322   case CPP_OPEN_SQUARE:
04323     postfix_expression
04324       = cp_parser_postfix_open_square_expression (parser,
04325               postfix_expression,
04326               false);
04327     idk = CP_ID_KIND_NONE;
04328     break;
04329 
04330   case CPP_OPEN_PAREN:
04331     /* postfix-expression ( expression-list [opt] ) */
04332     {
04333       bool koenig_p;
04334       bool is_builtin_constant_p;
04335       bool saved_integral_constant_expression_p = false;
04336       bool saved_non_integral_constant_expression_p = false;
04337       tree args;
04338 
04339       is_builtin_constant_p
04340         = DECL_IS_BUILTIN_CONSTANT_P (postfix_expression);
04341       if (is_builtin_constant_p)
04342         {
04343     /* The whole point of __builtin_constant_p is to allow
04344        non-constant expressions to appear as arguments.  */
04345     saved_integral_constant_expression_p
04346       = parser->integral_constant_expression_p;
04347     saved_non_integral_constant_expression_p
04348       = parser->non_integral_constant_expression_p;
04349     parser->integral_constant_expression_p = false;
04350         }
04351       args = (cp_parser_parenthesized_expression_list
04352         (parser, /*is_attribute_list=*/false,
04353          /*cast_p=*/false,
04354          /*non_constant_p=*/NULL));
04355       if (is_builtin_constant_p)
04356         {
04357     parser->integral_constant_expression_p
04358       = saved_integral_constant_expression_p;
04359     parser->non_integral_constant_expression_p
04360       = saved_non_integral_constant_expression_p;
04361         }
04362 
04363       if (args == error_mark_node)
04364         {
04365     postfix_expression = error_mark_node;
04366     break;
04367         }
04368 
04369       /* Function calls are not permitted in
04370          constant-expressions.  */
04371       if (! builtin_valid_in_constant_expr_p (postfix_expression)
04372     && cp_parser_non_integral_constant_expression (parser,
04373                      "a function call"))
04374         {
04375     postfix_expression = error_mark_node;
04376     break;
04377         }
04378 
04379       koenig_p = false;
04380       if (idk == CP_ID_KIND_UNQUALIFIED)
04381         {
04382     if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
04383       {
04384         if (args)
04385           {
04386       koenig_p = true;
04387       postfix_expression
04388         = perform_koenig_lookup (postfix_expression, args);
04389           }
04390         else
04391           postfix_expression
04392       = unqualified_fn_lookup_error (postfix_expression);
04393       }
04394     /* We do not perform argument-dependent lookup if
04395        normal lookup finds a non-function, in accordance
04396        with the expected resolution of DR 218.  */
04397     else if (args && is_overloaded_fn (postfix_expression))
04398       {
04399         tree fn = get_first_fn (postfix_expression);
04400 
04401         if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
04402           fn = OVL_CURRENT (TREE_OPERAND (fn, 0));
04403 
04404         /* Only do argument dependent lookup if regular
04405            lookup does not find a set of member functions.
04406            [basic.lookup.koenig]/2a  */
04407         if (!DECL_FUNCTION_MEMBER_P (fn))
04408           {
04409       koenig_p = true;
04410       postfix_expression
04411         = perform_koenig_lookup (postfix_expression, args);
04412           }
04413       }
04414         }
04415 
04416       if (TREE_CODE (postfix_expression) == COMPONENT_REF)
04417         {
04418     tree instance = TREE_OPERAND (postfix_expression, 0);
04419     tree fn = TREE_OPERAND (postfix_expression, 1);
04420 
04421     if (processing_template_decl
04422         && (type_dependent_expression_p (instance)
04423       || (!BASELINK_P (fn)
04424           && TREE_CODE (fn) != FIELD_DECL)
04425       || type_dependent_expression_p (fn)
04426       || any_type_dependent_arguments_p (args)))
04427       {
04428         postfix_expression
04429           = build_min_nt (CALL_EXPR, postfix_expression,
04430               args, NULL_TREE);
04431         break;
04432       }
04433 
04434     if (BASELINK_P (fn))
04435       postfix_expression
04436         = (build_new_method_call
04437            (instance, fn, args, NULL_TREE,
04438       (idk == CP_ID_KIND_QUALIFIED
04439        ? LOOKUP_NONVIRTUAL : LOOKUP_NORMAL),
04440       /*fn_p=*/NULL));
04441     else
04442       postfix_expression
04443         = finish_call_expr (postfix_expression, args,
04444           /*disallow_virtual=*/false,
04445           /*koenig_p=*/false);
04446         }
04447       else if (TREE_CODE (postfix_expression) == OFFSET_REF
04448          || TREE_CODE (postfix_expression) == MEMBER_REF
04449          || TREE_CODE (postfix_expression) == DOTSTAR_EXPR)
04450         postfix_expression = (build_offset_ref_call_from_tree
04451             (postfix_expression, args));
04452       else if (idk == CP_ID_KIND_QUALIFIED)
04453         /* A call to a static class member, or a namespace-scope
04454      function.  */
04455         postfix_expression
04456     = finish_call_expr (postfix_expression, args,
04457             /*disallow_virtual=*/true,
04458             koenig_p);
04459       else
04460         /* All other function calls.  */
04461         postfix_expression
04462     = finish_call_expr (postfix_expression, args,
04463             /*disallow_virtual=*/false,
04464             koenig_p);
04465 
04466       /* The POSTFIX_EXPRESSION is certainly no longer an id.  */
04467       idk = CP_ID_KIND_NONE;
04468     }
04469     break;
04470 
04471   case CPP_DOT:
04472   case CPP_DEREF:
04473     /* postfix-expression . template [opt] id-expression
04474        postfix-expression . pseudo-destructor-name
04475        postfix-expression -> template [opt] id-expression
04476        postfix-expression -> pseudo-destructor-name */
04477 
04478     /* Consume the `.' or `->' operator.  */
04479     cp_lexer_consume_token (parser->lexer);
04480 
04481     postfix_expression
04482       = cp_parser_postfix_dot_deref_expression (parser, token->type,
04483                   postfix_expression,
04484                   false, &idk);
04485     break;
04486 
04487   case CPP_PLUS_PLUS:
04488     /* postfix-expression ++  */
04489     /* Consume the `++' token.  */
04490     cp_lexer_consume_token (parser->lexer);
04491     /* Generate a representation for the complete expression.  */
04492     postfix_expression
04493       = finish_increment_expr (postfix_expression,
04494              POSTINCREMENT_EXPR);
04495     /* Increments may not appear in constant-expressions.  */
04496     if (cp_parser_non_integral_constant_expression (parser,
04497                 "an increment"))
04498       postfix_expression = error_mark_node;
04499     idk = CP_ID_KIND_NONE;
04500     break;
04501 
04502   case CPP_MINUS_MINUS:
04503     /* postfix-expression -- */
04504     /* Consume the `--' token.  */
04505     cp_lexer_consume_token (parser->lexer);
04506     /* Generate a representation for the complete expression.  */
04507     postfix_expression
04508       = finish_increment_expr (postfix_expression,
04509              POSTDECREMENT_EXPR);
04510     /* Decrements may not appear in constant-expressions.  */
04511     if (cp_parser_non_integral_constant_expression (parser,
04512                 "a decrement"))
04513       postfix_expression = error_mark_node;
04514     idk = CP_ID_KIND_NONE;
04515     break;
04516 
04517   default:
04518     return postfix_expression;
04519   }
04520     }
04521 
04522   /* We should never get here.  */
04523   gcc_unreachable ();
04524   return error_mark_node;
04525 }
04526 
04527 /* A subroutine of cp_parser_postfix_expression that also gets hijacked
04528    by cp_parser_builtin_offsetof.  We're looking for
04529 
04530      postfix-expression [ expression ]
04531 
04532    FOR_OFFSETOF is set if we're being called in that context, which
04533    changes how we deal with integer constant expressions.  */
04534 
04535 static tree
04536 cp_parser_postfix_open_square_expression (cp_parser *parser,
04537             tree postfix_expression,
04538             bool for_offsetof)
04539 {
04540   tree index;
04541 
04542   /* Consume the `[' token.  */
04543   cp_lexer_consume_token (parser->lexer);
04544 
04545   /* Parse the index expression.  */
04546   /* ??? For offsetof, there is a question of what to allow here.  If
04547      offsetof is not being used in an integral constant expression context,
04548      then we *could* get the right answer by computing the value at runtime.
04549      If we are in an integral constant expression context, then we might
04550      could accept any constant expression; hard to say without analysis.
04551      Rather than open the barn door too wide right away, allow only integer
04552      constant expressions here.  */
04553   if (for_offsetof)
04554     index = cp_parser_constant_expression (parser, false, NULL);
04555   else
04556     index = cp_parser_expression (parser, /*cast_p=*/false);
04557 
04558   /* Look for the closing `]'.  */
04559   cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
04560 
04561   /* Build the ARRAY_REF.  */
04562   postfix_expression = grok_array_decl (postfix_expression, index);
04563 
04564   /* When not doing offsetof, array references are not permitted in
04565      constant-expressions.  */
04566   if (!for_offsetof
04567       && (cp_parser_non_integral_constant_expression
04568     (parser, "an array reference")))
04569     postfix_expression = error_mark_node;
04570 
04571   return postfix_expression;
04572 }
04573 
04574 /* A subroutine of cp_parser_postfix_expression that also gets hijacked
04575    by cp_parser_builtin_offsetof.  We're looking for
04576 
04577      postfix-expression . template [opt] id-expression
04578      postfix-expression . pseudo-destructor-name
04579      postfix-expression -> template [opt] id-expression
04580      postfix-expression -> pseudo-destructor-name
04581 
04582    FOR_OFFSETOF is set if we're being called in that context.  That sorta
04583    limits what of the above we'll actually accept, but nevermind.
04584    TOKEN_TYPE is the "." or "->" token, which will already have been
04585    removed from the stream.  */
04586 
04587 static tree
04588 cp_parser_postfix_dot_deref_expression (cp_parser *parser,
04589           enum cpp_ttype token_type,
04590           tree postfix_expression,
04591           bool for_offsetof, cp_id_kind *idk)
04592 {
04593   tree name;
04594   bool dependent_p;
04595   bool pseudo_destructor_p;
04596   tree scope = NULL_TREE;
04597 
04598   /* If this is a `->' operator, dereference the pointer.  */
04599   if (token_type == CPP_DEREF)
04600     postfix_expression = build_x_arrow (postfix_expression);
04601   /* Check to see whether or not the expression is type-dependent.  */
04602   dependent_p = type_dependent_expression_p (postfix_expression);
04603   /* The identifier following the `->' or `.' is not qualified.  */
04604   parser->scope = NULL_TREE;
04605   parser->qualifying_scope = NULL_TREE;
04606   parser->object_scope = NULL_TREE;
04607   *idk = CP_ID_KIND_NONE;
04608   /* Enter the scope corresponding to the type of the object
04609      given by the POSTFIX_EXPRESSION.  */
04610   if (!dependent_p && TREE_TYPE (postfix_expression) != NULL_TREE)
04611     {
04612       scope = TREE_TYPE (postfix_expression);
04613       /* According to the standard, no expression should ever have
04614    reference type.  Unfortunately, we do not currently match
04615    the standard in this respect in that our internal representation
04616    of an expression may have reference type even when the standard
04617    says it does not.  Therefore, we have to manually obtain the
04618    underlying type here.  */
04619       scope = non_reference (scope);
04620       /* The type of the POSTFIX_EXPRESSION must be complete.  */
04621       if (scope == unknown_type_node)
04622   {
04623     error ("%qE does not have class type", postfix_expression);
04624     scope = NULL_TREE;
04625   }
04626       else
04627   scope = complete_type_or_else (scope, NULL_TREE);
04628       /* Let the name lookup machinery know that we are processing a
04629    class member access expression.  */
04630       parser->context->object_type = scope;
04631       /* If something went wrong, we want to be able to discern that case,
04632    as opposed to the case where there was no SCOPE due to the type
04633    of expression being dependent.  */
04634       if (!scope)
04635   scope = error_mark_node;
04636       /* If the SCOPE was erroneous, make the various semantic analysis
04637    functions exit quickly -- and without issuing additional error
04638    messages.  */
04639       if (scope == error_mark_node)
04640   postfix_expression = error_mark_node;
04641     }
04642 
04643   /* Assume this expression is not a pseudo-destructor access.  */
04644   pseudo_destructor_p = false;
04645 
04646   /* If the SCOPE is a scalar type, then, if this is a valid program,
04647      we must be looking at a pseudo-destructor-name.  */
04648   if (scope && SCALAR_TYPE_P (scope))
04649     {
04650       tree s;
04651       tree type;
04652 
04653       cp_parser_parse_tentatively (parser);
04654       /* Parse the pseudo-destructor-name.  */
04655       s = NULL_TREE;
04656       cp_parser_pseudo_destructor_name (parser, &s, &type);
04657       if (cp_parser_parse_definitely (parser))
04658   {
04659     pseudo_destructor_p = true;
04660     postfix_expression
04661       = finish_pseudo_destructor_expr (postfix_expression,
04662                s, TREE_TYPE (type));
04663   }
04664     }
04665 
04666   if (!pseudo_destructor_p)
04667     {
04668       /* If the SCOPE is not a scalar type, we are looking at an
04669    ordinary class member access expression, rather than a
04670    pseudo-destructor-name.  */
04671       bool template_p;
04672       /* Parse the id-expression.  */
04673       name = (cp_parser_id_expression
04674         (parser,
04675          cp_parser_optional_template_keyword (parser),
04676          /*check_dependency_p=*/true,
04677          &template_p,
04678          /*declarator_p=*/false,
04679          /*optional_p=*/false));
04680       /* In general, build a SCOPE_REF if the member name is qualified.
04681    However, if the name was not dependent and has already been
04682    resolved; there is no need to build the SCOPE_REF.  For example;
04683 
04684        struct X { void f(); };
04685        template <typename T> void f(T* t) { t->X::f(); }
04686 
04687    Even though "t" is dependent, "X::f" is not and has been resolved
04688    to a BASELINK; there is no need to include scope information.  */
04689 
04690       /* But we do need to remember that there was an explicit scope for
04691    virtual function calls.  */
04692       if (parser->scope)
04693   *idk = CP_ID_KIND_QUALIFIED;
04694 
04695       /* If the name is a template-id that names a type, we will get a
04696    TYPE_DECL here.  That is invalid code.  */
04697       if (TREE_CODE (name) == TYPE_DECL)
04698   {
04699     error ("invalid use of %qD", name);
04700     postfix_expression = error_mark_node;
04701   }
04702       else
04703   {
04704     if (name != error_mark_node && !BASELINK_P (name) && parser->scope)
04705       {
04706         name = build_qualified_name (/*type=*/NULL_TREE,
04707              parser->scope,
04708              name,
04709              template_p);
04710         parser->scope = NULL_TREE;
04711         parser->qualifying_scope = NULL_TREE;
04712         parser->object_scope = NULL_TREE;
04713       }
04714     if (scope && name && BASELINK_P (name))
04715       adjust_result_of_qualified_name_lookup
04716         (name, BINFO_TYPE (BASELINK_ACCESS_BINFO (name)), scope);
04717     postfix_expression
04718       = finish_class_member_access_expr (postfix_expression, name,
04719                  template_p);
04720   }
04721     }
04722 
04723   /* We no longer need to look up names in the scope of the object on
04724      the left-hand side of the `.' or `->' operator.  */
04725   parser->context->object_type = NULL_TREE;
04726 
04727   /* Outside of offsetof, these operators may not appear in
04728      constant-expressions.  */
04729   if (!for_offsetof
04730       && (cp_parser_non_integral_constant_expression
04731     (parser, token_type == CPP_DEREF ? "'->'" : "`.'")))
04732     postfix_expression = error_mark_node;
04733 
04734   return postfix_expression;
04735 }
04736 
04737 /* Parse a parenthesized expression-list.
04738 
04739    expression-list:
04740      assignment-expression
04741      expression-list, assignment-expression
04742 
04743    attribute-list:
04744      expression-list
04745      identifier
04746      identifier, expression-list
04747 
04748    CAST_P is true if this expression is the target of a cast.
04749 
04750    Returns a TREE_LIST.  The TREE_VALUE of each node is a
04751    representation of an assignment-expression.  Note that a TREE_LIST
04752    is returned even if there is only a single expression in the list.
04753    error_mark_node is returned if the ( and or ) are
04754    missing. NULL_TREE is returned on no expressions. The parentheses
04755    are eaten. IS_ATTRIBUTE_LIST is true if this is really an attribute
04756    list being parsed.  If NON_CONSTANT_P is non-NULL, *NON_CONSTANT_P
04757    indicates whether or not all of the expressions in the list were
04758    constant.  */
04759 
04760 static tree
04761 cp_parser_parenthesized_expression_list (cp_parser* parser,
04762            bool is_attribute_list,
04763            bool cast_p,
04764            bool *non_constant_p)
04765 {
04766   tree expression_list = NULL_TREE;
04767   bool fold_expr_p = is_attribute_list;
04768   tree identifier = NULL_TREE;
04769 
04770   /* Assume all the expressions will be constant.  */
04771   if (non_constant_p)
04772     *non_constant_p = false;
04773 
04774   if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
04775     return error_mark_node;
04776 
04777   /* Consume expressions until there are no more.  */
04778   if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
04779     while (true)
04780       {
04781   tree expr;
04782 
04783   /* At the beginning of attribute lists, check to see if the
04784      next token is an identifier.  */
04785   if (is_attribute_list
04786       && cp_lexer_peek_token (parser->lexer)->type == CPP_NAME)
04787     {
04788       cp_token *token;
04789 
04790       /* Consume the identifier.  */
04791       token = cp_lexer_consume_token (parser->lexer);
04792       /* Save the identifier.  */
04793       identifier = token->u.value;
04794     }
04795   else
04796     {
04797       /* Parse the next assignment-expression.  */
04798       if (non_constant_p)
04799         {
04800     bool expr_non_constant_p;
04801     expr = (cp_parser_constant_expression
04802       (parser, /*allow_non_constant_p=*/true,
04803        &expr_non_constant_p));
04804     if (expr_non_constant_p)
04805       *non_constant_p = true;
04806         }
04807       else
04808         expr = cp_parser_assignment_expression (parser, cast_p);
04809 
04810       if (fold_expr_p)
04811         expr = fold_non_dependent_expr (expr);
04812 
04813        /* Add it to the list.  We add error_mark_node
04814     expressions to the list, so that we can still tell if
04815     the correct form for a parenthesized expression-list
04816     is found. That gives better errors.  */
04817       expression_list = tree_cons (NULL_TREE, expr, expression_list);
04818 
04819       if (expr == error_mark_node)
04820         goto skip_comma;
04821     }
04822 
04823   /* After the first item, attribute lists look the same as
04824      expression lists.  */
04825   is_attribute_list = false;
04826 
04827       get_comma:;
04828   /* If the next token isn't a `,', then we are done.  */
04829   if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
04830     break;
04831 
04832   /* Otherwise, consume the `,' and keep going.  */
04833   cp_lexer_consume_token (parser->lexer);
04834       }
04835 
04836   if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
04837     {
04838       int ending;
04839 
04840     skip_comma:;
04841       /* We try and resync to an unnested comma, as that will give the
04842    user better diagnostics.  */
04843       ending = cp_parser_skip_to_closing_parenthesis (parser,
04844                   /*recovering=*/true,
04845                   /*or_comma=*/true,
04846                   /*consume_paren=*/true);
04847       if (ending < 0)
04848   goto get_comma;
04849       if (!ending)
04850   return error_mark_node;
04851     }
04852 
04853   /* We built up the list in reverse order so we must reverse it now.  */
04854   expression_list = nreverse (expression_list);
04855   if (identifier)
04856     expression_list = tree_cons (NULL_TREE, identifier, expression_list);
04857 
04858   return expression_list;
04859 }
04860 
04861 /* Parse a pseudo-destructor-name.
04862 
04863    pseudo-destructor-name:
04864      :: [opt] nested-name-specifier [opt] type-name :: ~ type-name
04865      :: [opt] nested-name-specifier template template-id :: ~ type-name
04866      :: [opt] nested-name-specifier [opt] ~ type-name
04867 
04868    If either of the first two productions is used, sets *SCOPE to the
04869    TYPE specified before the final `::'.  Otherwise, *SCOPE is set to
04870    NULL_TREE.  *TYPE is set to the TYPE_DECL for the final type-name,
04871    or ERROR_MARK_NODE if the parse fails.  */
04872 
04873 static void
04874 cp_parser_pseudo_destructor_name (cp_parser* parser,
04875           tree* scope,
04876           tree* type)
04877 {
04878   bool nested_name_specifier_p;
04879 
04880   /* Assume that things will not work out.  */
04881   *type = error_mark_node;
04882 
04883   /* Look for the optional `::' operator.  */
04884   cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/true);
04885   /* Look for the optional nested-name-specifier.  */
04886   nested_name_specifier_p
04887     = (cp_parser_nested_name_specifier_opt (parser,
04888               /*typename_keyword_p=*/false,
04889               /*check_dependency_p=*/true,
04890               /*type_p=*/false,
04891               /*is_declaration=*/true)
04892        != NULL_TREE);
04893   /* Now, if we saw a nested-name-specifier, we might be doing the
04894      second production.  */
04895   if (nested_name_specifier_p
04896       && cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
04897     {
04898       /* Consume the `template' keyword.  */
04899       cp_lexer_consume_token (parser->lexer);
04900       /* Parse the template-id.  */
04901       cp_parser_template_id (parser,
04902            /*template_keyword_p=*/true,
04903            /*check_dependency_p=*/false,
04904            /*is_declaration=*/true);
04905       /* Look for the `::' token.  */
04906       cp_parser_require (parser, CPP_SCOPE, "`::'");
04907     }
04908   /* If the next token is not a `~', then there might be some
04909      additional qualification.  */
04910   else if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMPL))
04911     {
04912       /* Look for the type-name.  */
04913       *scope = TREE_TYPE (cp_parser_type_name (parser));
04914 
04915       if (*scope == error_mark_node)
04916   return;
04917 
04918       /* If we don't have ::~, then something has gone wrong.  Since
04919    the only caller of this function is looking for something
04920    after `.' or `->' after a scalar type, most likely the
04921    program is trying to get a member of a non-aggregate
04922    type.  */
04923       if (cp_lexer_next_token_is_not (parser->lexer, CPP_SCOPE)
04924     || cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_COMPL)
04925   {
04926     cp_parser_error (parser, "request for member of non-aggregate type");
04927     return;
04928   }
04929 
04930       /* Look for the `::' token.  */
04931       cp_parser_require (parser, CPP_SCOPE, "`::'");
04932     }
04933   else
04934     *scope = NULL_TREE;
04935 
04936   /* Look for the `~'.  */
04937   cp_parser_require (parser, CPP_COMPL, "`~'");
04938   /* Look for the type-name again.  We are not responsible for
04939      checking that it matches the first type-name.  */
04940   *type = cp_parser_type_name (parser);
04941 }
04942 
04943 /* Parse a unary-expression.
04944 
04945    unary-expression:
04946      postfix-expression
04947      ++ cast-expression
04948      -- cast-expression
04949      unary-operator cast-expression
04950      sizeof unary-expression
04951      sizeof ( type-id )
04952      new-expression
04953      delete-expression
04954 
04955    GNU Extensions:
04956 
04957    unary-expression:
04958      __extension__ cast-expression
04959      __alignof__ unary-expression
04960      __alignof__ ( type-id )
04961      __real__ cast-expression
04962      __imag__ cast-expression
04963      && identifier
04964 
04965    ADDRESS_P is true iff the unary-expression is appearing as the
04966    operand of the `&' operator.   CAST_P is true if this expression is
04967    the target of a cast.
04968 
04969    Returns a representation of the expression.  */
04970 
04971 static tree
04972 cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p)
04973 {
04974   cp_token *token;
04975   enum tree_code unary_operator;
04976 
04977   /* Peek at the next token.  */
04978   token = cp_lexer_peek_token (parser->lexer);
04979   /* Some keywords give away the kind of expression.  */
04980   if (token->type == CPP_KEYWORD)
04981     {
04982       enum rid keyword = token->keyword;
04983 
04984       switch (keyword)
04985   {
04986   case RID_ALIGNOF:
04987   case RID_SIZEOF:
04988     {
04989       tree operand;
04990       enum tree_code op;
04991 
04992       op = keyword == RID_ALIGNOF ? ALIGNOF_EXPR : SIZEOF_EXPR;
04993       /* Consume the token.  */
04994       cp_lexer_consume_token (parser->lexer);
04995       /* Parse the operand.  */
04996       operand = cp_parser_sizeof_operand (parser, keyword);
04997 
04998       if (TYPE_P (operand))
04999         return cxx_sizeof_or_alignof_type (operand, op, true);
05000       else
05001         return cxx_sizeof_or_alignof_expr (operand, op);
05002     }
05003 
05004   case RID_NEW:
05005     return cp_parser_new_expression (parser);
05006 
05007   case RID_DELETE:
05008     return cp_parser_delete_expression (parser);
05009 
05010   case RID_EXTENSION:
05011     {
05012       /* The saved value of the PEDANTIC flag.  */
05013       int saved_pedantic;
05014       tree expr;
05015 
05016       /* Save away the PEDANTIC flag.  */
05017       cp_parser_extension_opt (parser, &saved_pedantic);
05018       /* Parse the cast-expression.  */
05019       expr = cp_parser_simple_cast_expression (parser);
05020       /* Restore the PEDANTIC flag.  */
05021       pedantic = saved_pedantic;
05022 
05023       return expr;
05024     }
05025 
05026   case RID_REALPART:
05027   case RID_IMAGPART:
05028     {
05029       tree expression;
05030 
05031       /* Consume the `__real__' or `__imag__' token.  */
05032       cp_lexer_consume_token (parser->lexer);
05033       /* Parse the cast-expression.  */
05034       expression = cp_parser_simple_cast_expression (parser);
05035       /* Create the complete representation.  */
05036       return build_x_unary_op ((keyword == RID_REALPART
05037               ? REALPART_EXPR : IMAGPART_EXPR),
05038              expression);
05039     }
05040     break;
05041 
05042   default:
05043     break;
05044   }
05045     }
05046 
05047   /* Look for the `:: new' and `:: delete', which also signal the
05048      beginning of a new-expression, or delete-expression,
05049      respectively.  If the next token is `::', then it might be one of
05050      these.  */
05051   if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
05052     {
05053       enum rid keyword;
05054 
05055       /* See if the token after the `::' is one of the keywords in
05056    which we're interested.  */
05057       keyword = cp_lexer_peek_nth_token (parser->lexer, 2)->keyword;
05058       /* If it's `new', we have a new-expression.  */
05059       if (keyword == RID_NEW)
05060   return cp_parser_new_expression (parser);
05061       /* Similarly, for `delete'.  */
05062       else if (keyword == RID_DELETE)
05063   return cp_parser_delete_expression (parser);
05064     }
05065 
05066   /* Look for a unary operator.  */
05067   unary_operator = cp_parser_unary_operator (token);
05068   /* The `++' and `--' operators can be handled similarly, even though
05069      they are not technically unary-operators in the grammar.  */
05070   if (unary_operator == ERROR_MARK)
05071     {
05072       if (token->type == CPP_PLUS_PLUS)
05073   unary_operator = PREINCREMENT_EXPR;
05074       else if (token->type == CPP_MINUS_MINUS)
05075   unary_operator = PREDECREMENT_EXPR;
05076       /* Handle the GNU address-of-label extension.  */
05077       else if (cp_parser_allow_gnu_extensions_p (parser)
05078          && token->type == CPP_AND_AND)
05079   {
05080     tree identifier;
05081 
05082     /* Consume the '&&' token.  */
05083     cp_lexer_consume_token (parser->lexer);
05084     /* Look for the identifier.  */
05085     identifier = cp_parser_identifier (parser);
05086     /* Create an expression representing the address.  */
05087     return finish_label_address_expr (identifier);
05088   }
05089     }
05090   if (unary_operator != ERROR_MARK)
05091     {
05092       tree cast_expression;
05093       tree expression = error_mark_node;
05094       const char *non_constant_p = NULL;
05095 
05096       /* Consume the operator token.  */
05097       token = cp_lexer_consume_token (parser->lexer);
05098       /* Parse the cast-expression.  */
05099       cast_expression
05100   = cp_parser_cast_expression (parser,
05101              unary_operator == ADDR_EXPR,
05102              /*cast_p=*/false);
05103       /* Now, build an appropriate representation.  */
05104       switch (unary_operator)
05105   {
05106   case INDIRECT_REF:
05107     non_constant_p = "`*'";
05108     expression = build_x_indirect_ref (cast_expression, "unary *");
05109     break;
05110 
05111   case ADDR_EXPR:
05112     non_constant_p = "`&'";
05113     /* Fall through.  */
05114   case BIT_NOT_EXPR:
05115     expression = build_x_unary_op (unary_operator, cast_expression);
05116     break;
05117 
05118   case PREINCREMENT_EXPR:
05119   case PREDECREMENT_EXPR:
05120     non_constant_p = (unary_operator == PREINCREMENT_EXPR
05121           ? "`++'" : "`--'");
05122     /* Fall through.  */
05123   case UNARY_PLUS_EXPR:
05124   case NEGATE_EXPR:
05125   case TRUTH_NOT_EXPR:
05126     expression = finish_unary_op_expr (unary_operator, cast_expression);
05127     break;
05128 
05129   default:
05130     gcc_unreachable ();
05131   }
05132 
05133       if (non_constant_p
05134     && cp_parser_non_integral_constant_expression (parser,
05135                non_constant_p))
05136   expression = error_mark_node;
05137 
05138       return expression;
05139     }
05140 
05141   return cp_parser_postfix_expression (parser, address_p, cast_p);
05142 }
05143 
05144 /* Returns ERROR_MARK if TOKEN is not a unary-operator.  If TOKEN is a
05145    unary-operator, the corresponding tree code is returned.  */
05146 
05147 static enum tree_code
05148 cp_parser_unary_operator (cp_token* token)
05149 {
05150   switch (token->type)
05151     {
05152     case CPP_MULT:
05153       return INDIRECT_REF;
05154 
05155     case CPP_AND:
05156       return ADDR_EXPR;
05157 
05158     case CPP_PLUS:
05159       return UNARY_PLUS_EXPR;
05160 
05161     case CPP_MINUS:
05162       return NEGATE_EXPR;
05163 
05164     case CPP_NOT:
05165       return TRUTH_NOT_EXPR;
05166 
05167     case CPP_COMPL:
05168       return BIT_NOT_EXPR;
05169 
05170     default:
05171       return ERROR_MARK;
05172     }
05173 }
05174 
05175 /* Parse a new-expression.
05176 
05177    new-expression:
05178      :: [opt] new new-placement [opt] new-type-id new-initializer [opt]
05179      :: [opt] new new-placement [opt] ( type-id ) new-initializer [opt]
05180 
05181    Returns a representation of the expression.  */
05182 
05183 static tree
05184 cp_parser_new_expression (cp_parser* parser)
05185 {
05186   bool global_scope_p;
05187   tree placement;
05188   tree type;
05189   tree initializer;
05190   tree nelts;
05191 
05192   /* Look for the optional `::' operator.  */
05193   global_scope_p
05194     = (cp_parser_global_scope_opt (parser,
05195            /*current_scope_valid_p=*/false)
05196        != NULL_TREE);
05197   /* Look for the `new' operator.  */
05198   cp_parser_require_keyword (parser, RID_NEW, "`new'");
05199   /* There's no easy way to tell a new-placement from the
05200      `( type-id )' construct.  */
05201   cp_parser_parse_tentatively (parser);
05202   /* Look for a new-placement.  */
05203   placement = cp_parser_new_placement (parser);
05204   /* If that didn't work out, there's no new-placement.  */
05205   if (!cp_parser_parse_definitely (parser))
05206     placement = NULL_TREE;
05207 
05208   /* If the next token is a `(', then we have a parenthesized
05209      type-id.  */
05210   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
05211     {
05212       /* Consume the `('.  */
05213       cp_lexer_consume_token (parser->lexer);
05214       /* Parse the type-id.  */
05215       type = cp_parser_type_id (parser);
05216       /* Look for the closing `)'.  */
05217       cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
05218       /* There should not be a direct-new-declarator in this production,
05219    but GCC used to allowed this, so we check and emit a sensible error
05220    message for this case.  */
05221       if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
05222   {
05223     error ("array bound forbidden after parenthesized type-id");
05224     inform ("try removing the parentheses around the type-id");
05225     cp_parser_direct_new_declarator (parser);
05226   }
05227       nelts = NULL_TREE;
05228     }
05229   /* Otherwise, there must be a new-type-id.  */
05230   else
05231     type = cp_parser_new_type_id (parser, &nelts);
05232 
05233   /* If the next token is a `(', then we have a new-initializer.  */
05234   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
05235     initializer = cp_parser_new_initializer (parser);
05236   else
05237     initializer = NULL_TREE;
05238 
05239   /* A new-expression may not appear in an integral constant
05240      expression.  */
05241   if (cp_parser_non_integral_constant_expression (parser, "`new'"))
05242     return error_mark_node;
05243 
05244   /* Create a representation of the new-expression.  */
05245   return build_new (placement, type, nelts, initializer, global_scope_p);
05246 }
05247 
05248 /* Parse a new-placement.
05249 
05250    new-placement:
05251      ( expression-list )
05252 
05253    Returns the same representation as for an expression-list.  */
05254 
05255 static tree
05256 cp_parser_new_placement (cp_parser* parser)
05257 {
05258   tree expression_list;
05259 
05260   /* Parse the expression-list.  */
05261   expression_list = (cp_parser_parenthesized_expression_list
05262          (parser, false, /*cast_p=*/false,
05263           /*non_constant_p=*/NULL));
05264 
05265   return expression_list;
05266 }
05267 
05268 /* Parse a new-type-id.
05269 
05270    new-type-id:
05271      type-specifier-seq new-declarator [opt]
05272 
05273    Returns the TYPE allocated.  If the new-type-id indicates an array
05274    type, *NELTS is set to the number of elements in the last array
05275    bound; the TYPE will not include the last array bound.  */
05276 
05277 static tree
05278 cp_parser_new_type_id (cp_parser* parser, tree *nelts)
05279 {
05280   cp_decl_specifier_seq type_specifier_seq;
05281   cp_declarator *new_declarator;
05282   cp_declarator *declarator;
05283   cp_declarator *outer_declarator;
05284   const char *saved_message;
05285   tree type;
05286 
05287   /* The type-specifier sequence must not contain type definitions.
05288      (It cannot contain declarations of new types either, but if they
05289      are not definitions we will catch that because they are not
05290      complete.)  */
05291   saved_message = parser->type_definition_forbidden_message;
05292   parser->type_definition_forbidden_message
05293     = "types may not be defined in a new-type-id";
05294   /* Parse the type-specifier-seq.  */
05295   cp_parser_type_specifier_seq (parser, /*is_condition=*/false,
05296         &type_specifier_seq);
05297   /* Restore the old message.  */
05298   parser->type_definition_forbidden_message = saved_message;
05299   /* Parse the new-declarator.  */
05300   new_declarator = cp_parser_new_declarator_opt (parser);
05301 
05302   /* Determine the number of elements in the last array dimension, if
05303      any.  */
05304   *nelts = NULL_TREE;
05305   /* Skip down to the last array dimension.  */
05306   declarator = new_declarator;
05307   outer_declarator = NULL;
05308   while (declarator && (declarator->kind == cdk_pointer
05309       || declarator->kind == cdk_ptrmem))
05310     {
05311       outer_declarator = declarator;
05312       declarator = declarator->declarator;
05313     }
05314   while (declarator
05315    && declarator->kind == cdk_array
05316    && declarator->declarator
05317    && declarator->declarator->kind == cdk_array)
05318     {
05319       outer_declarator = declarator;
05320       declarator = declarator->declarator;
05321     }
05322 
05323   if (declarator && declarator->kind == cdk_array)
05324     {
05325       *nelts = declarator->u.array.bounds;
05326       if (*nelts == error_mark_node)
05327   *nelts = integer_one_node;
05328 
05329       if (outer_declarator)
05330   outer_declarator->declarator = declarator->declarator;
05331       else
05332   new_declarator = NULL;
05333     }
05334 
05335   type = groktypename (&type_specifier_seq, new_declarator);
05336   if (TREE_CODE (type) == ARRAY_TYPE && *nelts == NULL_TREE)
05337     {
05338       *nelts = array_type_nelts_top (type);
05339       type = TREE_TYPE (type);
05340     }
05341   return type;
05342 }
05343 
05344 /* Parse an (optional) new-declarator.
05345 
05346    new-declarator:
05347      ptr-operator new-declarator [opt]
05348      direct-new-declarator
05349 
05350    Returns the declarator.  */
05351 
05352 static cp_declarator *
05353 cp_parser_new_declarator_opt (cp_parser* parser)
05354 {
05355   enum tree_code code;
05356   tree type;
05357   cp_cv_quals cv_quals;
05358 
05359   /* We don't know if there's a ptr-operator next, or not.  */
05360   cp_parser_parse_tentatively (parser);
05361   /* Look for a ptr-operator.  */
05362   code = cp_parser_ptr_operator (parser, &type, &cv_quals);
05363   /* If that worked, look for more new-declarators.  */
05364   if (cp_parser_parse_definitely (parser))
05365     {
05366       cp_declarator *declarator;
05367 
05368       /* Parse another optional declarator.  */
05369       declarator = cp_parser_new_declarator_opt (parser);
05370 
05371       /* Create the representation of the declarator.  */
05372       if (type)
05373   declarator = make_ptrmem_declarator (cv_quals, type, declarator);
05374       else if (code == INDIRECT_REF)
05375   declarator = make_pointer_declarator (cv_quals, declarator);
05376       else
05377   declarator = make_reference_declarator (cv_quals, declarator);
05378 
05379       return declarator;
05380     }
05381 
05382   /* If the next token is a `[', there is a direct-new-declarator.  */
05383   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
05384     return cp_parser_direct_new_declarator (parser);
05385 
05386   return NULL;
05387 }
05388 
05389 /* Parse a direct-new-declarator.
05390 
05391    direct-new-declarator:
05392      [ expression ]
05393      direct-new-declarator [constant-expression]
05394 
05395    */
05396 
05397 static cp_declarator *
05398 cp_parser_direct_new_declarator (cp_parser* parser)
05399 {
05400   cp_declarator *declarator = NULL;
05401 
05402   while (true)
05403     {
05404       tree expression;
05405 
05406       /* Look for the opening `['.  */
05407       cp_parser_require (parser, CPP_OPEN_SQUARE, "`['");
05408       /* The first expression is not required to be constant.  */
05409       if (!declarator)
05410   {
05411     expression = cp_parser_expression (parser, /*cast_p=*/false);
05412     /* The standard requires that the expression have integral
05413        type.  DR 74 adds enumeration types.  We believe that the
05414        real intent is that these expressions be handled like the
05415        expression in a `switch' condition, which also allows
05416        classes with a single conversion to integral or
05417        enumeration type.  */
05418     if (!processing_template_decl)
05419       {
05420         expression
05421     = build_expr_type_conversion (WANT_INT | WANT_ENUM,
05422                 expression,
05423                 /*complain=*/true);
05424         if (!expression)
05425     {
05426       error ("expression in new-declarator must have integral "
05427        "or enumeration type");
05428       expression = error_mark_node;
05429     }
05430       }
05431   }
05432       /* But all the other expressions must be.  */
05433       else
05434   expression
05435     = cp_parser_constant_expression (parser,
05436              /*allow_non_constant=*/false,
05437              NULL);
05438       /* Look for the closing `]'.  */
05439       cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
05440 
05441       /* Add this bound to the declarator.  */
05442       declarator = make_array_declarator (declarator, expression);
05443 
05444       /* If the next token is not a `[', then there are no more
05445    bounds.  */
05446       if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_SQUARE))
05447   break;
05448     }
05449 
05450   return declarator;
05451 }
05452 
05453 /* Parse a new-initializer.
05454 
05455    new-initializer:
05456      ( expression-list [opt] )
05457 
05458    Returns a representation of the expression-list.  If there is no
05459    expression-list, VOID_ZERO_NODE is returned.  */
05460 
05461 static tree
05462 cp_parser_new_initializer (cp_parser* parser)
05463 {
05464   tree expression_list;
05465 
05466   expression_list = (cp_parser_parenthesized_expression_list
05467          (parser, false, /*cast_p=*/false,
05468           /*non_constant_p=*/NULL));
05469   if (!expression_list)
05470     expression_list = void_zero_node;
05471 
05472   return expression_list;
05473 }
05474 
05475 /* Parse a delete-expression.
05476 
05477    delete-expression:
05478      :: [opt] delete cast-expression
05479      :: [opt] delete [ ] cast-expression
05480 
05481    Returns a representation of the expression.  */
05482 
05483 static tree
05484 cp_parser_delete_expression (cp_parser* parser)
05485 {
05486   bool global_scope_p;
05487   bool array_p;
05488   tree expression;
05489 
05490   /* Look for the optional `::' operator.  */
05491   global_scope_p
05492     = (cp_parser_global_scope_opt (parser,
05493            /*current_scope_valid_p=*/false)
05494        != NULL_TREE);
05495   /* Look for the `delete' keyword.  */
05496   cp_parser_require_keyword (parser, RID_DELETE, "`delete'");
05497   /* See if the array syntax is in use.  */
05498   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
05499     {
05500       /* Consume the `[' token.  */
05501       cp_lexer_consume_token (parser->lexer);
05502       /* Look for the `]' token.  */
05503       cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
05504       /* Remember that this is the `[]' construct.  */
05505       array_p = true;
05506     }
05507   else
05508     array_p = false;
05509 
05510   /* Parse the cast-expression.  */
05511   expression = cp_parser_simple_cast_expression (parser);
05512 
05513   /* A delete-expression may not appear in an integral constant
05514      expression.  */
05515   if (cp_parser_non_integral_constant_expression (parser, "`delete'"))
05516     return error_mark_node;
05517 
05518   return delete_sanity (expression, NULL_TREE, array_p, global_scope_p);
05519 }
05520 
05521 /* Parse a cast-expression.
05522 
05523    cast-expression:
05524      unary-expression
05525      ( type-id ) cast-expression
05526 
05527    ADDRESS_P is true iff the unary-expression is appearing as the
05528    operand of the `&' operator.   CAST_P is true if this expression is
05529    the target of a cast.
05530 
05531    Returns a representation of the expression.  */
05532 
05533 static tree
05534 cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p)
05535 {
05536   /* If it's a `(', then we might be looking at a cast.  */
05537   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
05538     {
05539       tree type = NULL_TREE;
05540       tree expr = NULL_TREE;
05541       bool compound_literal_p;
05542       const char *saved_message;
05543 
05544       /* There's no way to know yet whether or not this is a cast.
05545    For example, `(int (3))' is a unary-expression, while `(int)
05546    3' is a cast.  So, we resort to parsing tentatively.  */
05547       cp_parser_parse_tentatively (parser);
05548       /* Types may not be defined in a cast.  */
05549       saved_message = parser->type_definition_forbidden_message;
05550       parser->type_definition_forbidden_message
05551   = "types may not be defined in casts";
05552       /* Consume the `('.  */
05553       cp_lexer_consume_token (parser->lexer);
05554       /* A very tricky bit is that `(struct S) { 3 }' is a
05555    compound-literal (which we permit in C++ as an extension).
05556    But, that construct is not a cast-expression -- it is a
05557    postfix-expression.  (The reason is that `(struct S) { 3 }.i'
05558    is legal; if the compound-literal were a cast-expression,
05559    you'd need an extra set of parentheses.)  But, if we parse
05560    the type-id, and it happens to be a class-specifier, then we
05561    will commit to the parse at that point, because we cannot
05562    undo the action that is done when creating a new class.  So,
05563    then we cannot back up and do a postfix-expression.
05564 
05565    Therefore, we scan ahead to the closing `)', and check to see
05566    if the token after the `)' is a `{'.  If so, we are not
05567    looking at a cast-expression.
05568 
05569    Save tokens so that we can put them back.  */
05570       cp_lexer_save_tokens (parser->lexer);
05571       /* Skip tokens until the next token is a closing parenthesis.
05572    If we find the closing `)', and the next token is a `{', then
05573    we are looking at a compound-literal.  */
05574       compound_literal_p
05575   = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
05576               /*consume_paren=*/true)
05577      && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
05578       /* Roll back the tokens we skipped.  */
05579       cp_lexer_rollback_tokens (parser->lexer);
05580       /* If we were looking at a compound-literal, simulate an error
05581    so that the call to cp_parser_parse_definitely below will
05582    fail.  */
05583       if (compound_literal_p)
05584   cp_parser_simulate_error (parser);
05585       else
05586   {
05587     bool saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
05588     parser->in_type_id_in_expr_p = true;
05589     /* Look for the type-id.  */
05590     type = cp_parser_type_id (parser);
05591     /* Look for the closing `)'.  */
05592     cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
05593     parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
05594   }
05595 
05596       /* Restore the saved message.  */
05597       parser->type_definition_forbidden_message = saved_message;
05598 
05599       /* If ok so far, parse the dependent expression. We cannot be
05600    sure it is a cast. Consider `(T ())'.  It is a parenthesized
05601    ctor of T, but looks like a cast to function returning T
05602    without a dependent expression.  */
05603       if (!cp_parser_error_occurred (parser))
05604   expr = cp_parser_cast_expression (parser,
05605             /*address_p=*/false,
05606             /*cast_p=*/true);
05607 
05608       if (cp_parser_parse_definitely (parser))
05609   {
05610     /* Warn about old-style casts, if so requested.  */
05611     if (warn_old_style_cast
05612         && !in_system_header
05613         && !VOID_TYPE_P (type)
05614         && current_lang_name != lang_name_c)
05615       warning (OPT_Wold_style_cast, "use of old-style cast");
05616 
05617     /* Only type conversions to integral or enumeration types
05618        can be used in constant-expressions.  */
05619     if (!cast_valid_in_integral_constant_expression_p (type)
05620         && (cp_parser_non_integral_constant_expression
05621       (parser,
05622        "a cast to a type other than an integral or "
05623        "enumeration type")))
05624       return error_mark_node;
05625 
05626     /* Perform the cast.  */
05627     expr = build_c_cast (type, expr);
05628     return expr;
05629   }
05630     }
05631 
05632   /* If we get here, then it's not a cast, so it must be a
05633      unary-expression.  */
05634   return cp_parser_unary_expression (parser, address_p, cast_p);
05635 }
05636 
05637 /* Parse a binary expression of the general form:
05638 
05639    pm-expression:
05640      cast-expression
05641      pm-expression .* cast-expression
05642      pm-expression ->* cast-expression
05643 
05644    multiplicative-expression:
05645      pm-expression
05646      multiplicative-expression * pm-expression
05647      multiplicative-expression / pm-expression
05648      multiplicative-expression % pm-expression
05649 
05650    additive-expression:
05651      multiplicative-expression
05652      additive-expression + multiplicative-expression
05653      additive-expression - multiplicative-expression
05654 
05655    shift-expression:
05656      additive-expression
05657      shift-expression << additive-expression
05658      shift-expression >> additive-expression
05659 
05660    relational-expression:
05661      shift-expression
05662      relational-expression < shift-expression
05663      relational-expression > shift-expression
05664      relational-expression <= shift-expression
05665      relational-expression >= shift-expression
05666 
05667   GNU Extension:
05668 
05669    relational-expression:
05670      relational-expression <? shift-expression
05671      relational-expression >? shift-expression
05672 
05673    equality-expression:
05674      relational-expression
05675      equality-expression == relational-expression
05676      equality-expression != relational-expression
05677 
05678    and-expression:
05679      equality-expression
05680      and-expression & equality-expression
05681 
05682    exclusive-or-expression:
05683      and-expression
05684      exclusive-or-expression ^ and-expression
05685 
05686    inclusive-or-expression:
05687      exclusive-or-expression
05688      inclusive-or-expression | exclusive-or-expression
05689 
05690    logical-and-expression:
05691      inclusive-or-expression
05692      logical-and-expression && inclusive-or-expression
05693 
05694    logical-or-expression:
05695      logical-and-expression
05696      logical-or-expression || logical-and-expression
05697 
05698    All these are implemented with a single function like:
05699 
05700    binary-expression:
05701      simple-cast-expression
05702      binary-expression <token> binary-expression
05703 
05704    CAST_P is true if this expression is the target of a cast.
05705 
05706    The binops_by_token map is used to get the tree codes for each <token> type.
05707    binary-expressions are associated according to a precedence table.  */
05708 
05709 #define TOKEN_PRECEDENCE(token) \
05710   ((token->type == CPP_GREATER && !parser->greater_than_is_operator_p) \
05711    ? PREC_NOT_OPERATOR \
05712    : binops_by_token[token->type].prec)
05713 
05714 static tree
05715 cp_parser_binary_expression (cp_parser* parser, bool cast_p)
05716 {
05717   cp_parser_expression_stack stack;
05718   cp_parser_expression_stack_entry *sp = &stack[0];
05719   tree lhs, rhs;
05720   cp_token *token;
05721   enum tree_code tree_type;
05722   enum cp_parser_prec prec = PREC_NOT_OPERATOR, new_prec, lookahead_prec;
05723   bool overloaded_p;
05724 
05725   /* Parse the first expression.  */
05726   lhs = cp_parser_cast_expression (parser, /*address_p=*/false, cast_p);
05727 
05728   for (;;)
05729     {
05730       /* Get an operator token.  */
05731       token = cp_lexer_peek_token (parser->lexer);
05732 
05733       new_prec = TOKEN_PRECEDENCE (token);
05734 
05735       /* Popping an entry off the stack means we completed a subexpression:
05736    - either we found a token which is not an operator (`>' where it is not
05737      an operator, or prec == PREC_NOT_OPERATOR), in which case popping
05738      will happen repeatedly;
05739    - or, we found an operator which has lower priority.  This is the case
05740      where the recursive descent *ascends*, as in `3 * 4 + 5' after
05741      parsing `3 * 4'.  */
05742       if (new_prec <= prec)
05743   {
05744     if (sp == stack)
05745       break;
05746     else
05747       goto pop;
05748   }
05749 
05750      get_rhs:
05751       tree_type = binops_by_token[token->type].tree_type;
05752 
05753       /* We used the operator token.  */
05754       cp_lexer_consume_token (parser->lexer);
05755 
05756       /* Extract another operand.  It may be the RHS of this expression
05757    or the LHS of a new, higher priority expression.  */
05758       rhs = cp_parser_simple_cast_expression (parser);
05759 
05760       /* Get another operator token.  Look up its precedence to avoid
05761    building a useless (immediately popped) stack entry for common
05762    cases such as 3 + 4 + 5 or 3 * 4 + 5.  */
05763       token = cp_lexer_peek_token (parser->lexer);
05764       lookahead_prec = TOKEN_PRECEDENCE (token);
05765       if (lookahead_prec > new_prec)
05766   {
05767     /* ... and prepare to parse the RHS of the new, higher priority
05768        expression.  Since precedence levels on the stack are
05769        monotonically increasing, we do not have to care about
05770        stack overflows.  */
05771     sp->prec = prec;
05772     sp->tree_type = tree_type;
05773     sp->lhs = lhs;
05774     sp++;
05775     lhs = rhs;
05776     prec = new_prec;
05777     new_prec = lookahead_prec;
05778     goto get_rhs;
05779 
05780    pop:
05781     /* If the stack is not empty, we have parsed into LHS the right side
05782        (`4' in the example above) of an expression we had suspended.
05783        We can use the information on the stack to recover the LHS (`3')
05784        from the stack together with the tree code (`MULT_EXPR'), and
05785        the precedence of the higher level subexpression
05786        (`PREC_ADDITIVE_EXPRESSION').  TOKEN is the CPP_PLUS token,
05787        which will be used to actually build the additive expression.  */
05788     --sp;
05789     prec = sp->prec;
05790     tree_type = sp->tree_type;
05791     rhs = lhs;
05792     lhs = sp->lhs;
05793   }
05794 
05795       overloaded_p = false;
05796       lhs = build_x_binary_op (tree_type, lhs, rhs, &overloaded_p);
05797 
05798       /* If the binary operator required the use of an overloaded operator,
05799    then this expression cannot be an integral constant-expression.
05800    An overloaded operator can be used even if both operands are
05801    otherwise permissible in an integral constant-expression if at
05802    least one of the operands is of enumeration type.  */
05803 
05804       if (overloaded_p
05805     && (cp_parser_non_integral_constant_expression
05806         (parser, "calls to overloaded operators")))
05807   return error_mark_node;
05808     }
05809 
05810   return lhs;
05811 }
05812 
05813 
05814 /* Parse the `? expression : assignment-expression' part of a
05815    conditional-expression.  The LOGICAL_OR_EXPR is the
05816    logical-or-expression that started the conditional-expression.
05817    Returns a representation of the entire conditional-expression.
05818 
05819    This routine is used by cp_parser_assignment_expression.
05820 
05821      ? expression : assignment-expression
05822 
05823    GNU Extensions:
05824 
05825      ? : assignment-expression */
05826 
05827 static tree
05828 cp_parser_question_colon_clause (cp_parser* parser, tree logical_or_expr)
05829 {
05830   tree expr;
05831   tree assignment_expr;
05832 
05833   /* Consume the `?' token.  */
05834   cp_lexer_consume_token (parser->lexer);
05835   if (cp_parser_allow_gnu_extensions_p (parser)
05836       && cp_lexer_next_token_is (parser->lexer, CPP_COLON))
05837     /* Implicit true clause.  */
05838     expr = NULL_TREE;
05839   else
05840     /* Parse the expression.  */
05841     expr = cp_parser_expression (parser, /*cast_p=*/false);
05842 
05843   /* The next token should be a `:'.  */
05844   cp_parser_require (parser, CPP_COLON, "`:'");
05845   /* Parse the assignment-expression.  */
05846   assignment_expr = cp_parser_assignment_expression (parser, /*cast_p=*/false);
05847 
05848   /* Build the conditional-expression.  */
05849   return build_x_conditional_expr (logical_or_expr,
05850            expr,
05851            assignment_expr);
05852 }
05853 
05854 /* Parse an assignment-expression.
05855 
05856    assignment-expression:
05857      conditional-expression
05858      logical-or-expression assignment-operator assignment_expression
05859      throw-expression
05860 
05861    CAST_P is true if this expression is the target of a cast.
05862 
05863    Returns a representation for the expression.  */
05864 
05865 static tree
05866 cp_parser_assignment_expression (cp_parser* parser, bool cast_p)
05867 {
05868   tree expr;
05869 
05870   /* If the next token is the `throw' keyword, then we're looking at
05871      a throw-expression.  */
05872   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_THROW))
05873     expr = cp_parser_throw_expression (parser);
05874   /* Otherwise, it must be that we are looking at a
05875      logical-or-expression.  */
05876   else
05877     {
05878       /* Parse the binary expressions (logical-or-expression).  */
05879       expr = cp_parser_binary_expression (parser, cast_p);
05880       /* If the next token is a `?' then we're actually looking at a
05881    conditional-expression.  */
05882       if (cp_lexer_next_token_is (parser->lexer, CPP_QUERY))
05883   return cp_parser_question_colon_clause (parser, expr);
05884       else
05885   {
05886     enum tree_code assignment_operator;
05887 
05888     /* If it's an assignment-operator, we're using the second
05889        production.  */
05890     assignment_operator
05891       = cp_parser_assignment_operator_opt (parser);
05892     if (assignment_operator != ERROR_MARK)
05893       {
05894         tree rhs;
05895 
05896         /* Parse the right-hand side of the assignment.  */
05897         rhs = cp_parser_assignment_expression (parser, cast_p);
05898         /* An assignment may not appear in a
05899      constant-expression.  */
05900         if (cp_parser_non_integral_constant_expression (parser,
05901                     "an assignment"))
05902     return error_mark_node;
05903         /* Build the assignment expression.  */
05904         expr = build_x_modify_expr (expr,
05905             assignment_operator,
05906             rhs);
05907       }
05908   }
05909     }
05910 
05911   return expr;
05912 }
05913 
05914 /* Parse an (optional) assignment-operator.
05915 
05916    assignment-operator: one of
05917      = *= /= %= += -= >>= <<= &= ^= |=
05918 
05919    GNU Extension:
05920 
05921    assignment-operator: one of
05922      <?= >?=
05923 
05924    If the next token is an assignment operator, the corresponding tree
05925    code is returned, and the token is consumed.  For example, for
05926    `+=', PLUS_EXPR is returned.  For `=' itself, the code returned is
05927    NOP_EXPR.  For `/', TRUNC_DIV_EXPR is returned; for `%',
05928    TRUNC_MOD_EXPR is returned.  If TOKEN is not an assignment
05929    operator, ERROR_MARK is returned.  */
05930 
05931 static enum tree_code
05932 cp_parser_assignment_operator_opt (cp_parser* parser)
05933 {
05934   enum tree_code op;
05935   cp_token *token;
05936 
05937   /* Peek at the next toen.  */
05938   token = cp_lexer_peek_token (parser->lexer);
05939 
05940   switch (token->type)
05941     {
05942     case CPP_EQ:
05943       op = NOP_EXPR;
05944       break;
05945 
05946     case CPP_MULT_EQ:
05947       op = MULT_EXPR;
05948       break;
05949 
05950     case CPP_DIV_EQ:
05951       op = TRUNC_DIV_EXPR;
05952       break;
05953 
05954     case CPP_MOD_EQ:
05955       op = TRUNC_MOD_EXPR;
05956       break;
05957 
05958     case CPP_PLUS_EQ:
05959       op = PLUS_EXPR;
05960       break;
05961 
05962     case CPP_MINUS_EQ:
05963       op = MINUS_EXPR;
05964       break;
05965 
05966     case CPP_RSHIFT_EQ:
05967       op = RSHIFT_EXPR;
05968       break;
05969 
05970     case CPP_LSHIFT_EQ:
05971       op = LSHIFT_EXPR;
05972       break;
05973 
05974     case CPP_AND_EQ:
05975       op = BIT_AND_EXPR;
05976       break;
05977 
05978     case CPP_XOR_EQ:
05979       op = BIT_XOR_EXPR;
05980       break;
05981 
05982     case CPP_OR_EQ:
05983       op = BIT_IOR_EXPR;
05984       break;
05985 
05986     default:
05987       /* Nothing else is an assignment operator.  */
05988       op = ERROR_MARK;
05989     }
05990 
05991   /* If it was an assignment operator, consume it.  */
05992   if (op != ERROR_MARK)
05993     cp_lexer_consume_token (parser->lexer);
05994 
05995   return op;
05996 }
05997 
05998 /* Parse an expression.
05999 
06000    expression:
06001      assignment-expression
06002      expression , assignment-expression
06003 
06004    CAST_P is true if this expression is the target of a cast.
06005 
06006    Returns a representation of the expression.  */
06007 
06008 static tree
06009 cp_parser_expression (cp_parser* parser, bool cast_p)
06010 {
06011   tree expression = NULL_TREE;
06012 
06013   while (true)
06014     {
06015       tree assignment_expression;
06016 
06017       /* Parse the next assignment-expression.  */
06018       assignment_expression
06019   = cp_parser_assignment_expression (parser, cast_p);
06020       /* If this is the first assignment-expression, we can just
06021    save it away.  */
06022       if (!expression)
06023   expression = assignment_expression;
06024       else
06025   expression = build_x_compound_expr (expression,
06026               assignment_expression);
06027       /* If the next token is not a comma, then we are done with the
06028    expression.  */
06029       if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
06030   break;
06031       /* Consume the `,'.  */
06032       cp_lexer_consume_token (parser->lexer);
06033       /* A comma operator cannot appear in a constant-expression.  */
06034       if (cp_parser_non_integral_constant_expression (parser,
06035                   "a comma operator"))
06036   expression = error_mark_node;
06037     }
06038 
06039   return expression;
06040 }
06041 
06042 /* Parse a constant-expression.
06043 
06044    constant-expression:
06045      conditional-expression
06046 
06047   If ALLOW_NON_CONSTANT_P a non-constant expression is silently
06048   accepted.  If ALLOW_NON_CONSTANT_P is true and the expression is not
06049   constant, *NON_CONSTANT_P is set to TRUE.  If ALLOW_NON_CONSTANT_P
06050   is false, NON_CONSTANT_P should be NULL.  */
06051 
06052 static tree
06053 cp_parser_constant_expression (cp_parser* parser,
06054              bool allow_non_constant_p,
06055              bool *non_constant_p)
06056 {
06057   bool saved_integral_constant_expression_p;
06058   bool saved_allow_non_integral_constant_expression_p;
06059   bool saved_non_integral_constant_expression_p;
06060   tree expression;
06061 
06062   /* It might seem that we could simply parse the
06063      conditional-expression, and then check to see if it were
06064      TREE_CONSTANT.  However, an expression that is TREE_CONSTANT is
06065      one that the compiler can figure out is constant, possibly after
06066      doing some simplifications or optimizations.  The standard has a
06067      precise definition of constant-expression, and we must honor
06068      that, even though it is somewhat more restrictive.
06069 
06070      For example:
06071 
06072        int i[(2, 3)];
06073 
06074      is not a legal declaration, because `(2, 3)' is not a
06075      constant-expression.  The `,' operator is forbidden in a
06076      constant-expression.  However, GCC's constant-folding machinery
06077      will fold this operation to an INTEGER_CST for `3'.  */
06078 
06079   /* Save the old settings.  */
06080   saved_integral_constant_expression_p = parser->integral_constant_expression_p;
06081   saved_allow_non_integral_constant_expression_p
06082     = parser->allow_non_integral_constant_expression_p;
06083   saved_non_integral_constant_expression_p = parser->non_integral_constant_expression_p;
06084   /* We are now parsing a constant-expression.  */
06085   parser->integral_constant_expression_p = true;
06086   parser->allow_non_integral_constant_expression_p = allow_non_constant_p;
06087   parser->non_integral_constant_expression_p = false;
06088   /* Although the grammar says "conditional-expression", we parse an
06089      "assignment-expression", which also permits "throw-expression"
06090      and the use of assignment operators.  In the case that
06091      ALLOW_NON_CONSTANT_P is false, we get better errors than we would
06092      otherwise.  In the case that ALLOW_NON_CONSTANT_P is true, it is
06093      actually essential that we look for an assignment-expression.
06094      For example, cp_parser_initializer_clauses uses this function to
06095      determine whether a particular assignment-expression is in fact
06096      constant.  */
06097   expression = cp_parser_assignment_expression (parser, /*cast_p=*/false);
06098   /* Restore the old settings.  */
06099   parser->integral_constant_expression_p
06100     = saved_integral_constant_expression_p;
06101   parser->allow_non_integral_constant_expression_p
06102     = saved_allow_non_integral_constant_expression_p;
06103   if (allow_non_constant_p)
06104     *non_constant_p = parser->non_integral_constant_expression_p;
06105   else if (parser->non_integral_constant_expression_p)
06106     expression = error_mark_node;
06107   parser->non_integral_constant_expression_p
06108     = saved_non_integral_constant_expression_p;
06109 
06110   return expression;
06111 }
06112 
06113 /* Parse __builtin_offsetof.
06114 
06115    offsetof-expression:
06116      "__builtin_offsetof" "(" type-id "," offsetof-member-designator ")"
06117 
06118    offsetof-member-designator:
06119      id-expression
06120      | offsetof-member-designator "." id-expression
06121      | offsetof-member-designator "[" expression "]"  */
06122 
06123 static tree
06124 cp_parser_builtin_offsetof (cp_parser *parser)
06125 {
06126   int save_ice_p, save_non_ice_p;
06127   tree type, expr;
06128   cp_id_kind dummy;
06129 
06130   /* We're about to accept non-integral-constant things, but will
06131      definitely yield an integral constant expression.  Save and
06132      restore these values around our local parsing.  */
06133   save_ice_p = parser->integral_constant_expression_p;
06134   save_non_ice_p = parser->non_integral_constant_expression_p;
06135 
06136   /* Consume the "__builtin_offsetof" token.  */
06137   cp_lexer_consume_token (parser->lexer);
06138   /* Consume the opening `('.  */
06139   cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06140   /* Parse the type-id.  */
06141   type = cp_parser_type_id (parser);
06142   /* Look for the `,'.  */
06143   cp_parser_require (parser, CPP_COMMA, "`,'");
06144 
06145   /* Build the (type *)null that begins the traditional offsetof macro.  */
06146   expr = build_static_cast (build_pointer_type (type), null_pointer_node);
06147 
06148   /* Parse the offsetof-member-designator.  We begin as if we saw "expr->".  */
06149   expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DEREF, expr,
06150              true, &dummy);
06151   while (true)
06152     {
06153       cp_token *token = cp_lexer_peek_token (parser->lexer);
06154       switch (token->type)
06155   {
06156   case CPP_OPEN_SQUARE:
06157     /* offsetof-member-designator "[" expression "]" */
06158     expr = cp_parser_postfix_open_square_expression (parser, expr, true);
06159     break;
06160 
06161   case CPP_DOT:
06162     /* offsetof-member-designator "." identifier */
06163     cp_lexer_consume_token (parser->lexer);
06164     expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT, expr,
06165                true, &dummy);
06166     break;
06167 
06168   case CPP_CLOSE_PAREN:
06169     /* Consume the ")" token.  */
06170     cp_lexer_consume_token (parser->lexer);
06171     goto success;
06172 
06173   default:
06174     /* Error.  We know the following require will fail, but
06175        that gives the proper error message.  */
06176     cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06177     cp_parser_skip_to_closing_parenthesis (parser, true, false, true);
06178     expr = error_mark_node;
06179     goto failure;
06180   }
06181     }
06182 
06183  success:
06184   /* If we're processing a template, we can't finish the semantics yet.
06185      Otherwise we can fold the entire expression now.  */
06186   if (processing_template_decl)
06187     expr = build1 (OFFSETOF_EXPR, size_type_node, expr);
06188   else
06189     expr = finish_offsetof (expr);
06190 
06191  failure:
06192   parser->integral_constant_expression_p = save_ice_p;
06193   parser->non_integral_constant_expression_p = save_non_ice_p;
06194 
06195   return expr;
06196 }
06197 
06198 /* Statements [gram.stmt.stmt]  */
06199 
06200 /* Parse a statement.
06201 
06202    statement:
06203      labeled-statement
06204      expression-statement
06205      compound-statement
06206      selection-statement
06207      iteration-statement
06208      jump-statement
06209      declaration-statement
06210      try-block
06211 
06212   IN_COMPOUND is true when the statement is nested inside a
06213   cp_parser_compound_statement; this matters for certain pragmas.  */
06214 
06215 static void
06216 cp_parser_statement (cp_parser* parser, tree in_statement_expr,
06217          bool in_compound)
06218 {
06219   tree statement;
06220   cp_token *token;
06221   location_t statement_location;
06222 
06223  restart:
06224   /* There is no statement yet.  */
06225   statement = NULL_TREE;
06226   /* Peek at the next token.  */
06227   token = cp_lexer_peek_token (parser->lexer);
06228   /* Remember the location of the first token in the statement.  */
06229   statement_location = token->location;
06230   /* If this is a keyword, then that will often determine what kind of
06231      statement we have.  */
06232   if (token->type == CPP_KEYWORD)
06233     {
06234       enum rid keyword = token->keyword;
06235 
06236       switch (keyword)
06237   {
06238   case RID_CASE:
06239   case RID_DEFAULT:
06240     /* Looks like a labeled-statement with a case label.
06241        Parse the label, and then use tail recursion to parse
06242        the statement.  */
06243     cp_parser_label_for_labeled_statement (parser);
06244     goto restart;
06245 
06246   case RID_IF:
06247   case RID_SWITCH:
06248     statement = cp_parser_selection_statement (parser);
06249     break;
06250 
06251   case RID_WHILE:
06252   case RID_DO:
06253   case RID_FOR:
06254     statement = cp_parser_iteration_statement (parser);
06255     break;
06256 
06257   case RID_BREAK:
06258   case RID_CONTINUE:
06259   case RID_RETURN:
06260   case RID_GOTO:
06261     statement = cp_parser_jump_statement (parser);
06262     break;
06263 
06264     /* Objective-C++ exception-handling constructs.  */
06265   case RID_AT_TRY:
06266   case RID_AT_CATCH:
06267   case RID_AT_FINALLY:
06268   case RID_AT_SYNCHRONIZED:
06269   case RID_AT_THROW:
06270     statement = cp_parser_objc_statement (parser);
06271     break;
06272 
06273   case RID_TRY:
06274     statement = cp_parser_try_block (parser);
06275     break;
06276 
06277   default:
06278     /* It might be a keyword like `int' that can start a
06279        declaration-statement.  */
06280     break;
06281   }
06282     }
06283   else if (token->type == CPP_NAME)
06284     {
06285       /* If the next token is a `:', then we are looking at a
06286    labeled-statement.  */
06287       token = cp_lexer_peek_nth_token (parser->lexer, 2);
06288       if (token->type == CPP_COLON)
06289   {
06290     /* Looks like a labeled-statement with an ordinary label.
06291        Parse the label, and then use tail recursion to parse
06292        the statement.  */
06293     cp_parser_label_for_labeled_statement (parser);
06294     goto restart;
06295   }
06296     }
06297   /* Anything that starts with a `{' must be a compound-statement.  */
06298   else if (token->type == CPP_OPEN_BRACE)
06299     statement = cp_parser_compound_statement (parser, NULL, false);
06300   /* CPP_PRAGMA is a #pragma inside a function body, which constitutes
06301      a statement all its own.  */
06302   else if (token->type == CPP_PRAGMA)
06303     {
06304       /* Only certain OpenMP pragmas are attached to statements, and thus
06305    are considered statements themselves.  All others are not.  In
06306    the context of a compound, accept the pragma as a "statement" and
06307    return so that we can check for a close brace.  Otherwise we
06308    require a real statement and must go back and read one.  */
06309       if (in_compound)
06310   cp_parser_pragma (parser, pragma_compound);
06311       else if (!cp_parser_pragma (parser, pragma_stmt))
06312   goto restart;
06313       return;
06314     }
06315   else if (token->type == CPP_EOF)
06316     {
06317       cp_parser_error (parser, "expected statement");
06318       return;
06319     }
06320 
06321   /* Everything else must be a declaration-statement or an
06322      expression-statement.  Try for the declaration-statement
06323      first, unless we are looking at a `;', in which case we know that
06324      we have an expression-statement.  */
06325   if (!statement)
06326     {
06327       if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06328   {
06329     cp_parser_parse_tentatively (parser);
06330     /* Try to parse the declaration-statement.  */
06331     cp_parser_declaration_statement (parser);
06332     /* If that worked, we're done.  */
06333     if (cp_parser_parse_definitely (parser))
06334       return;
06335   }
06336       /* Look for an expression-statement instead.  */
06337       statement = cp_parser_expression_statement (parser, in_statement_expr);
06338     }
06339 
06340   /* Set the line number for the statement.  */
06341   if (statement && STATEMENT_CODE_P (TREE_CODE (statement)))
06342     SET_EXPR_LOCATION (statement, statement_location);
06343 }
06344 
06345 /* Parse the label for a labeled-statement, i.e.
06346 
06347    identifier :
06348    case constant-expression :
06349    default :
06350 
06351    GNU Extension:
06352    case constant-expression ... constant-expression : statement
06353 
06354    When a label is parsed without errors, the label is added to the
06355    parse tree by the finish_* functions, so this function doesn't
06356    have to return the label.  */
06357 
06358 static void
06359 cp_parser_label_for_labeled_statement (cp_parser* parser)
06360 {
06361   cp_token *token;
06362 
06363   /* The next token should be an identifier.  */
06364   token = cp_lexer_peek_token (parser->lexer);
06365   if (token->type != CPP_NAME
06366       && token->type != CPP_KEYWORD)
06367     {
06368       cp_parser_error (parser, "expected labeled-statement");
06369       return;
06370     }
06371 
06372   switch (token->keyword)
06373     {
06374     case RID_CASE:
06375       {
06376   tree expr, expr_hi;
06377   cp_token *ellipsis;
06378 
06379   /* Consume the `case' token.  */
06380   cp_lexer_consume_token (parser->lexer);
06381   /* Parse the constant-expression.  */
06382   expr = cp_parser_constant_expression (parser,
06383                 /*allow_non_constant_p=*/false,
06384                 NULL);
06385 
06386   ellipsis = cp_lexer_peek_token (parser->lexer);
06387   if (ellipsis->type == CPP_ELLIPSIS)
06388     {
06389       /* Consume the `...' token.  */
06390       cp_lexer_consume_token (parser->lexer);
06391       expr_hi =
06392         cp_parser_constant_expression (parser,
06393                /*allow_non_constant_p=*/false,
06394                NULL);
06395       /* We don't need to emit warnings here, as the common code
06396          will do this for us.  */
06397     }
06398   else
06399     expr_hi = NULL_TREE;
06400 
06401   if (parser->in_switch_statement_p)
06402     finish_case_label (expr, expr_hi);
06403   else
06404     error ("case label %qE not within a switch statement", expr);
06405       }
06406       break;
06407 
06408     case RID_DEFAULT:
06409       /* Consume the `default' token.  */
06410       cp_lexer_consume_token (parser->lexer);
06411 
06412       if (parser->in_switch_statement_p)
06413   finish_case_label (NULL_TREE, NULL_TREE);
06414       else
06415   error ("case label not within a switch statement");
06416       break;
06417 
06418     default:
06419       /* Anything else must be an ordinary label.  */
06420       finish_label_stmt (cp_parser_identifier (parser));
06421       break;
06422     }
06423 
06424   /* Require the `:' token.  */
06425   cp_parser_require (parser, CPP_COLON, "`:'");
06426 }
06427 
06428 /* Parse an expression-statement.
06429 
06430    expression-statement:
06431      expression [opt] ;
06432 
06433    Returns the new EXPR_STMT -- or NULL_TREE if the expression
06434    statement consists of nothing more than an `;'. IN_STATEMENT_EXPR_P
06435    indicates whether this expression-statement is part of an
06436    expression statement.  */
06437 
06438 static tree
06439 cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr)
06440 {
06441   tree statement = NULL_TREE;
06442 
06443   /* If the next token is a ';', then there is no expression
06444      statement.  */
06445   if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06446     statement = cp_parser_expression (parser, /*cast_p=*/false);
06447 
06448   /* Consume the final `;'.  */
06449   cp_parser_consume_semicolon_at_end_of_statement (parser);
06450 
06451   if (in_statement_expr
06452       && cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
06453     /* This is the final expression statement of a statement
06454        expression.  */
06455     statement = finish_stmt_expr_expr (statement, in_statement_expr);
06456   else if (statement)
06457     statement = finish_expr_stmt (statement);
06458   else
06459     finish_stmt ();
06460 
06461   return statement;
06462 }
06463 
06464 /* Parse a compound-statement.
06465 
06466    compound-statement:
06467      { statement-seq [opt] }
06468 
06469    Returns a tree representing the statement.  */
06470 
06471 static tree
06472 cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr,
06473             bool in_try)
06474 {
06475   tree compound_stmt;
06476 
06477   /* Consume the `{'.  */
06478   if (!cp_parser_require (parser, CPP_OPEN_BRACE, "`{'"))
06479     return error_mark_node;
06480   /* Begin the compound-statement.  */
06481   compound_stmt = begin_compound_stmt (in_try ? BCS_TRY_BLOCK : 0);
06482   /* Parse an (optional) statement-seq.  */
06483   cp_parser_statement_seq_opt (parser, in_statement_expr);
06484   /* Finish the compound-statement.  */
06485   finish_compound_stmt (compound_stmt);
06486   /* Consume the `}'.  */
06487   cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
06488 
06489   return compound_stmt;
06490 }
06491 
06492 /* Parse an (optional) statement-seq.
06493 
06494    statement-seq:
06495      statement
06496      statement-seq [opt] statement  */
06497 
06498 static void
06499 cp_parser_statement_seq_opt (cp_parser* parser, tree in_statement_expr)
06500 {
06501   /* Scan statements until there aren't any more.  */
06502   while (true)
06503     {
06504       cp_token *token = cp_lexer_peek_token (parser->lexer);
06505 
06506       /* If we're looking at a `}', then we've run out of statements.  */
06507       if (token->type == CPP_CLOSE_BRACE
06508     || token->type == CPP_EOF
06509     || token->type == CPP_PRAGMA_EOL)
06510   break;
06511 
06512       /* Parse the statement.  */
06513       cp_parser_statement (parser, in_statement_expr, true);
06514     }
06515 }
06516 
06517 /* Parse a selection-statement.
06518 
06519    selection-statement:
06520      if ( condition ) statement
06521      if ( condition ) statement else statement
06522      switch ( condition ) statement
06523 
06524    Returns the new IF_STMT or SWITCH_STMT.  */
06525 
06526 static tree
06527 cp_parser_selection_statement (cp_parser* parser)
06528 {
06529   cp_token *token;
06530   enum rid keyword;
06531 
06532   /* Peek at the next token.  */
06533   token = cp_parser_require (parser, CPP_KEYWORD, "selection-statement");
06534 
06535   /* See what kind of keyword it is.  */
06536   keyword = token->keyword;
06537   switch (keyword)
06538     {
06539     case RID_IF:
06540     case RID_SWITCH:
06541       {
06542   tree statement;
06543   tree condition;
06544 
06545   /* Look for the `('.  */
06546   if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
06547     {
06548       cp_parser_skip_to_end_of_statement (parser);
06549       return error_mark_node;
06550     }
06551 
06552   /* Begin the selection-statement.  */
06553   if (keyword == RID_IF)
06554     statement = begin_if_stmt ();
06555   else
06556     statement = begin_switch_stmt ();
06557 
06558   /* Parse the condition.  */
06559   condition = cp_parser_condition (parser);
06560   /* Look for the `)'.  */
06561   if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
06562     cp_parser_skip_to_closing_parenthesis (parser, true, false,
06563              /*consume_paren=*/true);
06564 
06565   if (keyword == RID_IF)
06566     {
06567       /* Add the condition.  */
06568       finish_if_stmt_cond (condition, statement);
06569 
06570       /* Parse the then-clause.  */
06571       cp_parser_implicitly_scoped_statement (parser);
06572       finish_then_clause (statement);
06573 
06574       /* If the next token is `else', parse the else-clause.  */
06575       if (cp_lexer_next_token_is_keyword (parser->lexer,
06576             RID_ELSE))
06577         {
06578     /* Consume the `else' keyword.  */
06579     cp_lexer_consume_token (parser->lexer);
06580     begin_else_clause (statement);
06581     /* Parse the else-clause.  */
06582     cp_parser_implicitly_scoped_statement (parser);
06583     finish_else_clause (statement);
06584         }
06585 
06586       /* Now we're all done with the if-statement.  */
06587       finish_if_stmt (statement);
06588     }
06589   else
06590     {
06591       bool in_switch_statement_p;
06592       unsigned char in_statement;
06593 
06594       /* Add the condition.  */
06595       finish_switch_cond (condition, statement);
06596 
06597       /* Parse the body of the switch-statement.  */
06598       in_switch_statement_p = parser->in_switch_statement_p;
06599       in_statement = parser->in_statement;
06600       parser->in_switch_statement_p = true;
06601       parser->in_statement |= IN_SWITCH_STMT;
06602       cp_parser_implicitly_scoped_statement (parser);
06603       parser->in_switch_statement_p = in_switch_statement_p;
06604       parser->in_statement = in_statement;
06605 
06606       /* Now we're all done with the switch-statement.  */
06607       finish_switch_stmt (statement);
06608     }
06609 
06610   return statement;
06611       }
06612       break;
06613 
06614     default:
06615       cp_parser_error (parser, "expected selection-statement");
06616       return error_mark_node;
06617     }
06618 }
06619 
06620 /* Parse a condition.
06621 
06622    condition:
06623      expression
06624      type-specifier-seq declarator = assignment-expression
06625 
06626    GNU Extension:
06627 
06628    condition:
06629      type-specifier-seq declarator asm-specification [opt]
06630        attributes [opt] = assignment-expression
06631 
06632    Returns the expression that should be tested.  */
06633 
06634 static tree
06635 cp_parser_condition (cp_parser* parser)
06636 {
06637   cp_decl_specifier_seq type_specifiers;
06638   const char *saved_message;
06639 
06640   /* Try the declaration first.  */
06641   cp_parser_parse_tentatively (parser);
06642   /* New types are not allowed in the type-specifier-seq for a
06643      condition.  */
06644   saved_message = parser->type_definition_forbidden_message;
06645   parser->type_definition_forbidden_message
06646     = "types may not be defined in conditions";
06647   /* Parse the type-specifier-seq.  */
06648   cp_parser_type_specifier_seq (parser, /*is_condition==*/true,
06649         &type_specifiers);
06650   /* Restore the saved message.  */
06651   parser->type_definition_forbidden_message = saved_message;
06652   /* If all is well, we might be looking at a declaration.  */
06653   if (!cp_parser_error_occurred (parser))
06654     {
06655       tree decl;
06656       tree asm_specification;
06657       tree attributes;
06658       cp_declarator *declarator;
06659       tree initializer = NULL_TREE;
06660 
06661       /* Parse the declarator.  */
06662       declarator = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
06663            /*ctor_dtor_or_conv_p=*/NULL,
06664            /*parenthesized_p=*/NULL,
06665            /*member_p=*/false);
06666       /* Parse the attributes.  */
06667       attributes = cp_parser_attributes_opt (parser);
06668       /* Parse the asm-specification.  */
06669       asm_specification = cp_parser_asm_specification_opt (parser);
06670       /* If the next token is not an `=', then we might still be
06671    looking at an expression.  For example:
06672 
06673      if (A(a).x)
06674 
06675    looks like a decl-specifier-seq and a declarator -- but then
06676    there is no `=', so this is an expression.  */
06677       cp_parser_require (parser, CPP_EQ, "`='");
06678       /* If we did see an `=', then we are looking at a declaration
06679    for sure.  */
06680       if (cp_parser_parse_definitely (parser))
06681   {
06682     tree pushed_scope;
06683     bool non_constant_p;
06684 
06685     /* Create the declaration.  */
06686     decl = start_decl (declarator, &type_specifiers,
06687            /*initialized_p=*/true,
06688            attributes, /*prefix_attributes=*/NULL_TREE,
06689            &pushed_scope);
06690     /* Parse the assignment-expression.  */
06691     initializer
06692       = cp_parser_constant_expression (parser,
06693                /*allow_non_constant_p=*/true,
06694                &non_constant_p);
06695     if (!non_constant_p)
06696       initializer = fold_non_dependent_expr (initializer);
06697 
06698     /* Process the initializer.  */
06699     cp_finish_decl (decl,
06700         initializer, !non_constant_p,
06701         asm_specification,
06702         LOOKUP_ONLYCONVERTING);
06703 
06704     if (pushed_scope)
06705       pop_scope (pushed_scope);
06706 
06707     return convert_from_reference (decl);
06708   }
06709     }
06710   /* If we didn't even get past the declarator successfully, we are
06711      definitely not looking at a declaration.  */
06712   else
06713     cp_parser_abort_tentative_parse (parser);
06714 
06715   /* Otherwise, we are looking at an expression.  */
06716   return cp_parser_expression (parser, /*cast_p=*/false);
06717 }
06718 
06719 /* Parse an iteration-statement.
06720 
06721    iteration-statement:
06722      while ( condition ) statement
06723      do statement while ( expression ) ;
06724      for ( for-init-statement condition [opt] ; expression [opt] )
06725        statement
06726 
06727    Returns the new WHILE_STMT, DO_STMT, or FOR_STMT.  */
06728 
06729 static tree
06730 cp_parser_iteration_statement (cp_parser* parser)
06731 {
06732   cp_token *token;
06733   enum rid keyword;
06734   tree statement;
06735   unsigned char in_statement;
06736 
06737   /* Peek at the next token.  */
06738   token = cp_parser_require (parser, CPP_KEYWORD, "iteration-statement");
06739   if (!token)
06740     return error_mark_node;
06741 
06742   /* Remember whether or not we are already within an iteration
06743      statement.  */
06744   in_statement = parser->in_statement;
06745 
06746   /* See what kind of keyword it is.  */
06747   keyword = token->keyword;
06748   switch (keyword)
06749     {
06750     case RID_WHILE:
06751       {
06752   tree condition;
06753 
06754   /* Begin the while-statement.  */
06755   statement = begin_while_stmt ();
06756   /* Look for the `('.  */
06757   cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06758   /* Parse the condition.  */
06759   condition = cp_parser_condition (parser);
06760   finish_while_stmt_cond (condition, statement);
06761   /* Look for the `)'.  */
06762   cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06763   /* Parse the dependent statement.  */
06764   parser->in_statement = IN_ITERATION_STMT;
06765   cp_parser_already_scoped_statement (parser);
06766   parser->in_statement = in_statement;
06767   /* We're done with the while-statement.  */
06768   finish_while_stmt (statement);
06769       }
06770       break;
06771 
06772     case RID_DO:
06773       {
06774   tree expression;
06775 
06776   /* Begin the do-statement.  */
06777   statement = begin_do_stmt ();
06778   /* Parse the body of the do-statement.  */
06779   parser->in_statement = IN_ITERATION_STMT;
06780   cp_parser_implicitly_scoped_statement (parser);
06781   parser->in_statement = in_statement;
06782   finish_do_body (statement);
06783   /* Look for the `while' keyword.  */
06784   cp_parser_require_keyword (parser, RID_WHILE, "`while'");
06785   /* Look for the `('.  */
06786   cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06787   /* Parse the expression.  */
06788   expression = cp_parser_expression (parser, /*cast_p=*/false);
06789   /* We're done with the do-statement.  */
06790   finish_do_stmt (expression, statement);
06791   /* Look for the `)'.  */
06792   cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06793   /* Look for the `;'.  */
06794   cp_parser_require (parser, CPP_SEMICOLON, "`;'");
06795       }
06796       break;
06797 
06798     case RID_FOR:
06799       {
06800   tree condition = NULL_TREE;
06801   tree expression = NULL_TREE;
06802 
06803   /* Begin the for-statement.  */
06804   statement = begin_for_stmt ();
06805   /* Look for the `('.  */
06806   cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06807   /* Parse the initialization.  */
06808   cp_parser_for_init_statement (parser);
06809   finish_for_init_stmt (statement);
06810 
06811   /* If there's a condition, process it.  */
06812   if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06813     condition = cp_parser_condition (parser);
06814   finish_for_cond (condition, statement);
06815   /* Look for the `;'.  */
06816   cp_parser_require (parser, CPP_SEMICOLON, "`;'");
06817 
06818   /* If there's an expression, process it.  */
06819   if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
06820     expression = cp_parser_expression (parser, /*cast_p=*/false);
06821   finish_for_expr (expression, statement);
06822   /* Look for the `)'.  */
06823   cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06824 
06825   /* Parse the body of the for-statement.  */
06826   parser->in_statement = IN_ITERATION_STMT;
06827   cp_parser_already_scoped_statement (parser);
06828   parser->in_statement = in_statement;
06829 
06830   /* We're done with the for-statement.  */
06831   finish_for_stmt (statement);
06832       }
06833       break;
06834 
06835     default:
06836       cp_parser_error (parser, "expected iteration-statement");
06837       statement = error_mark_node;
06838       break;
06839     }
06840 
06841   return statement;
06842 }
06843 
06844 /* Parse a for-init-statement.
06845 
06846    for-init-statement:
06847      expression-statement
06848      simple-declaration  */
06849 
06850 static void
06851 cp_parser_for_init_statement (cp_parser* parser)
06852 {
06853   /* If the next token is a `;', then we have an empty
06854      expression-statement.  Grammatically, this is also a
06855      simple-declaration, but an invalid one, because it does not
06856      declare anything.  Therefore, if we did not handle this case
06857      specially, we would issue an error message about an invalid
06858      declaration.  */
06859   if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06860     {
06861       /* We're going to speculatively look for a declaration, falling back
06862    to an expression, if necessary.  */
06863       cp_parser_parse_tentatively (parser);
06864       /* Parse the declaration.  */
06865       cp_parser_simple_declaration (parser,
06866             /*function_definition_allowed_p=*/false);
06867       /* If the tentative parse failed, then we shall need to look for an
06868    expression-statement.  */
06869       if (cp_parser_parse_definitely (parser))
06870   return;
06871     }
06872 
06873   cp_parser_expression_statement (parser, false);
06874 }
06875 
06876 /* Parse a jump-statement.
06877 
06878    jump-statement:
06879      break ;
06880      continue ;
06881      return expression [opt] ;
06882      goto identifier ;
06883 
06884    GNU extension:
06885 
06886    jump-statement:
06887      goto * expression ;
06888 
06889    Returns the new BREAK_STMT, CONTINUE_STMT, RETURN_EXPR, or GOTO_EXPR.  */
06890 
06891 static tree
06892 cp_parser_jump_statement (cp_parser* parser)
06893 {
06894   tree statement = error_mark_node;
06895   cp_token *token;
06896   enum rid keyword;
06897 
06898   /* Peek at the next token.  */
06899   token = cp_parser_require (parser, CPP_KEYWORD, "jump-statement");
06900   if (!token)
06901     return error_mark_node;
06902 
06903   /* See what kind of keyword it is.  */
06904   keyword = token->keyword;
06905   switch (keyword)
06906     {
06907     case RID_BREAK:
06908       switch (parser->in_statement)
06909   {
06910   case 0:
06911     error ("break statement not within loop or switch");
06912     break;
06913   default:
06914     gcc_assert ((parser->in_statement & IN_SWITCH_STMT)
06915           || parser->in_statement == IN_ITERATION_STMT);
06916     statement = finish_break_stmt ();
06917     break;
06918   case IN_OMP_BLOCK:
06919     error ("invalid exit from OpenMP structured block");
06920     break;
06921   case IN_OMP_FOR:
06922     error ("break statement used with OpenMP for loop");
06923     break;
06924   }
06925       cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06926       break;
06927 
06928     case RID_CONTINUE:
06929       switch (parser->in_statement & ~IN_SWITCH_STMT)
06930   {
06931   case 0:
06932     error ("continue statement not within a loop");
06933     break;
06934   case IN_ITERATION_STMT:
06935   case IN_OMP_FOR:
06936     statement = finish_continue_stmt ();
06937     break;
06938   case IN_OMP_BLOCK:
06939     error ("invalid exit from OpenMP structured block");
06940     break;
06941   default:
06942     gcc_unreachable ();
06943   }
06944       cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06945       break;
06946 
06947     case RID_RETURN:
06948       {
06949   tree expr;
06950 
06951   /* If the next token is a `;', then there is no
06952      expression.  */
06953   if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06954     expr = cp_parser_expression (parser, /*cast_p=*/false);
06955   else
06956     expr = NULL_TREE;
06957   /* Build the return-statement.  */
06958   statement = finish_return_stmt (expr);
06959   /* Look for the final `;'.  */
06960   cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06961       }
06962       break;
06963 
06964     case RID_GOTO:
06965       /* Create the goto-statement.  */
06966       if (cp_lexer_next_token_is (parser->lexer, CPP_MULT))
06967   {
06968     /* Issue a warning about this use of a GNU extension.  */
06969     if (pedantic)
06970       pedwarn ("ISO C++ forbids computed gotos");
06971     /* Consume the '*' token.  */
06972     cp_lexer_consume_token (parser->lexer);
06973     /* Parse the dependent expression.  */
06974     finish_goto_stmt (cp_parser_expression (parser, /*cast_p=*/false));
06975   }
06976       else
06977   finish_goto_stmt (cp_parser_identifier (parser));
06978       /* Look for the final `;'.  */
06979       cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06980       break;
06981 
06982     default:
06983       cp_parser_error (parser, "expected jump-statement");
06984       break;
06985     }
06986 
06987   return statement;
06988 }
06989 
06990 /* Parse a declaration-statement.
06991 
06992    declaration-statement:
06993      block-declaration  */
06994 
06995 static void
06996 cp_parser_declaration_statement (cp_parser* parser)
06997 {
06998   void *p;
06999 
07000   /* Get the high-water mark for the DECLARATOR_OBSTACK.  */
07001   p = obstack_alloc (&declarator_obstack, 0);
07002 
07003  /* Parse the block-declaration.  */
07004   cp_parser_block_declaration (parser, /*statement_p=*/true);
07005 
07006   /* Free any declarators allocated.  */
07007   obstack_free (&declarator_obstack, p);
07008 
07009   /* Finish off the statement.  */
07010   finish_stmt ();
07011 }
07012 
07013 /* Some dependent statements (like `if (cond) statement'), are
07014    implicitly in their own scope.  In other words, if the statement is
07015    a single statement (as opposed to a compound-statement), it is
07016    none-the-less treated as if it were enclosed in braces.  Any
07017    declarations appearing in the dependent statement are out of scope
07018    after control passes that point.  This function parses a statement,
07019    but ensures that is in its own scope, even if it is not a
07020    compound-statement.
07021 
07022    Returns the new statement.  */
07023 
07024 static tree
07025 cp_parser_implicitly_scoped_statement (cp_parser* parser)
07026 {
07027   tree statement;
07028 
07029   /* Mark if () ; with a special NOP_EXPR.  */
07030   if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
07031     {
07032       cp_lexer_consume_token (parser->lexer);
07033       statement = add_stmt (build_empty_stmt ());
07034     }
07035   /* if a compound is opened, we simply parse the statement directly.  */
07036   else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
07037     statement = cp_parser_compound_statement (parser, NULL, false);
07038   /* If the token is not a `{', then we must take special action.  */
07039   else
07040     {
07041       /* Create a compound-statement.  */
07042       statement = begin_compound_stmt (0);
07043       /* Parse the dependent-statement.  */
07044       cp_parser_statement (parser, NULL_TREE, false);
07045       /* Finish the dummy compound-statement.  */
07046       finish_compound_stmt (statement);
07047     }
07048 
07049   /* Return the statement.  */
07050   return statement;
07051 }
07052 
07053 /* For some dependent statements (like `while (cond) statement'), we
07054    have already created a scope.  Therefore, even if the dependent
07055    statement is a compound-statement, we do not want to create another
07056    scope.  */
07057 
07058 static void
07059 cp_parser_already_scoped_statement (cp_parser* parser)
07060 {
07061   /* If the token is a `{', then we must take special action.  */
07062   if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
07063     cp_parser_statement (parser, NULL_TREE, false);
07064   else
07065     {
07066       /* Avoid calling cp_parser_compound_statement, so that we
07067    don't create a new scope.  Do everything else by hand.  */
07068       cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
07069       cp_parser_statement_seq_opt (parser, NULL_TREE);
07070       cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
07071     }
07072 }
07073 
07074 /* Declarations [gram.dcl.dcl] */
07075 
07076 /* Parse an optional declaration-sequence.
07077 
07078    declaration-seq:
07079      declaration
07080      declaration-seq declaration  */
07081 
07082 static void
07083 cp_parser_declaration_seq_opt (cp_parser* parser)
07084 {
07085   while (true)
07086     {
07087       cp_token *token;
07088 
07089       token = cp_lexer_peek_token (parser->lexer);
07090 
07091       if (token->type == CPP_CLOSE_BRACE
07092     || token->type == CPP_EOF
07093     || token->type == CPP_PRAGMA_EOL)
07094   break;
07095 
07096       if (token->type == CPP_SEMICOLON)
07097   {
07098     /* A declaration consisting of a single semicolon is
07099        invalid.  Allow it unless we're being pedantic.  */
07100     cp_lexer_consume_token (parser->lexer);
07101     if (pedantic && !in_system_header)
07102       pedwarn ("extra %<;%>");
07103     continue;
07104   }
07105 
07106       /* If we're entering or exiting a region that's implicitly
07107    extern "C", modify the lang context appropriately.  */
07108       if (!parser->implicit_extern_c && token->implicit_extern_c)
07109   {
07110     push_lang_context (lang_name_c);
07111     parser->implicit_extern_c = true;
07112   }
07113       else if (parser->implicit_extern_c && !token->implicit_extern_c)
07114   {
07115     pop_lang_context ();
07116     parser->implicit_extern_c = false;
07117   }
07118 
07119       if (token->type == CPP_PRAGMA)
07120   {
07121     /* A top-level declaration can consist solely of a #pragma.
07122        A nested declaration cannot, so this is done here and not
07123        in cp_parser_declaration.  (A #pragma at block scope is
07124        handled in cp_parser_statement.)  */
07125     cp_parser_pragma (parser, pragma_external);
07126     continue;
07127   }
07128 
07129       /* Parse the declaration itself.  */
07130       cp_parser_declaration (parser);
07131     }
07132 }
07133 
07134 /* Parse a declaration.
07135 
07136    declaration:
07137      block-declaration
07138      function-definition
07139      template-declaration
07140      explicit-instantiation
07141      explicit-specialization
07142      linkage-specification
07143      namespace-definition
07144 
07145    GNU extension:
07146 
07147    declaration:
07148       __extension__ declaration */
07149 
07150 static void
07151 cp_parser_declaration (cp_parser* parser)
07152 {
07153   cp_token token1;
07154   cp_token token2;
07155   int saved_pedantic;
07156   void *p;
07157 
07158   /* Check for the `__extension__' keyword.  */
07159   if (cp_parser_extension_opt (parser, &saved_pedantic))
07160     {
07161       /* Parse the qualified declaration.  */
07162       cp_parser_declaration (parser);
07163       /* Restore the PEDANTIC flag.  */
07164       pedantic = saved_pedantic;
07165 
07166       return;
07167     }
07168 
07169   /* Try to figure out what kind of declaration is present.  */
07170   token1 = *cp_lexer_peek_token (parser->lexer);
07171 
07172   if (token1.type != CPP_EOF)
07173     token2 = *cp_lexer_peek_nth_token (parser->lexer, 2);
07174   else
07175     {
07176       token2.type = CPP_EOF;
07177       token2.keyword = RID_MAX;
07178     }
07179 
07180   /* Get the high-water mark for the DECLARATOR_OBSTACK.  */
07181   p = obstack_alloc (&declarator_obstack, 0);
07182 
07183   /* If the next token is `extern' and the following token is a string
07184      literal, then we have a linkage specification.  */
07185   if (token1.keyword == RID_EXTERN
07186       && cp_parser_is_string_literal (&token2))
07187     cp_parser_linkage_specification (parser);
07188   /* If the next token is `template', then we have either a template
07189      declaration, an explicit instantiation, or an explicit
07190      specialization.  */
07191   else if (token1.keyword == RID_TEMPLATE)
07192     {
07193       /* `template <>' indicates a template specialization.  */
07194       if (token2.type == CPP_LESS
07195     && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_GREATER)
07196   cp_parser_explicit_specialization (parser);
07197       /* `template <' indicates a template declaration.  */
07198       else if (token2.type == CPP_LESS)
07199   cp_parser_template_declaration (parser, /*member_p=*/false);
07200       /* Anything else must be an explicit instantiation.  */
07201       else
07202   cp_parser_explicit_instantiation (parser);
07203     }
07204   /* If the next token is `export', then we have a template
07205      declaration.  */
07206   else if (token1.keyword == RID_EXPORT)
07207     cp_parser_template_declaration (parser, /*member_p=*/false);
07208   /* If the next token is `extern', 'static' or 'inline' and the one
07209      after that is `template', we have a GNU extended explicit
07210      instantiation directive.  */
07211   else if (cp_parser_allow_gnu_extensions_p (parser)
07212      && (token1.keyword == RID_EXTERN
07213          || token1.keyword == RID_STATIC
07214          || token1.keyword == RID_INLINE)
07215      && token2.keyword == RID_TEMPLATE)
07216     cp_parser_explicit_instantiation (parser);
07217   /* If the next token is `namespace', check for a named or unnamed
07218      namespace definition.  */
07219   else if (token1.keyword == RID_NAMESPACE
07220      && (/* A named namespace definition.  */
07221          (token2.type == CPP_NAME
07222     && (cp_lexer_peek_nth_token (parser->lexer, 3)->type
07223         != CPP_EQ))
07224          /* An unnamed namespace definition.  */
07225          || token2.type == CPP_OPEN_BRACE
07226          || token2.keyword == RID_ATTRIBUTE))
07227     cp_parser_namespace_definition (parser);
07228   /* Objective-C++ declaration/definition.  */
07229   else if (c_dialect_objc () && OBJC_IS_AT_KEYWORD (token1.keyword))
07230     cp_parser_objc_declaration (parser);
07231   /* We must have either a block declaration or a function
07232      definition.  */
07233   else
07234     /* Try to parse a block-declaration, or a function-definition.  */
07235     cp_parser_block_declaration (parser, /*statement_p=*/false);
07236 
07237   /* Free any declarators allocated.  */
07238   obstack_free (&declarator_obstack, p);
07239 }
07240 
07241 /* Parse a block-declaration.
07242 
07243    block-declaration:
07244      simple-declaration
07245      asm-definition
07246      namespace-alias-definition
07247      using-declaration
07248      using-directive
07249 
07250    GNU Extension:
07251 
07252    block-declaration:
07253      __extension__ block-declaration
07254      label-declaration
07255 
07256    If STATEMENT_P is TRUE, then this block-declaration is occurring as
07257    part of a declaration-statement.  */
07258 
07259 static void
07260 cp_parser_block_declaration (cp_parser *parser,
07261            bool      statement_p)
07262 {
07263   cp_token *token1;
07264   int saved_pedantic;
07265 
07266   /* Check for the `__extension__' keyword.  */
07267   if (cp_parser_extension_opt (parser, &saved_pedantic))
07268     {
07269       /* Parse the qualified declaration.  */
07270       cp_parser_block_declaration (parser, statement_p);
07271       /* Restore the PEDANTIC flag.  */
07272       pedantic = saved_pedantic;
07273 
07274       return;
07275     }
07276 
07277   /* Peek at the next token to figure out which kind of declaration is
07278      present.  */
07279   token1 = cp_lexer_peek_token (parser->lexer);
07280 
07281   /* If the next keyword is `asm', we have an asm-definition.  */
07282   if (token1->keyword == RID_ASM)
07283     {
07284       if (statement_p)
07285   cp_parser_commit_to_tentative_parse (parser);
07286       cp_parser_asm_definition (parser);
07287     }
07288   /* If the next keyword is `namespace', we have a
07289      namespace-alias-definition.  */
07290   else if (token1->keyword == RID_NAMESPACE)
07291     cp_parser_namespace_alias_definition (parser);
07292   /* If the next keyword is `using', we have either a
07293      using-declaration or a using-directive.  */
07294   else if (token1->keyword == RID_USING)
07295     {
07296       cp_token *token2;
07297 
07298       if (statement_p)
07299   cp_parser_commit_to_tentative_parse (parser);
07300       /* If the token after `using' is `namespace', then we have a
07301    using-directive.  */
07302       token2 = cp_lexer_peek_nth_token (parser->lexer, 2);
07303       if (token2->keyword == RID_NAMESPACE)
07304   cp_parser_using_directive (parser);
07305       /* Otherwise, it's a using-declaration.  */
07306       else
07307   cp_parser_using_declaration (parser,
07308              /*access_declaration_p=*/false);
07309     }
07310   /* If the next keyword is `__label__' we have a label declaration.  */
07311   else if (token1->keyword == RID_LABEL)
07312     {
07313       if (statement_p)
07314   cp_parser_commit_to_tentative_parse (parser);
07315       cp_parser_label_declaration (parser);
07316     }
07317   /* Anything else must be a simple-declaration.  */
07318   else
07319     cp_parser_simple_declaration (parser, !statement_p);
07320 }
07321 
07322 /* Parse a simple-declaration.
07323 
07324    simple-declaration:
07325      decl-specifier-seq [opt] init-declarator-list [opt] ;
07326 
07327    init-declarator-list:
07328      init-declarator
07329      init-declarator-list , init-declarator
07330 
07331    If FUNCTION_DEFINITION_ALLOWED_P is TRUE, then we also recognize a
07332    function-definition as a simple-declaration.  */
07333 
07334 static void
07335 cp_parser_simple_declaration (cp_parser* parser,
07336             bool function_definition_allowed_p)
07337 {
07338   cp_decl_specifier_seq decl_specifiers;
07339   int declares_class_or_enum;
07340   bool saw_declarator;
07341 
07342   /* Defer access checks until we know what is being declared; the
07343      checks for names appearing in the decl-specifier-seq should be
07344      done as if we were in the scope of the thing being declared.  */
07345   push_deferring_access_checks (dk_deferred);
07346 
07347   /* Parse the decl-specifier-seq.  We have to keep track of whether
07348      or not the decl-specifier-seq declares a named class or
07349      enumeration type, since that is the only case in which the
07350      init-declarator-list is allowed to be empty.
07351 
07352      [dcl.dcl]
07353 
07354      In a simple-declaration, the optional init-declarator-list can be
07355      omitted only when declaring a class or enumeration, that is when
07356      the decl-specifier-seq contains either a class-specifier, an
07357      elaborated-type-specifier, or an enum-specifier.  */
07358   cp_parser_decl_specifier_seq (parser,
07359         CP_PARSER_FLAGS_OPTIONAL,
07360         &decl_specifiers,
07361         &declares_class_or_enum);
07362   /* We no longer need to defer access checks.  */
07363   stop_deferring_access_checks ();
07364 
07365   /* In a block scope, a valid declaration must always have a
07366      decl-specifier-seq.  By not trying to parse declarators, we can
07367      resolve the declaration/expression ambiguity more quickly.  */
07368   if (!function_definition_allowed_p
07369       && !decl_specifiers.any_specifiers_p)
07370     {
07371       cp_parser_error (parser, "expected declaration");
07372       goto done;
07373     }
07374 
07375   /* If the next two tokens are both identifiers, the code is
07376      erroneous. The usual cause of this situation is code like:
07377 
07378        T t;
07379 
07380      where "T" should name a type -- but does not.  */
07381   if (!decl_specifiers.type
07382       && cp_parser_parse_and_diagnose_invalid_type_name (parser))
07383     {
07384       /* If parsing tentatively, we should commit; we really are
07385    looking at a declaration.  */
07386       cp_parser_commit_to_tentative_parse (parser);
07387       /* Give up.  */
07388       goto done;
07389     }
07390 
07391   /* If we have seen at least one decl-specifier, and the next token
07392      is not a parenthesis, then we must be looking at a declaration.
07393      (After "int (" we might be looking at a functional cast.)  */
07394   if (decl_specifiers.any_specifiers_p
07395       && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
07396     cp_parser_commit_to_tentative_parse (parser);
07397 
07398   /* Keep going until we hit the `;' at the end of the simple
07399      declaration.  */
07400   saw_declarator = false;
07401   while (cp_lexer_next_token_is_not (parser->lexer,
07402              CPP_SEMICOLON))
07403     {
07404       cp_token *token;
07405       bool function_definition_p;
07406       tree decl;
07407 
07408       if (saw_declarator)
07409   {
07410     /* If we are processing next declarator, coma is expected */
07411     token = cp_lexer_peek_token (parser->lexer);
07412     gcc_assert (token->type == CPP_COMMA);
07413     cp_lexer_consume_token (parser->lexer);
07414   }
07415       else
07416   saw_declarator = true;
07417 
07418       /* Parse the init-declarator.  */
07419       decl = cp_parser_init_declarator (parser, &decl_specifiers,
07420           /*checks=*/NULL,
07421           function_definition_allowed_p,
07422           /*member_p=*/false,
07423           declares_class_or_enum,
07424           &function_definition_p);
07425       /* If an error occurred while parsing tentatively, exit quickly.
07426    (That usually happens when in the body of a function; each
07427    statement is treated as a declaration-statement until proven
07428    otherwise.)  */
07429       if (cp_parser_error_occurred (parser))
07430   goto done;
07431       /* Handle function definitions specially.  */
07432       if (function_definition_p)
07433   {
07434     /* If the next token is a `,', then we are probably
07435        processing something like:
07436 
07437          void f() {}, *p;
07438 
07439        which is erroneous.  */
07440     if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
07441       error ("mixing declarations and function-definitions is forbidden");
07442     /* Otherwise, we're done with the list of declarators.  */
07443     else
07444       {
07445         pop_deferring_access_checks ();
07446         return;
07447       }
07448   }
07449       /* The next token should be either a `,' or a `;'.  */
07450       token = cp_lexer_peek_token (parser->lexer);
07451       /* If it's a `,', there are more declarators to come.  */
07452       if (token->type == CPP_COMMA)
07453   /* will be consumed next time around */;
07454       /* If it's a `;', we are done.  */
07455       else if (token->type == CPP_SEMICOLON)
07456   break;
07457       /* Anything else is an error.  */
07458       else
07459   {
07460     /* If we have already issued an error message we don't need
07461        to issue another one.  */
07462     if (decl != error_mark_node
07463         || cp_parser_uncommitted_to_tentative_parse_p (parser))
07464       cp_parser_error (parser, "expected %<,%> or %<;%>");
07465     /* Skip tokens until we reach the end of the statement.  */
07466     cp_parser_skip_to_end_of_statement (parser);
07467     /* If the next token is now a `;', consume it.  */
07468     if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
07469       cp_lexer_consume_token (parser->lexer);
07470     goto done;
07471   }
07472       /* After the first time around, a function-definition is not
07473    allowed -- even if it was OK at first.  For example:
07474 
07475      int i, f() {}
07476 
07477    is not valid.  */
07478       function_definition_allowed_p = false;
07479     }
07480 
07481   /* Issue an error message if no declarators are present, and the
07482      decl-specifier-seq does not itself declare a class or
07483      enumeration.  */
07484   if (!saw_declarator)
07485     {
07486       if (cp_parser_declares_only_class_p (parser))
07487   shadow_tag (&decl_specifiers);
07488       /* Perform any deferred access checks.  */
07489       perform_deferred_access_checks ();
07490     }
07491 
07492   /* Consume the `;'.  */
07493   cp_parser_require (parser, CPP_SEMICOLON, "`;'");
07494 
07495  done:
07496   pop_deferring_access_checks ();
07497 }
07498 
07499 /* Parse a decl-specifier-seq.
07500 
07501    decl-specifier-seq:
07502      decl-specifier-seq [opt] decl-specifier
07503 
07504    decl-specifier:
07505      storage-class-specifier
07506      type-specifier
07507      function-specifier
07508      friend
07509      typedef
07510 
07511    GNU Extension:
07512 
07513    decl-specifier:
07514      attributes
07515 
07516    Set *DECL_SPECS to a representation of the decl-specifier-seq.
07517 
07518    The parser flags FLAGS is used to control type-specifier parsing.
07519 
07520    *DECLARES_CLASS_OR_ENUM is set to the bitwise or of the following
07521    flags:
07522 
07523      1: one of the decl-specifiers is an elaborated-type-specifier
07524   (i.e., a type declaration)
07525      2: one of the decl-specifiers is an enum-specifier or a
07526   class-specifier (i.e., a type definition)
07527 
07528    */
07529 
07530 static void
07531 cp_parser_decl_specifier_seq (cp_parser* parser,
07532             cp_parser_flags flags,
07533             cp_decl_specifier_seq *decl_specs,
07534             int* declares_class_or_enum)
07535 {
07536   bool constructor_possible_p = !parser->in_declarator_p;
07537 
07538   /* Clear DECL_SPECS.  */
07539   clear_decl_specs (decl_specs);
07540 
07541   /* Assume no class or enumeration type is declared.  */
07542   *declares_class_or_enum = 0;
07543 
07544   /* Keep reading specifiers until there are no more to read.  */
07545   while (true)
07546     {
07547       bool constructor_p;
07548       bool found_decl_spec;
07549       cp_token *token;
07550 
07551       /* Peek at the next token.  */
07552       token = cp_lexer_peek_token (parser->lexer);
07553       /* Handle attributes.  */
07554       if (token->keyword == RID_ATTRIBUTE)
07555   {
07556     /* Parse the attributes.  */
07557     decl_specs->attributes
07558       = chainon (decl_specs->attributes,
07559            cp_parser_attributes_opt (parser));
07560     continue;
07561   }
07562       /* Assume we will find a decl-specifier keyword.  */
07563       found_decl_spec = true;
07564       /* If the next token is an appropriate keyword, we can simply
07565    add it to the list.  */
07566       switch (token->keyword)
07567   {
07568     /* decl-specifier:
07569          friend  */
07570   case RID_FRIEND:
07571     if (!at_class_scope_p ())
07572       {
07573         error ("%<friend%> used outside of class");
07574         cp_lexer_purge_token (parser->lexer);
07575       }
07576     else
07577       {
07578         ++decl_specs->specs[(int) ds_friend];
07579         /* Consume the token.  */
07580         cp_lexer_consume_token (parser->lexer);
07581       }
07582     break;
07583 
07584     /* function-specifier:
07585          inline
07586          virtual
07587          explicit  */
07588   case RID_INLINE:
07589   case RID_VIRTUAL:
07590   case RID_EXPLICIT:
07591     cp_parser_function_specifier_opt (parser, decl_specs);
07592     break;
07593 
07594     /* decl-specifier:
07595          typedef  */
07596   case RID_TYPEDEF:
07597     ++decl_specs->specs[(int) ds_typedef];
07598     /* Consume the token.  */
07599     cp_lexer_consume_token (parser->lexer);
07600     /* A constructor declarator cannot appear in a typedef.  */
07601     constructor_possible_p = false;
07602     /* The "typedef" keyword can only occur in a declaration; we
07603        may as well commit at this point.  */
07604     cp_parser_commit_to_tentative_parse (parser);
07605 
07606           if (decl_specs->storage_class != sc_none)
07607             decl_specs->conflicting_specifiers_p = true;
07608     break;
07609 
07610     /* storage-class-specifier:
07611          auto
07612          register
07613          static
07614          extern
07615          mutable
07616 
07617        GNU Extension:
07618          thread  */
07619   case RID_AUTO:
07620   case RID_REGISTER:
07621   case RID_STATIC:
07622   case RID_EXTERN:
07623   case RID_MUTABLE:
07624     /* Consume the token.  */
07625     cp_lexer_consume_token (parser->lexer);
07626     cp_parser_set_storage_class (parser, decl_specs, token->keyword);
07627     break;
07628   case RID_THREAD:
07629     /* Consume the token.  */
07630     cp_lexer_consume_token (parser->lexer);
07631     ++decl_specs->specs[(int) ds_thread];
07632     break;
07633 
07634   default:
07635     /* We did not yet find a decl-specifier yet.  */
07636     found_decl_spec = false;
07637     break;
07638   }
07639 
07640       /* Constructors are a special case.  The `S' in `S()' is not a
07641    decl-specifier; it is the beginning of the declarator.  */
07642       constructor_p
07643   = (!found_decl_spec
07644      && constructor_possible_p
07645      && (cp_parser_constructor_declarator_p
07646          (parser, decl_specs->specs[(int) ds_friend] != 0)));
07647 
07648       /* If we don't have a DECL_SPEC yet, then we must be looking at
07649    a type-specifier.  */
07650       if (!found_decl_spec && !constructor_p)
07651   {
07652     int decl_spec_declares_class_or_enum;
07653     bool is_cv_qualifier;
07654     tree type_spec;
07655 
07656     type_spec
07657       = cp_parser_type_specifier (parser, flags,
07658           decl_specs,
07659           /*is_declaration=*/true,
07660           &decl_spec_declares_class_or_enum,
07661           &is_cv_qualifier);
07662 
07663     *declares_class_or_enum |= decl_spec_declares_class_or_enum;
07664 
07665     /* If this type-specifier referenced a user-defined type
07666        (a typedef, class-name, etc.), then we can't allow any
07667        more such type-specifiers henceforth.
07668 
07669        [dcl.spec]
07670 
07671        The longest sequence of decl-specifiers that could
07672        possibly be a type name is taken as the
07673        decl-specifier-seq of a declaration.  The sequence shall
07674        be self-consistent as described below.
07675 
07676        [dcl.type]
07677 
07678        As a general rule, at most one type-specifier is allowed
07679        in the complete decl-specifier-seq of a declaration.  The
07680        only exceptions are the following:
07681 
07682        -- const or volatile can be combined with any other
07683     type-specifier.
07684 
07685        -- signed or unsigned can be combined with char, long,
07686     short, or int.
07687 
07688        -- ..
07689 
07690        Example:
07691 
07692          typedef char* Pc;
07693          void g (const int Pc);
07694 
07695        Here, Pc is *not* part of the decl-specifier seq; it's
07696        the declarator.  Therefore, once we see a type-specifier
07697        (other than a cv-qualifier), we forbid any additional
07698        user-defined types.  We *do* still allow things like `int
07699        int' to be considered a decl-specifier-seq, and issue the
07700        error message later.  */
07701     if (type_spec && !is_cv_qualifier)
07702       flags |= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES;
07703     /* A constructor declarator cannot follow a type-specifier.  */
07704     if (type_spec)
07705       {
07706         constructor_possible_p = false;
07707         found_decl_spec = true;
07708       }
07709   }
07710 
07711       /* If we still do not have a DECL_SPEC, then there are no more
07712    decl-specifiers.  */
07713       if (!found_decl_spec)
07714   break;
07715 
07716       decl_specs->any_specifiers_p = true;
07717       /* After we see one decl-specifier, further decl-specifiers are
07718    always optional.  */
07719       flags |= CP_PARSER_FLAGS_OPTIONAL;
07720     }
07721 
07722   cp_parser_check_decl_spec (decl_specs);
07723 
07724   /* Don't allow a friend specifier with a class definition.  */
07725   if (decl_specs->specs[(int) ds_friend] != 0
07726       && (*declares_class_or_enum & 2))
07727     error ("class definition may not be declared a friend");
07728 }
07729 
07730 /* Parse an (optional) storage-class-specifier.
07731 
07732    storage-class-specifier:
07733      auto
07734      register
07735      static
07736      extern
07737      mutable
07738 
07739    GNU Extension:
07740 
07741    storage-class-specifier:
07742      thread
07743 
07744    Returns an IDENTIFIER_NODE corresponding to the keyword used.  */
07745 
07746 static tree
07747 cp_parser_storage_class_specifier_opt (cp_parser* parser)
07748 {
07749   switch (cp_lexer_peek_token (parser->lexer)->keyword)
07750     {
07751     case RID_AUTO:
07752     case RID_REGISTER:
07753     case RID_STATIC:
07754     case RID_EXTERN:
07755     case RID_MUTABLE:
07756     case RID_THREAD:
07757       /* Consume the token.  */
07758       return cp_lexer_consume_token (parser->lexer)->u.value;
07759 
07760     default:
07761       return NULL_TREE;
07762     }
07763 }
07764 
07765 /* Parse an (optional) function-specifier.
07766 
07767    function-specifier:
07768      inline
07769      virtual
07770      explicit
07771 
07772    Returns an IDENTIFIER_NODE corresponding to the keyword used.
07773    Updates DECL_SPECS, if it is non-NULL.  */
07774 
07775 static tree
07776 cp_parser_function_specifier_opt (cp_parser* parser,
07777           cp_decl_specifier_seq *decl_specs)
07778 {
07779   switch (cp_lexer_peek_token (parser->lexer)->keyword)
07780     {
07781     case RID_INLINE:
07782       if (decl_specs)
07783   ++decl_specs->specs[(int) ds_inline];
07784       break;
07785 
07786     case RID_VIRTUAL:
07787       /* 14.5.2.3 [temp.mem]
07788 
07789    A member function template shall not be virtual.  */
07790       if (PROCESSING_REAL_TEMPLATE_DECL_P ())
07791   error ("templates may not be %<virtual%>");
07792       else if (decl_specs)
07793   ++decl_specs->specs[(int) ds_virtual];
07794       break;
07795 
07796     case RID_EXPLICIT:
07797       if (decl_specs)
07798   ++decl_specs->specs[(int) ds_explicit];
07799       break;
07800 
07801     default:
07802       return NULL_TREE;
07803     }
07804 
07805   /* Consume the token.  */
07806   return cp_lexer_consume_token (parser->lexer)->u.value;
07807 }
07808 
07809 /* Parse a linkage-specification.
07810 
07811    linkage-specification:
07812      extern string-literal { declaration-seq [opt] }
07813      extern string-literal declaration  */
07814 
07815 static void
07816 cp_parser_linkage_specification (cp_parser* parser)
07817 {
07818   tree linkage;
07819 
07820   /* Look for the `extern' keyword.  */
07821   cp_parser_require_keyword (parser, RID_EXTERN, "`extern'");
07822 
07823   /* Look for the string-literal.  */
07824   linkage = cp_parser_string_literal (parser, false, false);
07825 
07826   /* Transform the literal into an identifier.  If the literal is a
07827      wide-character string, or contains embedded NULs, then we can't
07828      handle it as the user wants.  */
07829   if (strlen (TREE_STRING_POINTER (linkage))
07830       != (size_t) (TREE_STRING_LENGTH (linkage) - 1))
07831     {
07832       cp_parser_error (parser, "invalid linkage-specification");
07833       /* Assume C++ linkage.  */
07834       linkage = lang_name_cplusplus;
07835     }
07836   else
07837     linkage = get_identifier (TREE_STRING_POINTER (linkage));
07838 
07839   /* We're now using the new linkage.  */
07840   push_lang_context (linkage);
07841 
07842   /* If the next token is a `{', then we're using the first
07843      production.  */
07844   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
07845     {
07846       /* Consume the `{' token.  */
07847       cp_lexer_consume_token (parser->lexer);
07848       /* Parse the declarations.  */
07849       cp_parser_declaration_seq_opt (parser);
07850       /* Look for the closing `}'.  */
07851       cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
07852     }
07853   /* Otherwise, there's just one declaration.  */
07854   else
07855     {
07856       bool saved_in_unbraced_linkage_specification_p;
07857 
07858       saved_in_unbraced_linkage_specification_p
07859   = parser->in_unbraced_linkage_specification_p;
07860       parser->in_unbraced_linkage_specification_p = true;
07861       cp_parser_declaration (parser);
07862       parser->in_unbraced_linkage_specification_p
07863   = saved_in_unbraced_linkage_specification_p;
07864     }
07865 
07866   /* We're done with the linkage-specification.  */
07867   pop_lang_context ();
07868 }
07869 
07870 /* Special member functions [gram.special] */
07871 
07872 /* Parse a conversion-function-id.
07873 
07874    conversion-function-id:
07875      operator conversion-type-id
07876 
07877    Returns an IDENTIFIER_NODE representing the operator.  */
07878 
07879 static tree
07880 cp_parser_conversion_function_id (cp_parser* parser)
07881 {
07882   tree type;
07883   tree saved_scope;
07884   tree saved_qualifying_scope;
07885   tree saved_object_scope;
07886   tree pushed_scope = NULL_TREE;
07887 
07888   /* Look for the `operator' token.  */
07889   if (!cp_parser_require_keyword (parser, RID_OPERATOR, "`operator'"))
07890     return error_mark_node;
07891   /* When we parse the conversion-type-id, the current scope will be
07892      reset.  However, we need that information in able to look up the
07893      conversion function later, so we save it here.  */
07894   saved_scope = parser->scope;
07895   saved_qualifying_scope = parser->qualifying_scope;
07896   saved_object_scope = parser->object_scope;
07897   /* We must enter the scope of the class so that the names of
07898      entities declared within the class are available in the
07899      conversion-type-id.  For example, consider:
07900 
07901        struct S {
07902    typedef int I;
07903    operator I();
07904        };
07905 
07906        S::operator I() { ... }
07907 
07908      In order to see that `I' is a type-name in the definition, we
07909      must be in the scope of `S'.  */
07910   if (saved_scope)
07911     pushed_scope = push_scope (saved_scope);
07912   /* Parse the conversion-type-id.  */
07913   type = cp_parser_conversion_type_id (parser);
07914   /* Leave the scope of the class, if any.  */
07915   if (pushed_scope)
07916     pop_scope (pushed_scope);
07917   /* Restore the saved scope.  */
07918   parser->scope = saved_scope;
07919   parser->qualifying_scope = saved_qualifying_scope;
07920   parser->object_scope = saved_object_scope;
07921   /* If the TYPE is invalid, indicate failure.  */
07922   if (type == error_mark_node)
07923     return error_mark_node;
07924   return mangle_conv_op_name_for_type (type);
07925 }
07926 
07927 /* Parse a conversion-type-id:
07928 
07929    conversion-type-id:
07930      type-specifier-seq conversion-declarator [opt]
07931 
07932    Returns the TYPE specified.  */
07933 
07934 static tree
07935 cp_parser_conversion_type_id (cp_parser* parser)
07936 {
07937   tree attributes;
07938   cp_decl_specifier_seq type_specifiers;
07939   cp_declarator *declarator;
07940   tree type_specified;
07941 
07942   /* Parse the attributes.  */
07943   attributes = cp_parser_attributes_opt (parser);
07944   /* Parse the type-specifiers.  */
07945   cp_parser_type_specifier_seq (parser, /*is_condition=*/false,
07946         &type_specifiers);
07947   /* If that didn't work, stop.  */
07948   if (type_specifiers.type == error_mark_node)
07949     return error_mark_node;
07950   /* Parse the conversion-declarator.  */
07951   declarator = cp_parser_conversion_declarator_opt (parser);
07952 
07953   type_specified =  grokdeclarator (declarator, &type_specifiers, TYPENAME,
07954             /*initialized=*/0, &attributes);
07955   if (attributes)
07956     cplus_decl_attributes (&type_specified, attributes, /*flags=*/0);
07957   return type_specified;
07958 }
07959 
07960 /* Parse an (optional) conversion-declarator.
07961 
07962    conversion-declarator:
07963      ptr-operator conversion-declarator [opt]
07964 
07965    */
07966 
07967 static cp_declarator *
07968 cp_parser_conversion_declarator_opt (cp_parser* parser)
07969 {
07970   enum tree_code code;
07971   tree class_type;
07972   cp_cv_quals cv_quals;
07973 
07974   /* We don't know if there's a ptr-operator next, or not.  */
07975   cp_parser_parse_tentatively (parser);
07976   /* Try the ptr-operator.  */
07977   code = cp_parser_ptr_operator (parser, &class_type, &cv_quals);
07978   /* If it worked, look for more conversion-declarators.  */
07979   if (cp_parser_parse_definitely (parser))
07980     {
07981       cp_declarator *declarator;
07982 
07983       /* Parse another optional declarator.  */
07984       declarator = cp_parser_conversion_declarator_opt (parser);
07985 
07986       /* Create the representation of the declarator.  */
07987       if (class_type)
07988   declarator = make_ptrmem_declarator (cv_quals, class_type,
07989                declarator);
07990       else if (code == INDIRECT_REF)
07991   declarator = make_pointer_declarator (cv_quals, declarator);
07992       else
07993   declarator = make_reference_declarator (cv_quals, declarator);
07994 
07995       return declarator;
07996    }
07997 
07998   return NULL;
07999 }
08000 
08001 /* Parse an (optional) ctor-initializer.
08002 
08003    ctor-initializer:
08004      : mem-initializer-list
08005 
08006    Returns TRUE iff the ctor-initializer was actually present.  */
08007 
08008 static bool
08009 cp_parser_ctor_initializer_opt (cp_parser* parser)
08010 {
08011   /* If the next token is not a `:', then there is no
08012      ctor-initializer.  */
08013   if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
08014     {
08015       /* Do default initialization of any bases and members.  */
08016       if (DECL_CONSTRUCTOR_P (current_function_decl))
08017   finish_mem_initializers (NULL_TREE);
08018 
08019       return false;
08020     }
08021 
08022   /* Consume the `:' token.  */
08023   cp_lexer_consume_token (parser->lexer);
08024   /* And the mem-initializer-list.  */
08025   cp_parser_mem_initializer_list (parser);
08026 
08027   return true;
08028 }
08029 
08030 /* Parse a mem-initializer-list.
08031 
08032    mem-initializer-list:
08033      mem-initializer
08034      mem-initializer , mem-initializer-list  */
08035 
08036 static void
08037 cp_parser_mem_initializer_list (cp_parser* parser)
08038 {
08039   tree mem_initializer_list = NULL_TREE;
08040 
08041   /* Let the semantic analysis code know that we are starting the
08042      mem-initializer-list.  */
08043   if (!DECL_CONSTRUCTOR_P (current_function_decl))
08044     error ("only constructors take base initializers");
08045 
08046   /* Loop through the list.  */
08047   while (true)
08048     {
08049       tree mem_initializer;
08050 
08051       /* Parse the mem-initializer.  */
08052       mem_initializer = cp_parser_mem_initializer (parser);
08053       /* Add it to the list, unless it was erroneous.  */
08054       if (mem_initializer != error_mark_node)
08055   {
08056     TREE_CHAIN (mem_initializer) = mem_initializer_list;
08057     mem_initializer_list = mem_initializer;
08058   }
08059       /* If the next token is not a `,', we're done.  */
08060       if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
08061   break;
08062       /* Consume the `,' token.  */
08063       cp_lexer_consume_token (parser->lexer);
08064     }
08065 
08066   /* Perform semantic analysis.  */
08067   if (DECL_CONSTRUCTOR_P (current_function_decl))
08068     finish_mem_initializers (mem_initializer_list);
08069 }
08070 
08071 /* Parse a mem-initializer.
08072 
08073    mem-initializer:
08074      mem-initializer-id ( expression-list [opt] )
08075 
08076    GNU extension:
08077 
08078    mem-initializer:
08079      ( expression-list [opt] )
08080 
08081    Returns a TREE_LIST.  The TREE_PURPOSE is the TYPE (for a base
08082    class) or FIELD_DECL (for a non-static data member) to initialize;
08083    the TREE_VALUE is the expression-list.  An empty initialization
08084    list is represented by void_list_node.  */
08085 
08086 static tree
08087 cp_parser_mem_initializer (cp_parser* parser)
08088 {
08089   tree mem_initializer_id;
08090   tree expression_list;
08091   tree member;
08092 
08093   /* Find out what is being initialized.  */
08094   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
08095     {
08096       pedwarn ("anachronistic old-style base class initializer");
08097       mem_initializer_id = NULL_TREE;
08098     }
08099   else
08100     mem_initializer_id = cp_parser_mem_initializer_id (parser);
08101   member = expand_member_init (mem_initializer_id);
08102   if (member && !DECL_P (member))
08103     in_base_initializer = 1;
08104 
08105   expression_list
08106     = cp_parser_parenthesized_expression_list (parser, false,
08107                  /*cast_p=*/false,
08108                  /*non_constant_p=*/NULL);
08109   if (expression_list == error_mark_node)
08110     return error_mark_node;
08111   if (!expression_list)
08112     expression_list = void_type_node;
08113 
08114   in_base_initializer = 0;
08115 
08116   return member ? build_tree_list (member, expression_list) : error_mark_node;
08117 }
08118 
08119 /* Parse a mem-initializer-id.
08120 
08121    mem-initializer-id:
08122      :: [opt] nested-name-specifier [opt] class-name
08123      identifier
08124 
08125    Returns a TYPE indicating the class to be initializer for the first
08126    production.  Returns an IDENTIFIER_NODE indicating the data member
08127    to be initialized for the second production.  */
08128 
08129 static tree
08130 cp_parser_mem_initializer_id (cp_parser* parser)
08131 {
08132   bool global_scope_p;
08133   bool nested_name_specifier_p;
08134   bool template_p = false;
08135   tree id;
08136 
08137   /* `typename' is not allowed in this context ([temp.res]).  */
08138   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME))
08139     {
08140       error ("keyword %<typename%> not allowed in this context (a qualified "
08141        "member initializer is implicitly a type)");
08142       cp_lexer_consume_token (parser->lexer);
08143     }
08144   /* Look for the optional `::' operator.  */
08145   global_scope_p
08146     = (cp_parser_global_scope_opt (parser,
08147            /*current_scope_valid_p=*/false)
08148        != NULL_TREE);
08149   /* Look for the optional nested-name-specifier.  The simplest way to
08150      implement:
08151 
08152        [temp.res]
08153 
08154        The keyword `typename' is not permitted in a base-specifier or
08155        mem-initializer; in these contexts a qualified name that
08156        depends on a template-parameter is implicitly assumed to be a
08157        type name.
08158 
08159      is to assume that we have seen the `typename' keyword at this
08160      point.  */
08161   nested_name_specifier_p
08162     = (cp_parser_nested_name_specifier_opt (parser,
08163               /*typename_keyword_p=*/true,
08164               /*check_dependency_p=*/true,
08165               /*type_p=*/true,
08166               /*is_declaration=*/true)
08167        != NULL_TREE);
08168   if (nested_name_specifier_p)
08169     template_p = cp_parser_optional_template_keyword (parser);
08170   /* If there is a `::' operator or a nested-name-specifier, then we
08171      are definitely looking for a class-name.  */
08172   if (global_scope_p || nested_name_specifier_p)
08173     return cp_parser_class_name (parser,
08174          /*typename_keyword_p=*/true,
08175          /*template_keyword_p=*/template_p,
08176          none_type,
08177          /*check_dependency_p=*/true,
08178          /*class_head_p=*/false,
08179          /*is_declaration=*/true);
08180   /* Otherwise, we could also be looking for an ordinary identifier.  */
08181   cp_parser_parse_tentatively (parser);
08182   /* Try a class-name.  */
08183   id = cp_parser_class_name (parser,
08184            /*typename_keyword_p=*/true,
08185            /*template_keyword_p=*/false,
08186            none_type,
08187            /*check_dependency_p=*/true,
08188            /*class_head_p=*/false,
08189            /*is_declaration=*/true);
08190   /* If we found one, we're done.  */
08191   if (cp_parser_parse_definitely (parser))
08192     return id;
08193   /* Otherwise, look for an ordinary identifier.  */
08194   return cp_parser_identifier (parser);
08195 }
08196 
08197 /* Overloading [gram.over] */
08198 
08199 /* Parse an operator-function-id.
08200 
08201    operator-function-id:
08202      operator operator
08203 
08204    Returns an IDENTIFIER_NODE for the operator which is a
08205    human-readable spelling of the identifier, e.g., `operator +'.  */
08206 
08207 static tree
08208 cp_parser_operator_function_id (cp_parser* parser)
08209 {
08210   /* Look for the `operator' keyword.  */
08211   if (!cp_parser_require_keyword (parser, RID_OPERATOR, "`operator'"))
08212     return error_mark_node;
08213   /* And then the name of the operator itself.  */
08214   return cp_parser_operator (parser);
08215 }
08216 
08217 /* Parse an operator.
08218 
08219    operator:
08220      new delete new[] delete[] + - * / % ^ & | ~ ! = < >
08221      += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= &&
08222      || ++ -- , ->* -> () []
08223 
08224    GNU Extensions:
08225 
08226    operator:
08227      <? >? <?= >?=
08228 
08229    Returns an IDENTIFIER_NODE for the operator which is a
08230    human-readable spelling of the identifier, e.g., `operator +'.  */
08231 
08232 static tree
08233 cp_parser_operator (cp_parser* parser)
08234 {
08235   tree id = NULL_TREE;
08236   cp_token *token;
08237 
08238   /* Peek at the next token.  */
08239   token = cp_lexer_peek_token (parser->lexer);
08240   /* Figure out which operator we have.  */
08241   switch (token->type)
08242     {
08243     case CPP_KEYWORD:
08244       {
08245   enum tree_code op;
08246 
08247   /* The keyword should be either `new' or `delete'.  */
08248   if (token->keyword == RID_NEW)
08249     op = NEW_EXPR;
08250   else if (token->keyword == RID_DELETE)
08251     op = DELETE_EXPR;
08252   else
08253     break;
08254 
08255   /* Consume the `new' or `delete' token.  */
08256   cp_lexer_consume_token (parser->lexer);
08257 
08258   /* Peek at the next token.  */
08259   token = cp_lexer_peek_token (parser->lexer);
08260   /* If it's a `[' token then this is the array variant of the
08261      operator.  */
08262   if (token->type == CPP_OPEN_SQUARE)
08263     {
08264       /* Consume the `[' token.  */
08265       cp_lexer_consume_token (parser->lexer);
08266       /* Look for the `]' token.  */
08267       cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
08268       id = ansi_opname (op == NEW_EXPR
08269             ? VEC_NEW_EXPR : VEC_DELETE_EXPR);
08270     }
08271   /* Otherwise, we have the non-array variant.  */
08272   else
08273     id = ansi_opname (op);
08274 
08275   return id;
08276       }
08277 
08278     case CPP_PLUS:
08279       id = ansi_opname (PLUS_EXPR);
08280       break;
08281 
08282     case CPP_MINUS:
08283       id = ansi_opname (MINUS_EXPR);
08284       break;
08285 
08286     case CPP_MULT:
08287       id = ansi_opname (MULT_EXPR);
08288       break;
08289 
08290     case CPP_DIV:
08291       id = ansi_opname (TRUNC_DIV_EXPR);
08292       break;
08293 
08294     case CPP_MOD:
08295       id = ansi_opname (TRUNC_MOD_EXPR);
08296       break;
08297 
08298     case CPP_XOR:
08299       id = ansi_opname (BIT_XOR_EXPR);
08300       break;
08301 
08302     case CPP_AND:
08303       id = ansi_opname (BIT_AND_EXPR);
08304       break;
08305 
08306     case CPP_OR:
08307       id = ansi_opname (BIT_IOR_EXPR);
08308       break;
08309 
08310     case CPP_COMPL:
08311       id = ansi_opname (BIT_NOT_EXPR);
08312       break;
08313 
08314     case CPP_NOT:
08315       id = ansi_opname (TRUTH_NOT_EXPR);
08316       break;
08317 
08318     case CPP_EQ:
08319       id = ansi_assopname (NOP_EXPR);
08320       break;
08321 
08322     case CPP_LESS:
08323       id = ansi_opname (LT_EXPR);
08324       break;
08325 
08326     case CPP_GREATER:
08327       id = ansi_opname (GT_EXPR);
08328       break;
08329 
08330     case CPP_PLUS_EQ:
08331       id = ansi_assopname (PLUS_EXPR);
08332       break;
08333 
08334     case CPP_MINUS_EQ:
08335       id = ansi_assopname (MINUS_EXPR);
08336       break;
08337 
08338     case CPP_MULT_EQ:
08339       id = ansi_assopname (MULT_EXPR);
08340       break;
08341 
08342     case CPP_DIV_EQ:
08343       id = ansi_assopname (TRUNC_DIV_EXPR);
08344       break;
08345 
08346     case CPP_MOD_EQ:
08347       id = ansi_assopname (TRUNC_MOD_EXPR);
08348       break;
08349 
08350     case CPP_XOR_EQ:
08351       id = ansi_assopname (BIT_XOR_EXPR);
08352       break;
08353 
08354     case CPP_AND_EQ:
08355       id = ansi_assopname (BIT_AND_EXPR);
08356       break;
08357 
08358     case CPP_OR_EQ:
08359       id = ansi_assopname (BIT_IOR_EXPR);
08360       break;
08361 
08362     case CPP_LSHIFT:
08363       id = ansi_opname (LSHIFT_EXPR);
08364       break;
08365 
08366     case CPP_RSHIFT:
08367       id = ansi_opname (RSHIFT_EXPR);
08368       break;
08369 
08370     case CPP_LSHIFT_EQ:
08371       id = ansi_assopname (LSHIFT_EXPR);
08372       break;
08373 
08374     case CPP_RSHIFT_EQ:
08375       id = ansi_assopname (RSHIFT_EXPR);
08376       break;
08377 
08378     case CPP_EQ_EQ:
08379       id = ansi_opname (EQ_EXPR);
08380       break;
08381 
08382     case CPP_NOT_EQ:
08383       id = ansi_opname (NE_EXPR);
08384       break;
08385 
08386     case CPP_LESS_EQ:
08387       id = ansi_opname (LE_EXPR);
08388       break;
08389 
08390     case CPP_GREATER_EQ:
08391       id = ansi_opname (GE_EXPR);
08392       break;
08393 
08394     case CPP_AND_AND:
08395       id = ansi_opname (TRUTH_ANDIF_EXPR);
08396       break;
08397 
08398     case CPP_OR_OR:
08399       id = ansi_opname (TRUTH_ORIF_EXPR);
08400       break;
08401 
08402     case CPP_PLUS_PLUS:
08403       id = ansi_opname (POSTINCREMENT_EXPR);
08404       break;
08405 
08406     case CPP_MINUS_MINUS:
08407       id = ansi_opname (PREDECREMENT_EXPR);
08408       break;
08409 
08410     case CPP_COMMA:
08411       id = ansi_opname (COMPOUND_EXPR);
08412       break;
08413 
08414     case CPP_DEREF_STAR:
08415       id = ansi_opname (MEMBER_REF);
08416       break;
08417 
08418     case CPP_DEREF:
08419       id = ansi_opname (COMPONENT_REF);
08420       break;
08421 
08422     case CPP_OPEN_PAREN:
08423       /* Consume the `('.  */
08424       cp_lexer_consume_token (parser->lexer);
08425       /* Look for the matching `)'.  */
08426       cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
08427       return ansi_opname (CALL_EXPR);
08428 
08429     case CPP_OPEN_SQUARE:
08430       /* Consume the `['.  */
08431       cp_lexer_consume_token (parser->lexer);
08432       /* Look for the matching `]'.  */
08433       cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
08434       return ansi_opname (ARRAY_REF);
08435 
08436     default:
08437       /* Anything else is an error.  */
08438       break;
08439     }
08440 
08441   /* If we have selected an identifier, we need to consume the
08442      operator token.  */
08443   if (id)
08444     cp_lexer_consume_token (parser->lexer);
08445   /* Otherwise, no valid operator name was present.  */
08446   else
08447     {
08448       cp_parser_error (parser, "expected operator");
08449       id = error_mark_node;
08450     }
08451 
08452   return id;
08453 }
08454 
08455 /* Parse a template-declaration.
08456 
08457    template-declaration:
08458      export [opt] template < template-parameter-list > declaration
08459 
08460    If MEMBER_P is TRUE, this template-declaration occurs within a
08461    class-specifier.
08462 
08463    The grammar rule given by the standard isn't correct.  What
08464    is really meant is:
08465 
08466    template-declaration:
08467      export [opt] template-parameter-list-seq
08468        decl-specifier-seq [opt] init-declarator [opt] ;
08469      export [opt] template-parameter-list-seq
08470        function-definition
08471 
08472    template-parameter-list-seq:
08473      template-parameter-list-seq [opt]
08474      template < template-parameter-list >  */
08475 
08476 static void
08477 cp_parser_template_declaration (cp_parser* parser, bool member_p)
08478 {
08479   /* Check for `export'.  */
08480   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_EXPORT))
08481     {
08482       /* Consume the `export' token.  */
08483       cp_lexer_consume_token (parser->lexer);
08484       /* Warn that we do not support `export'.  */
08485       warning (0, "keyword %<export%> not implemented, and will be ignored");
08486     }
08487 
08488   cp_parser_template_declaration_after_export (parser, member_p);
08489 }
08490 
08491 /* Parse a template-parameter-list.
08492 
08493    template-parameter-list:
08494      template-parameter
08495      template-parameter-list , template-parameter
08496 
08497    Returns a TREE_LIST.  Each node represents a template parameter.
08498    The nodes are connected via their TREE_CHAINs.  */
08499 
08500 static tree
08501 cp_parser_template_parameter_list (cp_parser* parser)
08502 {
08503   tree parameter_list = NULL_TREE;
08504 
08505   begin_template_parm_list ();
08506   while (true)
08507     {
08508       tree parameter;
08509       cp_token *token;
08510       bool is_non_type;
08511 
08512       /* Parse the template-parameter.  */
08513       parameter = cp_parser_template_parameter (parser, &is_non_type);
08514       /* Add it to the list.  */
08515       if (parameter != error_mark_node)
08516   parameter_list = process_template_parm (parameter_list,
08517             parameter,
08518             is_non_type);
08519       else
08520        {
08521          tree err_parm = build_tree_list (parameter, parameter);
08522          TREE_VALUE (err_parm) = error_mark_node;
08523          parameter_list = chainon (parameter_list, err_parm);
08524        }
08525 
08526       /* Peek at the next token.  */
08527       token = cp_lexer_peek_token (parser->lexer);
08528       /* If it's not a `,', we're done.  */
08529       if (token->type != CPP_COMMA)
08530   break;
08531       /* Otherwise, consume the `,' token.  */
08532       cp_lexer_consume_token (parser->lexer);
08533     }
08534 
08535   return end_template_parm_list (parameter_list);
08536 }
08537 
08538 /* Parse a template-parameter.
08539 
08540    template-parameter:
08541      type-parameter
08542      parameter-declaration
08543 
08544    If all goes well, returns a TREE_LIST.  The TREE_VALUE represents
08545    the parameter.  The TREE_PURPOSE is the default value, if any.
08546    Returns ERROR_MARK_NODE on failure.  *IS_NON_TYPE is set to true
08547    iff this parameter is a non-type parameter.  */
08548 
08549 static tree
08550 cp_parser_template_parameter (cp_parser* parser, bool *is_non_type)
08551 {
08552   cp_token *token;
08553   cp_parameter_declarator *parameter_declarator;
08554   tree parm;
08555 
08556   /* Assume it is a type parameter or a template parameter.  */
08557   *is_non_type = false;
08558   /* Peek at the next token.  */
08559   token = cp_lexer_peek_token (parser->lexer);
08560   /* If it is `class' or `template', we have a type-parameter.  */
08561   if (token->keyword == RID_TEMPLATE)
08562     return cp_parser_type_parameter (parser);
08563   /* If it is `class' or `typename' we do not know yet whether it is a
08564      type parameter or a non-type parameter.  Consider:
08565 
08566        template <typename T, typename T::X X> ...
08567 
08568      or:
08569 
08570        template <class C, class D*> ...
08571 
08572      Here, the first parameter is a type parameter, and the second is
08573      a non-type parameter.  We can tell by looking at the token after
08574      the identifier -- if it is a `,', `=', or `>' then we have a type
08575      parameter.  */
08576   if (token->keyword == RID_TYPENAME || token->keyword == RID_CLASS)
08577     {
08578       /* Peek at the token after `class' or `typename'.  */
08579       token = cp_lexer_peek_nth_token (parser->lexer, 2);
08580       /* If it's an identifier, skip it.  */
08581       if (token->type == CPP_NAME)
08582   token = cp_lexer_peek_nth_token (parser->lexer, 3);
08583       /* Now, see if the token looks like the end of a template
08584    parameter.  */
08585       if (token->type == CPP_COMMA
08586     || token->type == CPP_EQ
08587     || token->type == CPP_GREATER)
08588   return cp_parser_type_parameter (parser);
08589     }
08590 
08591   /* Otherwise, it is a non-type parameter.
08592 
08593      [temp.param]
08594 
08595      When parsing a default template-argument for a non-type
08596      template-parameter, the first non-nested `>' is taken as the end
08597      of the template parameter-list rather than a greater-than
08598      operator.  */
08599   *is_non_type = true;
08600   parameter_declarator
08601      = cp_parser_parameter_declaration (parser, /*template_parm_p=*/true,
08602           /*parenthesized_p=*/NULL);
08603   parm = grokdeclarator (parameter_declarator->declarator,
08604        &parameter_declarator->decl_specifiers,
08605        PARM, /*initialized=*/0,
08606        /*attrlist=*/NULL);
08607   if (parm == error_mark_node)
08608     return error_mark_node;
08609   return build_tree_list (parameter_declarator->default_argument, parm);
08610 }
08611 
08612 /* Parse a type-parameter.
08613 
08614    type-parameter:
08615      class identifier [opt]
08616      class identifier [opt] = type-id
08617      typename identifier [opt]
08618      typename identifier [opt] = type-id
08619      template < template-parameter-list > class identifier [opt]
08620      template < template-parameter-list > class identifier [opt]
08621        = id-expression
08622 
08623    Returns a TREE_LIST.  The TREE_VALUE is itself a TREE_LIST.  The
08624    TREE_PURPOSE is the default-argument, if any.  The TREE_VALUE is
08625    the declaration of the parameter.  */
08626 
08627 static tree
08628 cp_parser_type_parameter (cp_parser* parser)
08629 {
08630   cp_token *token;
08631   tree parameter;
08632 
08633   /* Look for a keyword to tell us what kind of parameter this is.  */
08634   token = cp_parser_require (parser, CPP_KEYWORD,
08635            "`class', `typename', or `template'");
08636   if (!token)
08637     return error_mark_node;
08638 
08639   switch (token->keyword)
08640     {
08641     case RID_CLASS:
08642     case RID_TYPENAME:
08643       {
08644   tree identifier;
08645   tree default_argument;
08646 
08647   /* If the next token is an identifier, then it names the
08648      parameter.  */
08649   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
08650     identifier = cp_parser_identifier (parser);
08651   else
08652     identifier = NULL_TREE;
08653 
08654   /* Create the parameter.  */
08655   parameter = finish_template_type_parm (class_type_node, identifier);
08656 
08657   /* If the next token is an `=', we have a default argument.  */
08658   if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
08659     {
08660       /* Consume the `=' token.  */
08661       cp_lexer_consume_token (parser->lexer);
08662       /* Parse the default-argument.  */
08663       push_deferring_access_checks (dk_no_deferred);
08664       default_argument = cp_parser_type_id (parser);
08665       pop_deferring_access_checks ();
08666     }
08667   else
08668     default_argument = NULL_TREE;
08669 
08670   /* Create the combined representation of the parameter and the
08671      default argument.  */
08672   parameter = build_tree_list (default_argument, parameter);
08673       }
08674       break;
08675 
08676     case RID_TEMPLATE:
08677       {
08678   tree parameter_list;
08679   tree identifier;
08680   tree default_argument;
08681 
08682   /* Look for the `<'.  */
08683   cp_parser_require (parser, CPP_LESS, "`<'");
08684   /* Parse the template-parameter-list.  */
08685   parameter_list = cp_parser_template_parameter_list (parser);
08686   /* Look for the `>'.  */
08687   cp_parser_require (parser, CPP_GREATER, "`>'");
08688   /* Look for the `class' keyword.  */
08689   cp_parser_require_keyword (parser, RID_CLASS, "`class'");
08690   /* If the next token is an `=', then there is a
08691      default-argument.  If the next token is a `>', we are at
08692      the end of the parameter-list.  If the next token is a `,',
08693      then we are at the end of this parameter.  */
08694   if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ)
08695       && cp_lexer_next_token_is_not (parser->lexer, CPP_GREATER)
08696       && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
08697     {
08698       identifier = cp_parser_identifier (parser);
08699       /* Treat invalid names as if the parameter were nameless.  */
08700       if (identifier == error_mark_node)
08701         identifier = NULL_TREE;
08702     }
08703   else
08704     identifier = NULL_TREE;
08705 
08706   /* Create the template parameter.  */
08707   parameter = finish_template_template_parm (class_type_node,
08708                identifier);
08709 
08710   /* If the next token is an `=', then there is a
08711      default-argument.  */
08712   if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
08713     {
08714       bool is_template;
08715 
08716       /* Consume the `='.  */
08717       cp_lexer_consume_token (parser->lexer);
08718       /* Parse the id-expression.  */
08719       push_deferring_access_checks (dk_no_deferred);
08720       default_argument
08721         = cp_parser_id_expression (parser,
08722            /*template_keyword_p=*/false,
08723            /*check_dependency_p=*/true,
08724            /*template_p=*/&is_template,
08725            /*declarator_p=*/false,
08726            /*optional_p=*/false);
08727       if (TREE_CODE (default_argument) == TYPE_DECL)
08728         /* If the id-expression was a template-id that refers to
08729      a template-class, we already have the declaration here,
08730      so no further lookup is needed.  */
08731      ;
08732       else
08733         /* Look up the name.  */
08734         default_argument
08735     = cp_parser_lookup_name (parser, default_argument,
08736            none_type,
08737            /*is_template=*/is_template,
08738            /*is_namespace=*/false,
08739            /*check_dependency=*/true,
08740