PageRenderTime 62ms CodeModel.GetById 17ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 2ms

/osprey/kgccfe/gnu/cp/parse.y

https://bitbucket.org/osunix/open64
Happy | 4237 lines | 3855 code | 382 blank | 0 comment | 0 complexity | 8e59930d517f99696d21637ecc240a54 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/* YACC parser for C++ syntax.
   2   Copyright (C) 1988, 1989, 1993, 1994, 1995, 1996, 1997, 1998,
   3   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
   4   Hacked by Michael Tiemann (tiemann@cygnus.com)
   5
   6This file is part of GNU CC.
   7
   8GNU CC is free software; you can redistribute it and/or modify
   9it under the terms of the GNU General Public License as published by
  10the Free Software Foundation; either version 2, or (at your option)
  11any later version.
  12
  13GNU CC is distributed in the hope that it will be useful,
  14but WITHOUT ANY WARRANTY; without even the implied warranty of
  15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16GNU General Public License for more details.
  17
  18You should have received a copy of the GNU General Public License
  19along with GNU CC; see the file COPYING.  If not, write to
  20the Free Software Foundation, 59 Temple Place - Suite 330,
  21Boston, MA 02111-1307, USA.  */
  22
  23
  24/* This grammar is based on the GNU CC grammar.  */
  25
  26/* Note: Bison automatically applies a default action of "$$ = $1" for
  27   all derivations; this is applied before the explicit action, if one
  28   is given.  Keep this in mind when reading the actions.  */
  29
  30%{
  31#include "config.h"
  32
  33#include "system.h"
  34
  35#include "tree.h"
  36#include "input.h"
  37#include "flags.h"
  38#include "cp-tree.h"
  39#include "decl.h"
  40#include "lex.h"
  41#include "c-pragma.h"		/* For YYDEBUG definition.  */
  42#include "output.h"
  43#include "except.h"
  44#include "toplev.h"
  45#include "ggc.h"
  46
  47/* Like YYERROR but do call yyerror.  */
  48#define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  49
  50/* Like the default stack expander, except (1) use realloc when possible,
  51   (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
  52
  53   Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
  54   give malloced_yyvs its proper type.  This is ok since all we need from
  55   it is to be able to free it.  */
  56
  57static short *malloced_yyss;
  58static void *malloced_yyvs;
  59static int class_template_ok_as_expr;
  60
  61#define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ)			\
  62do {									\
  63  size_t newsize;							\
  64  short *newss;								\
  65  YYSTYPE *newvs;							\
  66  newsize = *(YYSSZ) *= 2;						\
  67  if (malloced_yyss)							\
  68    {									\
  69      newss = (short *)							\
  70	really_call_realloc (*(SS), newsize * sizeof (short));		\
  71      newvs = (YYSTYPE *)						\
  72	really_call_realloc (*(VS), newsize * sizeof (YYSTYPE));	\
  73    }									\
  74  else									\
  75    {									\
  76      newss = (short *) really_call_malloc (newsize * sizeof (short));	\
  77      newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
  78      if (newss)							\
  79        memcpy (newss, *(SS), (SSSIZE));				\
  80      if (newvs)							\
  81        memcpy (newvs, *(VS), (VSSIZE));				\
  82    }									\
  83  if (!newss || !newvs)							\
  84    {									\
  85      yyerror (MSG);							\
  86      return 2;								\
  87    }									\
  88  *(SS) = newss;							\
  89  *(VS) = newvs;							\
  90  malloced_yyss = newss;						\
  91  malloced_yyvs = (void *) newvs;					\
  92} while (0)
  93#define OP0(NODE) (TREE_OPERAND (NODE, 0))
  94#define OP1(NODE) (TREE_OPERAND (NODE, 1))
  95
  96/* Contains the statement keyword (if/while/do) to include in an
  97   error message if the user supplies an empty conditional expression.  */
  98static const char *cond_stmt_keyword;
  99
 100/* List of types and structure classes of the current declaration.  */
 101static GTY(()) tree current_declspecs;
 102
 103/* List of prefix attributes in effect.
 104   Prefix attributes are parsed by the reserved_declspecs and declmods
 105   rules.  They create a list that contains *both* declspecs and attrs.  */
 106/* ??? It is not clear yet that all cases where an attribute can now appear in
 107   a declspec list have been updated.  */
 108static GTY(()) tree prefix_attributes;
 109
 110/* When defining an enumeration, this is the type of the enumeration.  */
 111static GTY(()) tree current_enum_type;
 112
 113/* When parsing a conversion operator name, this is the scope of the
 114   operator itself.  */
 115static GTY(()) tree saved_scopes;
 116
 117static tree empty_parms PARAMS ((void));
 118static tree parse_decl0 PARAMS ((tree, tree, tree, tree, int));
 119static tree parse_decl PARAMS ((tree, tree, int));
 120static void parse_end_decl PARAMS ((tree, tree, tree));
 121static tree parse_field0 PARAMS ((tree, tree, tree, tree, tree, tree));
 122static tree parse_field PARAMS ((tree, tree, tree, tree));
 123static tree parse_bitfield0 PARAMS ((tree, tree, tree, tree, tree));
 124static tree parse_bitfield PARAMS ((tree, tree, tree));
 125static tree parse_method PARAMS ((tree, tree, tree));
 126static void frob_specs PARAMS ((tree, tree));
 127static void check_class_key PARAMS ((tree, tree));
 128static tree parse_scoped_id PARAMS ((tree));
 129static tree parse_xref_tag (tree, tree, int);
 130static tree parse_handle_class_head (tree, tree, tree, int, int *);
 131static void parse_decl_instantiation (tree, tree, tree);
 132static int parse_begin_function_definition (tree, tree);
 133static tree parse_finish_call_expr (tree, tree, int);
 134
 135/* Cons up an empty parameter list.  */
 136static inline tree
 137empty_parms ()
 138{
 139  tree parms;
 140
 141#ifndef NO_IMPLICIT_EXTERN_C
 142  if (in_system_header && current_class_type == NULL
 143      && current_lang_name == lang_name_c)
 144    parms = NULL_TREE;
 145  else
 146#endif
 147  parms = void_list_node;
 148  return parms;
 149}
 150
 151/* Record the decl-specifiers, attributes and type lookups from the
 152   decl-specifier-seq in a declaration.  */
 153
 154static void
 155frob_specs (specs_attrs, lookups)
 156     tree specs_attrs, lookups;
 157{
 158  save_type_access_control (lookups);
 159  split_specs_attrs (specs_attrs, &current_declspecs, &prefix_attributes);
 160  if (current_declspecs
 161      && TREE_CODE (current_declspecs) != TREE_LIST)
 162    current_declspecs = build_tree_list (NULL_TREE, current_declspecs);
 163  if (have_extern_spec)
 164    {
 165      /* We have to indicate that there is an "extern", but that it
 166         was part of a language specifier.  For instance,
 167
 168    	    extern "C" typedef int (*Ptr) ();
 169
 170         is well formed.  */
 171      current_declspecs = tree_cons (error_mark_node,
 172				     get_identifier ("extern"),
 173				     current_declspecs);
 174      have_extern_spec = false;
 175    }
 176}
 177
 178static tree
 179parse_decl (declarator, attributes, initialized)
 180     tree declarator, attributes;
 181     int initialized;
 182{
 183  return start_decl (declarator, current_declspecs, initialized,
 184		     attributes, prefix_attributes);
 185}
 186
 187static tree
 188parse_decl0 (declarator, specs_attrs, lookups, attributes, initialized)
 189     tree declarator, specs_attrs, lookups, attributes;
 190     int initialized;
 191{
 192  frob_specs (specs_attrs, lookups);
 193  return parse_decl (declarator, attributes, initialized);
 194}
 195
 196static void
 197parse_end_decl (decl, init, asmspec)
 198     tree decl, init, asmspec;
 199{
 200  /* If decl is NULL_TREE, then this was a variable declaration using
 201     () syntax for the initializer, so we handled it in grokdeclarator.  */
 202  if (decl)
 203    decl_type_access_control (decl);
 204  cp_finish_decl (decl, init, asmspec, init ? LOOKUP_ONLYCONVERTING : 0);
 205}
 206
 207static tree
 208parse_field (declarator, attributes, asmspec, init)
 209     tree declarator, attributes, asmspec, init;
 210{
 211  tree d = grokfield (declarator, current_declspecs, init, asmspec,
 212		      chainon (attributes, prefix_attributes));
 213  decl_type_access_control (d);
 214  return d;
 215}
 216
 217static tree
 218parse_field0 (declarator, specs_attrs, lookups, attributes, asmspec, init)
 219     tree declarator, specs_attrs, lookups, attributes, asmspec, init;
 220{
 221  frob_specs (specs_attrs, lookups);
 222  return parse_field (declarator, attributes, asmspec, init);
 223}
 224
 225static tree
 226parse_bitfield (declarator, attributes, width)
 227     tree declarator, attributes, width;
 228{
 229  tree d = grokbitfield (declarator, current_declspecs, width);
 230  cplus_decl_attributes (&d, chainon (attributes, prefix_attributes), 0);
 231  decl_type_access_control (d);
 232  return d;
 233}
 234
 235static tree
 236parse_bitfield0 (declarator, specs_attrs, lookups, attributes, width)
 237     tree declarator, specs_attrs, lookups, attributes, width;
 238{
 239  frob_specs (specs_attrs, lookups);
 240  return parse_bitfield (declarator, attributes, width);
 241}
 242
 243static tree
 244parse_method (declarator, specs_attrs, lookups)
 245     tree declarator, specs_attrs, lookups;
 246{
 247  tree d;
 248  frob_specs (specs_attrs, lookups);
 249  d = start_method (current_declspecs, declarator, prefix_attributes);
 250  decl_type_access_control (d);
 251  return d;
 252}
 253
 254static void
 255check_class_key (key, aggr)
 256     tree key;
 257     tree aggr;
 258{
 259  if (TREE_CODE (key) == TREE_LIST)
 260    key = TREE_VALUE (key);
 261  if ((key == union_type_node) != (TREE_CODE (aggr) == UNION_TYPE))
 262    pedwarn ("`%s' tag used in naming `%#T'",
 263	     key == union_type_node ? "union"
 264	     : key == record_type_node ? "struct" : "class", aggr);
 265}
 266
 267%}
 268
 269%start program
 270
 271%union { GTY(())
 272  long itype;
 273  tree ttype;
 274  char *strtype;
 275  enum tree_code code;
 276  flagged_type_tree ftype;
 277  struct unparsed_text *pi;
 278}
 279
 280/* All identifiers that are not reserved words
 281   and are not declared typedefs in the current block */
 282%token IDENTIFIER
 283
 284/* All identifiers that are declared typedefs in the current block.
 285   In some contexts, they are treated just like IDENTIFIER,
 286   but they can also serve as typespecs in declarations.  */
 287%token tTYPENAME
 288%token SELFNAME
 289
 290/* A template function.  */
 291%token PFUNCNAME
 292
 293/* Reserved words that specify storage class.
 294   yylval contains an IDENTIFIER_NODE which indicates which one.  */
 295%token SCSPEC
 296
 297/* Reserved words that specify type.
 298   yylval contains an IDENTIFIER_NODE which indicates which one.  */
 299%token TYPESPEC
 300
 301/* Reserved words that qualify type: "const" or "volatile".
 302   yylval contains an IDENTIFIER_NODE which indicates which one.  */
 303%token CV_QUALIFIER
 304
 305/* Character or numeric constants.
 306   yylval is the node for the constant.  */
 307%token CONSTANT
 308
 309/* __func__, __FUNCTION__ or __PRETTY_FUNCTION__.
 310   yylval contains an IDENTIFIER_NODE which indicates which one.  */
 311%token <ttype> VAR_FUNC_NAME
 312
 313/* String constants in raw form.
 314   yylval is a STRING_CST node.  */
 315%token STRING
 316
 317/* "...", used for functions with variable arglists.  */
 318%token ELLIPSIS
 319
 320/* the reserved words */
 321/* SCO include files test "ASM", so use something else.  */
 322%token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
 323%token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
 324%token SIGOF
 325%token ATTRIBUTE EXTENSION LABEL
 326%token REALPART IMAGPART VA_ARG
 327
 328/* the reserved words... C++ extensions */
 329%token <ttype> AGGR
 330%token <ttype> VISSPEC
 331%token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
 332%token NAMESPACE TYPENAME_KEYWORD USING
 333%token LEFT_RIGHT TEMPLATE
 334%token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
 335%token SCOPE EXPORT
 336
 337/* Define the operator tokens and their precedences.
 338   The value is an integer because, if used, it is the tree code
 339   to use in the expression made from the operator.  */
 340
 341%left EMPTY			/* used to resolve s/r with epsilon */
 342
 343%left error
 344
 345/* Add precedence rules to solve dangling else s/r conflict */
 346%nonassoc IF
 347%nonassoc ELSE
 348
 349%left IDENTIFIER PFUNCNAME tTYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD ATTRIBUTE
 350
 351%left '{' ',' ';'
 352
 353%nonassoc THROW
 354%right <code> ':'
 355%right <code> ASSIGN '='
 356%right <code> '?'
 357%left <code> OROR
 358%left <code> ANDAND
 359%left <code> '|'
 360%left <code> '^'
 361%left <code> '&'
 362%left <code> MIN_MAX
 363%left <code> EQCOMPARE
 364%left <code> ARITHCOMPARE '<' '>'
 365%left <code> LSHIFT RSHIFT
 366%left <code> '+' '-'
 367%left <code> '*' '/' '%'
 368%left <code> POINTSAT_STAR DOT_STAR
 369%right <code> UNARY PLUSPLUS MINUSMINUS '~'
 370%left HYPERUNARY
 371%left <ttype> LEFT_RIGHT
 372%left <code> POINTSAT '.' '(' '['
 373
 374%right SCOPE			/* C++ extension */
 375%nonassoc NEW DELETE TRY CATCH
 376
 377%type <code> unop
 378
 379%type <ttype> identifier IDENTIFIER tTYPENAME CONSTANT expr nonnull_exprlist
 380%type <ttype> PFUNCNAME maybe_identifier
 381%type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
 382%type <ttype> expr_no_commas expr_no_comma_rangle
 383%type <ttype> cast_expr unary_expr primary STRING
 384%type <ttype> reserved_declspecs boolean_literal
 385%type <ttype> reserved_typespecquals
 386%type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
 387%type <ttype> init initlist maybeasm maybe_init defarg defarg1
 388%type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
 389%type <ttype> maybe_attribute attributes attribute attribute_list attrib
 390%type <ttype> any_word unoperator
 391
 392%type <itype> save_lineno
 393%type <ttype> simple_stmt simple_if
 394
 395%type <ttype> declarator notype_declarator after_type_declarator
 396%type <ttype> notype_declarator_intern absdcl_intern
 397%type <ttype> after_type_declarator_intern
 398%type <ttype> direct_notype_declarator direct_after_type_declarator
 399%type <itype> components notype_components
 400%type <ttype> component_decl component_decl_1
 401%type <ttype> component_declarator component_declarator0
 402%type <ttype> notype_component_declarator notype_component_declarator0
 403%type <ttype> after_type_component_declarator after_type_component_declarator0
 404%type <ttype> absdcl cv_qualifiers
 405%type <ttype> direct_abstract_declarator conversion_declarator
 406%type <ttype> new_declarator direct_new_declarator
 407%type <ttype> xexpr parmlist parms bad_parm
 408%type <ttype> identifiers_or_typenames
 409%type <ttype> fcast_or_absdcl regcast_or_absdcl
 410%type <ttype> expr_or_declarator expr_or_declarator_intern
 411%type <ttype> complex_notype_declarator
 412%type <ttype> notype_unqualified_id unqualified_id qualified_id
 413%type <ttype> template_id do_id object_template_id notype_template_declarator
 414%type <ttype> overqualified_id notype_qualified_id any_id
 415%type <ttype> complex_direct_notype_declarator functional_cast
 416%type <ttype> complex_parmlist parms_comma
 417%type <ttype> namespace_qualifier namespace_using_decl
 418
 419%type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs
 420%type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
 421%type <ftype> structsp typespecqual_reserved parm named_parm full_parm
 422%type <ftype> declmods
 423
 424%type <itype> extension
 425
 426/* C++ extensions */
 427%token <ttype> PTYPENAME
 428%token <ttype> EXTERN_LANG_STRING ALL
 429%token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
 430%token <pi> PRE_PARSED_FUNCTION_DECL
 431%type <ttype> component_constructor_declarator
 432%type <ttype> fn_def2 return_id constructor_declarator
 433%type <ttype> begin_function_body_
 434%type <ttype> class_head class_head_apparent_template
 435%type <ftype> class_head_decl class_head_defn
 436%type <ttype> base_class_list
 437%type <ttype> base_class_access_list
 438%type <ttype> base_class maybe_base_class_list base_class_1
 439%type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
 440%type <ttype> operator_name
 441%type <ttype> object aggr
 442%type <itype> new delete
 443/* %type <ttype> primary_no_id */
 444%type <ttype> maybe_parmlist
 445%type <ttype> begin_member_init member_init
 446%type <ftype> member_init_list
 447%type <ttype> template_parm_header template_spec_header template_header
 448%type <ttype> template_parm_list template_parm
 449%type <ttype> template_type_parm template_template_parm
 450%type <code>  template_close_bracket
 451%type <ttype> apparent_template_type
 452%type <ttype> template_type template_arg_list template_arg_list_opt
 453%type <ttype> template_arg template_arg_1
 454%type <ttype> condition xcond paren_cond_or_null
 455%type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
 456%type <ttype> complete_type_name notype_identifier nonnested_type
 457%type <ttype> complex_type_name nested_name_specifier_1
 458%type <ttype> new_initializer new_placement
 459%type <ttype> using_decl
 460%type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2
 461%type <ttype> explicit_template_type
 462/* in order to recognize aggr tags as defining and thus shadowing.  */
 463%token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
 464%type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
 465%type <ttype> handler_args
 466%type <ttype> self_template_type finish_template_type_
 467
 468%token NSNAME
 469%type <ttype> NSNAME
 470
 471/* Used in lex.c for parsing pragmas.  */
 472%token END_OF_LINE
 473
 474/* lex.c and pt.c depend on this being the last token.  Define
 475   any new tokens before this one!  */
 476%token END_OF_SAVED_INPUT
 477
 478%{
 479/* Tell yyparse how to print a token's value, if yydebug is set.  */
 480#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
 481extern void yyprint			PARAMS ((FILE *, int, YYSTYPE));
 482%}
 483
 484%%
 485program:
 486	  /* empty */
 487               { finish_translation_unit (); }
 488	| extdefs
 489               { finish_translation_unit (); }
 490	;
 491
 492/* the reason for the strange actions in this rule
 493 is so that notype_initdecls when reached via datadef
 494 can find a valid list of type and sc specs in $0.  */
 495
 496extdefs:
 497		{ $<ttype>$ = NULL_TREE; }
 498	  lang_extdef
 499		{ $<ttype>$ = NULL_TREE; ggc_collect (); }
 500	| extdefs lang_extdef
 501		{ $<ttype>$ = NULL_TREE; ggc_collect (); }
 502	;
 503
 504extdefs_opt:
 505	  extdefs
 506	| /* empty */
 507	;
 508
 509.hush_warning:
 510		{ have_extern_spec = true;
 511		  $<ttype>$ = NULL_TREE; }
 512	;
 513.warning_ok:
 514		{ have_extern_spec = false; }
 515	;
 516
 517extension:
 518	EXTENSION
 519		{ $$ = pedantic;
 520		  pedantic = 0; }
 521	;
 522
 523asm_keyword:
 524	  ASM_KEYWORD
 525	;
 526
 527lang_extdef:
 528		{ if (pending_lang_change) do_pending_lang_change();
 529		  type_lookups = NULL_TREE; }
 530	  extdef
 531		{ if (! toplevel_bindings_p ())
 532		  pop_everything (); }
 533	;
 534
 535extdef:
 536	  fndef eat_saved_input
 537		{ do_pending_inlines (); }
 538	| datadef
 539		{ do_pending_inlines (); }
 540
 541	| EXPORT
 542		{ warning ("keyword `export' not implemented, and will be ignored"); }
 543	  template_def
 544		{ do_pending_inlines (); }
 545	| template_def
 546		{ do_pending_inlines (); }
 547	| asm_keyword '(' STRING ')' ';'
 548		{ assemble_asm ($3); }
 549	| extern_lang_string '{' extdefs_opt '}'
 550		{ pop_lang_context (); }
 551	| extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
 552		{ do_pending_inlines (); pop_lang_context (); }
 553	| extern_lang_string .hush_warning datadef .warning_ok
 554		{ do_pending_inlines (); pop_lang_context (); }
 555	| NAMESPACE identifier '{'
 556		{ push_namespace ($2); }
 557	  extdefs_opt '}'
 558		{ pop_namespace (); }
 559	| NAMESPACE '{'
 560		{ push_namespace (NULL_TREE); }
 561	  extdefs_opt '}'
 562		{ pop_namespace (); }
 563	| namespace_alias
 564	| using_decl ';'
 565		{ do_toplevel_using_decl ($1); }
 566	| using_directive
 567	| extension extdef
 568		{ pedantic = $1; }
 569	;
 570
 571namespace_alias:
 572          NAMESPACE identifier '='
 573                { begin_only_namespace_names (); }
 574          any_id ';'
 575		{
 576		  end_only_namespace_names ();
 577		  if (lastiddecl)
 578		    $5 = lastiddecl;
 579		  do_namespace_alias ($2, $5);
 580		}
 581	;
 582
 583using_decl:
 584	  USING qualified_id
 585		{ $$ = $2; }
 586	| USING global_scope qualified_id
 587		{ $$ = $3; }
 588	| USING global_scope unqualified_id
 589		{ $$ = $3; }
 590	;
 591
 592namespace_using_decl:
 593	  USING namespace_qualifier identifier
 594	        { $$ = build_nt (SCOPE_REF, $2, $3); }
 595	| USING global_scope identifier
 596	        { $$ = build_nt (SCOPE_REF, global_namespace, $3); }
 597	| USING global_scope namespace_qualifier identifier
 598	        { $$ = build_nt (SCOPE_REF, $3, $4); }
 599	;
 600
 601using_directive:
 602	  USING NAMESPACE
 603		{ begin_only_namespace_names (); }
 604	  any_id ';'
 605		{
 606		  end_only_namespace_names ();
 607		  /* If no declaration was found, the using-directive is
 608		     invalid. Since that was not reported, we need the
 609		     identifier for the error message. */
 610		  if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
 611		    $4 = lastiddecl;
 612		  do_using_directive ($4);
 613		}
 614	;
 615
 616namespace_qualifier:
 617	  NSNAME SCOPE
 618		{
 619		  if (TREE_CODE ($$) == IDENTIFIER_NODE)
 620		    $$ = lastiddecl;
 621		  got_scope = $$;
 622		}
 623	| namespace_qualifier NSNAME SCOPE
 624		{
 625		  $$ = $2;
 626		  if (TREE_CODE ($$) == IDENTIFIER_NODE)
 627		    $$ = lastiddecl;
 628		  got_scope = $$;
 629		}
 630        ;
 631
 632any_id:
 633	  unqualified_id
 634	| qualified_id
 635	| global_scope qualified_id
 636		{ $$ = $2; }
 637	| global_scope unqualified_id
 638		{ $$ = $2; }
 639	;
 640
 641extern_lang_string:
 642	EXTERN_LANG_STRING
 643		{ push_lang_context ($1); }
 644	| extern_lang_string EXTERN_LANG_STRING
 645		{ if (current_lang_name != $2)
 646		    error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
 647		  pop_lang_context (); push_lang_context ($2); }
 648	;
 649
 650template_parm_header:
 651	  TEMPLATE '<'
 652		{ begin_template_parm_list (); }
 653	  template_parm_list '>'
 654		{ $$ = end_template_parm_list ($4); }
 655	;
 656
 657template_spec_header:
 658	  TEMPLATE '<' '>'
 659                { begin_specialization();
 660		  $$ = NULL_TREE; }
 661	;
 662
 663template_header:
 664	  template_parm_header
 665	| template_spec_header
 666	;
 667
 668template_parm_list:
 669	  template_parm
 670		{ $$ = process_template_parm (NULL_TREE, $1); }
 671	| template_parm_list ',' template_parm
 672		{ $$ = process_template_parm ($1, $3); }
 673	;
 674
 675maybe_identifier:
 676	  identifier
 677	  	{ $$ = $1; }
 678	|	/* empty */
 679		{ $$ = NULL_TREE; }
 680        ;
 681
 682template_type_parm:
 683	  aggr maybe_identifier
 684                { $$ = finish_template_type_parm ($1, $2); }
 685	| TYPENAME_KEYWORD maybe_identifier
 686                { $$ = finish_template_type_parm (class_type_node, $2); }
 687	;
 688
 689template_template_parm:
 690	  template_parm_header aggr maybe_identifier
 691                { $$ = finish_template_template_parm ($2, $3); }
 692	;
 693
 694template_parm:
 695	/* The following rules introduce a new reduce/reduce
 696	   conflict on the ',' and '>' input tokens: they are valid
 697	   prefixes for a `structsp', which means they could match a
 698	   nameless parameter.  See 14.6, paragraph 3.
 699	   By putting them before the `parm' rule, we get
 700	   their match before considering them nameless parameter
 701	   declarations.  */
 702	  template_type_parm
 703		{ $$ = build_tree_list (NULL_TREE, $1); }
 704	| template_type_parm '=' type_id
 705		{ $$ = build_tree_list (groktypename ($3.t), $1); }
 706	| parm
 707		{ $$ = build_tree_list (NULL_TREE, $1.t); }
 708	| parm '=' expr_no_comma_rangle
 709		{ $$ = build_tree_list ($3, $1.t); }
 710	| template_template_parm
 711		{ $$ = build_tree_list (NULL_TREE, $1); }
 712	| template_template_parm '=' template_arg
 713		{
 714		  $3 = check_template_template_default_arg ($3);
 715		  $$ = build_tree_list ($3, $1);
 716		}
 717	;
 718
 719template_def:
 720	  template_header template_extdef
 721                { finish_template_decl ($1); }
 722	| template_header error  %prec EMPTY
 723                { finish_template_decl ($1); }
 724	;
 725
 726template_extdef:
 727	  fndef eat_saved_input
 728		{ do_pending_inlines (); }
 729	| template_datadef
 730		{ do_pending_inlines (); }
 731	| template_def
 732		{ do_pending_inlines (); }
 733	| extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
 734		{ do_pending_inlines ();
 735		  pop_lang_context (); }
 736	| extern_lang_string .hush_warning template_datadef .warning_ok
 737		{ do_pending_inlines ();
 738		  pop_lang_context (); }
 739	| extension template_extdef
 740		{ pedantic = $1; }
 741	;
 742
 743template_datadef:
 744	  nomods_initdecls ';'
 745	| declmods notype_initdecls ';'
 746		{}
 747	| typed_declspecs initdecls ';'
 748                { note_list_got_semicolon ($1.t); }
 749	| structsp ';'
 750                {
 751		  if ($1.t != error_mark_node)
 752                    {
 753		      maybe_process_partial_specialization ($1.t);
 754		      note_got_semicolon ($1.t);
 755	            }
 756                }
 757	;
 758
 759datadef:
 760	  nomods_initdecls ';'
 761	| declmods notype_initdecls ';'
 762		{}
 763	| typed_declspecs initdecls ';'
 764                { note_list_got_semicolon ($1.t); }
 765        | declmods ';'
 766		{ pedwarn ("empty declaration"); }
 767	| explicit_instantiation ';'
 768	| typed_declspecs ';'
 769		{
 770		  tree t, attrs;
 771		  split_specs_attrs ($1.t, &t, &attrs);
 772		  shadow_tag (t);
 773		  note_list_got_semicolon ($1.t);
 774		}
 775	| error ';'
 776	| error '}'
 777	| error END_OF_SAVED_INPUT
 778		{ end_input (); }
 779	| ';'
 780	| bad_decl
 781	;
 782
 783ctor_initializer_opt:
 784	  nodecls
 785	| base_init
 786	;
 787
 788maybe_return_init:
 789	  /* empty */
 790	| return_init
 791	| return_init ';'
 792	;
 793
 794eat_saved_input:
 795	  /* empty */
 796	| END_OF_SAVED_INPUT
 797	;
 798
 799/* The outermost block of a function really begins before the
 800   mem-initializer-list, so we open one there and suppress the one that
 801   actually corresponds to the curly braces.  */
 802function_body:
 803	  begin_function_body_ ctor_initializer_opt save_lineno '{'
 804		{ $<ttype>$ = begin_compound_stmt (/*has_no_scope=*/1); }
 805	  compstmtend
 806                {
 807		  STMT_LINENO ($<ttype>5) = $3;
 808		  finish_compound_stmt (/*has_no_scope=*/1, $<ttype>5);
 809		  finish_function_body ($1);
 810		}
 811	;
 812
 813fndef:
 814	  fn.def1 maybe_return_init function_body
 815		{ expand_body (finish_function (0)); }
 816	| fn.def1 maybe_return_init function_try_block
 817		{ expand_body (finish_function (0)); }
 818	| fn.def1 maybe_return_init error
 819		{ }
 820	;
 821
 822constructor_declarator:
 823	  nested_name_specifier SELFNAME '('
 824                { $$ = begin_constructor_declarator ($1, $2); }
 825	  parmlist ')' cv_qualifiers exception_specification_opt
 826		{ $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
 827	| nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
 828                { $$ = begin_constructor_declarator ($1, $2);
 829		  $$ = make_call_declarator ($$, empty_parms (), $4, $5);
 830		}
 831	| global_scope nested_name_specifier SELFNAME '('
 832                { $$ = begin_constructor_declarator ($2, $3); }
 833	 parmlist ')' cv_qualifiers exception_specification_opt
 834		{ $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
 835	| global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
 836		{ $$ = begin_constructor_declarator ($2, $3);
 837		  $$ = make_call_declarator ($$, empty_parms (), $5, $6);
 838		}
 839	| nested_name_specifier self_template_type '('
 840                { $$ = begin_constructor_declarator ($1, $2); }
 841	  parmlist ')' cv_qualifiers exception_specification_opt
 842		{ $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
 843	| nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
 844		{ $$ = begin_constructor_declarator ($1, $2);
 845		  $$ = make_call_declarator ($$, empty_parms (), $4, $5);
 846		}
 847	| global_scope nested_name_specifier self_template_type '('
 848                { $$ = begin_constructor_declarator ($2, $3); }
 849	 parmlist ')' cv_qualifiers exception_specification_opt
 850		{ $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
 851	| global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
 852		{ $$ = begin_constructor_declarator ($2, $3);
 853		  $$ = make_call_declarator ($$, empty_parms (), $5, $6);
 854		}
 855	;
 856
 857fn.def1:
 858	  typed_declspecs declarator
 859		{ check_for_new_type ("return type", $1);
 860		  if (!parse_begin_function_definition ($1.t, $2))
 861		    YYERROR1; }
 862	| declmods notype_declarator
 863		{ if (!parse_begin_function_definition ($1.t, $2))
 864		    YYERROR1; }
 865	| notype_declarator
 866		{ if (!parse_begin_function_definition (NULL_TREE, $1))
 867		    YYERROR1; }
 868	| declmods constructor_declarator
 869		{ if (!parse_begin_function_definition ($1.t, $2))
 870		    YYERROR1; }
 871	| constructor_declarator
 872		{ if (!parse_begin_function_definition (NULL_TREE, $1))
 873		    YYERROR1; }
 874	;
 875
 876/* ANSI allows optional parentheses around constructor class names.
 877   See ISO/IEC 14882:1998(E) 12.1.  */
 878
 879component_constructor_declarator:
 880          SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
 881                { $$ = make_call_declarator ($1, $3, $5, $6); }
 882        | '(' SELFNAME ')' '(' parmlist ')' cv_qualifiers
 883                exception_specification_opt
 884                { $$ = make_call_declarator ($2, $5, $7, $8); }
 885        | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
 886                { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
 887        | '(' SELFNAME ')' LEFT_RIGHT cv_qualifiers exception_specification_opt
 888                { $$ = make_call_declarator ($2, empty_parms (), $5, $6); }
 889	| self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
 890		{ $$ = make_call_declarator ($1, $3, $5, $6); }
 891	| self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
 892		{ $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
 893	;
 894
 895/* more C++ complexity.  See component_decl for a comment on the
 896   reduce/reduce conflict introduced by these rules.  */
 897fn_def2:
 898	  declmods component_constructor_declarator
 899		{ $$ = parse_method ($2, $1.t, $1.lookups);
 900		 rest_of_mdef:
 901		  if (! $$)
 902		    YYERROR1;
 903		  if (yychar == YYEMPTY)
 904		    yychar = YYLEX;
 905		  snarf_method ($$); }
 906	| component_constructor_declarator
 907		{ $$ = parse_method ($1, NULL_TREE, NULL_TREE);
 908		  goto rest_of_mdef; }
 909	| typed_declspecs declarator
 910		{ $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
 911	| declmods notype_declarator
 912		{ $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
 913	| notype_declarator
 914		{ $$ = parse_method ($1, NULL_TREE, NULL_TREE);
 915		  goto rest_of_mdef; }
 916	| declmods constructor_declarator
 917		{ $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
 918	| constructor_declarator
 919		{ $$ = parse_method ($1, NULL_TREE, NULL_TREE);
 920		  goto rest_of_mdef; }
 921	;
 922
 923return_id:
 924	  RETURN_KEYWORD IDENTIFIER
 925		{
 926		  $$ = $2;
 927		}
 928	;
 929
 930return_init:
 931	  return_id maybe_init
 932		{ finish_named_return_value ($<ttype>$, $2); }
 933	| return_id '(' nonnull_exprlist ')'
 934		{ finish_named_return_value ($<ttype>$, $3); }
 935	| return_id LEFT_RIGHT
 936		{ finish_named_return_value ($<ttype>$, NULL_TREE); }
 937	;
 938
 939base_init:
 940	  ':' { begin_mem_initializers (); } member_init_list
 941		{
 942		  if ($3.new_type_flag == 0)
 943		    error ("no base or member initializers given following ':'");
 944		  finish_mem_initializers ($3.t);
 945		}
 946	;
 947
 948begin_function_body_:
 949	  /* empty */
 950		{
 951		  $$ = begin_function_body ();
 952		}
 953	;
 954
 955member_init_list:
 956	  /* empty */
 957		{
 958		  $$.new_type_flag = 0;
 959		  $$.t = NULL_TREE;
 960		}
 961	| member_init
 962		{
 963		  $$.new_type_flag = 1;
 964		  $$.t = $1;
 965		}
 966	| member_init_list ',' member_init
 967                {
 968		  if ($3)
 969		    {
 970		      $$.new_type_flag = 1;
 971		      TREE_CHAIN ($3) = $1.t;
 972		      $$.t = $3;
 973		    }
 974		  else
 975		    $$ = $1;
 976		}
 977	| member_init_list error
 978	;
 979
 980begin_member_init:
 981	  /* empty */
 982		{
 983 		  if (current_class_name)
 984		    pedwarn ("anachronistic old style base class initializer");
 985		  $$ = expand_member_init (NULL_TREE);
 986		  in_base_initializer = $$ && !DECL_P ($$);
 987		}
 988	| notype_identifier
 989		{ $$ = expand_member_init ($1);
 990		  in_base_initializer = $$ && !DECL_P ($$); }
 991	| nonnested_type
 992		{ $$ = expand_member_init ($1);
 993		  in_base_initializer = $$ && !DECL_P ($$); }
 994	| typename_sub
 995		{ $$ = expand_member_init ($1);
 996		  in_base_initializer = $$ && !DECL_P ($$); }
 997	;
 998
 999member_init:
1000	  begin_member_init '(' nonnull_exprlist ')'
1001		{ in_base_initializer = 0;
1002		  $$ = $1 ? build_tree_list ($1, $3) : NULL_TREE; }
1003	| begin_member_init LEFT_RIGHT
1004		{ in_base_initializer = 0;
1005		  $$ = $1 ? build_tree_list ($1, void_type_node) : NULL_TREE; }
1006        | error
1007                { in_base_initializer = 0;
1008		  $$ = NULL_TREE; }
1009	;
1010
1011identifier:
1012	  IDENTIFIER
1013	| tTYPENAME
1014	| SELFNAME
1015	| PTYPENAME
1016	| NSNAME
1017	;
1018
1019notype_identifier:
1020	  IDENTIFIER
1021	| PTYPENAME
1022	| NSNAME  %prec EMPTY
1023	;
1024
1025identifier_defn:
1026	  IDENTIFIER_DEFN
1027	| TYPENAME_DEFN
1028	| PTYPENAME_DEFN
1029	;
1030
1031explicit_instantiation:
1032	  TEMPLATE begin_explicit_instantiation typespec ';'
1033		{ do_type_instantiation ($3.t, NULL_TREE, 1);
1034		  yyungetc (';', 1); }
1035          end_explicit_instantiation
1036	| TEMPLATE begin_explicit_instantiation typed_declspecs declarator
1037		{ tree specs = strip_attrs ($3.t);
1038		  parse_decl_instantiation (specs, $4, NULL_TREE); }
1039          end_explicit_instantiation
1040	| TEMPLATE begin_explicit_instantiation notype_declarator
1041		{ parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
1042          end_explicit_instantiation
1043	| TEMPLATE begin_explicit_instantiation constructor_declarator
1044		{ parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
1045          end_explicit_instantiation
1046	| SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
1047		{ do_type_instantiation ($4.t, $1, 1);
1048		  yyungetc (';', 1); }
1049          end_explicit_instantiation
1050		{}
1051	| SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
1052          declarator
1053		{ tree specs = strip_attrs ($4.t);
1054		  parse_decl_instantiation (specs, $5, $1); }
1055          end_explicit_instantiation
1056		{}
1057	| SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
1058		{ parse_decl_instantiation (NULL_TREE, $4, $1); }
1059          end_explicit_instantiation
1060		{}
1061	| SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
1062		{ parse_decl_instantiation (NULL_TREE, $4, $1); }
1063          end_explicit_instantiation
1064		{}
1065	;
1066
1067begin_explicit_instantiation:
1068      { begin_explicit_instantiation(); }
1069        ;
1070
1071end_explicit_instantiation:
1072      { end_explicit_instantiation(); }
1073        ;
1074
1075/* The TYPENAME expansions are to deal with use of a template class name as
1076  a template within the class itself, where the template decl is hidden by
1077  a type decl.  Got all that?  */
1078
1079template_type:
1080	  PTYPENAME '<' template_arg_list_opt template_close_bracket
1081	    finish_template_type_
1082                { $$ = $5; }
1083	| tTYPENAME  '<' template_arg_list_opt template_close_bracket
1084	    finish_template_type_
1085                { $$ = $5; }
1086	| self_template_type
1087	;
1088
1089apparent_template_type:
1090	  template_type
1091	| identifier '<' template_arg_list_opt '>'
1092	    finish_template_type_
1093		{ $$ = $5; }
1094        ;
1095
1096self_template_type:
1097	  SELFNAME  '<' template_arg_list_opt template_close_bracket
1098	    finish_template_type_
1099                { $$ = $5; }
1100	;
1101
1102finish_template_type_:
1103                {
1104		  if (yychar == YYEMPTY)
1105		    yychar = YYLEX;
1106
1107		  $$ = finish_template_type ($<ttype>-3, $<ttype>-1,
1108					     yychar == SCOPE);
1109		}
1110        ;
1111
1112template_close_bracket:
1113	  '>'
1114	| RSHIFT
1115		{
1116		  /* Handle `Class<Class<Type>>' without space in the `>>' */
1117		  pedwarn ("`>>' should be `> >' in template class name");
1118		  yyungetc ('>', 1);
1119		}
1120	;
1121
1122template_arg_list_opt:
1123         /* empty */
1124                 { $$ = NULL_TREE; }
1125       | template_arg_list 
1126       ;
1127
1128template_arg_list:
1129        template_arg
1130		{ $$ = build_tree_list (NULL_TREE, $$); }
1131	| template_arg_list ',' template_arg
1132		{ $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
1133	;
1134
1135template_arg:
1136                { ++class_template_ok_as_expr; }
1137        template_arg_1 
1138                { 
1139		  --class_template_ok_as_expr; 
1140		  $$ = $2; 
1141		}
1142        ;
1143
1144template_arg_1:
1145	  type_id
1146		{ $$ = groktypename ($1.t); }
1147	| PTYPENAME
1148		{
1149		  $$ = lastiddecl;
1150		  if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
1151		    $$ = TREE_TYPE ($$);
1152		}
1153	| global_scope PTYPENAME
1154		{
1155		  $$ = lastiddecl;
1156		  if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
1157		    $$ = TREE_TYPE ($$);
1158		}
1159	| expr_no_comma_rangle
1160	| nested_name_specifier TEMPLATE identifier
1161		{
1162		  if (!processing_template_decl)
1163		    {
1164		      error ("use of template qualifier outside template");
1165		      $$ = error_mark_node;
1166		    }
1167		  else
1168		    $$ = make_unbound_class_template ($1, $3, tf_error | tf_parsing);
1169		}
1170	;
1171
1172unop:
1173	  '-'
1174		{ $$ = NEGATE_EXPR; }
1175	| '+'
1176		{ $$ = CONVERT_EXPR; }
1177	| PLUSPLUS
1178		{ $$ = PREINCREMENT_EXPR; }
1179	| MINUSMINUS
1180		{ $$ = PREDECREMENT_EXPR; }
1181	| '!'
1182		{ $$ = TRUTH_NOT_EXPR; }
1183	;
1184
1185expr:
1186	  nontrivial_exprlist
1187		{ $$ = build_x_compound_expr ($$); }
1188	| expr_no_commas
1189	;
1190
1191paren_expr_or_null:
1192	LEFT_RIGHT
1193		{ error ("ISO C++ forbids an empty condition for `%s'",
1194			 cond_stmt_keyword);
1195		  $$ = integer_zero_node; }
1196	| '(' expr ')'
1197                { $$ = $2; }
1198	;
1199
1200paren_cond_or_null:
1201	LEFT_RIGHT
1202		{ error ("ISO C++ forbids an empty condition for `%s'",
1203			 cond_stmt_keyword);
1204		  $$ = integer_zero_node; }
1205	| '(' condition ')'
1206                { $$ = $2; }
1207	;
1208
1209xcond:
1210	  /* empty */
1211		{ $$ = NULL_TREE; }
1212	| condition
1213	| error
1214		{ $$ = NULL_TREE; }
1215	;
1216
1217condition:
1218	  type_specifier_seq declarator maybeasm maybe_attribute '='
1219		{ {
1220		  tree d;
1221		  for (d = getdecls (); d; d = TREE_CHAIN (d))
1222		    if (TREE_CODE (d) == TYPE_DECL) {
1223		      tree s = TREE_TYPE (d);
1224		      if (TREE_CODE (s) == RECORD_TYPE)
1225			error ("definition of class `%T' in condition", s);
1226		      else if (TREE_CODE (s) == ENUMERAL_TYPE)
1227			error ("definition of enum `%T' in condition", s);
1228		    }
1229		  }
1230		  current_declspecs = $1.t;
1231		  $<ttype>$ = parse_decl ($<ttype>2, $4, 1);
1232		}
1233	  init
1234		{
1235		  parse_end_decl ($<ttype>6, $7, $4);
1236		  $$ = convert_from_reference ($<ttype>6);
1237		  if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
1238		    error ("definition of array `%#D' in condition", $$);
1239		}
1240	| expr
1241	;
1242
1243compstmtend:
1244	  '}'
1245	| maybe_label_decls stmts '}'
1246	| maybe_label_decls stmts error '}'
1247	| maybe_label_decls error '}'
1248	;
1249
1250nontrivial_exprlist:
1251	  expr_no_commas ',' expr_no_commas
1252		{ $$ = tree_cons (NULL_TREE, $$,
1253		                  build_tree_list (NULL_TREE, $3)); }
1254	| expr_no_commas ',' error
1255		{ $$ = tree_cons (NULL_TREE, $$,
1256		                  build_tree_list (NULL_TREE, error_mark_node)); }
1257	| nontrivial_exprlist ',' expr_no_commas
1258		{ chainon ($$, build_tree_list (NULL_TREE, $3)); }
1259	| nontrivial_exprlist ',' error
1260		{ chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
1261	;
1262
1263nonnull_exprlist:
1264	  expr_no_commas
1265		{ $$ = build_tree_list (NULL_TREE, $$); }
1266	| nontrivial_exprlist
1267	;
1268
1269unary_expr:
1270	  primary  %prec UNARY
1271		{ $$ = $1; }
1272	/* __extension__ turns off -pedantic for following primary.  */
1273	| extension cast_expr  	  %prec UNARY
1274		{ $$ = $2;
1275		  pedantic = $1; }
1276	| '*' cast_expr   %prec UNARY
1277		{ $$ = build_x_indirect_ref ($2, "unary *"); }
1278	| '&' cast_expr   %prec UNARY
1279		{ $$ = build_x_unary_op (ADDR_EXPR, $2); }
1280	| '~' cast_expr
1281		{ $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
1282	| unop cast_expr  %prec UNARY
1283                { $$ = finish_unary_op_expr ($1, $2); }
1284	/* Refer to the address of a label as a pointer.  */
1285	| ANDAND identifier
1286		{ $$ = finish_label_address_expr ($2); }
1287	| sizeof unary_expr  %prec UNARY
1288		{ $$ = finish_sizeof ($2);
1289		  skip_evaluation--; }
1290	| sizeof '(' type_id ')'  %prec HYPERUNARY
1291		{ $$ = finish_sizeof (groktypename ($3.t));
1292		  check_for_new_type ("sizeof", $3);
1293		  skip_evaluation--; }
1294	| alignof unary_expr  %prec UNARY
1295		{ $$ = finish_alignof ($2);
1296		  skip_evaluation--; }
1297	| alignof '(' type_id ')'  %prec HYPERUNARY
1298		{ $$ = finish_alignof (groktypename ($3.t));
1299		  check_for_new_type ("alignof", $3);
1300		  skip_evaluation--; }
1301
1302	/* The %prec EMPTY's here are required by the = init initializer
1303	   syntax extension; see below.  */
1304	| new new_type_id  %prec EMPTY
1305		{ $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
1306		  check_for_new_type ("new", $2); }
1307	| new new_type_id new_initializer
1308		{ $$ = build_new (NULL_TREE, $2.t, $3, $1);
1309		  check_for_new_type ("new", $2); }
1310	| new new_placement new_type_id  %prec EMPTY
1311		{ $$ = build_new ($2, $3.t, NULL_TREE, $1);
1312		  check_for_new_type ("new", $3); }
1313	| new new_placement new_type_id new_initializer
1314		{ $$ = build_new ($2, $3.t, $4, $1);
1315		  check_for_new_type ("new", $3); }
1316	| new '(' type_id ')'
1317            %prec EMPTY
1318		{ $$ = build_new (NULL_TREE, groktypename($3.t),
1319				  NULL_TREE, $1);
1320		  check_for_new_type ("new", $3); }
1321	| new '(' type_id ')' new_initializer
1322		{ $$ = build_new (NULL_TREE, groktypename($3.t), $5, $1);
1323		  check_for_new_type ("new", $3); }
1324	| new new_placement '(' type_id ')' %prec EMPTY
1325		{ $$ = build_new ($2, groktypename($4.t), NULL_TREE, $1);
1326		  check_for_new_type ("new", $4); }
1327	| new new_placement '(' type_id ')' new_initializer
1328		{ $$ = build_new ($2, groktypename($4.t), $6, $1);
1329		  check_for_new_type ("new", $4); }
1330
1331	| delete cast_expr  %prec UNARY
1332		{ $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
1333	| delete '[' ']' cast_expr  %prec UNARY
1334		{ $$ = delete_sanity ($4, NULL_TREE, 1, $1);
1335		  if (yychar == YYEMPTY)
1336		    yychar = YYLEX; }
1337	| delete '[' expr ']' cast_expr  %prec UNARY
1338		{ $$ = delete_sanity ($5, $3, 2, $1);
1339		  if (yychar == YYEMPTY)
1340		    yychar = YYLEX; }
1341	| REALPART cast_expr %prec UNARY
1342		{ $$ = build_x_unary_op (REALPART_EXPR, $2); }
1343	| IMAGPART cast_expr %prec UNARY
1344		{ $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
1345	;
1346
1347new_placement:
1348	  '(' nonnull_exprlist ')'
1349                { $$ = $2; }
1350	| '{' nonnull_exprlist '}'
1351                { pedwarn ("old style placement syntax, use () instead");
1352		  $$ = $2; }
1353	;
1354
1355new_initializer:
1356	  '(' nonnull_exprlist ')'
1357		{ $$ = $2; }
1358	| LEFT_RIGHT
1359		{ $$ = void_zero_node; }
1360	| '(' typespec ')'
1361		{
1362		  error ("`%T' is not a valid expression", $2.t);
1363		  $$ = error_mark_node;
1364		}
1365	| '=' init
1366		{
1367		  /* This was previously allowed as an extension, but
1368		     was removed in G++ 3.3.  */
1369		  error ("initialization of new expression with `='");
1370		  $$ = error_mark_node;
1371		}
1372	;
1373
1374/* This is necessary to postpone reduction of `int ((int)(int)(int))'.  */
1375regcast_or_absdcl:
1376	  '(' type_id ')'  %prec EMPTY
1377		{ $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
1378		  $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
1379		  check_for_new_type ("cast", $2); }
1380	| regcast_or_absdcl '(' type_id ')'  %prec EMPTY
1381		{ $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
1382		  $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
1383		  check_for_new_type ("cast", $3); }
1384	;
1385
1386cast_expr:
1387	  unary_expr
1388	| regcast_or_absdcl unary_expr  %prec UNARY
1389		{ $$ = reparse_absdcl_as_casts ($$, $2); }
1390	| regcast_or_absdcl '{' initlist maybecomma '}'  %prec UNARY
1391		{
1392		  tree init = build_nt (CONSTRUCTOR, NULL_TREE,
1393					nreverse ($3));
1394		  if (pedantic)
1395		    pedwarn ("ISO C++ forbids compound literals");
1396		  /* Indicate that this was a C99 compound literal.  */
1397		  TREE_HAS_CONSTRUCTOR (init) = 1;
1398
1399		  $$ = reparse_absdcl_as_casts ($$, init);
1400		}
1401	;
1402
1403expr_no_commas:
1404	  cast_expr
1405	/* Handle general members.  */
1406	| expr_no_commas POINTSAT_STAR expr_no_commas
1407		{ $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1408	| expr_no_commas DOT_STAR expr_no_commas
1409		{ $$ = build_m_component_ref ($$, $3); }
1410	| expr_no_commas '+' expr_no_commas
1411		{ $$ = build_x_binary_op ($2, $$, $3); }
1412	| expr_no_commas '-' expr_no_commas
1413		{ $$ = build_x_binary_op ($2, $$, $3); }
1414	| expr_no_commas '*' expr_no_commas
1415		{ $$ = build_x_binary_op ($2, $$, $3); }
1416	| expr_no_commas '/' expr_no_commas
1417		{ $$ = build_x_binary_op ($2, $$, $3); }
1418	| expr_no_commas '%' expr_no_commas
1419		{ $$ = build_x_binary_op ($2, $$, $3); }
1420	| expr_no_commas LSHIFT expr_no_commas
1421		{ $$ = build_x_binary_op ($2, $$, $3); }
1422	| expr_no_commas RSHIFT expr_no_commas
1423		{ $$ = build_x_binary_op ($2, $$, $3); }
1424	| expr_no_commas ARITHCOMPARE expr_no_commas
1425		{ $$ = build_x_binary_op ($2, $$, $3); }
1426	| expr_no_commas '<' expr_no_commas
1427		{ $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1428	| expr_no_commas '>' expr_no_commas
1429		{ $$ = build_x_binary_op (GT_EXPR, $$, $3); }
1430	| expr_no_commas EQCOMPARE expr_no_commas
1431		{ $$ = build_x_binary_op ($2, $$, $3); }
1432	| expr_no_commas MIN_MAX expr_no_commas
1433		{ $$ = build_x_binary_op ($2, $$, $3); }
1434	| expr_no_commas '&' expr_no_commas
1435		{ $$ = build_x_binary_op ($2, $$, $3); }
1436	| expr_no_commas '|' expr_no_commas
1437		{ $$ = build_x_binary_op ($2, $$, $3); }
1438	| expr_no_commas '^' expr_no_commas
1439		{ $$ = build_x_binary_op ($2, $$, $3); }
1440	| expr_no_commas ANDAND expr_no_commas
1441		{ $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1442	| expr_no_commas OROR expr_no_commas
1443		{ $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1444	| expr_no_commas '?' xexpr ':' expr_no_commas
1445		{ $$ = build_x_conditional_expr ($$, $3, $5); }
1446	| expr_no_commas '=' expr_no_commas
1447		{ $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
1448		  if ($$ != error_mark_node)
1449                    C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1450	| expr_no_commas ASSIGN expr_no_commas
1451		{ $$ = build_x_modify_expr ($$, $2, $3); }
1452	| THROW
1453		{ $$ = build_throw (NULL_TREE); }
1454	| THROW expr_no_commas
1455		{ $$ = build_throw ($2); }
1456	;
1457
1458expr_no_comma_rangle:
1459	  cast_expr
1460	/* Handle general members.  */
1461	| expr_no_comma_rangle POINTSAT_STAR expr_no_comma_rangle
1462		{ $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1463	| expr_no_comma_rangle DOT_STAR expr_no_comma_rangle
1464		{ $$ = build_m_component_ref ($$, $3); }
1465	| expr_no_comma_rangle '+' expr_no_comma_rangle
1466		{ $$ = build_x_binary_op ($2, $$, $3); }
1467	| expr_no_comma_rangle '-' expr_no_comma_rangle
1468		{ $$ = build_x_binary_op ($2, $$, $3); }
1469	| expr_no_comma_rangle '*' expr_no_comma_rangle
1470		{ $$ = build_x_binary_op ($2, $$, $3); }
1471	| expr_no_comma_rangle '/' expr_no_comma_rangle
1472		{ $$ = build_x_binary_op ($2, $$, $3); }
1473	| expr_no_comma_rangle '%' expr_no_comma_rangle
1474		{ $$ = build_x_binary_op ($2, $$, $3); }
1475	| expr_no_comma_rangle LSHIFT expr_no_comma_rangle
1476		{ $$ = build_x_binary_op ($2, $$, $3); }
1477	| expr_no_comma_rangle RSHIFT expr_no_comma_rangle
1478		{ $$ = build_x_binary_op ($2, $$, $3); }
1479	| expr_no_comma_rangle ARITHCOMPARE expr_no_comma_rangle
1480		{ $$ = build_x_binary_op ($2, $$, $3); }
1481	| expr_no_comma_rangle '<' expr_no_comma_rangle
1482		{ $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1483	| expr_no_comma_rangle EQCOMPARE expr_no_comma_rangle
1484		{ $$ = build_x_binary_op ($2, $$, $3); }
1485	| expr_no_comma_rangle MIN_MAX expr_no_comma_rangle
1486		{ $$ = build_x_binary_op ($2, $$, $3); }
1487	| expr_no_comma_rangle '&' expr_no_comma_rangle
1488		{ $$ = build_x_binary_op ($2, $$, $3); }
1489	| expr_no_comma_rangle '|' expr_no_comma_rangle
1490		{ $$ = build_x_binary_op ($2, $$, $3); }
1491	| expr_no_comma_rangle '^' expr_no_comma_rangle
1492		{ $$ = build_x_binary_op ($2, $$, $3); }
1493	| expr_no_comma_rangle ANDAND expr_no_comma_rangle
1494		{ $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1495	| expr_no_comma_rangle OROR expr_no_comma_rangle
1496		{ $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1497	| expr_no_comma_rangle '?' xexpr ':' expr_no_comma_rangle
1498		{ $$ = build_x_conditional_expr ($$, $3, $5); }
1499	| expr_no_comma_rangle '=' expr_no_comma_rangle
1500		{ $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
1501		  if ($$ != error_mark_node)
1502                    C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1503	| expr_no_comma_rangle ASSIGN expr_no_comma_rangle
1504		{ $$ = build_x_modify_expr ($$, $2, $3); }
1505	| THROW
1506		{ $$ = build_throw (NULL_TREE); }
1507	| THROW expr_no_comma_rangle
1508		{ $$ = build_throw ($2); }
1509	;
1510
1511notype_unqualified_id:
1512	  '~' see_typename identifier
1513		{ $$ = build_nt (BIT_NOT_EXPR, $3); }
1514	| '~' see_typename template_type
1515		{ $$ = build_nt (BIT_NOT_EXPR, $3); }
1516        | template_id
1517	| operator_name
1518	| IDENTIFIER
1519	| PTYPENAME
1520	| NSNAME  %prec EMPTY
1521	;
1522
1523do_id:
1524		{
1525		  /* If lastiddecl is a BASELINK we're in an
1526		     expression like S::f<int>, so don't
1527		     do_identifier; we only do that for unqualified
1528		     identifiers.  */
1529	          if (!lastiddecl || !BASELINK_P (lastiddecl))
1530		    $$ = do_identifier ($<ttype>-1, 3, NULL_TREE);
1531		  else
1532		    $$ = $<ttype>-1;
1533		}
1534        ;
1535
1536template_id:
1537          PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
1538                { 
1539		  tree template_name = $3;
1540		  if (TREE_CODE (template_name) == COMPONENT_REF)
1541		    template_name = TREE_OPERAND (template_name, 1);
1542		  $$ = lookup_template_function (template_name, $4); 
1543		}
1544        | operator_name '<' do_id template_arg_list_opt template_close_bracket
1545                { 
1546		  tree template_name = $3;
1547		  if (TREE_CODE (template_name) == COMPONENT_REF)
1548		    template_name = TREE_OPERAND (template_name, 1);
1549		  $$ = lookup_template_function (template_name, $4); 
1550		}
1551	;
1552
1553object_template_id:
1554        TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
1555                { $$ = lookup_template_function ($2, $4); }
1556        | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
1557                { $$ = lookup_template_function ($2, $4); }
1558        | TEMPLATE operator_name '<' template_arg_list_opt
1559          template_close_bracket
1560                { $$ = lookup_template_function ($2, $4); }
1561        ;
1562
1563unqualified_id:
1564	  notype_unqualified_id
1565	| tTYPENAME
1566	| SELFNAME
1567	;
1568
1569expr_or_declarator_intern:
1570	  expr_or_declarator
1571	| attributes expr_or_declarator
1572		{
1573		  /* Provide support for '(' attributes '*' declarator ')'
1574		     etc */
1575		  $$ = tree_cons ($1, $2, NULL_TREE);
1576		}
1577	;
1578
1579expr_or_declarator:
1580	  notype_unqualified_id
1581	| '*' expr_or_declarator_intern  %prec UNARY
1582		{ $$ = build_nt (INDIRECT_REF, $2); }
1583	| '&' expr_or_declarator_intern  %prec UNARY
1584		{ $$ = build_nt (ADDR_EXPR, $2); }
1585	| '(' expr_or_declarator_intern ')'
1586		{ $$ = $2; }
1587	;
1588
1589notype_template_declarator:
1590	  IDENTIFIER '<' template_arg_list_opt template_close_bracket
1591                { $$ = lookup_template_function ($1, $3); }
1592	| NSNAME '<' template_arg_list template_close_bracket
1593                { $$ = lookup_template_function ($1, $3); }
1594	;
1595
1596direct_notype_declarator:
1597	  complex_direct_notype_declarator
1598	/* This precedence declaration is to prefer this reduce
1599	   to the Koenig lookup shift in primary, below.  I hate yacc.  */
1600	| notype_unqualified_id %prec '('
1601	| notype_template_declarator
1602	| '(' expr_or_declarator_intern ')'
1603                { $$ = finish_decl_parsing ($2); }
1604	;
1605
1606primary:
1607	  notype_unqualified_id
1608		{
1609		  if (TREE_CODE ($1) == BIT_NOT_EXPR)
1610		    $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
1611		  else
1612		    $$ = finish_id_expr ($1);
1613		}
1614	| CONSTANT
1615	| boolean_literal
1616	| STRING
1617		{
1618		  $$ = fix_string_type ($$);
1619		  /* fix_string_type doesn't set up TYPE_MAIN_VARIANT of
1620		     a const array the way we want, so fix it.  */
1621		  if (flag_const_strings)
1622		    TREE_TYPE ($$) = build_cplus_array_type
1623		      (TREE_TYPE (TREE_TYPE ($$)),
1624		       TYPE_DOMAIN (TREE_TYPE ($$)));
1625		}
1626	| VAR_FUNC_NAME
1627               { $$ = finish_fname ($1); }
1628	| '(' expr ')'
1629		{ $$ = finish_parenthesized_expr ($2); }
1630	| '(' expr_or_declarator_intern ')'
1631		{ $2 = reparse_decl_as_expr (NULL_TREE, $2);
1632		  $$ = finish_parenthesized_expr ($2); }
1633	| '(' error ')'
1634		{ $$ = error_mark_node; }
1635	| '('
1636		{ if (!at_function_scope_p ())
1637		    {
1638		      error ("braced-group within expression allowed only inside a function");
1639		      YYERROR;
1640		    }
1641		  if (pedantic)
1642		    pedwarn ("ISO C++ forbids braced-groups within expressions");
1643		  $<ttype>$ = begin_stmt_expr ();
1644		}
1645	  compstmt_or_stmtexpr ')'
1646               { $$ = finish_stmt_expr ($<ttype>2); }
1647        /* Koenig lookup support
1648           We could store lastiddecl in $1 to avoid another lookup,
1649           but that would result in many additional reduce/reduce conflicts. */
1650        | notype_unqualified_id '(' nonnull_exprlist ')'
1651               { $$ = parse_finish_call_expr ($1, $3, 1); }
1652        | notype_unqualified_id LEFT_RIGHT
1653               { $$ = parse_finish_call_expr ($1, NULL_TREE, 1); }
1654	| primary '(' nonnull_exprlist ')'
1655               { $$ = parse_finish_call_expr ($1, $3, 0); }
1656	| primary LEFT_RIGHT
1657               { $$ = parse_finis…

Large files files are truncated, but you can click here to view the full file