home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cplusplus-8 / cplus-parse.y < prev    next >
Encoding:
Text File  |  1992-02-07  |  104.7 KB  |  3,932 lines

  1. /* YACC parser for C++ syntax.
  2.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* This grammar is based on the GNU CC grammar.  */
  23.  
  24. /* Also note: this version contains experimental exception
  25.    handling features.  They could break, change, disappear,
  26.    or otherwise exhibit volatile behavior.  Don't depend on
  27.    me (Michael Tiemann) to protect you from any negative impact
  28.    this may have on your professional, personal, or spiritual life.  */
  29.  
  30. %{
  31. #include "config.h"
  32.  
  33. #include <stdio.h>
  34. #include <errno.h>
  35.  
  36. #include "tree.h"
  37. #include "input.h"
  38. #include "cplus-parse.h"
  39. #include "cplus-tree.h"
  40. #include "assert.h"
  41.  
  42. /* C++ extensions */
  43. extern tree ridpointers[];    /* need this up here */
  44. extern tree void_list_node;
  45.  
  46. #ifndef errno
  47. extern int errno;
  48. #endif
  49.  
  50. extern int end_of_file;
  51.  
  52. void yyerror ();
  53.  
  54. /* Like YYERROR but do call yyerror.  */
  55. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  56.  
  57. /* Contains error message to give if user tries to declare
  58.    a variable where one does not belong.  */
  59. static char *stmt_decl_msg = 0;
  60.  
  61. #ifdef OBJCPLUS
  62.  
  63. #include "objc-actions.h"
  64.  
  65. /* the `decl' list operators optimization is not appropriate for Objective-C */
  66. #define build_decl_list     build_tree_list
  67. #define decl_tree_cons         tree_cons
  68.  
  69. #define YYDEBUG 1
  70.  
  71. #endif /* OBJCPLUS */
  72.  
  73. #ifndef YYDEBUG
  74. /* Cause the `yydebug' variable to be defined.  */
  75. int yydebug;
  76. #endif
  77.  
  78. /* Cons up an empty parameter list.  */
  79. #ifdef __GNU__
  80. __inline
  81. #endif
  82. static tree
  83. empty_parms ()
  84. {
  85.   tree parms;
  86.  
  87.   if (strict_prototype)
  88.     parms = void_list_node;
  89.   else
  90.     parms = NULL_TREE;
  91.   return parms;
  92. }
  93.  
  94. void yyhook ();
  95. %}
  96.  
  97. %start program
  98.  
  99. %union {long itype; tree ttype; enum tree_code code; }
  100.  
  101. /* All identifiers that are not reserved words
  102.    and are not declared typedefs in the current block */
  103. %token IDENTIFIER
  104.  
  105. /* All identifiers that are declared typedefs in the current block.
  106.    In some contexts, they are treated just like IDENTIFIER,
  107.    but they can also serve as typespecs in declarations.  */
  108. %token TYPENAME
  109.  
  110. /* Reserved words that specify storage class.
  111.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  112. %token SCSPEC
  113.  
  114. /* Reserved words that specify type.
  115.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  116. %token TYPESPEC
  117.  
  118. /* Reserved words that qualify type: "const" or "volatile".
  119.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  120. %token TYPE_QUAL
  121.  
  122. /* Character or numeric constants.
  123.    yylval is the node for the constant.  */
  124. %token CONSTANT
  125.  
  126. /* String constants in raw form.
  127.    yylval is a STRING_CST node.  */
  128. %token STRING
  129.  
  130. /* "...", used for functions with variable arglists.  */
  131. %token ELLIPSIS
  132.  
  133. /* the reserved words */
  134. %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  135. %token BREAK CONTINUE RETURN GOTO ASM TYPEOF ALIGNOF
  136. %token ATTRIBUTE
  137.  
  138. /* the reserved words... C++ extensions */
  139. %token <ttype> AGGR
  140. %token DELETE NEW OVERLOAD PRIVATE PUBLIC PROTECTED THIS OPERATOR
  141. %token DYNAMIC POINTSAT_LEFT_RIGHT LEFT_RIGHT
  142. %token <itype> SCOPE
  143.  
  144. /* the Objective-C keywords */
  145. %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
  146. %token CLASSNAME PROTOCOL OBJECTNAME CLASS ALIAS
  147.  
  148. /* Objective-C string constants in raw form.
  149.    yylval is a OBJC_STRING_CST node.  */
  150. %token OBJC_STRING
  151.  
  152. /* Define the operator tokens and their precedences.
  153.    The value is an integer because, if used, it is the tree code
  154.    to use in the expression made from the operator.  */
  155.  
  156. %left EMPTY            /* used to resolve s/r with epsilon */
  157.  
  158. /* Add precedence rules to solve dangling else s/r conflict */
  159. %nonassoc IF
  160. %nonassoc ELSE
  161.  
  162. %left IDENTIFIER TYPENAME TYPENAME_COLON SCSPEC TYPESPEC TYPE_QUAL ENUM AGGR
  163.  
  164. %left '{' ','
  165.  
  166. %right <code> ASSIGN '='
  167. %right <code> '?' ':' RANGE
  168. %left <code> OROR
  169. %left <code> ANDAND
  170. %left <code> '|'
  171. %left <code> '^'
  172. %left <code> '&'
  173. %left <code> MIN_MAX
  174. %left <code> EQCOMPARE
  175. %left <code> ARITHCOMPARE
  176. %left <code> LSHIFT RSHIFT
  177. %left <code> '+' '-'
  178. %left <code> '*' '/' '%'
  179. %right <code> UNARY PLUSPLUS MINUSMINUS
  180. %left HYPERUNARY
  181. %left <ttype> PAREN_STAR_PAREN PAREN_X_SCOPE_STAR_PAREN PAREN_X_SCOPE_REF_PAREN LEFT_RIGHT
  182. %left <code> POINTSAT '.' '(' '['
  183.  
  184. %right SCOPE            /* C++ extension */
  185. %nonassoc NEW DELETE RAISE RAISES RERAISE TRY EXCEPT CATCH
  186. %right DYNAMIC
  187.  
  188. %type <code> unop
  189.  
  190. %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist /* exprlist */
  191. %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
  192. %type <ttype> typed_declspecs reserved_declspecs
  193. %type <ttype> typed_typespecs reserved_typespecquals
  194. %type <ttype> declmods typespec typespecqual_reserved
  195. %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
  196. %type <itype> initdecls notype_initdecls initdcl    /* C++ modification */
  197. %type <ttype> init initlist maybeasm
  198. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  199. %type <ttype> maybe_attribute attribute_list attrib
  200.  
  201. %type <ttype> compstmt except_stmts
  202.  
  203. %type <ttype> declarator notype_declarator after_type_declarator
  204.  
  205. %type <ttype> structsp opt.component_decl_list component_decl_list component_decl components component_declarator
  206. %type <ttype> enumlist enumerator
  207. %type <ttype> typename absdcl absdcl1 type_quals
  208. %type <ttype> xexpr see_typename parmlist parms parm bad_parm
  209.  
  210. /* C++ extensions */
  211. %token <ttype> TYPENAME_COLON TYPENAME_SCOPE TYPENAME_ELLIPSIS
  212. %token <ttype> PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL
  213. %type <ttype> fn.def2 dummy_decl x_typespec return_id
  214. %type <ttype> class_head opt.init base_class_list base_class_visibility_list
  215. %type <ttype> after_type_declarator_no_typename
  216. %type <ttype> maybe_raises raise_identifier raise_identifiers
  217. %type <ttype> component_declarator0 scoped_identifier
  218. %type <ttype> forhead.1 identifier_or_opname operator_name
  219. %type <ttype> new delete object primary_no_id aggr nonmomentary_expr
  220. %type <itype> LC forhead.2 initdcl0 notype_initdcl0 wrapper member_init_list
  221. %type <itype> .scope try
  222.  
  223. /* the Objective-C productions */
  224.  
  225. %type <itype> setspecs        /* just for now */
  226.  
  227. %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
  228. %type <ttype> methoddecl unaryselector keywordselector selector
  229. %type <ttype> keyworddecl receiver objcmessageexpr messageargs 
  230. %type <ttype> keywordexpr keywordarglist keywordarg
  231. %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr 
  232. %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr 
  233. %type <ttype> objc_string protocolrefs identifier_list identifier_colon
  234. %type <ttype> objcprotocolexpr CLASSNAME OBJC_STRING OBJECTNAME
  235.  
  236. %{
  237. /* the declaration found for the last IDENTIFIER token read in.
  238.    yylex must look this up to detect typedefs, which get token type TYPENAME,
  239.    so it is left around in case the identifier is not a typedef but is
  240.    used in a context which makes it a reference to a variable.  */
  241. tree lastiddecl;
  242.  
  243. tree make_pointer_declarator (), make_reference_declarator ();
  244.  
  245. tree combine_strings ();
  246. void reinit_parse_for_function ();
  247. void reinit_parse_for_method ();
  248.  
  249. /* List of types and structure classes of the current declaration.  */
  250. tree current_declspecs;
  251.  
  252. int undeclared_variable_notice;    /* 1 if we explained undeclared var errors.  */
  253.  
  254. int yylex ();
  255. extern FILE *finput;
  256.  
  257. #ifdef OBJCPLUS
  258.  
  259. /* List of Objective-C specific information */
  260.  
  261. static tree objc_interface_context;
  262. static tree objc_implementation_context;
  263. tree objc_method_context;
  264. tree objc_ivar_chain;
  265. static tree objc_ivar_context;
  266. static enum tree_code objc_inherit_code;
  267. int objc_receiver_context;
  268. static int objc_public_flag;
  269.  
  270. extern char *token_buffer;
  271.  
  272. tree current_objc_implementation_context (void)
  273. {
  274.   return objc_implementation_context;
  275. }
  276.  
  277. #endif /* OBJCPLUS */
  278. %}
  279.  
  280. %%
  281. program: .program /* empty */
  282.                 { objc_finish (); }
  283.     | .program extdefs
  284.                 { objc_finish ();
  285.           finish_file (); }
  286.     ;
  287.  
  288. .program: /* empty */
  289.         {
  290.           if (flag_cadillac)
  291.             cadillac_start ();
  292.         }
  293.  
  294. /* the reason for the strange actions in this rule
  295.  is so that notype_initdecls when reached via datadef
  296.  can find a valid list of type and sc specs in $0. */
  297.  
  298. extdefs:
  299.       {$<ttype>$ = NULL_TREE; } extdef
  300.     | extdefs {$<ttype>$ = NULL_TREE; } extdef
  301.     ;
  302.  
  303. extdef:
  304.       fndef
  305.         { if (pending_inlines) do_pending_inlines (); }
  306.     | datadef
  307.         { if (pending_inlines) do_pending_inlines (); }
  308.     | objcdef
  309.         { if (pending_inlines) do_pending_inlines (); }
  310.     | overloaddef
  311.     | ASM '(' string ')' ';'
  312.         { if (pedantic)
  313.             warning ("ANSI C forbids use of `asm' keyword");
  314.           if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  315.           assemble_asm ($3); }
  316.     | extern_lang_string '{' extdefs '}'
  317.         { pop_lang_context (); }
  318.     | extern_lang_string '{' '}'
  319.         { pop_lang_context (); }
  320.     | extern_lang_string fndef
  321.         { if (pending_inlines) do_pending_inlines ();
  322.           pop_lang_context (); }
  323.     | extern_lang_string datadef
  324.         { if (pending_inlines) do_pending_inlines ();
  325.           pop_lang_context (); }
  326.     ;
  327.  
  328. extern_lang_string:
  329.       EXTERN_LANG_STRING
  330.         { push_lang_context ($1); }
  331.     ;
  332.  
  333. overloaddef:
  334.       OVERLOAD ov_identifiers ';'
  335.  
  336. ov_identifiers: IDENTIFIER
  337.         { declare_overloaded ($1); }
  338.     | ov_identifiers ',' IDENTIFIER
  339.         { declare_overloaded ($3); }
  340.     ;
  341.       
  342. dummy_decl: /* empty */
  343.         { $$ = NULL_TREE; }
  344.     ;
  345.  
  346. datadef:
  347.       dummy_decl notype_initdecls ';'
  348.         { if (pedantic)
  349.             error ("ANSI C forbids data definition lacking type or storage class");
  350.             else if (! flag_traditional)
  351.               warning ("data definition lacks type or storage class"); }
  352.     | declmods notype_initdecls ';'
  353.         {}
  354.     /* Normal case to make fast: "int i;".  */
  355.     | declmods declarator ';'
  356.         { tree d;
  357.           d = start_decl ($2, $1, 0, NULL_TREE);
  358.           finish_decl (d, NULL_TREE, NULL_TREE);
  359.         }
  360.     | typed_declspecs initdecls ';'
  361.         {
  362.           end_exception_decls ();
  363.           note_got_semicolon ($1);
  364.         }
  365.     /* Normal case: make this fast.  */
  366.     | typed_declspecs declarator ';'
  367.         { tree d;
  368.           d = start_decl ($2, $1, 0, NULL_TREE);
  369.           finish_decl (d, NULL_TREE, NULL_TREE);
  370.           end_exception_decls ();
  371.           note_got_semicolon ($1);
  372.         }
  373.         | declmods ';'
  374.       { error ("empty declaration"); }
  375.     | typed_declspecs ';'
  376.       {
  377.         shadow_tag ($1);
  378.         note_got_semicolon ($1);
  379.       }
  380.     | error ';'
  381.     | error '}'
  382.     | ';'
  383.     ;
  384.  
  385. fndef:
  386.       fn.def1 base_init compstmt_or_error
  387.         {
  388.           finish_function (lineno, 1);
  389.           /* finish_function performs these three statements:
  390.  
  391.              expand_end_bindings (getdecls (), 1, 0);
  392.              poplevel (1, 1, 0);
  393.  
  394.              expand_end_bindings (0, 0, 0);
  395.              poplevel (0, 0, 1);
  396.              */
  397.         }
  398.     | fn.def1 return_init base_init compstmt_or_error
  399.         {
  400.           finish_function (lineno, 1);
  401.           /* finish_function performs these three statements:
  402.  
  403.              expand_end_bindings (getdecls (), 1, 0);
  404.              poplevel (1, 1, 0);
  405.  
  406.              expand_end_bindings (0, 0, 0);
  407.              poplevel (0, 0, 1);
  408.              */
  409.         }
  410.     | fn.def1 nodecls compstmt_or_error
  411.         { finish_function (lineno, 0); }
  412.     | fn.def1 return_init ';' nodecls compstmt_or_error
  413.         { finish_function (lineno, 0); }
  414.     | fn.def1 return_init nodecls compstmt_or_error
  415.         { finish_function (lineno, 0); }
  416.     | typed_declspecs declarator error
  417.         {}
  418.     | declmods notype_declarator error
  419.         {}
  420.     | dummy_decl notype_declarator error
  421.         {}
  422.     ;
  423.  
  424. fn.def1:
  425.       typed_declspecs declarator maybe_raises
  426.         { if (! start_function ($1, $2, $3, 0))
  427.             YYERROR;
  428.           reinit_parse_for_function (); }
  429.     | declmods notype_declarator maybe_raises
  430.         { if (! start_function ($1, $2, $3, 0))
  431.             YYERROR;
  432.           reinit_parse_for_function (); }
  433.     | dummy_decl notype_declarator maybe_raises
  434.         { if (! start_function (NULL_TREE, $2, $3, 0))
  435.             YYERROR;
  436.           reinit_parse_for_function (); }
  437.     | dummy_decl TYPENAME '(' parmlist ')' type_quals maybe_raises
  438.         { if (! start_function (NULL_TREE, build_parse_node (CALL_EXPR, $2, $4, $6), $7, 0))
  439.             YYERROR;
  440.           reinit_parse_for_function (); }
  441.     | dummy_decl TYPENAME LEFT_RIGHT type_quals maybe_raises
  442.         { if (! start_function (NULL_TREE, build_parse_node (CALL_EXPR, $2, empty_parms (), $4), $5, 0))
  443.             YYERROR;
  444.           reinit_parse_for_function (); }
  445.     | PRE_PARSED_FUNCTION_DECL
  446.         { start_function (NULL_TREE, $1, NULL_TREE, 1);
  447.           reinit_parse_for_function (); }
  448.     ;
  449.  
  450. /* more C++ complexity */
  451. fn.def2:
  452.       typed_declspecs '(' parmlist ')' type_quals maybe_raises
  453.         {
  454.           tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5);
  455.           $$ = start_method (TREE_CHAIN ($1), decl, $6);
  456.           if (! $$)
  457.             YYERROR;
  458.           if (yychar == YYEMPTY)
  459.             yychar = YYLEX;
  460.           reinit_parse_for_method (yychar, $$); }
  461.     | typed_declspecs LEFT_RIGHT type_quals maybe_raises
  462.         {
  463.           tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), empty_parms (), $3);
  464.           $$ = start_method (TREE_CHAIN ($1), decl, $4);
  465.           if (! $$)
  466.             YYERROR;
  467.           if (yychar == YYEMPTY)
  468.             yychar = YYLEX;
  469.           reinit_parse_for_method (yychar, $$); }
  470.     | typed_declspecs declarator maybe_raises
  471.         { $$ = start_method ($1, $2, $3);
  472.           if (! $$)
  473.             YYERROR;
  474.           if (yychar == YYEMPTY)
  475.             yychar = YYLEX;
  476.           reinit_parse_for_method (yychar, $$); }
  477.     | declmods '(' parmlist ')' type_quals maybe_raises
  478.         {
  479.           tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5);
  480.           $$ = start_method (TREE_CHAIN ($1), decl, $6);
  481.           if (! $$)
  482.             YYERROR;
  483.           if (yychar == YYEMPTY)
  484.             yychar = YYLEX;
  485.           reinit_parse_for_method (yychar, $$); }
  486.     | declmods LEFT_RIGHT type_quals maybe_raises
  487.         {
  488.           tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), empty_parms (), $3);
  489.           $$ = start_method (TREE_CHAIN ($1), decl, $4);
  490.           if (! $$)
  491.             YYERROR;
  492.           if (yychar == YYEMPTY)
  493.             yychar = YYLEX;
  494.           reinit_parse_for_method (yychar, $$); }
  495.     | declmods declarator maybe_raises
  496.         { $$ = start_method ($1, $2, $3);
  497.           if (! $$)
  498.             YYERROR;
  499.           if (yychar == YYEMPTY)
  500.             yychar = YYLEX;
  501.           reinit_parse_for_method (yychar, $$); }
  502.     | dummy_decl notype_declarator maybe_raises
  503.         { $$ = start_method (NULL_TREE, $2, $3);
  504.           if (! $$)
  505.             YYERROR;
  506.           if (yychar == YYEMPTY)
  507.             yychar = YYLEX;
  508.           reinit_parse_for_method (yychar, $$); }
  509.     ;
  510.  
  511. return_id: RETURN IDENTIFIER
  512.         {
  513.           if (! current_function_parms_stored)
  514.             store_parm_decls ();
  515.           $$ = $2;
  516.         }
  517.     ;
  518.  
  519. return_init: return_id opt.init
  520.         {
  521.           extern tree value_identifier;
  522.           tree result;
  523.  
  524.           result = DECL_RESULT (current_function_decl);
  525.           if (DECL_NAME (result) == value_identifier)
  526.             DECL_NAME (result) = $1;
  527.           else
  528.             error ("return identifier `%s' already in place",
  529.                IDENTIFIER_POINTER (DECL_NAME (result)));
  530.           store_return_init ($2);
  531.         }
  532.     | return_id '(' nonnull_exprlist ')'
  533.         {
  534.           extern tree value_identifier;
  535.           tree result;
  536.  
  537.           result = DECL_RESULT (current_function_decl);
  538.           if (DECL_NAME (result) == value_identifier)
  539.             DECL_NAME (result) = $1;
  540.           else
  541.             error ("return identifier `%s' already in place",
  542.                IDENTIFIER_POINTER (DECL_NAME (result)));
  543.           store_return_init ($3);
  544.         }
  545.     | return_id LEFT_RIGHT
  546.         {
  547.           extern tree value_identifier;
  548.           tree result;
  549.  
  550.           result = DECL_RESULT (current_function_decl);
  551.           if (DECL_NAME (result) == value_identifier)
  552.             DECL_NAME (result) = $1;
  553.           else
  554.             error ("return identifier `%s' already in place",
  555.                IDENTIFIER_POINTER (DECL_NAME (result)));
  556.           store_return_init (NULL_TREE);
  557.         }
  558.     ;
  559.  
  560. base_init:
  561.       ':' .set_base_init member_init_list
  562.         {
  563.           if ($3 == 0)
  564.             error ("no base initializers given following ':'");
  565.           setup_vtbl_ptr ();
  566.         }
  567.     ;
  568.  
  569. .set_base_init:
  570.     /* empty */
  571.         {
  572.           int preserve = (current_class_type
  573.                   && TYPE_USES_VIRTUAL_BASECLASSES (current_class_type));
  574.           preserve = 0;    /* "in charge" arg means we no longer
  575.                    need this hack.  */
  576.           if (! current_function_parms_stored)
  577.             store_parm_decls ();
  578.           else if (preserve)
  579.             preserve_data ();
  580.  
  581.           /* Flag that we are processing base and member initializers.  */
  582.           current_vtable_decl = error_mark_node;
  583.  
  584.           if (DECL_CONSTRUCTOR_P (current_function_decl))
  585.             {
  586.               /* Make a contour for the initializer list.  */
  587.               pushlevel (0);
  588.               clear_last_expr ();
  589.               expand_start_bindings (0);
  590.             }
  591.           else if (current_class_type == NULL_TREE)
  592.             error ("base initializers not allowed for non-member functions");
  593.           else if (! DECL_CONSTRUCTOR_P (current_function_decl))
  594.             error ("only constructors take base initializers");
  595.         }
  596.     ;
  597.  
  598. member_init_list:
  599.       /* empty */
  600.         { $$ = 0; }
  601.     | member_init
  602.         { $$ = 1; }
  603.     | member_init_list ',' member_init
  604.     | member_init_list error
  605.     ;
  606.  
  607.  
  608.  
  609. member_init: '(' nonnull_exprlist ')'
  610.         {
  611.           if (current_class_name && pedantic)
  612.             warning ("old style base class initialization; use `%s (...)'",
  613.                  IDENTIFIER_POINTER (current_class_name));
  614.           expand_member_init (C_C_D, NULL_TREE, $2);
  615.         }
  616.     | LEFT_RIGHT
  617.         {
  618.           if (current_class_name && pedantic)
  619.             warning ("old style base class initialization; use `%s (...)'",
  620.                  IDENTIFIER_POINTER (current_class_name));
  621.           expand_member_init (C_C_D, NULL_TREE, void_type_node);
  622.         }
  623.     | identifier '(' nonnull_exprlist ')'
  624.         {
  625.           expand_member_init (C_C_D, $1, $3);
  626.         }
  627.     | identifier LEFT_RIGHT
  628.         { expand_member_init (C_C_D, $1, void_type_node); }
  629.     | scoped_identifier identifier '(' nonnull_exprlist ')'
  630.         {
  631.           tree base, basetype;
  632.           tree scopes = $1;
  633.  
  634.           if (TREE_CODE (scopes) == SCOPE_REF)
  635.             /* just a pain to do this right now.  */
  636.             abort ();
  637.  
  638.           if (current_class_type == NULL_TREE
  639.               || ! is_aggr_typedef (scopes, 1))
  640.             break;
  641.           basetype = get_base_type (TREE_TYPE (TREE_TYPE (scopes)),
  642.                         current_class_type, 1);
  643.           if (basetype == error_mark_node)
  644.             break;
  645.           if (basetype == 0)
  646.             {
  647.               error_not_base_type (TREE_TYPE (TREE_TYPE (scopes)), current_class_type);
  648.               break;
  649.             }
  650.  
  651.           base = convert_pointer_to (basetype, current_class_decl);
  652.           expand_member_init (build_indirect_ref (base), $2, $4);
  653.         }
  654.     | scoped_identifier identifier LEFT_RIGHT
  655.         {
  656.           tree basetype, base;
  657.           tree scopes = $1;
  658.           if (TREE_CODE (scopes) == SCOPE_REF)
  659.             /* just a pain to do this right now.  */
  660.             abort ();
  661.  
  662.           if (current_class_type == NULL_TREE
  663.               || ! is_aggr_typedef (scopes, 1))
  664.             break;
  665.           basetype = get_base_type (TREE_TYPE (TREE_TYPE (scopes)),
  666.                         current_class_type, 1);
  667.           if (basetype == error_mark_node)
  668.             break;
  669.           if (basetype == 0)
  670.             {
  671.               error_not_base_type (TREE_TYPE (TREE_TYPE (scopes)), current_class_type);
  672.               break;
  673.             }
  674.  
  675.           base = convert_pointer_to (basetype, current_class_decl);
  676.           expand_member_init (build_indirect_ref (base), $2, void_type_node);
  677.         }
  678.     ;
  679.  
  680. identifier:
  681.       IDENTIFIER
  682.     | TYPENAME
  683.     | OBJECTNAME
  684.         | CLASSNAME
  685.     ;
  686.  
  687. identifier_or_opname:
  688.       IDENTIFIER
  689.     | TYPENAME
  690.     | OBJECTNAME
  691.     | CLASSNAME
  692.     | '~' identifier
  693.         { $$ = build_parse_node (BIT_NOT_EXPR, $2); }
  694.     | operator_name
  695.         { $$ = hack_operator ($1);
  696.           if ($$ == error_mark_node)
  697.             $$ = get_identifier ("<missing operator>"); }
  698.     | wrapper IDENTIFIER
  699.         { $$ = hack_wrapper ($1, NULL_TREE, $2); }
  700.     | wrapper TYPENAME
  701.         { $$ = hack_wrapper ($1, NULL_TREE, $2); }
  702.     | wrapper operator_name
  703.         { $$ = hack_wrapper ($1, NULL_TREE, $2); }
  704.     | wrapper scoped_identifier IDENTIFIER
  705.         { $$ = hack_wrapper ($1, $2, $3); }
  706.     | wrapper scoped_identifier operator_name
  707.         { $$ = hack_wrapper ($1, $2, $3); }
  708.     ;
  709.  
  710. wrapper:  LEFT_RIGHT
  711.         { $$ = 0; }
  712.     | '~' LEFT_RIGHT
  713.         { $$ = 1; }
  714.     | LEFT_RIGHT '?'
  715.         { $$ = 2; }
  716.     ;
  717.  
  718. unop:     '-'
  719.         { $$ = NEGATE_EXPR; }
  720.     | '+'
  721.         { $$ = CONVERT_EXPR; }
  722.     | PLUSPLUS
  723.         { $$ = PREINCREMENT_EXPR; }
  724.     | MINUSMINUS
  725.         { $$ = PREDECREMENT_EXPR; }
  726.     | '!'
  727.         { $$ = TRUTH_NOT_EXPR; }
  728.     ;
  729.  
  730. expr:      nonnull_exprlist
  731.         { $$ = build_x_compound_expr ($1); }
  732.     /* Ugly, but faster.  */
  733.     | expr_no_commas
  734.         {
  735.           if (TREE_CODE ($1) == CALL_EXPR
  736.               && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE ($1)))
  737.             $$ = cleanup_after_call ($1);
  738.         }
  739.     ;
  740.  
  741. /* Now obsolete.
  742. exprlist:
  743.       / * empty * /
  744.         { $$ = NULL_TREE; }
  745.     | nonnull_exprlist
  746.     ;
  747. */
  748.  
  749. nonnull_exprlist:
  750.       expr_no_commas
  751.         { $$ = build_tree_list (NULL_TREE, $1); }
  752.     | nonnull_exprlist ',' expr_no_commas
  753.         { chainon ($1, build_tree_list (NULL_TREE, $3)); }
  754.     | nonnull_exprlist ',' error
  755.         { chainon ($1, build_tree_list (NULL_TREE, error_mark_node)); }
  756.     ;
  757.  
  758. unary_expr:
  759.       primary %prec UNARY
  760.         {
  761.           if (TREE_CODE ($1) == TYPE_EXPR)
  762.             $$ = build_component_type_expr (C_C_D, $1, NULL_TREE, 1);
  763.           else
  764.             $$ = $1;
  765.         }
  766.     | '*' cast_expr   %prec UNARY
  767.         { $$ = build_x_indirect_ref ($2, "unary *"); }
  768.     | '&' cast_expr   %prec UNARY
  769.         { $$ = build_x_unary_op (ADDR_EXPR, $2); }
  770.     | '~' cast_expr   %prec UNARY
  771.         { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
  772.     | unop cast_expr  %prec UNARY
  773.         { $$ = build_x_unary_op ($1, $2);
  774.           if ($1 == NEGATE_EXPR && TREE_CODE ($2) == INTEGER_CST)
  775.             TREE_NEGATED_INT ($$) = 1;
  776.         }
  777.     | SIZEOF unary_expr  %prec UNARY
  778.         { if (TREE_CODE ($2) == COMPONENT_REF
  779.               && TREE_PACKED (TREE_OPERAND ($2, 1)))
  780.             error ("sizeof applied to a bit-field");
  781.           /* ANSI says arrays and functions are converted inside comma.
  782.              But we can't really convert them in build_compound_expr
  783.              because that would break commas in lvalues.
  784.              So do the conversion here if operand was a comma.  */
  785.           if (TREE_CODE ($2) == COMPOUND_EXPR
  786.               && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
  787.               || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
  788.             $2 = default_conversion ($2);
  789.           $$ = c_sizeof (TREE_TYPE ($2)); }
  790.     | SIZEOF '(' typename ')'  %prec HYPERUNARY
  791.         { $$ = c_sizeof (groktypename ($3)); }
  792.     | ALIGNOF unary_expr  %prec UNARY
  793.         { if (TREE_CODE ($2) == COMPONENT_REF
  794.               && TREE_PACKED (TREE_OPERAND ($2, 1)))
  795.             error ("`__alignof' applied to a bit-field");
  796.           if (TREE_CODE ($2) == INDIRECT_REF)
  797.             {
  798.               tree t = TREE_OPERAND ($2, 0);
  799.               tree best = t;
  800.               int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  801.               while (TREE_CODE (t) == NOP_EXPR
  802.                  && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
  803.             {
  804.               int thisalign;
  805.               t = TREE_OPERAND (t, 0);
  806.               thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  807.               if (thisalign > bestalign)
  808.                 best = t, bestalign = thisalign;
  809.             }
  810.               $$ = c_alignof (TREE_TYPE (TREE_TYPE (best)));
  811.             }
  812.           else
  813.             {
  814.               /* ANSI says arrays and fns are converted inside comma.
  815.              But we can't convert them in build_compound_expr
  816.              because that would break commas in lvalues.
  817.              So do the conversion here if operand was a comma.  */
  818.               if (TREE_CODE ($2) == COMPOUND_EXPR
  819.               && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
  820.                   || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
  821.             $2 = default_conversion ($2);
  822.               $$ = c_alignof (TREE_TYPE ($2));
  823.             }
  824.         }
  825.     | ALIGNOF '(' typename ')'  %prec HYPERUNARY
  826.         { $$ = c_alignof (groktypename ($3)); }
  827.  
  828.     | .scope new typename %prec '='
  829.         { $$ = build_new ($2, $3, NULL_TREE, $1); }
  830.     | .scope new x_typespec '(' nonnull_exprlist ')'
  831.         { $$ = build_new ($2, $3, $5, $1); }
  832.     | .scope new x_typespec LEFT_RIGHT
  833.         { $$ = build_new ($2, $3, NULL_TREE, $1); }
  834.     | .scope new typename '=' init %prec '='
  835.         { $$ = build_new ($2, $3, $5, $1); }
  836.     | .scope new '(' typename ')'
  837.         { $$ = build_new ($2, $4, NULL_TREE, $1); }
  838.     /* Unswallow a ':' which is probably meant for ?: expression.  */
  839.     | .scope new TYPENAME_COLON
  840.         { yyungetc (':', 1);
  841.           $$ = build_new ($2, $3, NULL_TREE, $1); }
  842.  
  843.     | delete cast_expr  %prec UNARY
  844.         { tree expr = stabilize_reference (convert_from_reference ($2));
  845.           tree type = TREE_TYPE (expr);
  846.  
  847.           if (integer_zerop (expr))
  848.             $$ = build1 (NOP_EXPR, void_type_node, expr);
  849.           else if (TREE_CODE (type) != POINTER_TYPE)
  850.             {
  851.               error ("non-pointer type to `delete'");
  852.               $$ = error_mark_node;
  853.               break;
  854.             }
  855.           if (TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
  856.             $$ = build_delete (type, expr, integer_three_node,
  857.                        LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, $1);
  858.           else if (! TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (type)))
  859.             $$ = build_x_delete (type, expr, $1);
  860.           else
  861.             $$ = build_delete (type, expr, integer_three_node,
  862.                        LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 0);
  863.         }
  864.     | delete '[' expr ']' cast_expr  %prec UNARY
  865.         {
  866.           tree maxindex = build_binary_op (MINUS_EXPR, $3, integer_one_node);
  867.           tree exp = stabilize_reference (convert_from_reference ($5));
  868.           tree elt_size = c_sizeof (TREE_TYPE (exp));
  869.  
  870.           if (yychar == YYEMPTY)
  871.             yychar = YYLEX;
  872.  
  873.           $$ = build_vec_delete (exp, maxindex, elt_size, NULL_TREE,
  874.                      integer_one_node, integer_two_node);
  875.         }
  876.     ;
  877.  
  878. cast_expr:
  879.       unary_expr
  880.     | '(' typename ')' expr_no_commas  %prec UNARY
  881.         { tree type = groktypename ($2);
  882.           $$ = build_c_cast (type, $4); }
  883.     | '(' typename ')' '{' initlist maybecomma '}'  %prec UNARY
  884.         { tree type = groktypename ($2);
  885.           tree init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5));
  886.           if (pedantic)
  887.             warning ("ANSI C forbids constructor-expressions");
  888.           /* Indicate that this was a GNU C constructor expression.  */
  889.           TREE_HAS_CONSTRUCTOR (init) = 1;
  890.           $$ = digest_init (type, init, 0);
  891.           if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
  892.             {
  893.               int failure = complete_array_type (type, $$, 1);
  894.               if (failure)
  895.             abort ();
  896.             }
  897.         }
  898.     ;
  899.  
  900. expr_no_commas:
  901.       cast_expr
  902.     | expr_no_commas '+' expr_no_commas
  903.         { $$ = build_x_binary_op ($2, $1, $3); }
  904.     | expr_no_commas '-' expr_no_commas
  905.         { $$ = build_x_binary_op ($2, $1, $3); }
  906.     | expr_no_commas '*' expr_no_commas
  907.         { $$ = build_x_binary_op ($2, $1, $3); }
  908.     | expr_no_commas '/' expr_no_commas
  909.         { $$ = build_x_binary_op ($2, $1, $3); }
  910.     | expr_no_commas '%' expr_no_commas
  911.         { $$ = build_x_binary_op ($2, $1, $3); }
  912.     | expr_no_commas LSHIFT expr_no_commas
  913.         { $$ = build_x_binary_op ($2, $1, $3); }
  914.     | expr_no_commas RSHIFT expr_no_commas
  915.         { $$ = build_x_binary_op ($2, $1, $3); }
  916.     | expr_no_commas ARITHCOMPARE expr_no_commas
  917.         { $$ = build_x_binary_op ($2, $1, $3); }
  918.     | expr_no_commas EQCOMPARE expr_no_commas
  919.         { $$ = build_x_binary_op ($2, $1, $3); }
  920.     | expr_no_commas MIN_MAX expr_no_commas
  921.         { $$ = build_x_binary_op ($2, $1, $3); }
  922.     | expr_no_commas '&' expr_no_commas
  923.         { $$ = build_x_binary_op ($2, $1, $3); }
  924.     | expr_no_commas '|' expr_no_commas
  925.         { $$ = build_x_binary_op ($2, $1, $3); }
  926.     | expr_no_commas '^' expr_no_commas
  927.         { $$ = build_x_binary_op ($2, $1, $3); }
  928.     | expr_no_commas ANDAND expr_no_commas
  929.         { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
  930.     | expr_no_commas OROR expr_no_commas
  931.         { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
  932.     | expr_no_commas '?' xexpr ':' expr_no_commas
  933.         { $$ = build_x_conditional_expr ($1, $3, $5); }
  934.     | expr_no_commas '=' expr_no_commas
  935.         { $$ = build_modify_expr ($1, NOP_EXPR, $3); }
  936.     | expr_no_commas ASSIGN expr_no_commas
  937.         { register tree rval;
  938.           if (rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, $1, $3, $2))
  939.             $$ = rval;
  940.           else
  941.             $$ = build_modify_expr ($1, $2, $3); }
  942.  
  943.     /* Handle general members.  */
  944.     | object '*' expr_no_commas   %prec UNARY
  945.         { $$ = build_m_component_ref ($1, build_x_indirect_ref ($3, "unary *")); }
  946.     | object '&' expr_no_commas   %prec UNARY
  947.         { $$ = build_m_component_ref ($1, build_x_unary_op (ADDR_EXPR, $3)); }
  948.     | object unop expr_no_commas  %prec UNARY
  949.         { $$ = build_m_component_ref ($1, build_x_unary_op ($2, $3)); }
  950.     | object '(' typename ')' expr_no_commas  %prec UNARY
  951.         { tree type = groktypename ($3);
  952.           $$ = build_m_component_ref ($1, build_c_cast (type, $5)); }
  953.     | object primary_no_id  %prec UNARY
  954.         { $$ = build_m_component_ref ($1, $2); }
  955.     ;
  956.  
  957. primary:
  958.     IDENTIFIER
  959.         { $$ = do_identifier ($1); }
  960.     | operator_name
  961.         {
  962.           tree op = hack_operator ($1);
  963.           if (TREE_CODE (op) != IDENTIFIER_NODE)
  964.             $$ = op;
  965.           else
  966.             {
  967.               $$ = lookup_name (op);
  968.               if ($$ == NULL_TREE)
  969.             {
  970.               error ("operator %s not defined", operator_name_string (op));
  971.               $$ = error_mark_node;
  972.             }
  973.             }
  974.         }
  975.     | CONSTANT
  976.     | string
  977.         { $$ = combine_strings ($1); }
  978.     | '(' expr ')'
  979.         { $$ = $2; }
  980.     | '(' error ')'
  981.         { $$ = error_mark_node; }
  982.     | '('
  983.         { if (current_function_decl == 0)
  984.             {
  985.               error ("braced-group within expression allowed only inside a function");
  986.               YYERROR;
  987.             }
  988.           keep_next_level ();
  989.           $<ttype>$ = expand_start_stmt_expr (); }
  990.       compstmt ')'
  991.         { tree rtl_exp;
  992.           if (pedantic)
  993.             warning ("ANSI C forbids braced-groups within expressions");
  994.           rtl_exp = expand_end_stmt_expr ($<ttype>2);
  995.           $$ = $3;
  996.           TREE_USED ($$) = 0;
  997.           /* Since the statements have side effects,
  998.              consider this volatile.  */
  999.           TREE_VOLATILE ($$) = 1;
  1000.           TREE_TYPE ($$) = TREE_TYPE (rtl_exp);
  1001.           STMT_BODY ($$) = rtl_exp; }
  1002.     | primary '(' nonnull_exprlist ')'
  1003.         { $$ = build_x_function_call ($1, $3, current_class_decl); }
  1004.     | primary LEFT_RIGHT
  1005.         { $$ = build_x_function_call ($1, NULL_TREE, current_class_decl); }
  1006.     | primary '[' expr ']'
  1007.         {
  1008.         do_array:
  1009.           {
  1010.             tree type = TREE_TYPE ($1);
  1011.             if (type == error_mark_node || $3 == error_mark_node)
  1012.               $$ = error_mark_node;
  1013.             else if (type == NULL_TREE)
  1014.               {
  1015.             /* Something has gone very wrong.  Assume we
  1016.                are mistakenly reducing an expression
  1017.                instead of a declaration.  */
  1018.             error ("parser may be lost: is there a '{' missing somewhere?");
  1019.             $$ = NULL_TREE;
  1020.               }
  1021.             else
  1022.               {
  1023.             if (TREE_CODE (type) == OFFSET_TYPE)
  1024.               type = TREE_TYPE (type);
  1025.             if (TREE_CODE (type) == REFERENCE_TYPE)
  1026.               type = TREE_TYPE (type);
  1027.  
  1028.             if (TYPE_LANG_SPECIFIC (type) &&
  1029.                 TYPE_OVERLOADS_ARRAY_REF (type))
  1030.               $$ = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, $1, $3);
  1031.             else if (TREE_CODE (type) == POINTER_TYPE
  1032.                  || TREE_CODE (type) == ARRAY_TYPE)
  1033.               $$ = build_array_ref ($1, $3);
  1034.             else
  1035.               error("[] applied to non-pointer type");
  1036.               }
  1037.           }
  1038.         }
  1039.     | object identifier_or_opname  %prec UNARY
  1040.         { $$ = build_component_ref ($1, $2, NULL_TREE, 1); }
  1041.     | object scoped_identifier identifier_or_opname %prec UNARY
  1042.         {
  1043.           tree basetype = (TREE_CODE ($2) == SCOPE_REF) ? TREE_OPERAND ($2, 1) : $2;
  1044.           if (is_aggr_typedef (basetype, 1))
  1045.             {
  1046.               basetype = TREE_TYPE (TREE_TYPE (basetype));
  1047.  
  1048.               if ($1 == error_mark_node)
  1049.             $$ = error_mark_node;
  1050.               else if (basetype_or_else (basetype, TREE_TYPE ($1)))
  1051.             $$ = build_component_ref (build_scoped_ref ($1, $2), $3, NULL_TREE, 1);
  1052.               else
  1053.             $$ = error_mark_node;
  1054.             }
  1055.           else $$ = error_mark_node;
  1056.         }
  1057.     | primary PLUSPLUS
  1058.         { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $1); }
  1059.     | primary MINUSMINUS
  1060.         { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $1); }
  1061.  
  1062.     /* C++ extensions */
  1063.     | THIS
  1064.         { if (current_class_decl)
  1065.             {
  1066. #ifdef WARNING_ABOUT_CCD
  1067.               TREE_USED (current_class_decl) = 1;
  1068. #endif
  1069.               $$ = current_class_decl;
  1070.             }
  1071.           else if (current_function_decl
  1072.                && DECL_STATIC_FUNCTION_P (current_function_decl))
  1073.             {
  1074.               error ("`this' is unavailable for static member functions");
  1075.               $$ = error_mark_node;
  1076.             }
  1077.           else
  1078.             {
  1079.               if (current_function_decl)
  1080.             error ("invalid use of `this' in non-member function");
  1081.               else
  1082.             error ("invalid use of `this' at top level");
  1083.               $$ = error_mark_node;
  1084.             }
  1085.         }
  1086.     | dummy_decl TYPE_QUAL '(' nonnull_exprlist ')'
  1087.         {
  1088.           tree type;
  1089.           tree id = $2;
  1090.  
  1091.           /* This is a C cast in C++'s `functional' notation.  */
  1092.           if ($4 == error_mark_node)
  1093.             {
  1094.               $$ = error_mark_node;
  1095.               break;
  1096.             }
  1097. #if 0
  1098.           if ($4 == NULL_TREE)
  1099.             {
  1100.               error ("cannot cast null list to type `%s'",
  1101.                      IDENTIFIER_POINTER (TYPE_NAME ($2)));
  1102.               $$ = error_mark_node;
  1103.               break;
  1104.             }
  1105. #endif
  1106.           if (type == error_mark_node)
  1107.             $$ = error_mark_node;
  1108.           else
  1109.             {
  1110.               if (id == ridpointers[(int) RID_CONST])
  1111.                 type = build_type_variant (integer_type_node, 1, 0);
  1112.               else if (id == ridpointers[(int) RID_VOLATILE])
  1113.                 type = build_type_variant (integer_type_node, 0, 1);
  1114.               else if (id == ridpointers[(int) RID_FRIEND])
  1115.                 {
  1116.                   error ("cannot cast expression to `friend' type");
  1117.                   $$ = error_mark_node;
  1118.                   break;
  1119.                 }
  1120.               else abort ();
  1121.               $$ = build_c_cast (type, build_compound_expr ($4));
  1122.             }
  1123.         }
  1124.     | x_typespec '(' nonnull_exprlist ')'
  1125.         { $$ = build_functional_cast ($1, $3); }
  1126.     | x_typespec LEFT_RIGHT
  1127.         { $$ = build_functional_cast ($1, NULL_TREE); }
  1128.     | SCOPE IDENTIFIER
  1129.         {
  1130.         do_scoped_identifier:
  1131.           $$ = IDENTIFIER_GLOBAL_VALUE ($2);
  1132.           if (yychar == YYEMPTY)
  1133.             yychar = YYLEX;
  1134.           if (! $$)
  1135.             {
  1136.               if (yychar == '(' || yychar == LEFT_RIGHT)
  1137.             {
  1138.               $$ = implicitly_declare ($2);
  1139.             }
  1140.               else
  1141.             {
  1142.               if (IDENTIFIER_GLOBAL_VALUE ($2) != error_mark_node)
  1143.                 error ("undeclared variable `%s' (first use here)",
  1144.                    IDENTIFIER_POINTER ($2));
  1145.               $$ = error_mark_node;
  1146.               /* Prevent repeated error messages.  */
  1147.               IDENTIFIER_GLOBAL_VALUE ($2) = error_mark_node;
  1148.             }
  1149.             }
  1150.           else if (TREE_CODE ($$) == CONST_DECL)
  1151.             $$ = DECL_INITIAL ($$);
  1152.           if (! TREE_USED ($$))
  1153.             {
  1154.               if (TREE_EXTERNAL ($$))
  1155.             assemble_external ($$);
  1156.               TREE_USED ($$) = 1;
  1157.             }
  1158.         }
  1159.     | SCOPE operator_name
  1160.         {
  1161.           $2 = hack_operator ($2);
  1162.           if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1163.             goto do_scoped_identifier;
  1164.         do_scoped_operator:
  1165.           $$ = $2;
  1166.         }
  1167.     | scoped_identifier identifier_or_opname  %prec HYPERUNARY
  1168.         { $$ = build_offset_ref ($1, $2); }
  1169.     | scoped_identifier identifier_or_opname '(' nonnull_exprlist ')'
  1170.         { $$ = build_member_call ($1, $2, $4); }
  1171.     | scoped_identifier identifier_or_opname LEFT_RIGHT
  1172.         { $$ = build_member_call ($1, $2, NULL_TREE); }
  1173.  
  1174.     | object identifier_or_opname '(' nonnull_exprlist ')'
  1175.         { $$ = build_method_call ($1, $2, $4, NULL_TREE,
  1176.                       (LOOKUP_NORMAL|LOOKUP_AGGR)); }
  1177.     | object identifier_or_opname LEFT_RIGHT
  1178.         { $$ = build_method_call ($1, $2, NULL_TREE, NULL_TREE,
  1179.                       (LOOKUP_NORMAL|LOOKUP_AGGR)); }
  1180.     | object scoped_identifier identifier_or_opname '(' nonnull_exprlist ')'
  1181.         { $$ = build_scoped_method_call ($1, $2, $3, $5); }
  1182.     | object scoped_identifier identifier_or_opname LEFT_RIGHT
  1183.         { $$ = build_scoped_method_call ($1, $2, $3, NULL_TREE); }
  1184.  
  1185.     /* Objective-C extensions */
  1186.     | objcmessageexpr
  1187.         { $$ = build_message_expr ($1); }
  1188.     | objcselectorexpr
  1189.         { $$ = build_selector_expr ($1); }
  1190.     | objcprotocolexpr
  1191.         { $$ = build_protocol_expr ($1); }
  1192.     | objcencodeexpr
  1193.         { $$ = build_encode_expr ($1); }
  1194.     | objc_string
  1195.         { $$ = build_objc_string_object ($1); }
  1196.     ;
  1197.  
  1198. primary_no_id:
  1199.       '(' expr ')'
  1200.         { $$ = $2; }
  1201.     | '(' error ')'
  1202.         { $$ = error_mark_node; }
  1203.     | '('
  1204.         { if (current_function_decl == 0)
  1205.             {
  1206.               error ("braced-group within expression allowed only inside a function");
  1207.               YYERROR;
  1208.             }
  1209.           $<ttype>$ = expand_start_stmt_expr (); }
  1210.       compstmt ')'
  1211.         { if (pedantic)
  1212.             warning ("ANSI C forbids braced-groups within expressions");
  1213.           $$ = expand_end_stmt_expr ($<ttype>2); }
  1214.     | primary_no_id '(' nonnull_exprlist ')'
  1215.         { $$ = build_x_function_call ($1, $3, current_class_decl); }
  1216.     | primary_no_id LEFT_RIGHT
  1217.         { $$ = build_x_function_call ($1, NULL_TREE, current_class_decl); }
  1218.     | primary_no_id '[' expr ']'
  1219.         { goto do_array; }
  1220.     | primary_no_id PLUSPLUS
  1221.         { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $1); }
  1222.     | primary_no_id MINUSMINUS
  1223.         { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $1); }
  1224.     | SCOPE IDENTIFIER
  1225.         { goto do_scoped_identifier; }
  1226.     | SCOPE operator_name
  1227.         { $2 = hack_operator ($2);
  1228.           if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1229.             goto do_scoped_identifier;
  1230.           goto do_scoped_operator;
  1231.         }
  1232.     ;
  1233.  
  1234. new:      NEW
  1235.         { $$ = NULL_TREE; }
  1236.     | NEW '{' nonnull_exprlist '}'
  1237.         { $$ = $3; }
  1238.     | NEW DYNAMIC  %prec EMPTY
  1239.         { $$ = void_type_node; }
  1240.     | NEW DYNAMIC '(' string ')'
  1241.         { $$ = combine_strings ($4); }
  1242.     ;
  1243.  
  1244. .scope:
  1245.     /* empty  */
  1246.         { $$ = 0; }
  1247.     | SCOPE
  1248.         { $$ = 1; }
  1249.     ;
  1250.  
  1251. delete:      DELETE
  1252.         { $$ = NULL_TREE; }
  1253.     | SCOPE delete
  1254.         { if ($2)
  1255.             error ("extra `::' before `delete' ignored");
  1256.           $$ = error_mark_node;
  1257.         }
  1258.     ;
  1259.  
  1260. /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
  1261. string:
  1262.       STRING
  1263.     | string STRING
  1264.         { $$ = chainon ($1, $2); }
  1265.     ;
  1266.  
  1267. /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
  1268.    onto it.  */
  1269. objc_string:
  1270.       OBJC_STRING
  1271.     | objc_string OBJC_STRING
  1272.         { $$ = chainon ($1, $2); }
  1273.     ;
  1274.  
  1275. nodecls:
  1276.       /* empty */
  1277.         {
  1278.           if (! current_function_parms_stored)
  1279.             store_parm_decls ();
  1280.           setup_vtbl_ptr ();
  1281.         }
  1282.     ;
  1283.  
  1284. object:      primary '.'
  1285.         {
  1286.           if ($1 == error_mark_node)
  1287.             $$ = error_mark_node;
  1288.           else
  1289.             {
  1290.               tree type = TREE_TYPE ($1);
  1291.  
  1292.               if (IS_AGGR_TYPE (type)
  1293.               || (TREE_CODE (type) == REFERENCE_TYPE
  1294.                   && IS_AGGR_TYPE (TREE_TYPE (type))))
  1295.             $$ = $1;
  1296.               else
  1297.             {
  1298.               error ("object in '.' expression is not of aggregate type");
  1299.               $$ = error_mark_node;
  1300.             }
  1301.             }
  1302.         }
  1303.     | primary POINTSAT
  1304.         {
  1305.           $$ = build_x_arrow ($1);
  1306.         }
  1307.     ;
  1308.  
  1309. decl:
  1310.       typed_declspecs initdecls ';'
  1311.         {
  1312.           resume_momentary ($2);
  1313.           note_got_semicolon ($1);
  1314.         }
  1315.     /* Normal case: make this fast.  */
  1316.     | typed_declspecs declarator ';'
  1317.         { tree d;
  1318.           int yes = suspend_momentary ();
  1319.           d = start_decl ($2, $1, 0, NULL_TREE);
  1320.           finish_decl (d, NULL_TREE, NULL_TREE);
  1321.           resume_momentary (yes);
  1322.           note_got_semicolon ($1);
  1323.         }
  1324.     | declmods notype_initdecls ';'
  1325.         { resume_momentary ($2); }
  1326.     /* Normal case: make this fast.  */
  1327.     | declmods declarator ';'
  1328.         { tree d;
  1329.           int yes = suspend_momentary ();
  1330.           d = start_decl ($2, $1, 0, NULL_TREE);
  1331.           finish_decl (d, NULL_TREE, NULL_TREE);
  1332.           resume_momentary (yes);
  1333.         }
  1334.     | typed_declspecs ';'
  1335.         {
  1336.           shadow_tag ($1);
  1337.           note_got_semicolon ($1);
  1338.         }
  1339.     | declmods ';'
  1340.         { warning ("empty declaration"); }
  1341.     ;
  1342.  
  1343. /* Any kind of declarator (thus, all declarators allowed
  1344.    after an explicit typespec).  */
  1345.  
  1346. declarator:
  1347.       after_type_declarator
  1348.     | notype_declarator
  1349.     ;
  1350.  
  1351. /* Declspecs which contain at least one type specifier or typedef name.
  1352.    (Just `const' or `volatile' is not enough.)
  1353.    A typedef'd name following these is taken as a name to be declared.  */
  1354.  
  1355. typed_declspecs:
  1356.       x_typespec
  1357.         { $$ = list_hash_lookup_or_cons ($1); }
  1358.     | declmods typespec
  1359.         { $$ = hash_tree_chain ($2, $1); }
  1360.     | x_typespec reserved_declspecs
  1361.         { $$ = hash_tree_chain ($1, $2); }
  1362.     | declmods typespec reserved_declspecs
  1363.         { $$ = hash_tree_chain ($2, hash_chainon ($3, $1)); }
  1364.     ;
  1365.  
  1366. reserved_declspecs:  /* empty
  1367.         { $$ = NULL_TREE; } */
  1368.       typespecqual_reserved
  1369.         { $$ = build_decl_list (NULL_TREE, $1); }
  1370.     | SCSPEC
  1371.         { $$ = build_decl_list (NULL_TREE, $1); }
  1372.     | reserved_declspecs typespecqual_reserved
  1373.         { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
  1374.     | reserved_declspecs SCSPEC
  1375.         { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
  1376.     ;
  1377.  
  1378. /* List of just storage classes and type modifiers.
  1379.    A declaration can start with just this, but then it cannot be used
  1380.    to redeclare a typedef-name.  */
  1381.  
  1382. declmods:
  1383.       dummy_decl TYPE_QUAL
  1384.         { $$ = IDENTIFIER_AS_LIST ($2); }
  1385.     | dummy_decl SCSPEC
  1386.         { $$ = IDENTIFIER_AS_LIST ($2); }
  1387.     | declmods TYPE_QUAL
  1388.         { $$ = hash_tree_chain ($2, $1); }
  1389.     | declmods SCSPEC
  1390.         { $$ = hash_tree_chain ($2, $1); }
  1391.     ;
  1392.  
  1393.  
  1394. /* Used instead of declspecs where storage classes are not allowed
  1395.    (that is, for typenames and structure components).
  1396.  
  1397.    C++ can takes storage classes for structure components.
  1398.    Don't accept a typedef-name if anything but a modifier precedes it.  */
  1399.  
  1400. typed_typespecs:
  1401.       x_typespec  %prec EMPTY
  1402.         { $$ = build_decl_list_1 ($1); }
  1403.     | nonempty_type_quals typespec
  1404.         { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
  1405.     | x_typespec reserved_typespecquals
  1406.         { $$ = decl_tree_cons (NULL_TREE, $1, $2); }
  1407.     | nonempty_type_quals typespec reserved_typespecquals
  1408.         { $$ = decl_tree_cons (NULL_TREE, $2, hash_chainon ($3, $1)); }
  1409.     ;
  1410.  
  1411. reserved_typespecquals:
  1412.       typespecqual_reserved
  1413.         { $$ = build_decl_list_1 ($1); }
  1414.     | reserved_typespecquals typespecqual_reserved
  1415.         { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
  1416.     ;
  1417.  
  1418. /* A typespec (but not a type qualifier).
  1419.    Once we have seen one of these in a declaration,
  1420.    if a typedef name appears then it is being redeclared.  */
  1421.  
  1422. typespec: TYPESPEC
  1423.     | structsp
  1424.     | TYPENAME
  1425.         | CLASSNAME protocolrefs
  1426.         { $$ = get_static_reference ($1, $2); }
  1427.     | OBJECTNAME protocolrefs
  1428.             { $$ = get_object_reference ($2); }
  1429.     | TYPEOF '(' expr ')'
  1430.         { $$ = TREE_TYPE ($3);
  1431.           if (pedantic)
  1432.             warning ("ANSI C forbids `typeof'"); }
  1433.     | TYPEOF '(' typename ')'
  1434.         { $$ = groktypename ($3);
  1435.           if (pedantic)
  1436.             warning ("ANSI C forbids `typeof'"); }
  1437.     ;
  1438.  
  1439. /* A typespec that is a reserved word, or a type qualifier.  */
  1440.  
  1441. typespecqual_reserved: TYPESPEC
  1442.     | TYPE_QUAL
  1443.     | structsp
  1444.     ;
  1445.  
  1446. x_typespec:
  1447.       dummy_decl TYPESPEC
  1448.         { $$ = $2; }
  1449.     | dummy_decl structsp
  1450.         { $$ = $2; }
  1451.     | dummy_decl TYPENAME
  1452.         { $$ = $2; }
  1453.         | dummy_decl CLASSNAME protocolrefs
  1454.         { $$ = get_static_reference ($2, $3); }
  1455.     | dummy_decl OBJECTNAME protocolrefs
  1456.             { $$ = get_object_reference ($3); }
  1457.     | dummy_decl TYPEOF '(' expr ')'
  1458.         { $$ = TREE_TYPE ($4);
  1459.           if (pedantic)
  1460.             warning ("ANSI C forbids `typeof'") }
  1461.     | dummy_decl TYPEOF '(' typename ')'
  1462.         { $$ = groktypename ($4);
  1463.           if (pedantic)
  1464.             warning ("ANSI C forbids `typeof'") }
  1465.     ;
  1466.  
  1467. initdecls:
  1468.       initdcl0
  1469.     | initdecls ',' initdcl
  1470.     ;
  1471.  
  1472. notype_initdecls:
  1473.       notype_initdcl0
  1474.     | notype_initdecls ',' initdcl
  1475.     ;
  1476.  
  1477. maybeasm:
  1478.       /* empty */
  1479.         { $$ = NULL_TREE; }
  1480.     | ASM '(' string ')'
  1481.         { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  1482.           $$ = $3;
  1483.           if (pedantic)
  1484.             warning ("ANSI C forbids use of `asm' keyword");
  1485.         }
  1486.     ;
  1487.  
  1488. initdcl0:
  1489.       declarator maybe_raises maybeasm maybe_attribute '='
  1490.         { current_declspecs = $<ttype>0;
  1491.           $<itype>5 = suspend_momentary ();
  1492.           $<ttype>$ = start_decl ($1, current_declspecs, 1, $2); }
  1493.       init
  1494. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1495.         { finish_decl ($<ttype>6, $7, $3);
  1496.           $$ = $<itype>5; }
  1497.     | declarator maybe_raises maybeasm maybe_attribute
  1498.         { tree d;
  1499.           current_declspecs = $<ttype>0;
  1500.           $$ = suspend_momentary ();
  1501.           d = start_decl ($1, current_declspecs, 0, $2);
  1502.           finish_decl (d, NULL_TREE, $3); }
  1503.     ;
  1504.  
  1505. initdcl:
  1506.       declarator maybe_raises maybeasm maybe_attribute '='
  1507.         { $<ttype>$ = start_decl ($1, current_declspecs, 1, $2); }
  1508.       init
  1509. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1510.         { finish_decl ($<ttype>6, $7, $3); }
  1511.     | declarator maybe_raises maybeasm maybe_attribute
  1512.         { tree d = start_decl ($1, current_declspecs, 0, $2);
  1513.           finish_decl (d, NULL_TREE, $3); }
  1514.     ;
  1515.  
  1516. notype_initdcl0:
  1517.       notype_declarator maybe_raises maybeasm maybe_attribute '='
  1518.         { current_declspecs = $<ttype>0;
  1519.           $<itype>5 = suspend_momentary ();
  1520.           $<ttype>$ = start_decl ($1, current_declspecs, 1, $2); }
  1521.       init
  1522. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1523.         { finish_decl ($<ttype>6, $7, $3);
  1524.           $$ = $<itype>5; }
  1525.     | notype_declarator maybe_raises maybeasm maybe_attribute
  1526.         { tree d;
  1527.           current_declspecs = $<ttype>0;
  1528.           $$ = suspend_momentary ();
  1529.           d = start_decl ($1, current_declspecs, 0, $2);
  1530.           finish_decl (d, NULL_TREE, $3); }
  1531.     ;
  1532.  
  1533. /* the * rules are dummies to accept the Apollo extended syntax
  1534.    so that the header files compile. */
  1535. maybe_attribute:
  1536.     /* empty */
  1537.     { $$ = NULL_TREE; }
  1538.     | ATTRIBUTE '(' '(' attribute_list ')' ')'
  1539.         { $$ = $4; }
  1540.     ;
  1541.  
  1542. attribute_list
  1543.     : attrib
  1544.     | attribute_list ',' attrib
  1545.     ;
  1546.  
  1547. attrib
  1548.     : IDENTIFIER
  1549.     { warning ("`%s' attribute directive ignored",
  1550.            IDENTIFIER_POINTER ($1));
  1551.       $$ = $1; }
  1552.     | IDENTIFIER '(' CONSTANT ')'
  1553.     { /* if not "aligned(1)", then issue warning */
  1554.       if (strcmp (IDENTIFIER_POINTER ($1), "aligned") != 0
  1555.           || TREE_CODE ($3) != INTEGER_CST
  1556.           || TREE_INT_CST_LOW ($3) != 1)
  1557.         warning ("`%s' attribute directive ignored",
  1558.              IDENTIFIER_POINTER ($1));
  1559.       $$ = $1; }
  1560.     | IDENTIFIER '(' identifiers ')'
  1561.     { warning ("`%s' attribute directive ignored",
  1562.            IDENTIFIER_POINTER ($1));
  1563.       $$ = $1; }
  1564.     ;
  1565.  
  1566. identifiers:
  1567.       IDENTIFIER
  1568.         { }
  1569.     | identifiers ',' IDENTIFIER
  1570.         { }
  1571.     ;
  1572.  
  1573. init:
  1574.       expr_no_commas %prec '='
  1575.     | '{' '}'
  1576.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  1577.           TREE_HAS_CONSTRUCTOR ($$) = 1;
  1578.           if (pedantic)
  1579.             warning ("ANSI C forbids empty initializer braces"); }
  1580.     | '{' initlist '}'
  1581.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
  1582.           TREE_HAS_CONSTRUCTOR ($$) = 1; }
  1583.     | '{' initlist ',' '}'
  1584.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
  1585.           TREE_HAS_CONSTRUCTOR ($$) = 1; }
  1586.     | error
  1587.         { $$ = NULL_TREE; }
  1588.     ;
  1589.  
  1590. /* This chain is built in reverse order,
  1591.    and put in forward order where initlist is used.  */
  1592. initlist:
  1593.       init
  1594.         { $$ = build_tree_list (NULL_TREE, $1); }
  1595.     | initlist ',' init
  1596.         { $$ = tree_cons (NULL_TREE, $3, $1); }
  1597.     ;
  1598.  
  1599. structsp:
  1600.       ENUM identifier '{'
  1601.         { $<itype>3 = suspend_momentary ();
  1602.           $$ = start_enum ($2); }
  1603.       enumlist maybecomma_warn '}'
  1604.         { $$ = finish_enum ($<ttype>4, $5);
  1605.           resume_momentary ($<itype>3);
  1606.           check_for_missing_semicolon ($<ttype>4); }
  1607.     | ENUM identifier '{' '}'
  1608.         { $$ = finish_enum (start_enum ($2), NULL_TREE);
  1609.           check_for_missing_semicolon ($$); }
  1610.     | ENUM '{'
  1611.         { $<itype>2 = suspend_momentary ();
  1612.           $$ = start_enum (make_anon_name ()); }
  1613.       enumlist maybecomma_warn '}'
  1614.         { $$ = finish_enum ($<ttype>3, $4);
  1615.           resume_momentary ($<itype>1);
  1616.           check_for_missing_semicolon ($<ttype>3); }
  1617.     | ENUM '{' '}'
  1618.         { $$ = finish_enum (start_enum (make_anon_name()), NULL_TREE);
  1619.           check_for_missing_semicolon ($$); }
  1620.     | ENUM identifier
  1621.         { $$ = xref_tag (enum_type_node, $2, NULL_TREE); }
  1622.  
  1623.     /* C++ extensions, merged with C to avoid shift/reduce conflicts */
  1624.     | class_head LC opt.component_decl_list '}'
  1625.         {
  1626.           if (TREE_CODE ($1) == ENUMERAL_TYPE)
  1627.             $$ = $1;
  1628.           else if (CLASSTYPE_DECLARED_EXCEPTION ($1))
  1629.             $$ = finish_exception ($1, $3);
  1630.           else
  1631.             $$ = finish_struct ($1, $3, 0, 0);
  1632.             
  1633.           if ($2 & 1)
  1634.             resume_temporary_allocation ();
  1635.           if ($2 & 2)
  1636.             resume_momentary (1);
  1637.           check_for_missing_semicolon ($$);
  1638.         }
  1639.     | class_head LC opt.component_decl_list '}' ';'
  1640.         { if (TREE_CODE ($1) == ENUMERAL_TYPE)
  1641.             $$ = $1;
  1642.           else if (CLASSTYPE_DECLARED_EXCEPTION ($1))
  1643.             warning ("empty exception declaration\n");
  1644.           else
  1645.             $$ = finish_struct ($1, $3, 1, 1);
  1646.           if ($2 & 1)
  1647.             resume_temporary_allocation ();
  1648.           if ($2 & 2)
  1649.             resume_momentary (1);
  1650.           note_got_semicolon ($$);
  1651.           yyungetc (';', 0); }
  1652.     | class_head  %prec EMPTY
  1653.         { $$ = $1; }
  1654.     ;
  1655.  
  1656. maybecomma:
  1657.       /* empty */
  1658.     | ','
  1659.     ;
  1660.  
  1661. maybecomma_warn:
  1662.       /* empty */
  1663.     | ','
  1664.         { if (pedantic) warning ("comma at end of enumerator list"); }
  1665.     ;
  1666.  
  1667. aggr:      AGGR
  1668.         { $$ = $1; }
  1669.     | DYNAMIC AGGR
  1670.         { $$ = build_tree_list (NULL_TREE, $2); }
  1671.     | DYNAMIC '(' string ')' AGGR
  1672.         { $$ = build_tree_list ($3, $5); }
  1673.     | aggr SCSPEC
  1674.         { error ("storage class specifier `%s' not allow after struct or class", IDENTIFIER_POINTER ($2));
  1675.         }
  1676.     | aggr TYPESPEC
  1677.         { error ("type specifier `%s' not allow after struct or class", IDENTIFIER_POINTER ($2));
  1678.         }
  1679.     | aggr TYPE_QUAL
  1680.         { error ("type qualifier `%s' not allow after struct or class", IDENTIFIER_POINTER ($2));
  1681.         }
  1682.     | aggr AGGR
  1683.         { error ("no body nor ';' separates two class, struct or union declarations");
  1684.         }
  1685.  
  1686. class_head:
  1687.       aggr  %prec EMPTY
  1688.         { $$ = xref_tag ($1, make_anon_name (), NULL_TREE); }
  1689.     | aggr identifier  %prec EMPTY
  1690.         { $$ = xref_tag ($1, $2, NULL_TREE); }
  1691.     | aggr IDENTIFIER ':' base_class_list  %prec EMPTY
  1692.         { $$ = xref_tag ($1, $2, $4); }
  1693.     | aggr TYPENAME_COLON  %prec EMPTY
  1694.         { yyungetc (':', 1);
  1695.           $$ = xref_tag ($1, $2, NULL_TREE); }
  1696.     | aggr TYPENAME_COLON base_class_list  %prec EMPTY
  1697.         { $$ = xref_tag ($1, $2, $3); }
  1698.     ;
  1699.  
  1700. base_class_list:
  1701.       identifier
  1702.         { if (! is_aggr_typedef ($1, 1))
  1703.             $$ = NULL_TREE;
  1704.           else $$ = build_tree_list ((tree)visibility_default, $1); }
  1705.     | base_class_visibility_list identifier
  1706.         { if (! is_aggr_typedef ($2, 1))
  1707.             $$ = NULL_TREE;
  1708.           else $$ = build_tree_list ($1, $2); }
  1709.     | base_class_list ',' identifier
  1710.         { if (! is_aggr_typedef ($3, 1))
  1711.             $$ = NULL_TREE;
  1712.           else $$ = chainon ($1, build_tree_list ((tree)visibility_default, $3)); }
  1713.     | base_class_list ',' base_class_visibility_list identifier
  1714.         { if (! is_aggr_typedef ($4, 1))
  1715.             $$ = NULL_TREE;
  1716.           else $$ = chainon ($1, build_tree_list ($3, $4)); }
  1717.     ;
  1718.  
  1719. base_class_visibility_list:
  1720.       PUBLIC
  1721.         { $$ = (tree)visibility_public; }
  1722.     | PRIVATE
  1723.         { $$ = (tree)visibility_private; }
  1724.     | SCSPEC
  1725.         { if ($1 != ridpointers[(int)RID_VIRTUAL])
  1726.             sorry ("non-virtual visibility");
  1727.           $$ = (tree)visibility_default_virtual; }
  1728.     | base_class_visibility_list PUBLIC
  1729.         { if ($1 == (tree)visibility_private)
  1730.             error ("base class cannot be public and private");
  1731.           else if ($1 == (tree)visibility_default_virtual)
  1732.             $$ = (tree)visibility_public_virtual; }
  1733.     | base_class_visibility_list PRIVATE
  1734.         { if ($1 == (tree)visibility_public)
  1735.             error ("base class cannot be private and public");
  1736.           else if ($1 == (tree)visibility_default_virtual)
  1737.             $$ = (tree)visibility_private_virtual; }
  1738.     | base_class_visibility_list SCSPEC
  1739.         { if ($2 != ridpointers[(int)RID_VIRTUAL])
  1740.             sorry ("non-virtual visibility");
  1741.           if ($1 == (tree)visibility_public)
  1742.             $$ = (tree)visibility_public_virtual;
  1743.           else if ($1 == (tree)visibility_private)
  1744.             $$ = (tree)visibility_private_virtual; }
  1745.     ;
  1746.  
  1747. LC: '{'
  1748.         { int temp = allocation_temporary_p ();
  1749.           int momentary = suspend_momentary ();
  1750.           if (temp)
  1751.             end_temporary_allocation ();
  1752.           $$ = (momentary << 1) | temp;
  1753.           if (! IS_AGGR_TYPE ($<ttype>0))
  1754.             {
  1755.               $<ttype>0 = make_lang_type (RECORD_TYPE);
  1756.               TYPE_NAME ($<ttype>0) = get_identifier ("erroneous type");
  1757.             }
  1758.           pushclass ($<ttype>0, 0); }
  1759.  
  1760. opt.component_decl_list:
  1761.     /* empty */
  1762.         { $$ = NULL_TREE; }
  1763.     | component_decl_list
  1764.         { $$ = build_tree_list ((tree)visibility_default, $1); }
  1765.     | opt.component_decl_list PUBLIC ':' component_decl_list
  1766.         { $$ = chainon ($1, build_tree_list ((tree)visibility_public, $4)); }
  1767.     | opt.component_decl_list PRIVATE ':' component_decl_list
  1768.         { $$ = chainon ($1, build_tree_list ((tree)visibility_private, $4)); }
  1769.     | opt.component_decl_list PROTECTED ':' component_decl_list
  1770.         { $$ = chainon ($1, build_tree_list ((tree)visibility_protected, $4)); }
  1771.     | opt.component_decl_list PUBLIC ':'
  1772.     | opt.component_decl_list PRIVATE ':'
  1773.     | opt.component_decl_list PROTECTED ':'
  1774.     ;
  1775.  
  1776. component_decl_list:
  1777.       component_decl
  1778.         { if ($1 == void_type_node) $$ = NULL_TREE; }
  1779.     | component_decl_list component_decl
  1780.         { if ($2 != NULL_TREE && $2 != void_type_node)
  1781.             $$ = chainon ($1, $2); }
  1782.     | component_decl_list ';'
  1783.         { if (pedantic)
  1784.             warning ("extra semicolon in struct or union specified"); }
  1785.     /* foo(sizeof(struct{ @defs(ClassName)})); */
  1786.     | DEFS '(' CLASSNAME ')'
  1787.         {
  1788.           tree interface = lookup_interface ($3);
  1789.  
  1790.           if (interface)
  1791.             $$ = get_class_ivars (interface);
  1792.           else
  1793.             {
  1794.               error ("Cannot find interface declaration for `%s'",
  1795.                  IDENTIFIER_POINTER ($3));
  1796.               $$ = error_mark_node;
  1797.             }
  1798.         }
  1799.     ;
  1800.  
  1801. component_decl:
  1802.       typed_declspecs components ';'
  1803.         {
  1804.         do_components:
  1805.           if ($2 == void_type_node)
  1806.             /* We just got some friends.
  1807.                They have been recorded elsewhere.  */
  1808.             $$ = NULL_TREE;
  1809.           else if ($2 == NULL_TREE)
  1810.             {
  1811.               tree t = groktypename (build_decl_list ($1, NULL_TREE));
  1812.               if (t == NULL_TREE)
  1813.             {
  1814.               error ("error in component specification");
  1815.               $$ = NULL_TREE;
  1816.             }
  1817.               else if (TREE_CODE (t) == UNION_TYPE)
  1818.             {
  1819.               /* handle anonymous unions */
  1820.               if (CLASSTYPE_METHOD_VEC (t))
  1821.                 sorry ("methods in anonymous unions");
  1822.               $$ = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
  1823.               DECL_ANON_UNION_ELEM ($$) = 1;
  1824.             }
  1825.               else if (TREE_CODE (t) == ENUMERAL_TYPE)
  1826.             $$ = grok_enum_decls (t, NULL_TREE);
  1827.               else if (TREE_CODE (t) == RECORD_TYPE)
  1828.             {
  1829.               if (TYPE_LANG_SPECIFIC (t)
  1830.                   && CLASSTYPE_DECLARED_EXCEPTION (t))
  1831.                 shadow_tag ($1);
  1832.               $$ = NULL_TREE;
  1833.             }
  1834.               else if (t != void_type_node)
  1835.             {
  1836.               error ("empty component declaration");
  1837.               $$ = NULL_TREE;
  1838.             }
  1839.               else $$ = NULL_TREE;
  1840.             }
  1841.           else
  1842.             {
  1843.               tree t = TREE_TYPE ($2);
  1844.               if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL (t))
  1845.             $$ = grok_enum_decls (t, $2);
  1846.               else
  1847.             $$ = $2;
  1848.             }
  1849.           end_exception_decls ();
  1850.         }
  1851.     | typed_declspecs '(' parmlist ')' ';'
  1852.         { $$ = groktypefield ($1, $3); }
  1853.     | typed_declspecs '(' parmlist ')' '}'
  1854.         { error ("missing ';' before right brace");
  1855.           yyungetc ('}', 0);
  1856.           $$ = groktypefield ($1, $3); }
  1857.     | typed_declspecs LEFT_RIGHT ';'
  1858.         { $$ = groktypefield ($1, empty_parms ()); }
  1859.     | typed_declspecs LEFT_RIGHT '}'
  1860.         { error ("missing ';' before right brace");
  1861.           yyungetc ('}', 0);
  1862.           $$ = groktypefield ($1, empty_parms ()); }
  1863.     | declmods components ';'
  1864.         { goto do_components; }
  1865.     /* Normal case: make this fast.  */
  1866.     | declmods declarator ';'
  1867.         { $$ = grokfield ($2, $1, 0, 0, 0, 0); }
  1868.     | declmods components '}'
  1869.         { error ("missing ';' before right brace");
  1870.           yyungetc ('}', 0);
  1871.           goto do_components; }
  1872.     | declmods '(' parmlist ')' ';'
  1873.         { $$ = groktypefield ($1, $3); }
  1874.     | declmods '(' parmlist ')' '}'
  1875.         { error ("missing ';' before right brace");
  1876.           yyungetc ('}', 0);
  1877.           $$ = groktypefield ($1, $3); }
  1878.     | declmods LEFT_RIGHT ';'
  1879.         { $$ = groktypefield ($1, empty_parms ()); }
  1880.     | declmods LEFT_RIGHT '}'
  1881.         { error ("missing ';' before right brace");
  1882.           yyungetc ('}', 0);
  1883.           $$ = groktypefield ($1, empty_parms ()); }
  1884.     | ':' expr_no_commas ';'
  1885.         { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
  1886.     | ':' expr_no_commas '}'
  1887.         { error ("missing ';' before right brace");
  1888.           yyungetc ('}', 0);
  1889.           $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
  1890.     | error
  1891.         { $$ = NULL_TREE; }
  1892.  
  1893.     /* C++: handle constructors, destructors and inline functions */
  1894.     /* note that INLINE is like a TYPESPEC */
  1895.     | fn.def2 ':' /* base_init compstmt */
  1896.         { $$ = finish_method ($1); }
  1897.     | fn.def2 '{' /* nodecls compstmt */
  1898.         { $$ = finish_method ($1); }
  1899.     | dummy_decl notype_declarator maybe_raises ';'
  1900.         { $$ = grokfield ($2, NULL_TREE, $3, NULL_TREE, NULL_TREE); }
  1901.     | dummy_decl notype_declarator maybe_raises '}'
  1902.         { error ("missing ';' before right brace");
  1903.           yyungetc ('}', 0);
  1904.           $$ = grokfield ($2, NULL_TREE, $3, NULL_TREE, NULL_TREE); }
  1905.     ;
  1906.  
  1907. components:
  1908.       /* empty: possibly anonymous */
  1909.         { $$ = NULL_TREE; }
  1910.     | component_declarator0
  1911.     | components ',' component_declarator
  1912.         {
  1913.           /* In this context, void_type_node encodes
  1914.              friends.  They have been recorded elsewhere.  */
  1915.           if ($1 == void_type_node)
  1916.             $$ = $3;
  1917.           else
  1918.             $$ = chainon ($1, $3);
  1919.         }
  1920.     ;
  1921.  
  1922. component_declarator0:
  1923.       declarator maybe_raises maybeasm opt.init
  1924.         { current_declspecs = $<ttype>0;
  1925.           $$ = grokfield ($1, current_declspecs, $2, $4, $3); }
  1926.     | IDENTIFIER ':' expr_no_commas
  1927.         { current_declspecs = $<ttype>0;
  1928.           $$ = grokbitfield ($1, current_declspecs, $3); }
  1929.     | TYPENAME_COLON expr_no_commas
  1930.         { current_declspecs = $<ttype>0;
  1931.           $$ = grokbitfield ($1, current_declspecs, $2); }
  1932.     | ':' expr_no_commas
  1933.         { current_declspecs = $<ttype>0;
  1934.           $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
  1935.     ;
  1936.  
  1937. component_declarator:
  1938.       declarator maybe_raises maybeasm opt.init
  1939.         { $$ = grokfield ($1, current_declspecs, $2, $4, $3); }
  1940.     | IDENTIFIER ':' expr_no_commas
  1941.         { $$ = grokbitfield ($1, current_declspecs, $3); }
  1942.     | TYPENAME_COLON expr_no_commas
  1943.         { $$ = grokbitfield ($1, current_declspecs, $2); }
  1944.     | ':' expr_no_commas
  1945.         { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
  1946.     ;
  1947.  
  1948. /* We chain the enumerators in reverse order.
  1949.    Because of the way enums are built, the order is
  1950.    insignificant.  Take advantage of this fact.  */
  1951.  
  1952. enumlist:
  1953.       enumerator
  1954.     | enumlist ',' enumerator
  1955.         { TREE_CHAIN ($3) = $1; $$ = $3; }
  1956.     ;
  1957.  
  1958. enumerator:
  1959.       identifier
  1960.         { $$ = build_enumerator ($1, NULL_TREE); }
  1961.     | identifier '=' expr_no_commas
  1962.         { $$ = build_enumerator ($1, $3); }
  1963.     ;
  1964.  
  1965. typename:
  1966.       typed_typespecs absdcl
  1967.         { $$ = build_decl_list ($1, $2); }
  1968.     | nonempty_type_quals absdcl
  1969.         { $$ = build_decl_list ($1, $2); }
  1970.     ;
  1971.  
  1972. absdcl:   /* an abstract declarator */
  1973.     /* empty */ %prec EMPTY
  1974.         { $$ = NULL_TREE; }
  1975.     | absdcl1  %prec EMPTY
  1976.     ;
  1977.  
  1978. nonempty_type_quals:
  1979.       dummy_decl TYPE_QUAL
  1980.         { $$ = IDENTIFIER_AS_LIST ($2); }
  1981.     | nonempty_type_quals TYPE_QUAL
  1982.         { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
  1983.     ;
  1984.  
  1985. type_quals:
  1986.       /* empty */
  1987.         { $$ = NULL_TREE; }
  1988.     | type_quals TYPE_QUAL
  1989.         { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
  1990.     ;
  1991.  
  1992. /* These rules must follow the rules for function declarations
  1993.    and component declarations.  That way, longer rules are prefered.  */
  1994.  
  1995. /* An expression which will not live on the momentary obstack.  */
  1996. nonmomentary_expr:
  1997.     { $<itype>$ = suspend_momentary (); } expr
  1998.     { resume_momentary ($<itype>1); $$ = $2; }
  1999.  
  2000. /* This rule needs to be bfore after_type_declarator so that we resolve
  2001.    the reduce/reduce conflict in state 111 correctly.  We need to resolve it
  2002.    the same way that vanilla C++ resolves the reduce/reduce conflict in state
  2003.    105.  That is we must assume that we are processing a typespec rather than
  2004.    an after_type_declarator when we see a TYPENAME and aren't sure.  For the
  2005.    OBJECTNAME case this means we must read any protocolrefs, and then resume
  2006.    processing the typespec. */
  2007. protocolrefs:
  2008.           /* empty */
  2009.         {
  2010.                   $$ = NULL_TREE;
  2011.                 }
  2012.     | ARITHCOMPARE identifier_list ARITHCOMPARE
  2013.         {
  2014.           if ($1 == LT_EXPR && $3 == GT_EXPR)
  2015.                     $$ = $2;
  2016.           else
  2017.             YYERROR1;
  2018.         }
  2019.     ;
  2020.  
  2021. /* A declarator that is allowed only after an explicit typespec.  */
  2022. /* may all be followed by prec '.' */
  2023. after_type_declarator:
  2024.       after_type_declarator '(' nonnull_exprlist ')' type_quals  %prec '.'
  2025.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2026.     | after_type_declarator '(' parmlist ')' type_quals  %prec '.'
  2027.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2028.     | after_type_declarator LEFT_RIGHT type_quals  %prec '.'
  2029.         { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
  2030.     | after_type_declarator '(' error ')' type_quals  %prec '.'
  2031.         { $$ = build_parse_node (CALL_EXPR, $1, NULL_TREE, NULL_TREE); }
  2032.     | after_type_declarator '[' nonmomentary_expr ']'
  2033.         { $$ = build_parse_node (ARRAY_REF, $1, $3); }
  2034.     | after_type_declarator '[' ']'
  2035.         { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
  2036.     | '(' dummy_decl after_type_declarator_no_typename ')'
  2037.         { $$ = $3; }
  2038.     | '(' '*' type_quals after_type_declarator ')'
  2039.         { $$ = make_pointer_declarator ($3, $4); }
  2040.     | PAREN_STAR_PAREN
  2041.         { $$ = $1;
  2042.           see_typename (); }
  2043.     | PAREN_X_SCOPE_STAR_PAREN
  2044.         { $$ = $1;
  2045.           see_typename (); }
  2046.     | PAREN_X_SCOPE_REF_PAREN
  2047.         { $$ = $1;
  2048.           see_typename (); }
  2049.     | '(' '&' type_quals after_type_declarator ')'
  2050.         { $$ = make_reference_declarator ($3, $4); }
  2051.     | '*' type_quals after_type_declarator  %prec UNARY
  2052.         { $$ = make_pointer_declarator ($2, $3); }
  2053.     | '&' type_quals after_type_declarator  %prec UNARY
  2054.         { $$ = make_reference_declarator ($2, $3); }
  2055.     | TYPENAME
  2056.     | OBJECTNAME
  2057.     ;
  2058.  
  2059. after_type_declarator_no_typename:
  2060.       after_type_declarator_no_typename '(' nonnull_exprlist ')' type_quals  %prec '.'
  2061.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2062.     | after_type_declarator_no_typename '(' parmlist ')' type_quals  %prec '.'
  2063.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2064.     | after_type_declarator_no_typename LEFT_RIGHT type_quals  %prec '.'
  2065.         { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
  2066.     | after_type_declarator_no_typename '(' error ')' type_quals  %prec '.'
  2067.         { $$ = build_parse_node (CALL_EXPR, $1, NULL_TREE, NULL_TREE); }
  2068.     | after_type_declarator_no_typename '[' nonmomentary_expr ']'
  2069.         { $$ = build_parse_node (ARRAY_REF, $1, $3); }
  2070.     | after_type_declarator_no_typename '[' ']'
  2071.         { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
  2072.     | '(' dummy_decl after_type_declarator_no_typename ')'
  2073.         { $$ = $3; }
  2074.     | PAREN_STAR_PAREN
  2075.         { $$ = $1;
  2076.           see_typename (); }
  2077.     | PAREN_X_SCOPE_STAR_PAREN
  2078.         { $$ = $1;
  2079.           see_typename (); }
  2080.     | PAREN_X_SCOPE_REF_PAREN
  2081.         { $$ = $1;
  2082.           see_typename (); }
  2083.     | '*' type_quals after_type_declarator  %prec UNARY
  2084.         { $$ = make_pointer_declarator ($2, $3); }
  2085.     | '&' type_quals after_type_declarator  %prec UNARY
  2086.         { $$ = make_reference_declarator ($2, $3); }
  2087.     ;
  2088.  
  2089. /* A declarator allowed whether or not there has been
  2090.    an explicit typespec.  These cannot redeclare a typedef-name.  */
  2091.  
  2092. notype_declarator:
  2093.       notype_declarator '(' nonnull_exprlist ')' type_quals  %prec '.'
  2094.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2095.     | notype_declarator '(' parmlist ')' type_quals  %prec '.'
  2096.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2097.     | notype_declarator LEFT_RIGHT type_quals  %prec '.'
  2098.         { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
  2099.     | notype_declarator '(' error ')' type_quals  %prec '.'
  2100.         { $$ = build_parse_node (CALL_EXPR, $1, NULL_TREE, NULL_TREE); }
  2101.     | '(' notype_declarator ')'
  2102.         { $$ = $2; }
  2103.     | '*' type_quals notype_declarator  %prec UNARY
  2104.         { $$ = make_pointer_declarator ($2, $3); }
  2105.     | '&' type_quals notype_declarator  %prec UNARY
  2106.         { $$ = make_reference_declarator ($2, $3); }
  2107.     | notype_declarator '[' nonmomentary_expr ']'
  2108.         { $$ = build_parse_node (ARRAY_REF, $1, $3); }
  2109.     | notype_declarator '[' ']'
  2110.         { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
  2111.     | IDENTIFIER
  2112.         { see_typename (); }
  2113.  
  2114.     /* C++ extensions.  */
  2115.     | operator_name
  2116.         { see_typename (); }
  2117.  
  2118.     | '~' TYPENAME
  2119.         { see_typename ();
  2120.           $$ = build_parse_node (BIT_NOT_EXPR, $2); }
  2121.     | '~' IDENTIFIER
  2122.         { see_typename ();
  2123.           $$ = build_parse_node (BIT_NOT_EXPR, $2); }
  2124.     | LEFT_RIGHT identifier
  2125.         {
  2126.           see_typename ();
  2127.           $$ = build_parse_node (WRAPPER_EXPR, $2);
  2128.         }
  2129.     | LEFT_RIGHT '?' identifier
  2130.         {
  2131.           see_typename ();
  2132.           $$ = build_parse_node (WRAPPER_EXPR,
  2133.                  build_parse_node (COND_EXPR, $3, NULL_TREE, NULL_TREE));
  2134.         }
  2135.     | '~' LEFT_RIGHT identifier
  2136.         { see_typename ();
  2137.           $$ = build_parse_node (ANTI_WRAPPER_EXPR, $3); }
  2138.     | TYPENAME_SCOPE type_quals notype_declarator  %prec '('
  2139.         { see_typename ();
  2140.           $$ = build_parse_node (SCOPE_REF, $1, $3); }
  2141.     | TYPENAME_SCOPE TYPENAME  %prec '('
  2142.         { $$ = build_parse_node (SCOPE_REF, $1, $2); }
  2143.     | TYPENAME_SCOPE see_typename TYPENAME '(' nonnull_exprlist ')' type_quals  %prec '.'
  2144.         { $$ = build_parse_node (SCOPE_REF, $1,
  2145.                  build_parse_node (CALL_EXPR, $3, $5, $7)); }
  2146.     | TYPENAME_SCOPE see_typename TYPENAME '(' parmlist ')' type_quals  %prec '.'
  2147.         { $$ = build_parse_node (SCOPE_REF, $1,
  2148.                  build_parse_node (CALL_EXPR, $3, $5, $7)); }
  2149.     | TYPENAME_SCOPE see_typename TYPENAME LEFT_RIGHT type_quals  %prec '.'
  2150.         { $$ = build_parse_node (SCOPE_REF, $1,
  2151.                  build_parse_node (CALL_EXPR, $3, empty_parms (), $5)); }
  2152.     | TYPENAME_SCOPE see_typename TYPENAME '(' error ')' type_quals  %prec '.'
  2153.         { $$ = build_parse_node (SCOPE_REF, $1, build_parse_node (CALL_EXPR, $3, NULL_TREE, NULL_TREE)); }
  2154.     | SCOPE see_typename notype_declarator
  2155.         { $$ = build_parse_node (SCOPE_REF, NULL_TREE, $3); }
  2156.     ;
  2157.  
  2158. scoped_identifier:
  2159.       TYPENAME_SCOPE
  2160. /* causes an unfortunate ambiquity in objc - snaroff 3/10/90 */
  2161. /*    | IDENTIFIER SCOPE */
  2162.     | scoped_identifier TYPENAME_SCOPE
  2163.         { $$ = build_parse_node (SCOPE_REF, $1, $2); }
  2164.     ;
  2165.  
  2166. absdcl1:  /* a nonempty abstract declarator */
  2167.       '(' absdcl1 ')'
  2168.         { see_typename ();
  2169.           $$ = $2; }
  2170.       /* `(typedef)1' is `int'.  */
  2171.     | '*' type_quals absdcl1  %prec EMPTY
  2172.         { $$ = make_pointer_declarator ($2, $3); }
  2173.     | '*' type_quals  %prec EMPTY
  2174.         { $$ = make_pointer_declarator ($2, NULL_TREE); }
  2175.     | PAREN_STAR_PAREN
  2176.         { $$ = $1;
  2177.           see_typename (); }
  2178.     | PAREN_X_SCOPE_STAR_PAREN
  2179.         { $$ = $1;
  2180.           see_typename (); }
  2181.     | PAREN_X_SCOPE_REF_PAREN
  2182.         { $$ = $1;
  2183.           see_typename (); }
  2184.     | '&' type_quals absdcl1 %prec EMPTY
  2185.         { $$ = make_reference_declarator ($2, $3); }
  2186.     | '&' type_quals %prec EMPTY
  2187.         { $$ = make_reference_declarator ($2, NULL_TREE); }
  2188.     | absdcl1 '(' parmlist ')' type_quals  %prec '.'
  2189.         { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
  2190.     | absdcl1 LEFT_RIGHT type_quals  %prec '.'
  2191.         { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
  2192.     | absdcl1 '[' nonmomentary_expr ']'  %prec '.'
  2193.         { $$ = build_parse_node (ARRAY_REF, $1, $3); }
  2194.     | absdcl1 '[' ']'  %prec '.'
  2195.         { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
  2196.     | '(' parmlist ')' type_quals  %prec '.'
  2197.         { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); }
  2198.     | LEFT_RIGHT type_quals  %prec '.'
  2199.         { $$ = build_parse_node (CALL_EXPR, NULL_TREE, empty_parms (), $2); }
  2200.     | '[' nonmomentary_expr ']'  %prec '.'
  2201.         { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
  2202.     | '[' ']'  %prec '.'
  2203.         { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
  2204.     | TYPENAME_SCOPE type_quals absdcl1  %prec EMPTY
  2205.         { $$ = build_parse_node (SCOPE_REF, $1, $3); }
  2206.     | IDENTIFIER SCOPE type_quals absdcl1  %prec EMPTY
  2207.         { $$ = build_parse_node (SCOPE_REF, $1, $4); }
  2208.     | TYPENAME_SCOPE type_quals %prec EMPTY
  2209.         { $$ = build_parse_node (SCOPE_REF, $1, 0); }
  2210.     | IDENTIFIER SCOPE type_quals %prec EMPTY
  2211.         { $$ = build_parse_node (SCOPE_REF, $1, 0); }
  2212.     ;
  2213.  
  2214. /* at least one statement, the first of which parses without error.  */
  2215. /* stmts is used only after decls, so an invalid first statement
  2216.    is actually regarded as an invalid decl and part of the decls.  */
  2217.  
  2218. stmts:
  2219.       stmt
  2220.     | stmts stmt
  2221.     | stmts errstmt
  2222.     ;
  2223.  
  2224. errstmt:  error ';'
  2225.     ;
  2226.  
  2227. /* build the LET_STMT node before parsing its contents,
  2228.   so that any LET_STMTs within the context can have their display pointers
  2229.   set up to point at this one.  */
  2230.  
  2231. .pushlevel:  /* empty */
  2232.         {
  2233.           pushlevel (0);
  2234.           clear_last_expr ();
  2235.           push_momentary ();
  2236.           expand_start_bindings (0);
  2237.           stmt_decl_msg = 0;
  2238.     
  2239.                   /* Objective-C stuff */
  2240.           if (objc_method_context)
  2241.             add_objc_decls();
  2242.         }
  2243.     ;
  2244.  
  2245. /* This is the body of a function definition.
  2246.    It causes syntax errors to ignore to the next openbrace.  */
  2247. compstmt_or_error:
  2248.       compstmt
  2249.         {}
  2250.     | error compstmt
  2251.     ;
  2252.  
  2253. compstmt: '{' '}'
  2254.         { $$ = 0; }
  2255.     | '{' .pushlevel stmts '}'
  2256.         { tree decls;
  2257.  
  2258.           pop_implicit_try_blocks (NULL_TREE);
  2259.           decls = getdecls ();
  2260.           expand_end_bindings (decls, decls != 0, 1);
  2261.           $$ = poplevel (decls != 0, 1, 0);
  2262.           pop_momentary (); }
  2263.     | '{' .pushlevel error '}'
  2264.         { pop_implicit_try_blocks (NULL_TREE);
  2265.           expand_end_bindings (getdecls (), 0, 1);
  2266.           $$ = poplevel (0, 0, 0);
  2267.           pop_momentary (); }
  2268.     ;
  2269.  
  2270. simple_if:
  2271.       IF '(' expr ')'
  2272.         { emit_line_note (input_filename, lineno);
  2273.           expand_start_cond (truthvalue_conversion ($3), 0);
  2274.           stmt_decl_msg = "if"; }
  2275.       stmt
  2276.         { stmt_decl_msg = 0; }
  2277.     ;
  2278.  
  2279. stmt:
  2280.       compstmt
  2281.         { finish_stmt (); }
  2282.     | decl
  2283.         { if (stmt_decl_msg)
  2284.             error ("declaration after %s invalid", stmt_decl_msg);
  2285.           stmt_decl_msg = 0;
  2286.           finish_stmt (); }
  2287.     | expr ';'
  2288.         { emit_line_note (input_filename, lineno);
  2289.           /* Do default conversion if safe and possibly important,
  2290.              in case within ({...}).  */
  2291.           if ((TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
  2292.                && lvalue_p ($1))
  2293.               || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
  2294.             $1 = default_conversion ($1);
  2295.           cplus_expand_expr_stmt ($1);
  2296.           clear_momentary ();
  2297.           finish_stmt (); }
  2298.     | simple_if ELSE
  2299.         { expand_start_else ();
  2300.           stmt_decl_msg = "else"; }
  2301.       stmt
  2302.         { expand_end_else ();
  2303.           stmt_decl_msg = 0;
  2304.           finish_stmt (); }
  2305.     | simple_if %prec IF
  2306.         { expand_end_cond ();
  2307.           stmt_decl_msg = 0;
  2308.           finish_stmt (); }
  2309.     | WHILE
  2310.         { emit_nop ();
  2311.           emit_line_note (input_filename, lineno);
  2312.           expand_start_loop (1); }
  2313.       '(' expr ')'
  2314.         { expand_exit_loop_if_false (truthvalue_conversion ($4));
  2315.           stmt_decl_msg = "while"; }
  2316.       stmt
  2317.         { 
  2318.           expand_end_loop ();
  2319.           stmt_decl_msg = 0;
  2320.           finish_stmt (); }
  2321.     | DO
  2322.         { emit_nop ();
  2323.           emit_line_note (input_filename, lineno);
  2324.           expand_start_loop_continue_elsewhere (1);
  2325.           stmt_decl_msg = "do"; }
  2326.       stmt WHILE
  2327.         { stmt_decl_msg = 0;
  2328.           expand_loop_continue_here (); }
  2329.       '(' expr ')' ';'
  2330.         { emit_line_note (input_filename, lineno);
  2331.           expand_exit_loop_if_false (truthvalue_conversion ($7));
  2332.           expand_end_loop ();
  2333.           clear_momentary ();
  2334.           finish_stmt (); }
  2335.     | forhead.1
  2336.         { emit_nop ();
  2337.           emit_line_note (input_filename, lineno);
  2338.           if ($1) cplus_expand_expr_stmt ($1);
  2339.           expand_start_loop_continue_elsewhere (1); }
  2340.       xexpr ';'
  2341.         { emit_line_note (input_filename, lineno);
  2342.           if ($3) expand_exit_loop_if_false (truthvalue_conversion ($3)); }
  2343.       xexpr ')'
  2344.         /* Don't let the tree nodes for $6 be discarded
  2345.            by clear_momentary during the parsing of the next stmt.  */
  2346.         { push_momentary ();
  2347.           stmt_decl_msg = "for"; }
  2348.       stmt
  2349.         { emit_line_note (input_filename, lineno);
  2350.           expand_loop_continue_here ();
  2351.           if ($6) cplus_expand_expr_stmt ($6);
  2352.           pop_momentary ();
  2353.           expand_end_loop ();
  2354.           stmt_decl_msg = 0;
  2355.           finish_stmt (); }
  2356.     | forhead.2
  2357.         { emit_nop ();
  2358.           emit_line_note (input_filename, lineno);
  2359.           expand_start_loop_continue_elsewhere (1); }
  2360.       xexpr ';'
  2361.         { emit_line_note (input_filename, lineno);
  2362.           if ($3) expand_exit_loop_if_false (truthvalue_conversion ($3)); }
  2363.       xexpr ')'
  2364.         /* Don't let the tree nodes for $6 be discarded
  2365.            by clear_momentary during the parsing of the next stmt.  */
  2366.         { push_momentary ();
  2367.           stmt_decl_msg = "for";
  2368.           $<itype>7 = lineno; }
  2369.       stmt
  2370.         { emit_line_note (input_filename, $<itype>7);
  2371.           expand_loop_continue_here ();
  2372.           if ($6) cplus_expand_expr_stmt ($6);
  2373.           pop_momentary ();
  2374.           expand_end_loop ();
  2375.           pop_implicit_try_blocks (NULL_TREE);
  2376.           if ($1)
  2377.             {
  2378.               register keep = $1 > 0;
  2379.               if (keep) expand_end_bindings (0, keep, 1);
  2380.               poplevel (keep, 1, 0);
  2381.               pop_momentary ();
  2382.             }
  2383.           stmt_decl_msg = 0;
  2384.           finish_stmt ();
  2385.         }
  2386.     | SWITCH '(' expr ')'
  2387.         { emit_line_note (input_filename, lineno);
  2388.           c_expand_start_case ($3);
  2389.           /* Don't let the tree nodes for $3 be discarded by
  2390.              clear_momentary during the parsing of the next stmt.  */
  2391.           push_momentary ();
  2392.           stmt_decl_msg = "switch"; }
  2393.       stmt
  2394.         { expand_end_case ($3);
  2395.           pop_momentary ();
  2396.           stmt_decl_msg = 0;
  2397.           finish_stmt (); }
  2398.     | CASE expr ':'
  2399.         { register tree value = $2;
  2400.           register tree label
  2401.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  2402.  
  2403.           /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  2404.              Strip such NOP_EXPRs.  */
  2405.           if (TREE_CODE (value) == NOP_EXPR
  2406.               && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  2407.             value = TREE_OPERAND (value, 0);
  2408.  
  2409.           if (TREE_READONLY_DECL_P (value))
  2410.             {
  2411.               value = decl_constant_value (value);
  2412.               /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  2413.              Strip such NOP_EXPRs.  */
  2414.               if (TREE_CODE (value) == NOP_EXPR
  2415.               && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  2416.             value = TREE_OPERAND (value, 0);
  2417.             }
  2418.           value = fold (value);
  2419.  
  2420.           if (TREE_CODE (value) != INTEGER_CST
  2421.               && value != error_mark_node)
  2422.             {
  2423.               error ("case label does not reduce to an integer constant");
  2424.               value = error_mark_node;
  2425.             }
  2426.           else
  2427.             /* Promote char or short to int.  */
  2428.             value = default_conversion (value);
  2429.           if (value != error_mark_node)
  2430.             {
  2431.               int success = pushcase (value, label);
  2432.               if (success == 1)
  2433.             error ("case label not within a switch statement");
  2434.               else if (success == 2)
  2435.             error ("duplicate case value");
  2436.               else if (success == 3)
  2437.             warning ("case value out of range");
  2438.             }
  2439.           define_case_label (label);
  2440.         }
  2441.       stmt
  2442.     | CASE expr RANGE expr ':'
  2443.         { register tree value1 = $2;
  2444.           register tree value2 = $4;
  2445.           register tree label
  2446.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  2447.  
  2448.           if (pedantic)
  2449.             {
  2450.               error ("ANSI C does not allow range expressions in switch statement");
  2451.               value1 = error_mark_node;
  2452.               value2 = error_mark_node;
  2453.               break;
  2454.             }
  2455.           /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  2456.              Strip such NOP_EXPRs.  */
  2457.           if (TREE_CODE (value1) == NOP_EXPR
  2458.               && TREE_TYPE (value1) == TREE_TYPE (TREE_OPERAND (value1, 0)))
  2459.             value1 = TREE_OPERAND (value1, 0);
  2460.  
  2461.           if (TREE_READONLY_DECL_P (value1))
  2462.             {
  2463.               value1 = decl_constant_value (value1);
  2464.               /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  2465.              Strip such NOP_EXPRs.  */
  2466.               if (TREE_CODE (value1) == NOP_EXPR
  2467.               && TREE_TYPE (value1) == TREE_TYPE (TREE_OPERAND (value1, 0)))
  2468.             value1 = TREE_OPERAND (value1, 0);
  2469.             }
  2470.           value1 = fold (value1);
  2471.  
  2472.           /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  2473.              Strip such NOP_EXPRs.  */
  2474.           if (TREE_CODE (value2) == NOP_EXPR
  2475.               && TREE_TYPE (value2) == TREE_TYPE (TREE_OPERAND (value2, 0)))
  2476.             value2 = TREE_OPERAND (value2, 0);
  2477.  
  2478.           if (TREE_READONLY_DECL_P (value2))
  2479.             {
  2480.               value2 = decl_constant_value (value2);
  2481.               /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  2482.              Strip such NOP_EXPRs.  */
  2483.               if (TREE_CODE (value2) == NOP_EXPR
  2484.               && TREE_TYPE (value2) == TREE_TYPE (TREE_OPERAND (value2, 0)))
  2485.             value2 = TREE_OPERAND (value2, 0);
  2486.             }
  2487.           value2 = fold (value2);
  2488.  
  2489.  
  2490.           if (TREE_CODE (value1) != INTEGER_CST
  2491.               && value1 != error_mark_node)
  2492.             {
  2493.               error ("case label does not reduce to an integer constant");
  2494.               value1 = error_mark_node;
  2495.             }
  2496.           if (TREE_CODE (value2) != INTEGER_CST
  2497.               && value2 != error_mark_node)
  2498.             {
  2499.               error ("case label does not reduce to an integer constant");
  2500.               value2 = error_mark_node;
  2501.             }
  2502.           if (value1 != error_mark_node
  2503.               && value2 != error_mark_node)
  2504.             {
  2505.               int success = pushcase_range (value1, value2, label);
  2506.               if (success == 1)
  2507.             error ("case label not within a switch statement");
  2508.               else if (success == 2)
  2509.             error ("duplicate (or overlapping) case value");
  2510.               else if (success == 3)
  2511.             warning ("case value out of range");
  2512.               else if (success == 4)
  2513.             warning ("empty range specified");
  2514.             }
  2515.           define_case_label (label);
  2516.         }
  2517.       stmt
  2518.     | DEFAULT ':'
  2519.         {
  2520.           register tree label
  2521.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  2522.           int success = pushcase (NULL_TREE, label);
  2523.           if (success == 1)
  2524.             error ("default label not within a switch statement");
  2525.           else if (success == 2)
  2526.             error ("multiple default labels in one switch");
  2527.         }
  2528.       stmt
  2529.     | BREAK ';'
  2530.         { emit_line_note (input_filename, lineno);
  2531.           if ( ! expand_exit_something ())
  2532.             error ("break statement not within loop or switch"); }
  2533.     | CONTINUE ';'
  2534.         { emit_line_note (input_filename, lineno);
  2535.           if (! expand_continue_loop ())
  2536.             error ("continue statement not within a loop"); }
  2537.     | RETURN ';'
  2538.         { emit_line_note (input_filename, lineno);
  2539.           c_expand_return (NULL_TREE); }
  2540.     | RETURN expr ';'
  2541.         { emit_line_note (input_filename, lineno);
  2542.           c_expand_return ($2);
  2543.           finish_stmt ();
  2544.         }
  2545.     | ASM maybe_type_qual '(' string ')' ';'
  2546.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  2547.           emit_line_note (input_filename, lineno);
  2548.           expand_asm ($4);
  2549.           finish_stmt ();
  2550.         }
  2551.     /* This is the case with just output operands.  */
  2552.     | ASM maybe_type_qual '(' string ':' asm_operands ')' ';'
  2553.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  2554.           emit_line_note (input_filename, lineno);
  2555.           c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
  2556.                      $2 == ridpointers[(int)RID_VOLATILE],
  2557.                      input_filename, lineno);
  2558.           finish_stmt ();
  2559.         }
  2560.     /* This is the case with input operands as well.  */
  2561.     | ASM maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
  2562.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  2563.           emit_line_note (input_filename, lineno);
  2564.           c_expand_asm_operands ($4, $6, $8, NULL_TREE,
  2565.                      $2 == ridpointers[(int)RID_VOLATILE],
  2566.                      input_filename, lineno);
  2567.           finish_stmt ();
  2568.         }
  2569.     /* This is the case with clobbered registers as well.  */
  2570.     | ASM maybe_type_qual '(' string ':' asm_operands ':'
  2571.         asm_operands ':' asm_clobbers ')' ';'
  2572.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  2573.           emit_line_note (input_filename, lineno);
  2574.           c_expand_asm_operands ($4, $6, $8, $10,
  2575.                      $2 == ridpointers[(int)RID_VOLATILE],
  2576.                      input_filename, lineno);
  2577.           finish_stmt ();
  2578.         }
  2579.     | GOTO identifier ';'
  2580.         { tree decl;
  2581.           emit_line_note (input_filename, lineno);
  2582.           decl = lookup_label ($2);
  2583.           TREE_USED (decl) = 1;
  2584.           expand_goto (decl); }
  2585.     | IDENTIFIER ':'
  2586.         { tree label = define_label (input_filename, lineno, $1);
  2587.           emit_nop ();
  2588.           if (label)
  2589.             expand_label (label); }
  2590.       stmt
  2591.         { finish_stmt (); }
  2592.     | TYPENAME_COLON
  2593.         { tree label = define_label (input_filename, lineno, $1);
  2594.           if (label)
  2595.             expand_label (label); }
  2596.       stmt
  2597.         { finish_stmt (); }
  2598.     | ';'
  2599.         { finish_stmt (); }
  2600.  
  2601.     /* Exception handling extentions.  */
  2602.     | RAISE raise_identifier '(' nonnull_exprlist ')' ';'
  2603.         { cplus_expand_raise ($2, $4, NULL_TREE);
  2604.           finish_stmt (); }
  2605.     | RAISE raise_identifier LEFT_RIGHT ';'
  2606.         { cplus_expand_raise ($2, NULL_TREE, NULL_TREE);
  2607.           finish_stmt (); }
  2608.     | RAISE identifier ';'
  2609.         { cplus_expand_reraise ($2);
  2610.           finish_stmt (); }
  2611.     | try EXCEPT identifier '{'
  2612.         {
  2613.           tree decl = cplus_expand_end_try ($1);
  2614.           $<ttype>2 = current_exception_type;
  2615.           $<ttype>4 = current_exception_decl;
  2616.           $<ttype>$ = current_exception_object;
  2617.           cplus_expand_start_except ($3, decl);
  2618.           pushlevel (0);
  2619.           clear_last_expr ();
  2620.           push_momentary ();
  2621.           expand_start_bindings (0);
  2622.           stmt_decl_msg = 0;
  2623.         }
  2624.       except_stmts '}'
  2625.         {
  2626.           tree decls = getdecls ();
  2627.           tree block;
  2628.           /* If there is a default exception to handle,
  2629.              handle it here.  */
  2630.           if ($6)
  2631.             {
  2632.               tree decl = build_decl (CPLUS_CATCH_DECL, NULL_TREE, 0);
  2633.  
  2634.               pushlevel (1);
  2635.               expand_start_bindings (0);
  2636.               expand_expr ($6, 0, 0, 0);
  2637.               expand_end_bindings (0, 1, 0);
  2638.               block = poplevel (1, 0, 0);
  2639.  
  2640.               /* This is a catch block.  */
  2641.               TREE_LANG_FLAG_2 (block) = 1;
  2642.               STMT_VARS (block) = decl;
  2643.             }
  2644.  
  2645.           expand_end_bindings (decls, 1, 1);
  2646.           block = poplevel (1, 1, 0);
  2647.           TREE_LANG_FLAG_3 (block) = 1;
  2648.           pop_momentary ();
  2649.           current_exception_type = $<ttype>2;
  2650.           current_exception_decl = $<ttype>4;
  2651.           current_exception_object = $<ttype>5;
  2652.           cplus_expand_end_except ($6);
  2653.         }
  2654.     | try RERAISE raise_identifiers /* ';' checked for at bottom.  */
  2655.         { tree name = get_identifier ("(compiler error)");
  2656.           tree orig_ex_type = current_exception_type;
  2657.           tree orig_ex_decl = current_exception_decl;
  2658.           tree orig_ex_obj = current_exception_object;
  2659.           tree decl = cplus_expand_end_try ($1), decls;
  2660.           tree block;
  2661.  
  2662.           /* Start hidden EXCEPT.  */
  2663.           cplus_expand_start_except (name, decl);
  2664.           pushlevel (0);
  2665.           clear_last_expr ();
  2666.           push_momentary ();
  2667.           expand_start_bindings (0);
  2668.           stmt_decl_msg = 0;
  2669.  
  2670.           /* This sets up the reraise.  */
  2671.           cplus_expand_reraise ($3);
  2672.  
  2673.           decls = getdecls ();
  2674.           expand_end_bindings (decls, 1, 1);
  2675.           block = poplevel (1, 1, 0);
  2676.           TREE_LANG_FLAG_3 (block) = 1;
  2677.           pop_momentary ();
  2678.           current_exception_type = orig_ex_type;
  2679.           current_exception_decl = orig_ex_decl;
  2680.           current_exception_object = orig_ex_obj;
  2681.           /* This will reraise for us.  */
  2682.           cplus_expand_end_except (error_mark_node);
  2683.           if (yychar == YYEMPTY)
  2684.             yychar = YYLEX;
  2685.           if (yychar != ';')
  2686.             error ("missing ';' after reraise statement");
  2687.         }
  2688.     | try  %prec EMPTY
  2689.         { yyerror ("`except' missing after `try' statement");
  2690.           /* Terminate the binding contour started by special
  2691.              code in `.pushlevel'.  Automagically pops off
  2692.              the conditional we started for `try' stmt.  */
  2693.           cplus_expand_end_try ($1);
  2694.           expand_end_bindings (0, 0, 1);
  2695.           poplevel (0, 0, 0);
  2696.           pop_momentary ();
  2697.           YYERROR; }
  2698.     ;
  2699.  
  2700. try:      TRY '{' '}'
  2701.         { $$ = 0; }
  2702.     | try_head stmts '}'
  2703.         {
  2704.           $$ = 1;
  2705.           pop_implicit_try_blocks (NULL_TREE);
  2706.         }
  2707.     | try_head error '}'
  2708.         {
  2709.           $$ = 0;
  2710.           pop_implicit_try_blocks (NULL_TREE);
  2711.         }
  2712.     ;
  2713.  
  2714. try_head: TRY '{' { cplus_expand_start_try (0); } .pushlevel
  2715.  
  2716. except_stmts:
  2717.       /* empty */
  2718.         { $$ = NULL_TREE; }
  2719.     | except_stmts raise_identifier
  2720.         {
  2721.           tree type = lookup_exception_type (current_class_type, current_class_name, $2);
  2722.           if (type == NULL_TREE)
  2723.             {
  2724.               error ("`%s' is not an exception type",
  2725.                  IDENTIFIER_POINTER (TREE_VALUE ($2)));
  2726.               current_exception_type = NULL_TREE;
  2727.               TREE_TYPE (current_exception_object) = error_mark_node;
  2728.             }
  2729.           else
  2730.             {
  2731.               current_exception_type = type;
  2732.               /* In-place union.  */
  2733.               TREE_TYPE (current_exception_object) = type;
  2734.             }
  2735.           $2 = cplus_expand_start_catch ($2);
  2736.           pushlevel (1);
  2737.           expand_start_bindings (0);
  2738.         }
  2739.       compstmt
  2740.         {
  2741.           expand_end_bindings (0, 1, 0);
  2742.           $4 = poplevel (1, 0, 0);
  2743.  
  2744.           cplus_expand_end_catch (0);
  2745.  
  2746.           /* Mark this as a catch block.  */
  2747.           TREE_LANG_FLAG_2 ($4) = 1;
  2748.           if ($2 != error_mark_node)
  2749.             {
  2750.               tree decl = build_decl (CPLUS_CATCH_DECL, DECL_NAME ($2), 0);
  2751.               DECL_RTL (decl) = DECL_RTL ($2);
  2752.               TREE_CHAIN (decl) = STMT_VARS ($4);
  2753.               STMT_VARS ($4) = decl;
  2754.             }
  2755.         }
  2756.     | except_stmts DEFAULT
  2757.         {
  2758.           if ($1)
  2759.             error ("duplicate default in exception handler");
  2760.           current_exception_type = NULL_TREE;
  2761.           /* Takes it right out of scope.  */
  2762.           TREE_TYPE (current_exception_object) = error_mark_node;
  2763.  
  2764.           if (! expand_catch_default ())
  2765.             compiler_error ("default catch botch");
  2766.  
  2767.           /* The default exception is handled as the
  2768.              last in the chain of exceptions handled.  */
  2769.           do_pending_stack_adjust ();
  2770.           start_sequence ();
  2771.           $1 = make_node (RTL_EXPR);
  2772.           TREE_TYPE ($1) = void_type_node;
  2773.         }
  2774.       compstmt
  2775.         {
  2776.           do_pending_stack_adjust ();
  2777.           if (! expand_catch (NULL_TREE))
  2778.             compiler_error ("except nesting botch");
  2779.           if (! expand_end_catch ())
  2780.             compiler_error ("except nesting botch");
  2781.           RTL_EXPR_SEQUENCE ($1) = (struct rtx_def *)get_insns ();
  2782.           if ($4)
  2783.             {
  2784.               /* Mark this block as the default catch block.  */
  2785.               TREE_LANG_FLAG_1 ($4) = 1;
  2786.               TREE_LANG_FLAG_2 ($4) = 1;
  2787.             }
  2788.           end_sequence ();
  2789.         }
  2790.     ;
  2791.  
  2792. forhead.1:
  2793.       FOR '(' ';'
  2794.         { $$ = NULL_TREE; }
  2795.     | FOR '(' expr ';'
  2796.         { $$ = $3; }
  2797.     | FOR '(' '{' '}'
  2798.         { $$ = NULL_TREE; }
  2799.     ;
  2800.  
  2801. forhead.2:
  2802.       FOR '(' decl
  2803.         { $$ = 0; }
  2804.     | FOR '(' error ';'
  2805.         { $$ = 0; }
  2806.     | FOR '(' '{' .pushlevel stmts '}'
  2807.         { $$ = 1; }
  2808.     | FOR '(' '{' .pushlevel error '}'
  2809.         { $$ = -1; }
  2810.     ;
  2811.  
  2812. /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
  2813.  
  2814. maybe_type_qual:
  2815.     /* empty */
  2816.         { if (pedantic)
  2817.             warning ("ANSI C forbids use of `asm' keyword");
  2818.           emit_line_note (input_filename, lineno); }
  2819.     | TYPE_QUAL
  2820.         { if (pedantic)
  2821.             warning ("ANSI C forbids use of `asm' keyword");
  2822.           emit_line_note (input_filename, lineno); }
  2823.     ;
  2824.  
  2825. xexpr:
  2826.     /* empty */
  2827.         { $$ = NULL_TREE; }
  2828.     | expr
  2829.     | error
  2830.         { $$ = NULL_TREE; }
  2831.     ;
  2832.  
  2833. /* These are the operands other than the first string and colon
  2834.    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
  2835. asm_operands: /* empty */
  2836.         { $$ = NULL_TREE; }
  2837.     | nonnull_asm_operands
  2838.     ;
  2839.  
  2840. nonnull_asm_operands:
  2841.       asm_operand
  2842.     | nonnull_asm_operands ',' asm_operand
  2843.         { $$ = chainon ($1, $3); }
  2844.     ;
  2845.  
  2846. asm_operand:
  2847.       STRING '(' expr ')'
  2848.         { $$ = build_tree_list ($1, $3); }
  2849.     ;
  2850.  
  2851. asm_clobbers:
  2852.       STRING
  2853.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  2854.     | asm_clobbers ',' STRING
  2855.         { $$ = tree_cons (NULL_TREE, $3, $1); }
  2856.     ;
  2857.  
  2858. /* This is what appears inside the parens in a function declarator.
  2859.    Its value is represented in the format that grokdeclarator expects.
  2860.  
  2861.    In C++, declaring a function with no parameters
  2862.    means that that function takes *no* parameters.  */
  2863. parmlist:  /* empty */
  2864.         {
  2865.           if (strict_prototype)
  2866.             $$ = void_list_node;
  2867.           else
  2868.             $$ = NULL_TREE;
  2869.         }
  2870.     | parms
  2871.           {
  2872.           $$ = chainon ($1, void_list_node);
  2873.           TREE_PARMLIST ($$) = 1;
  2874.         }
  2875.     | parms ',' ELLIPSIS
  2876.         {
  2877.           $$ = $1;
  2878.           TREE_PARMLIST ($$) = 1;
  2879.         }
  2880.     /* C++ allows an ellipsis without a separating ',' */
  2881.     | parms ELLIPSIS
  2882.         {
  2883.           $$ = $1;
  2884.           TREE_PARMLIST ($$) = 1;
  2885.         }
  2886.     | ELLIPSIS
  2887.         {
  2888.           $$ = NULL_TREE;
  2889.         }
  2890.     | TYPENAME_ELLIPSIS
  2891.         {
  2892.           $$ = $1;
  2893.           TREE_PARMLIST ($$) = 1;
  2894.         }
  2895.     | parms TYPENAME_ELLIPSIS
  2896.         {
  2897.           $$ = $1;
  2898.           TREE_PARMLIST ($$) = 1;
  2899.         }
  2900.     | parms ':'
  2901.         {
  2902.           /* This helps us recover from really nasty
  2903.              parse errors, for example, a missing right
  2904.              parenthesis.  */
  2905.           yyerror ("possibly missing ')'");
  2906.           $$ = chainon ($1, void_list_node);
  2907.           TREE_PARMLIST ($$) = 1;
  2908.           yyungetc (':', 0);
  2909.           yychar = ')';
  2910.         }
  2911.     ;
  2912.  
  2913. /* A nonempty list of parameter declarations or type names.  */
  2914. parms:
  2915.       parm opt.init
  2916.         { $$ = build_tree_list ($2, $1); }
  2917.     | parms ',' parm opt.init
  2918.         { $$ = chainon ($1, build_tree_list ($4, $3)); }
  2919.     | parms ',' bad_parm opt.init
  2920.         { $$ = chainon ($1, build_tree_list ($4, $3)); }
  2921.     ;
  2922.  
  2923. /* A single parameter declaration or parameter type name,
  2924.    as found in a parmlist.  */
  2925. parm:
  2926.       typed_declspecs dont_see_typename notype_declarator
  2927.         { $$ = build_tree_list ($1, $3);
  2928.           see_typename (); }
  2929.     | typed_declspecs dont_see_typename absdcl
  2930.         { $$ = build_tree_list ($1, $3);
  2931.           see_typename (); }
  2932.     | declmods dont_see_typename notype_declarator
  2933.         { $$ = build_tree_list ($1, $3);
  2934.           see_typename (); }
  2935.     | declmods dont_see_typename absdcl
  2936.         { $$ = build_tree_list ($1, $3);
  2937.           see_typename (); }
  2938.     ;
  2939.  
  2940. see_typename: type_quals
  2941.     { see_typename (); }
  2942.     ;
  2943.  
  2944. dont_see_typename: /* empty */
  2945.     { dont_see_typename (); }
  2946.     ;
  2947.  
  2948. bad_parm:
  2949.       dummy_decl notype_declarator
  2950.         {
  2951.           warning ("type specifier omitted for parameter");
  2952.           $$ = build_tree_list (TREE_PURPOSE (TREE_VALUE ($<ttype>-1)), $2);
  2953.         }
  2954.     | dummy_decl absdcl
  2955.         {
  2956.           warning ("type specifier omitted for parameter");
  2957.           $$ = build_tree_list (TREE_PURPOSE (TREE_VALUE ($<ttype>-1)), $2);
  2958.         }
  2959.     ;
  2960.  
  2961.     /* C++ extension: allow for initialization */
  2962. opt.init:
  2963.       /* empty */
  2964.         { $$ = NULL_TREE; }
  2965.     | '=' init
  2966.         { $$ = $2; }
  2967.     ;
  2968.  
  2969. maybe_raises:
  2970.       /* empty */
  2971.         { $$ = NULL_TREE; }
  2972.     | RAISES raise_identifiers  %prec EMPTY
  2973.         { $$ = $2; }
  2974.     ;
  2975.  
  2976. raise_identifier:
  2977.       ALL
  2978.         { $$ = void_list_node; }
  2979.     | IDENTIFIER
  2980.         { $$ = build_decl_list (NULL_TREE, $1); }
  2981.     | TYPENAME
  2982.         { $$ = build_decl_list (NULL_TREE, $1); }
  2983.     | OBJECTNAME
  2984.         { $$ = build_decl_list (NULL_TREE, $1); }
  2985.     | SCOPE IDENTIFIER
  2986.         { $$ = build_decl_list (void_type_node, $2); }
  2987.     | SCOPE TYPENAME
  2988.         { $$ = build_decl_list (void_type_node, $2); }
  2989.     | scoped_identifier IDENTIFIER
  2990.         { $$ = build_decl_list ($1, $2); }
  2991.     | scoped_identifier TYPENAME
  2992.         { $$ = build_decl_list ($1, $2); }
  2993.  
  2994. raise_identifiers:
  2995.       raise_identifier
  2996.     | raise_identifiers ',' raise_identifier
  2997.         {
  2998.             TREE_CHAIN ($3) = $1;
  2999.           $$ = $3;
  3000.         }
  3001.     ;
  3002.  
  3003. operator_name:
  3004.       OPERATOR '*'
  3005.         { $$ = build_opid (0, MULT_EXPR); }
  3006.     | OPERATOR '/'
  3007.         { $$ = build_opid (0, TRUNC_DIV_EXPR); }
  3008.     | OPERATOR '%'
  3009.         { $$ = build_opid (0, TRUNC_MOD_EXPR); }
  3010.     | OPERATOR '+'
  3011.         { $$ = build_opid (0, PLUS_EXPR); }
  3012.     | OPERATOR '-'
  3013.         { $$ = build_opid (0, MINUS_EXPR); }
  3014.     | OPERATOR '&'
  3015.         { $$ = build_opid (0, BIT_AND_EXPR); }
  3016.     | OPERATOR '|'
  3017.         { $$ = build_opid (0, BIT_IOR_EXPR); }
  3018.     | OPERATOR '^'
  3019.         { $$ = build_opid (0, BIT_XOR_EXPR); }
  3020.     | OPERATOR '~'
  3021.         { $$ = build_opid (0, BIT_NOT_EXPR); }
  3022.     | OPERATOR ','
  3023.         { $$ = build_opid (0, COMPOUND_EXPR); }
  3024.     | OPERATOR ARITHCOMPARE
  3025.         { $$ = build_opid (0, $2); }
  3026.     | OPERATOR EQCOMPARE
  3027.         { $$ = build_opid (0, $2); }
  3028.     | OPERATOR ASSIGN
  3029.         { $$ = build_opid (MODIFY_EXPR, $2); }
  3030.     | OPERATOR '='
  3031.         {
  3032.           $$ = build_opid (MODIFY_EXPR, NOP_EXPR);
  3033.           if (current_class_type)
  3034.             {
  3035.               TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
  3036.               TYPE_GETS_ASSIGNMENT (current_class_type) = 1;
  3037.             }
  3038.         }
  3039.     | OPERATOR LSHIFT
  3040.         { $$ = build_opid (0, $2); }
  3041.     | OPERATOR RSHIFT
  3042.         { $$ = build_opid (0, $2); }
  3043.     | OPERATOR PLUSPLUS
  3044.         { $$ = build_opid (0, POSTINCREMENT_EXPR); }
  3045.     | OPERATOR MINUSMINUS
  3046.         { $$ = build_opid (0, PREDECREMENT_EXPR); }
  3047.     | OPERATOR ANDAND
  3048.         { $$ = build_opid (0, TRUTH_ANDIF_EXPR); }
  3049.     | OPERATOR OROR
  3050.         { $$ = build_opid (0, TRUTH_ORIF_EXPR); }
  3051.     | OPERATOR '!'
  3052.         { $$ = build_opid (0, TRUTH_NOT_EXPR); }
  3053.     | OPERATOR '?' ':'
  3054.         { $$ = build_opid (0, COND_EXPR); }
  3055.     | OPERATOR MIN_MAX
  3056.         { $$ = build_opid (0, $2); }
  3057.     | OPERATOR POINTSAT  %prec EMPTY
  3058.         { $$ = build_opid (0, COMPONENT_REF); }
  3059.     | OPERATOR POINTSAT_LEFT_RIGHT type_quals  %prec '.'
  3060.         {
  3061.           if (yychar == YYEMPTY)
  3062.             yychar = YYLEX;
  3063.           if (yychar == '(' || yychar == LEFT_RIGHT)
  3064.             {
  3065.               $$ = build_opid (0, METHOD_CALL_EXPR);
  3066.               if (current_class_type)
  3067.             {
  3068.               tree t = current_class_type;
  3069.               while (t)
  3070.                 {
  3071.                   TYPE_OVERLOADS_METHOD_CALL_EXPR (t) = 1;
  3072.                   t = TYPE_NEXT_VARIANT (t);
  3073.                 }
  3074.             }
  3075.             }
  3076.           else
  3077.             $$ = build_parse_node (CALL_EXPR, build_opid (0, COMPONENT_REF), void_list_node, $3);
  3078.         }
  3079.     | OPERATOR LEFT_RIGHT
  3080.         { $$ = build_opid (0, CALL_EXPR);
  3081.           if (current_class_type)
  3082.             {
  3083.               tree t = current_class_type;
  3084.               while (t)
  3085.             {
  3086.               TYPE_OVERLOADS_CALL_EXPR (t) = 1;
  3087.               t = TYPE_NEXT_VARIANT (t);
  3088.             }
  3089.             }
  3090.         }
  3091.     | OPERATOR '[' ']'
  3092.         { $$ = build_opid (0, ARRAY_REF);
  3093.           if (current_class_type)
  3094.             {
  3095.               tree t = current_class_type;
  3096.               while (t)
  3097.             {
  3098.               TYPE_OVERLOADS_ARRAY_REF (t) = 1;
  3099.               t = TYPE_NEXT_VARIANT (t);
  3100.             }
  3101.             }
  3102.         }
  3103.     | OPERATOR NEW
  3104.         {
  3105.           $$ = build_opid (0, NEW_EXPR);
  3106.           if (current_class_type)
  3107.             {
  3108.               tree t = current_class_type;
  3109.               while (t)
  3110.             {
  3111.               TREE_GETS_NEW (t) = 1;
  3112.               t = TYPE_NEXT_VARIANT (t);
  3113.             }
  3114.             }
  3115.         }
  3116.     | OPERATOR DELETE
  3117.         {
  3118.           $$ = build_opid (0, DELETE_EXPR);
  3119.           if (current_class_type)
  3120.             {
  3121.               tree t = current_class_type;
  3122.               while (t)
  3123.             {
  3124.               TREE_GETS_DELETE (t) = 1;
  3125.               t = TYPE_NEXT_VARIANT (t);
  3126.             }
  3127.             }
  3128.         }
  3129.  
  3130.     /* These should do `groktypename' and set up TREE_HAS_X_CONVERSION
  3131.        here, rather than doing it in class.c .  */
  3132.     | OPERATOR typed_typespecs absdcl
  3133.         {
  3134.           $$ = build1 (TYPE_EXPR, $2, $3);
  3135.         }
  3136.     | OPERATOR error
  3137.         { $$ = build_opid (ERROR_MARK, ERROR_MARK); }
  3138.     ;
  3139.  
  3140. /*
  3141.  *    Objective-C productions.
  3142.  */
  3143.  
  3144. /* records the type and storage class specs to use for processing
  3145.    the declarators that follow */
  3146.    
  3147. setspecs: /* empty */
  3148.         { current_declspecs = $<ttype>0;
  3149.           $$ = suspend_momentary (); }
  3150.     ;
  3151.  
  3152. objcdef:
  3153.       classdef
  3154.     | classdecl
  3155.     | aliasdecl
  3156.     | protocoldef
  3157.     | methoddef
  3158.     | END
  3159.         {
  3160.           if (objc_implementation_context)
  3161.                     {
  3162.             finish_class(objc_implementation_context);    
  3163.             objc_ivar_chain = NULL_TREE;
  3164.             objc_implementation_context = NULL_TREE;
  3165.             }
  3166.           else
  3167.             warning("`@end' must appear in an implementation context");
  3168.         }
  3169.     ;
  3170.  
  3171. /* A nonempty list of identifiers.  */
  3172. identifier_list:
  3173.       identifier
  3174.         { $$ = build_tree_list (NULL_TREE, $1); }
  3175.     | identifier_list ',' identifier
  3176.         { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  3177.     ;
  3178.  
  3179. classdecl:
  3180.       CLASS identifier_list ';'
  3181.         {
  3182.           objc_declare_class ($2);
  3183.         }
  3184.  
  3185. aliasdecl:
  3186.       ALIAS identifier identifier ';'
  3187.         {
  3188.           objc_declare_alias ($2, $3);
  3189.         }
  3190.  
  3191. /* This is necessary for living in this c++ parser */
  3192. identifier_colon:
  3193.       identifier ':'
  3194.         { $$ = $1 }
  3195.     | TYPENAME_COLON
  3196.     ;
  3197.  
  3198. classdef:
  3199.       INTERFACE identifier protocolrefs '{'
  3200.         {
  3201.           objc_interface_context = objc_ivar_context
  3202.             = start_class (CLASS_INTERFACE, $2, NULL_TREE, $3);
  3203.                   objc_public_flag = 0;
  3204.         }
  3205.       ivar_decl_list '}'
  3206.         {
  3207.                   continue_class (objc_interface_context);
  3208.         }
  3209.       methodprotolist
  3210.       END
  3211.         {
  3212.           finish_class (objc_interface_context);
  3213.           objc_interface_context = NULL_TREE;
  3214.         }
  3215.  
  3216.     | INTERFACE identifier protocolrefs
  3217.         {
  3218.           objc_interface_context
  3219.             = start_class (CLASS_INTERFACE, $2, NULL_TREE, $3);
  3220.                   continue_class (objc_interface_context);
  3221.         }
  3222.       methodprotolist
  3223.       END
  3224.         { 
  3225.           finish_class(objc_interface_context);    
  3226.           objc_interface_context = NULL_TREE; 
  3227.         }
  3228.  
  3229.     | INTERFACE identifier_colon identifier protocolrefs '{'
  3230.         {
  3231.           objc_interface_context = objc_ivar_context
  3232.             = start_class (CLASS_INTERFACE, $2, $3, $4);
  3233.                   objc_public_flag = 0;
  3234.         }
  3235.       ivar_decl_list '}'
  3236.         {
  3237.                   continue_class (objc_interface_context);
  3238.         }
  3239.       methodprotolist
  3240.       END
  3241.         { 
  3242.           finish_class(objc_interface_context);    
  3243.           objc_interface_context = NULL_TREE; 
  3244.         }
  3245.  
  3246.     | INTERFACE identifier_colon identifier protocolrefs
  3247.         {
  3248.           objc_interface_context
  3249.             = start_class (CLASS_INTERFACE, $2, $3, $4);
  3250.                   continue_class (objc_interface_context);
  3251.         }
  3252.       methodprotolist
  3253.       END
  3254.         {
  3255.           finish_class (objc_interface_context);
  3256.           objc_interface_context = NULL_TREE;
  3257.         }
  3258.  
  3259.     | IMPLEMENTATION identifier '{'
  3260.         {
  3261.           objc_implementation_context = objc_ivar_context
  3262.             = start_class (CLASS_IMPLEMENTATION, $2, NULL_TREE, NULL_TREE);
  3263.                   objc_public_flag = 0;
  3264.         }
  3265.       ivar_decl_list '}'
  3266.         {
  3267.                   objc_ivar_chain
  3268.             = continue_class (objc_implementation_context);
  3269.         }
  3270.  
  3271.     | IMPLEMENTATION identifier
  3272.         {
  3273.           objc_implementation_context
  3274.             = start_class (CLASS_IMPLEMENTATION, $2, NULL_TREE, NULL_TREE);
  3275.                   objc_ivar_chain
  3276.             = continue_class (objc_implementation_context);
  3277.         }
  3278.  
  3279.     | IMPLEMENTATION identifier_colon identifier '{'
  3280.         {
  3281.           objc_implementation_context = objc_ivar_context
  3282.             = start_class (CLASS_IMPLEMENTATION, $2, $3, NULL_TREE);
  3283.                   objc_public_flag = 0;
  3284.         }
  3285.       ivar_decl_list '}'
  3286.         {
  3287.                   objc_ivar_chain
  3288.             = continue_class (objc_implementation_context);
  3289.         }
  3290.  
  3291.     | IMPLEMENTATION identifier_colon identifier
  3292.         {
  3293.           objc_implementation_context
  3294.             = start_class (CLASS_IMPLEMENTATION, $2, $3, NULL_TREE);
  3295.                   objc_ivar_chain
  3296.             = continue_class (objc_implementation_context);
  3297.         }
  3298.  
  3299.     | INTERFACE identifier '(' identifier ')' protocolrefs
  3300.         {
  3301.           objc_interface_context
  3302.             = start_class (CATEGORY_INTERFACE, $2, $4, $6);
  3303.                   continue_class (objc_interface_context);
  3304.         }
  3305.       methodprotolist
  3306.       END
  3307.         {
  3308.           finish_class (objc_interface_context);
  3309.           objc_interface_context = NULL_TREE;
  3310.         }
  3311.  
  3312.     | IMPLEMENTATION identifier '(' identifier ')'
  3313.         {
  3314.           objc_implementation_context
  3315.             = start_class (CATEGORY_IMPLEMENTATION, $2, $4, NULL_TREE);
  3316.                   objc_ivar_chain
  3317.             = continue_class (objc_implementation_context);
  3318.         }
  3319.     ;
  3320.  
  3321. protocoldef:
  3322.       PROTOCOL identifier protocolrefs
  3323.         {
  3324.         remember_protocol_qualifiers ();
  3325.         objc_interface_context = 
  3326.             start_protocol(PROTOCOL_INTERFACE, $2, $3);
  3327.         }
  3328.       methodprotolist
  3329.       END
  3330.         {
  3331.         forget_protocol_qualifiers();
  3332.         finish_protocol(objc_interface_context);
  3333.         objc_interface_context = NULL_TREE;
  3334.         }
  3335.     ;
  3336.  
  3337. ivar_decl_list:   
  3338.           ivar_decl_list visibility_spec ivar_decls
  3339.         | ivar_decls
  3340.         ;
  3341.  
  3342. visibility_spec:
  3343.       PRIVATE { objc_public_flag = 2; }
  3344.     | PROTECTED { objc_public_flag = 0; }
  3345.     | PUBLIC { objc_public_flag = 1; }
  3346.     ;
  3347.  
  3348. ivar_decls:
  3349.           /* empty */
  3350.         { 
  3351.                   $$ = NULL_TREE; 
  3352.                 }
  3353.     | ivar_decls ivar_decl ';'
  3354.     | ivar_decls ';'
  3355.         { 
  3356.                   if (pedantic) 
  3357.             warning ("extra semicolon in struct or union specified"); 
  3358.                 }
  3359.     ;
  3360.  
  3361.  
  3362. /* There is a shift-reduce conflict here, because `components' may
  3363.    start with a `typename'.  It happens that shifting (the default resolution)
  3364.    does the right thing, because it treats the `typename' as part of
  3365.    a `typed_typespecs'.
  3366.  
  3367.    It is possible that this same technique would allow the distinction
  3368.    between `notype_initdecls' and `initdecls' to be eliminated.
  3369.    But I am being cautious and not trying it.  */
  3370.  
  3371. ivar_decl:
  3372.     typed_typespecs setspecs ivars
  3373.             { 
  3374.                   $$ = $3;
  3375.           resume_momentary ($2);
  3376.                 }
  3377.     | nonempty_type_quals setspecs ivars
  3378.             { 
  3379.                   $$ = $3;
  3380.           resume_momentary ($2);
  3381.                 }
  3382.     | error
  3383.         { $$ = NULL_TREE; }
  3384.     ;
  3385.  
  3386. ivars:
  3387.       /* empty */
  3388.         { $$ = NULL_TREE; }
  3389.     | ivar_declarator
  3390.     | ivars ',' ivar_declarator
  3391.     ;
  3392.  
  3393. ivar_declarator:
  3394.       declarator
  3395.         { 
  3396.                 $$ = add_instance_variable(objc_ivar_context, objc_public_flag,
  3397.                            $1, current_declspecs, NULL_TREE); 
  3398.                 }
  3399.     | declarator ':' expr_no_commas
  3400.         { 
  3401.                 $$ = add_instance_variable(objc_ivar_context, objc_public_flag,
  3402.                            $1, current_declspecs, $3); 
  3403.                 }
  3404.     | ':' expr_no_commas
  3405.         { 
  3406.                 $$ = add_instance_variable(objc_ivar_context, objc_public_flag,
  3407.                            NULL_TREE, current_declspecs, $2); 
  3408.                 }
  3409.     ;
  3410.  
  3411. methoddef:
  3412.       '+' 
  3413.         {
  3414.           if (objc_implementation_context)
  3415.             objc_inherit_code = CLASS_METHOD_DECL;
  3416.                   else
  3417.             fatal("Illegal method definition - must be in a class context.");
  3418.         }
  3419.       methoddecl 
  3420.         { 
  3421.           add_class_method(objc_implementation_context,$3);
  3422.           start_method_def ($3);
  3423.           objc_method_context = $3;
  3424.         }
  3425.       optarglist
  3426.         {
  3427.           continue_method_def();
  3428.         }
  3429.       compstmt_or_error
  3430.         { 
  3431.           finish_method_def (); 
  3432.           objc_method_context = NULL_TREE; 
  3433.         }
  3434.  
  3435.     | '-' 
  3436.         {
  3437.           if (objc_implementation_context)
  3438.             objc_inherit_code = INSTANCE_METHOD_DECL;
  3439.                   else
  3440.             fatal("Illegal method definition - must be in a class context.");
  3441.         }
  3442.       methoddecl 
  3443.         { 
  3444.           add_instance_method(objc_implementation_context,$3);
  3445.           start_method_def ($3); 
  3446.           objc_method_context = $3;
  3447.         }
  3448.       optarglist
  3449.         {
  3450.           continue_method_def();
  3451.         }
  3452.       compstmt_or_error
  3453.         { 
  3454.           finish_method_def (); 
  3455.           objc_method_context = NULL_TREE; 
  3456.         }
  3457.     ;
  3458.  
  3459. /* the reason for the strange actions in this rule
  3460.  is so that notype_initdecls when reached via datadef
  3461.  can find a valid list of type and sc specs in $0. */
  3462.  
  3463. methodprotolist:
  3464.       /* empty  */
  3465.     | {$<ttype>$ = NULL_TREE; } methodprotolist2
  3466.     ;
  3467.  
  3468. methodprotolist2:         /* eliminates a shift/reduce conflict */
  3469.       methodproto 
  3470.     | datadef
  3471.     | methodprotolist2 methodproto
  3472.     | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
  3473.     ;
  3474.  
  3475. semi_or_error:
  3476.       ';'
  3477.     | error
  3478.     ;
  3479.  
  3480. methodproto:
  3481.       '+' 
  3482.         {
  3483.           objc_inherit_code = CLASS_METHOD_DECL;
  3484.         }
  3485.       methoddecl 
  3486.         { 
  3487.           add_class_method(objc_interface_context,$3);
  3488.         }
  3489.       semi_or_error
  3490.  
  3491.     | '-' 
  3492.         {
  3493.           objc_inherit_code = INSTANCE_METHOD_DECL;
  3494.         }
  3495.       methoddecl 
  3496.         {
  3497.           add_instance_method(objc_interface_context,$3);
  3498.         }
  3499.       semi_or_error
  3500.     ;
  3501.  
  3502. methoddecl:
  3503.       '(' typename ')' unaryselector 
  3504.         { 
  3505.         $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE); 
  3506.         }
  3507.  
  3508.     | unaryselector 
  3509.         { 
  3510.         $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE); 
  3511.         }
  3512.  
  3513.     | '(' typename ')' keywordselector optparmlist
  3514.         { 
  3515.         $$ = build_method_decl (objc_inherit_code, $2, $4, $5); 
  3516.         }
  3517.  
  3518.     | keywordselector optparmlist
  3519.         { 
  3520.         $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2); 
  3521.         }
  3522.     ;
  3523.  
  3524. /* "optarglist" assumes that start_method_def() has already been called...
  3525.    if it is not, the "xdecls" will not be placed in the proper scope */
  3526.  
  3527. optarglist:
  3528.       /* empty */
  3529.     | ';' myxdecls
  3530.     ;
  3531.  
  3532. /* to get around the following situation: "int foo(int a) int b; {}" that
  3533.    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
  3534.  
  3535. myxdecls:
  3536.       /* empty */
  3537.     | mydecls
  3538.     ;
  3539.  
  3540. mydecls:
  3541.     mydecl
  3542.     | errstmt
  3543.     | mydecls mydecl
  3544.     | mydecl errstmt
  3545.     ;
  3546.  
  3547. mydecl:
  3548.     typed_declspecs setspecs myparms ';'
  3549.         { resume_momentary ($2); }
  3550.     | typed_declspecs ';'
  3551.         { shadow_tag ($1); }
  3552.     | declmods ';'
  3553.         { warning ("empty declaration"); }
  3554.     ;
  3555.  
  3556. /* this must be converted to live in the g++ world...snaroff */
  3557.  
  3558. myparms:    
  3559.     myparm
  3560.         { objcplus_push_parm_decl ($1); }
  3561.     | myparms ',' myparm
  3562.         { objcplus_push_parm_decl ($3); }
  3563.     ;
  3564.  
  3565. /* A single parameter declaration or parameter type name,
  3566.    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
  3567.  
  3568. myparm:
  3569.      dont_see_typename notype_declarator
  3570.         { $$ = build_tree_list (current_declspecs, $2)    ; }
  3571.     | notype_declarator
  3572.         { $$ = build_tree_list (current_declspecs, $1)    ; }
  3573.     | absdcl
  3574.         { $$ = build_tree_list (current_declspecs, $1)    ; }
  3575.     ;
  3576.  
  3577. optparmlist:
  3578.       /* empty */
  3579.         { 
  3580.               $$ = NULL_TREE; 
  3581.         }
  3582.     | ',' ELLIPSIS
  3583.         {
  3584.           /* oh what a kludge! */
  3585.           $$ = (tree)1;    
  3586.         }
  3587.     | ',' 
  3588.         { 
  3589.           pushlevel (0); 
  3590.         } 
  3591.       parmlist    
  3592.         { 
  3593.             /* returns a tree list node generated by `get_parm_info()' */
  3594.           $$ = $3; 
  3595.           poplevel(0,0,0);
  3596.         }
  3597.     ;
  3598.  
  3599. unaryselector:
  3600.       selector
  3601.     ;
  3602.  
  3603. keywordselector:
  3604.       keyworddecl
  3605.  
  3606.     | keywordselector keyworddecl
  3607.         { 
  3608.           $$ = chainon($1, $2);
  3609.         }
  3610.     ;
  3611.  
  3612. selector:
  3613.       IDENTIFIER 
  3614.         | TYPENAME
  3615.     | OBJECTNAME
  3616.     | reservedwords
  3617.     ;
  3618.  
  3619. reservedwords:
  3620.       ENUM { $$ = get_identifier(token_buffer); }
  3621.     | AGGR { $$ = get_identifier(token_buffer); }
  3622.     | IF { $$ = get_identifier(token_buffer); }
  3623.     | ELSE { $$ = get_identifier(token_buffer); }
  3624.     | WHILE { $$ = get_identifier(token_buffer); }
  3625.     | DO { $$ = get_identifier(token_buffer); }
  3626.     | FOR { $$ = get_identifier(token_buffer); }
  3627.     | SWITCH { $$ = get_identifier(token_buffer); }
  3628.     | CASE { $$ = get_identifier(token_buffer); }
  3629.     | DEFAULT { $$ = get_identifier(token_buffer); }
  3630.     | BREAK { $$ = get_identifier(token_buffer); }
  3631.     | CONTINUE { $$ = get_identifier(token_buffer); }
  3632.     | RETURN  { $$ = get_identifier(token_buffer); }
  3633.     | GOTO { $$ = get_identifier(token_buffer); }
  3634.     | ASM { $$ = get_identifier(token_buffer); }
  3635.         | SIZEOF { $$ = get_identifier(token_buffer); } 
  3636.     | TYPEOF { $$ = get_identifier(token_buffer); }
  3637.     | ALIGNOF { $$ = get_identifier(token_buffer); }
  3638.     | NEW { $$ = get_identifier(token_buffer); }
  3639.     | DELETE { $$ = get_identifier(token_buffer); }
  3640.     | OPERATOR { $$ = get_identifier(token_buffer); }
  3641.     | PUBLIC { $$ = get_identifier(token_buffer); }
  3642.     | PRIVATE { $$ = get_identifier(token_buffer); }
  3643.     | PROTECTED { $$ = get_identifier(token_buffer); }
  3644.     | OVERLOAD { $$ = get_identifier(token_buffer); }
  3645.     | TYPESPEC 
  3646.      /*    | TYPE_QUAL ...this caused an ambiquity in g++, snaroff */
  3647.     ;
  3648.  
  3649. keyworddecl:
  3650.       selector ':' '(' typename ')' identifier
  3651.         { 
  3652.           $$ = build_keyword_decl($1, $4, $6);
  3653.         }
  3654.  
  3655.     | selector ':' identifier
  3656.         { 
  3657.           $$ = build_keyword_decl($1, NULL_TREE, $3);
  3658.         }
  3659.  
  3660.     | ':' '(' typename ')' identifier
  3661.         { 
  3662.           $$ = build_keyword_decl(NULL_TREE, $3, $5);
  3663.         }
  3664.  
  3665.     | ':' identifier
  3666.         { 
  3667.           $$ = build_keyword_decl(NULL_TREE, NULL_TREE, $2);
  3668.         }
  3669.     ;
  3670.  
  3671. messageargs:
  3672.       selector
  3673.         | keywordarglist
  3674.     ;
  3675.  
  3676. keywordarglist:
  3677.       keywordarg
  3678.     | keywordarglist keywordarg
  3679.         { 
  3680.           $$ = chainon($1, $2);
  3681.         }
  3682.     ;
  3683.  
  3684.  
  3685. keywordexpr:    
  3686.       nonnull_exprlist
  3687.         { 
  3688.           if (TREE_CHAIN($1) == NULL_TREE)
  3689.             /* just return the expr., remove a level of indirection */
  3690.             $$ = TREE_VALUE($1);
  3691.                   else
  3692.             /* we have a comma expr., we will collapse later */
  3693.             $$ = $1;
  3694.         }
  3695.     ;
  3696.  
  3697. keywordarg:
  3698.       selector ':' keywordexpr
  3699.         {
  3700.           $$ = build_tree_list($1, $3);
  3701.         }
  3702.     | ':' keywordexpr
  3703.         {
  3704.           $$ = build_tree_list(NULL_TREE,$2);
  3705.         }
  3706.     ;
  3707.  
  3708. receiver:
  3709.       expr
  3710.     | CLASSNAME
  3711.         {
  3712.           $$ = get_class_reference($1);
  3713.         }
  3714.     ;
  3715.  
  3716. objcmessageexpr:
  3717.       '[' 
  3718.         { objc_receiver_context = 1; }
  3719.       receiver 
  3720.         { objc_receiver_context = 0; }
  3721.       messageargs ']'
  3722.         {
  3723.           $$ = build_tree_list($3,$5);
  3724.         }
  3725.     ;
  3726.  
  3727. selectorarg:
  3728.       selector
  3729.         | keywordnamelist
  3730.     ;
  3731.  
  3732. keywordnamelist:
  3733.       keywordname
  3734.     | keywordnamelist keywordname
  3735.         { 
  3736.           $$ = chainon($1, $2);
  3737.         }
  3738.     ;
  3739.  
  3740. keywordname:
  3741.       selector ':' 
  3742.         {
  3743.           $$ = build_tree_list($1, NULL_TREE);
  3744.         }
  3745.     | ':' 
  3746.         {
  3747.           $$ = build_tree_list(NULL_TREE,NULL_TREE);
  3748.         }
  3749.     ;
  3750.  
  3751. objcselectorexpr:
  3752.       SELECTOR '(' selectorarg ')'
  3753.         {
  3754.           $$ = $3;
  3755.         }
  3756.     ;
  3757.  
  3758. objcprotocolexpr:
  3759.       PROTOCOL '(' identifier ')'
  3760.         {
  3761.           $$ = $3;
  3762.         }
  3763.     ;
  3764.  
  3765. /* extension to support C-structures in the archiver */
  3766.  
  3767. objcencodeexpr:
  3768.       ENCODE '(' typename ')'
  3769.         {
  3770.           $$ = groktypename($3);
  3771.         }
  3772.     ;
  3773.  
  3774. %%
  3775.  
  3776. #if YYDEBUG != 0
  3777. db_yyerror (s, yyps, yychar)
  3778.      char *s;
  3779.      short *yyps;
  3780.      int yychar;
  3781. {
  3782.   FILE *yyout;
  3783.   char buf[1024];
  3784.   int st;
  3785.  
  3786.   yyerror (s);
  3787.   printf ("State is %d, input token number is %d.\n", *yyps, yychar);
  3788.  
  3789. #ifdef PARSE_OUTPUT
  3790.   if (*yyps < 1) fatal ("Cannot start from here");
  3791.   else if ((yyout = fopen (PARSE_OUTPUT, "r")) == NULL)
  3792.     error ("cannot open file %s", PARSE_OUTPUT);
  3793.   else
  3794.     {
  3795.       printf ("That is to say,\n\n");
  3796.       while (fgets(buf, sizeof (buf)-1, yyout))
  3797.     {
  3798.       if (buf[0] != 's') continue;
  3799.       st = atoi (buf+6);
  3800.       if (st != *yyps) continue;
  3801.       printf ("%s", buf);
  3802.       while (fgets (buf, sizeof (buf)-1, yyout))
  3803.         {
  3804.           if (buf[0] == 's') break;
  3805.           printf ("%s", buf);
  3806.         }
  3807.       break;
  3808.     }
  3809.       printf ("With the token %s\n", yytname[YYTRANSLATE (yychar)]);
  3810.       fclose (yyout);
  3811.     }
  3812. #endif
  3813. }
  3814. #endif
  3815.  
  3816. void
  3817. yyerror (string)
  3818.      char *string;
  3819. {
  3820.   extern FILE *finput;
  3821.   extern char *token_buffer;
  3822.   char buf[200];
  3823.  
  3824.   strcpy (buf, string);
  3825.  
  3826.   /* We can't print string and character constants well
  3827.      because the token_buffer contains the result of processing escapes.  */
  3828.   if (end_of_file || feof (finput))
  3829.     strcat (buf, " at end of input");
  3830.   else if (token_buffer[0] == 0)
  3831.     strcat (buf, " at null character");
  3832.   else if (token_buffer[0] == '"')
  3833.     strcat (buf, " before string constant");
  3834.   else if (token_buffer[0] == '\'')
  3835.     strcat (buf, " before character constant");
  3836.   else
  3837.     strcat (buf, " before `%s'");
  3838.  
  3839.   error (buf, token_buffer);
  3840. }
  3841.  
  3842. static int *reduce_count;
  3843. static int *token_count;
  3844.  
  3845. #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
  3846. #define TOKEN_LENGTH (256 + YYNTBASE + 1)
  3847.  
  3848. int *
  3849. init_parse ()
  3850. {
  3851. #ifdef GATHER_STATISTICS
  3852.   reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
  3853.   bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
  3854.   reduce_count += 1;
  3855.   token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
  3856.   bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
  3857.   token_count += 1;
  3858. #endif
  3859.   return token_count;
  3860. }
  3861.  
  3862. #ifdef GATHER_STATISTICS
  3863. void
  3864. yyhook (yyn)
  3865.      int yyn;
  3866. {
  3867.   reduce_count[yyn] += 1;
  3868. }
  3869. #endif
  3870.  
  3871. static int reduce_cmp (p, q)
  3872.      int *p, *q;
  3873. {
  3874.   return reduce_count[*q] - reduce_count[*p];
  3875. }
  3876.  
  3877. static int token_cmp (p, q)
  3878.      int *p, *q;
  3879. {
  3880.   return token_count[*q] - token_count[*p];
  3881. }
  3882.  
  3883. void
  3884. print_parse_statistics ()
  3885. {
  3886.   int i;
  3887.   int maxlen = REDUCE_LENGTH;
  3888.   unsigned *sorted;
  3889.   
  3890.   if (reduce_count[-1] == 0)
  3891.     return;
  3892.  
  3893.   if (TOKEN_LENGTH > REDUCE_LENGTH)
  3894.     maxlen = TOKEN_LENGTH;
  3895.   sorted = (unsigned *) alloca (sizeof (int) * maxlen);
  3896.  
  3897.   for (i = 0; i < TOKEN_LENGTH; i++)
  3898.     sorted[i] = i;
  3899.   qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
  3900.   for (i = 0; i < TOKEN_LENGTH; i++)
  3901.     {
  3902.       int index = sorted[i];
  3903.       if (token_count[index] == 0)
  3904.     break;
  3905.       if (token_count[index] < token_count[-1])
  3906.     break;
  3907.       fprintf (stderr, "token %d", index);
  3908. #if YYDEBUG
  3909.       fprintf (stderr, ", `%s'", yytname[YYTRANSLATE (index)]);
  3910. #endif
  3911.       fprintf (stderr, ", count = %d\n", token_count[index]);
  3912.     }
  3913.   fprintf (stderr, "\n");
  3914.   for (i = 0; i < REDUCE_LENGTH; i++)
  3915.     sorted[i] = i;
  3916.   qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
  3917.   for (i = 0; i < REDUCE_LENGTH; i++)
  3918.     {
  3919.       int index = sorted[i];
  3920.       if (reduce_count[index] == 0)
  3921.     break;
  3922.       if (reduce_count[index] < reduce_count[-1])
  3923.     break;
  3924.       fprintf (stderr, "rule %d", index);
  3925. #if YYDEBUG
  3926.       fprintf (stderr, ", line %d", yyrline[index]);
  3927. #endif
  3928.       fprintf (stderr, ", count = %d\n", reduce_count[index]);
  3929.     }
  3930.   fprintf (stderr, "\n");
  3931. }
  3932.