PageRenderTime 68ms CodeModel.GetById 23ms app.highlight 7ms RepoModel.GetById 26ms app.codeStats 1ms

/interfaces/gcc/c_files/cp/parse.y

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

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