PageRenderTime 25ms CodeModel.GetById 5ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/osprey/kg++fe/gnu/parse.y

https://bitbucket.org/osunix/open64
Happy | 4998 lines | 4537 code | 461 blank | 0 comment | 0 complexity | 0526240d65a09eb832332774a4ed6222 MD5 | raw file

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

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

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