PageRenderTime 77ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/opensource.apple.com/source/gcc_legacy/gcc_legacy-938/gcc/objc/objc-parse.y

#
Happy | 2090 lines | 1904 code | 186 blank | 0 comment | 0 complexity | 0f3afb24e776707c725749d5d0d3f48b MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0

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

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>objc-parse.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">objc-parse.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /*WARNING: This file is automatically generated!*/
  24. /*WARNING: This file is automatically generated!*/
  25. /* YACC parser for C syntax and for Objective C. -*-c-*-
  26. Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
  27. This file is part of GNU CC.
  28. GNU CC is free software; you can redistribute it and/or modify
  29. it under the terms of the GNU General Public License as published by
  30. the Free Software Foundation; either version 2, or (at your option)
  31. any later version.
  32. GNU CC is distributed in the hope that it will be useful,
  33. but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. GNU General Public License for more details.
  36. You should have received a copy of the GNU General Public License
  37. along with GNU CC; see the file COPYING. If not, write to
  38. the Free Software Foundation, 59 Temple Place - Suite 330,
  39. Boston, MA 02111-1307, USA. */
  40. /* This file defines the grammar of C and that of Objective C.
  41. ifobjc ... end ifobjc conditionals contain code for Objective C only.
  42. ifc ... end ifc conditionals contain code for C only.
  43. Sed commands in Makefile.in are used to convert this file into
  44. c-parse.y and into objc-parse.y. */
  45. /* To whomever it may concern: I have heard that such a thing was once
  46. written by AT&amp;T, but I have never seen it. */
  47. %expect 66
  48. /* These are the 23 conflicts you should get in parse.output;
  49. the state numbers may vary if minor changes in the grammar are made.
  50. State 42 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
  51. State 44 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  52. State 103 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  53. State 110 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
  54. State 111 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  55. State 115 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  56. State 132 contains 1 shift/reduce conflict. (See comment at component_decl.)
  57. State 180 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
  58. State 194 contains 2 shift/reduce conflict. (Four ways to parse this.)
  59. State 202 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  60. State 214 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  61. State 220 contains 1 shift/reduce conflict. (Two ways to recover from error.)
  62. State 304 contains 2 shift/reduce conflicts. (Four ways to parse this.)
  63. State 335 contains 2 shift/reduce conflicts. (Four ways to parse this.)
  64. State 347 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
  65. State 352 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
  66. State 383 contains 2 shift/reduce conflicts. (Four ways to parse this.)
  67. State 434 contains 2 shift/reduce conflicts. (Four ways to parse this.) */
  68. %{
  69. #include &quot;config.h&quot;
  70. #include &quot;system.h&quot;
  71. #include &lt;setjmp.h&gt;
  72. #include &quot;tree.h&quot;
  73. #include &quot;input.h&quot;
  74. #include &quot;c-lex.h&quot;
  75. #include &quot;c-tree.h&quot;
  76. #include &quot;flags.h&quot;
  77. #include &quot;output.h&quot;
  78. #include &quot;toplev.h&quot;
  79. #ifdef MULTIBYTE_CHARS
  80. #include &lt;locale.h&gt;
  81. #endif
  82. #include &quot;objc-act.h&quot;
  83. /* Since parsers are distinct for each language, put the language string
  84. definition here. */
  85. char *language_string = &quot;GNU Obj-C&quot;;
  86. static tree last_compound_expr, last_compound_list;
  87. #ifndef errno
  88. extern int errno;
  89. #endif
  90. void yyerror ();
  91. /* Like YYERROR but do call yyerror. */
  92. #define YYERROR1 { yyerror (&quot;syntax error&quot;); YYERROR; }
  93. /* Cause the `yydebug' variable to be defined. */
  94. #define YYDEBUG 1
  95. %}
  96. %start program
  97. %union {long itype; tree ttype; enum tree_code code;
  98. char *filename; int lineno; int ends_in_label; }
  99. /* All identifiers that are not reserved words
  100. and are not declared typedefs in the current block */
  101. %token IDENTIFIER
  102. /* All identifiers that are declared typedefs in the current block.
  103. In some contexts, they are treated just like IDENTIFIER,
  104. but they can also serve as typespecs in declarations. */
  105. %token TYPENAME
  106. /* Reserved words that specify storage class.
  107. yylval contains an IDENTIFIER_NODE which indicates which one. */
  108. %token SCSPEC
  109. /* Reserved words that specify type.
  110. yylval contains an IDENTIFIER_NODE which indicates which one. */
  111. %token TYPESPEC
  112. /* Reserved words that qualify type: &quot;const&quot;, &quot;volatile&quot;, or &quot;restrict&quot;.
  113. yylval contains an IDENTIFIER_NODE which indicates which one. */
  114. %token TYPE_QUAL
  115. /* Character or numeric constants.
  116. yylval is the node for the constant. */
  117. %token CONSTANT
  118. /* String constants in raw form.
  119. yylval is a STRING_CST node. */
  120. %token STRING
  121. /* &quot;...&quot;, used for functions with variable arglists. */
  122. %token ELLIPSIS
  123. /* the reserved words */
  124. /* SCO include files test &quot;ASM&quot;, so use something else. */
  125. %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  126. %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
  127. %token ATTRIBUTE EXTENSION LABEL
  128. %token REALPART IMAGPART
  129. %token VEC_STEP
  130. /* Add precedence rules to solve dangling else s/r conflict */
  131. %nonassoc IF
  132. %nonassoc ELSE
  133. /* Define the operator tokens and their precedences.
  134. The value is an integer because, if used, it is the tree code
  135. to use in the expression made from the operator. */
  136. %right &lt;code&gt; ASSIGN '='
  137. %right &lt;code&gt; '?' ':'
  138. %left &lt;code&gt; OROR
  139. %left &lt;code&gt; ANDAND
  140. %left &lt;code&gt; '|'
  141. %left &lt;code&gt; '^'
  142. %left &lt;code&gt; '&amp;'
  143. %left &lt;code&gt; EQCOMPARE
  144. %left &lt;code&gt; ARITHCOMPARE
  145. %left &lt;code&gt; LSHIFT RSHIFT
  146. %left &lt;code&gt; '+' '-'
  147. %left &lt;code&gt; '*' '/' '%'
  148. %right &lt;code&gt; UNARY PLUSPLUS MINUSMINUS
  149. %left HYPERUNARY
  150. %left &lt;code&gt; POINTSAT '.' '(' '['
  151. /* The Objective-C keywords. These are included in C and in
  152. Objective C, so that the token codes are the same in both. */
  153. %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
  154. %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
  155. /* Objective-C string constants in raw form.
  156. yylval is an OBJC_STRING_CST node. */
  157. %token OBJC_STRING
  158. %type &lt;code&gt; unop
  159. %type &lt;ttype&gt; identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
  160. %type &lt;ttype&gt; expr_no_commas cast_expr unary_expr primary string STRING
  161. %type &lt;ttype&gt; typed_declspecs reserved_declspecs
  162. %type &lt;ttype&gt; typed_typespecs reserved_typespecquals
  163. %type &lt;ttype&gt; declmods typespec typespecqual_reserved
  164. %type &lt;ttype&gt; typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
  165. %type &lt;ttype&gt; declmods_no_prefix_attr
  166. %type &lt;ttype&gt; SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
  167. %type &lt;ttype&gt; initdecls notype_initdecls initdcl notype_initdcl
  168. %type &lt;ttype&gt; init maybeasm
  169. %type &lt;ttype&gt; asm_operands nonnull_asm_operands asm_operand asm_clobbers
  170. %type &lt;ttype&gt; maybe_attribute attributes attribute attribute_list attrib
  171. %type &lt;ttype&gt; any_word
  172. %type &lt;ttype&gt; compstmt
  173. %type &lt;ttype&gt; declarator
  174. %type &lt;ttype&gt; notype_declarator after_type_declarator
  175. %type &lt;ttype&gt; parm_declarator
  176. %type &lt;ttype&gt; structsp component_decl_list component_decl_list2
  177. %type &lt;ttype&gt; component_decl components component_declarator
  178. %type &lt;ttype&gt; enumlist enumerator
  179. %type &lt;ttype&gt; struct_head union_head enum_head
  180. %type &lt;ttype&gt; typename absdcl absdcl1 type_quals
  181. %type &lt;ttype&gt; xexpr parms parm identifiers
  182. %type &lt;ttype&gt; parmlist parmlist_1 parmlist_2
  183. %type &lt;ttype&gt; parmlist_or_identifiers parmlist_or_identifiers_1
  184. %type &lt;ttype&gt; identifiers_or_typenames
  185. %type &lt;itype&gt; setspecs
  186. %type &lt;ends_in_label&gt; lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
  187. %type &lt;filename&gt; save_filename
  188. %type &lt;lineno&gt; save_lineno
  189. /* the Objective-C nonterminals */
  190. %type &lt;ttype&gt; ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
  191. %type &lt;ttype&gt; methoddecl unaryselector keywordselector selector
  192. %type &lt;ttype&gt; keyworddecl receiver objcmessageexpr messageargs
  193. %type &lt;ttype&gt; keywordexpr keywordarglist keywordarg
  194. %type &lt;ttype&gt; myparms myparm optparmlist reservedwords objcselectorexpr
  195. %type &lt;ttype&gt; selectorarg keywordnamelist keywordname objcencodeexpr
  196. %type &lt;ttype&gt; objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
  197. %type &lt;ttype&gt; CLASSNAME OBJC_STRING OBJECTNAME
  198. %type &lt;ttype&gt; objc_openbracket.expr_no_commas
  199. %type &lt;ttype&gt; objc_return_type_mods
  200. %{
  201. /* Number of statements (loosely speaking) and compound statements
  202. seen so far. */
  203. static int stmt_count;
  204. static int compstmt_count;
  205. /* Input file and line number of the end of the body of last simple_if;
  206. used by the stmt-rule immediately after simple_if returns. */
  207. static char *if_stmt_file;
  208. static int if_stmt_line;
  209. /* List of types and structure classes of the current declaration. */
  210. static tree current_declspecs = NULL_TREE;
  211. static tree prefix_attributes = NULL_TREE;
  212. /* Stack of saved values of current_declspecs and prefix_attributes. */
  213. static tree declspec_stack;
  214. /* 1 if we explained undeclared var errors. */
  215. static int undeclared_variable_notice;
  216. /* Objective-C specific information */
  217. tree objc_interface_context;
  218. tree objc_implementation_context;
  219. tree objc_method_context;
  220. tree objc_ivar_chain;
  221. tree objc_ivar_context;
  222. enum tree_code objc_inherit_code;
  223. int objc_receiver_context;
  224. int objc_public_flag;
  225. #ifdef MODERN_OBJC_SYNTAX
  226. extern flag_modern_objc_syntax;
  227. #endif
  228. /* Tell yyparse how to print a token's value, if yydebug is set. */
  229. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  230. extern void yyprint PROTO ((FILE *, int, YYSTYPE));
  231. %}
  232. %%
  233. program: /* empty */
  234. { if (pedantic)
  235. pedwarn (&quot;ANSI C forbids an empty source file&quot;);
  236. finish_file ();
  237. }
  238. | extdefs
  239. {
  240. /* In case there were missing closebraces,
  241. get us back to the global binding level. */
  242. while (! global_bindings_p ())
  243. poplevel (0, 0, 0);
  244. finish_file ();
  245. }
  246. ;
  247. /* the reason for the strange actions in this rule
  248. is so that notype_initdecls when reached via datadef
  249. can find a valid list of type and sc specs in $0. */
  250. extdefs:
  251. {$&lt;ttype&gt;$ = NULL_TREE; } extdef
  252. | extdefs {$&lt;ttype&gt;$ = NULL_TREE; } extdef
  253. ;
  254. extdef:
  255. fndef
  256. | datadef
  257. | objcdef
  258. | ASM_KEYWORD '(' expr ')' ';'
  259. { STRIP_NOPS ($3);
  260. if ((TREE_CODE ($3) == ADDR_EXPR
  261. &amp;&amp; TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
  262. || TREE_CODE ($3) == STRING_CST)
  263. assemble_asm ($3);
  264. else
  265. error (&quot;argument of `asm' is not a constant string&quot;); }
  266. | extension extdef
  267. { pedantic = $&lt;itype&gt;1; }
  268. ;
  269. datadef:
  270. setspecs notype_initdecls ';'
  271. { if (pedantic)
  272. error (&quot;ANSI C forbids data definition with no type or storage class&quot;);
  273. else if (!flag_traditional)
  274. warning (&quot;data definition has no type or storage class&quot;);
  275. current_declspecs = TREE_VALUE (declspec_stack);
  276. prefix_attributes = TREE_PURPOSE (declspec_stack);
  277. declspec_stack = TREE_CHAIN (declspec_stack);
  278. resume_momentary ($1); }
  279. | declmods setspecs notype_initdecls ';'
  280. { current_declspecs = TREE_VALUE (declspec_stack);
  281. prefix_attributes = TREE_PURPOSE (declspec_stack);
  282. declspec_stack = TREE_CHAIN (declspec_stack);
  283. resume_momentary ($2); }
  284. | typed_declspecs setspecs initdecls ';'
  285. { current_declspecs = TREE_VALUE (declspec_stack);
  286. prefix_attributes = TREE_PURPOSE (declspec_stack);
  287. declspec_stack = TREE_CHAIN (declspec_stack);
  288. resume_momentary ($2); }
  289. | declmods ';'
  290. { pedwarn (&quot;empty declaration&quot;); }
  291. | typed_declspecs ';'
  292. { shadow_tag ($1); }
  293. | error ';'
  294. | error '}'
  295. | ';'
  296. { if (pedantic)
  297. pedwarn (&quot;ANSI C does not allow extra `;' outside of a function&quot;); }
  298. ;
  299. fndef:
  300. typed_declspecs setspecs declarator
  301. {
  302. #ifdef MODERN_OBJC_SYNTAX
  303. if (flag_modern_objc_syntax &amp;&amp; objc_implementation_context)
  304. {
  305. tree md = build_method_decl_from_ansiproto($3, $1,
  306. objc_implementation_context);
  307. start_method_def(md);
  308. objc_method_context = md;
  309. objc_receiver_context = 1;
  310. }
  311. else
  312. {
  313. #endif
  314. if (! start_function (current_declspecs, $3,
  315. prefix_attributes, NULL_TREE, 0))
  316. YYERROR1;
  317. reinit_parse_for_function ();
  318. #ifdef MODERN_OBJC_SYNTAX
  319. }
  320. #endif
  321. }
  322. old_style_parm_decls
  323. {
  324. #ifdef MODERN_OBJC_SYNTAX
  325. if (objc_implementation_context &amp;&amp; objc_method_context)
  326. continue_method_def();
  327. else
  328. #endif
  329. store_parm_decls ();
  330. }
  331. compstmt_or_error
  332. {
  333. #ifdef MODERN_OBJC_SYNTAX
  334. if (objc_implementation_context &amp;&amp; objc_method_context)
  335. {
  336. finish_method_def();
  337. objc_method_context = NULL_TREE;
  338. objc_receiver_context = 0;
  339. }
  340. else
  341. {
  342. #endif
  343. finish_function (0);
  344. current_declspecs = TREE_VALUE (declspec_stack);
  345. prefix_attributes = TREE_PURPOSE (declspec_stack);
  346. declspec_stack = TREE_CHAIN (declspec_stack);
  347. resume_momentary ($2);
  348. #ifdef MODERN_OBJC_SYNTAX
  349. }
  350. #endif
  351. }
  352. | typed_declspecs setspecs declarator error
  353. { current_declspecs = TREE_VALUE (declspec_stack);
  354. prefix_attributes = TREE_PURPOSE (declspec_stack);
  355. declspec_stack = TREE_CHAIN (declspec_stack);
  356. resume_momentary ($2); }
  357. | declmods setspecs notype_declarator
  358. { if (! start_function (current_declspecs, $3,
  359. prefix_attributes, NULL_TREE, 0))
  360. YYERROR1;
  361. reinit_parse_for_function (); }
  362. old_style_parm_decls
  363. { store_parm_decls (); }
  364. compstmt_or_error
  365. { finish_function (0);
  366. current_declspecs = TREE_VALUE (declspec_stack);
  367. prefix_attributes = TREE_PURPOSE (declspec_stack);
  368. declspec_stack = TREE_CHAIN (declspec_stack);
  369. resume_momentary ($2); }
  370. | declmods setspecs notype_declarator error
  371. { current_declspecs = TREE_VALUE (declspec_stack);
  372. prefix_attributes = TREE_PURPOSE (declspec_stack);
  373. declspec_stack = TREE_CHAIN (declspec_stack);
  374. resume_momentary ($2); }
  375. | setspecs notype_declarator
  376. { if (! start_function (NULL_TREE, $2,
  377. prefix_attributes, NULL_TREE, 0))
  378. YYERROR1;
  379. reinit_parse_for_function (); }
  380. old_style_parm_decls
  381. { store_parm_decls (); }
  382. compstmt_or_error
  383. { finish_function (0);
  384. current_declspecs = TREE_VALUE (declspec_stack);
  385. prefix_attributes = TREE_PURPOSE (declspec_stack);
  386. declspec_stack = TREE_CHAIN (declspec_stack);
  387. resume_momentary ($1); }
  388. | setspecs notype_declarator error
  389. { current_declspecs = TREE_VALUE (declspec_stack);
  390. prefix_attributes = TREE_PURPOSE (declspec_stack);
  391. declspec_stack = TREE_CHAIN (declspec_stack);
  392. resume_momentary ($1); }
  393. ;
  394. identifier:
  395. IDENTIFIER
  396. | TYPENAME
  397. | OBJECTNAME
  398. | CLASSNAME
  399. ;
  400. unop: '&amp;'
  401. { $$ = ADDR_EXPR; }
  402. | '-'
  403. { $$ = NEGATE_EXPR; }
  404. | '+'
  405. { $$ = CONVERT_EXPR; }
  406. | PLUSPLUS
  407. { $$ = PREINCREMENT_EXPR; }
  408. | MINUSMINUS
  409. { $$ = PREDECREMENT_EXPR; }
  410. | '~'
  411. { $$ = BIT_NOT_EXPR; }
  412. | '!'
  413. { $$ = TRUTH_NOT_EXPR; }
  414. ;
  415. expr: nonnull_exprlist
  416. { $$ = last_compound_expr
  417. = build_compound_expr (last_compound_list = $1); }
  418. ;
  419. exprlist:
  420. /* empty */
  421. { $$ = NULL_TREE; }
  422. | nonnull_exprlist
  423. ;
  424. nonnull_exprlist:
  425. expr_no_commas
  426. { $$ = build_tree_list (NULL_TREE, $1); }
  427. | nonnull_exprlist ',' expr_no_commas
  428. { chainon ($1, build_tree_list (NULL_TREE, $3)); }
  429. ;
  430. unary_expr:
  431. primary
  432. | '*' cast_expr %prec UNARY
  433. { $$ = build_indirect_ref ($2, &quot;unary *&quot;); }
  434. /* __extension__ turns off -pedantic for following primary. */
  435. | extension cast_expr %prec UNARY
  436. { $$ = $2;
  437. pedantic = $&lt;itype&gt;1; }
  438. | unop cast_expr %prec UNARY
  439. { $$ = build_unary_op ($1, $2, 0);
  440. overflow_warning ($$); }
  441. /* Refer to the address of a label as a pointer. */
  442. | ANDAND identifier
  443. { tree label = lookup_label ($2);
  444. if (pedantic)
  445. pedwarn (&quot;ANSI C forbids `&amp;&amp;'&quot;);
  446. if (label == 0)
  447. $$ = null_pointer_node;
  448. else
  449. {
  450. TREE_USED (label) = 1;
  451. $$ = build1 (ADDR_EXPR, ptr_type_node, label);
  452. TREE_CONSTANT ($$) = 1;
  453. }
  454. }
  455. /* This seems to be impossible on some machines, so let's turn it off.
  456. You can use __builtin_next_arg to find the anonymous stack args.
  457. | '&amp;' ELLIPSIS
  458. { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
  459. $$ = error_mark_node;
  460. if (TREE_VALUE (tree_last (types)) == void_type_node)
  461. error (&quot;`&amp;...' used in function with fixed number of arguments&quot;);
  462. else
  463. {
  464. if (pedantic)
  465. pedwarn (&quot;ANSI C forbids `&amp;...'&quot;);
  466. $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
  467. $$ = build_unary_op (ADDR_EXPR, $$, 0);
  468. } }
  469. */
  470. | sizeof unary_expr %prec UNARY
  471. { skip_evaluation--;
  472. if (TREE_CODE ($2) == COMPONENT_REF
  473. &amp;&amp; DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
  474. error (&quot;`sizeof' applied to a bit-field&quot;);
  475. $$ = c_sizeof (TREE_TYPE ($2)); }
  476. | sizeof '(' typename ')' %prec HYPERUNARY
  477. { skip_evaluation--;
  478. $$ = c_sizeof (groktypename ($3)); }
  479. | alignof unary_expr %prec UNARY
  480. { skip_evaluation--;
  481. $$ = c_alignof_expr ($2); }
  482. | alignof '(' typename ')' %prec HYPERUNARY
  483. { skip_evaluation--;
  484. $$ = c_alignof (groktypename ($3)); }
  485. | vec_step unary_expr %prec UNARY
  486. { skip_evaluation--;
  487. $$ = c_vec_step_expr ($2); }
  488. | vec_step '(' typename ')' %prec HYPERUNARY
  489. { skip_evaluation--;
  490. $$ = c_vec_step (groktypename ($3)); }
  491. | REALPART cast_expr %prec UNARY
  492. { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
  493. | IMAGPART cast_expr %prec UNARY
  494. { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
  495. ;
  496. sizeof:
  497. SIZEOF { skip_evaluation++; }
  498. ;
  499. alignof:
  500. ALIGNOF { skip_evaluation++; }
  501. ;
  502. vec_step:
  503. VEC_STEP { skip_evaluation++; }
  504. ;
  505. cast_expr:
  506. unary_expr
  507. | '(' typename ')' cast_expr %prec UNARY
  508. { tree type = groktypename ($2);
  509. /* If typename is a vector type, check for the form of a
  510. vector constant. The cast_expr must be of the form
  511. '(' nonnull_expr_list ')' and the expression list must
  512. consist of integer constants or floating point
  513. constants. Unfortunately, we need the actual list of
  514. constants, not the value after the list was reduced by
  515. build_compound_expr. We hack around this by saving
  516. the last input and result of build_compound_expr and
  517. using them here. */
  518. tree last = $4;
  519. STRIP_NOPS(last);
  520. if (TREE_CODE (type) == VECTOR_TYPE
  521. &amp;&amp; $4 == last_compound_expr
  522. &amp;&amp; (TREE_CODE (last) == INTEGER_CST
  523. || TREE_CODE (last) == REAL_CST))
  524. $$ = build_vector_constant (type, last_compound_list);
  525. else
  526. $$ = build_c_cast (type, $4); }
  527. | '(' typename ')' '{'
  528. { start_init (NULL_TREE, NULL, 0);
  529. $2 = groktypename ($2);
  530. really_start_incremental_init ($2); }
  531. initlist_maybe_comma '}' %prec UNARY
  532. { char *name;
  533. tree result = pop_init_level (0);
  534. tree type = $2;
  535. finish_init ();
  536. if (pedantic &amp;&amp; ! flag_isoc9x)
  537. pedwarn (&quot;ANSI C forbids constructor expressions&quot;);
  538. if (TYPE_NAME (type) != 0)
  539. {
  540. if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  541. name = IDENTIFIER_POINTER (TYPE_NAME (type));
  542. else
  543. name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  544. }
  545. else
  546. name = &quot;&quot;;
  547. $$ = result;
  548. if (TREE_CODE (type) == ARRAY_TYPE &amp;&amp; TYPE_SIZE (type) == 0)
  549. {
  550. int failure = complete_array_type (type, $$, 1);
  551. if (failure)
  552. abort ();
  553. }
  554. }
  555. ;
  556. expr_no_commas:
  557. cast_expr
  558. | expr_no_commas '+' expr_no_commas
  559. { $$ = parser_build_binary_op ($2, $1, $3); }
  560. | expr_no_commas '-' expr_no_commas
  561. { $$ = parser_build_binary_op ($2, $1, $3); }
  562. | expr_no_commas '*' expr_no_commas
  563. { $$ = parser_build_binary_op ($2, $1, $3); }
  564. | expr_no_commas '/' expr_no_commas
  565. { $$ = parser_build_binary_op ($2, $1, $3); }
  566. | expr_no_commas '%' expr_no_commas
  567. { $$ = parser_build_binary_op ($2, $1, $3); }
  568. | expr_no_commas LSHIFT expr_no_commas
  569. { $$ = parser_build_binary_op ($2, $1, $3); }
  570. | expr_no_commas RSHIFT expr_no_commas
  571. { $$ = parser_build_binary_op ($2, $1, $3); }
  572. | expr_no_commas ARITHCOMPARE expr_no_commas
  573. { $$ = parser_build_binary_op ($2, $1, $3); }
  574. | expr_no_commas EQCOMPARE expr_no_commas
  575. { $$ = parser_build_binary_op ($2, $1, $3); }
  576. | expr_no_commas '&amp;' expr_no_commas
  577. { $$ = parser_build_binary_op ($2, $1, $3); }
  578. | expr_no_commas '|' expr_no_commas
  579. { $$ = parser_build_binary_op ($2, $1, $3); }
  580. | expr_no_commas '^' expr_no_commas
  581. { $$ = parser_build_binary_op ($2, $1, $3); }
  582. | expr_no_commas ANDAND
  583. { $1 = truthvalue_conversion (default_conversion ($1));
  584. skip_evaluation += $1 == boolean_false_node; }
  585. expr_no_commas
  586. { skip_evaluation -= $1 == boolean_false_node;
  587. $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
  588. | expr_no_commas OROR
  589. { $1 = truthvalue_conversion (default_conversion ($1));
  590. skip_evaluation += $1 == boolean_true_node; }
  591. expr_no_commas
  592. { skip_evaluation -= $1 == boolean_true_node;
  593. $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
  594. | expr_no_commas '?'
  595. { $1 = truthvalue_conversion (default_conversion ($1));
  596. skip_evaluation += $1 == boolean_false_node; }
  597. expr ':'
  598. { skip_evaluation += (($1 == boolean_true_node)
  599. - ($1 == boolean_false_node)); }
  600. expr_no_commas
  601. { skip_evaluation -= $1 == boolean_true_node;
  602. $$ = build_conditional_expr ($1, $4, $7); }
  603. | expr_no_commas '?'
  604. { if (pedantic)
  605. pedwarn (&quot;ANSI C forbids omitting the middle term of a ?: expression&quot;);
  606. /* Make sure first operand is calculated only once. */
  607. $&lt;ttype&gt;2 = save_expr ($1);
  608. $1 = truthvalue_conversion (default_conversion ($&lt;ttype&gt;2));
  609. skip_evaluation += $1 == boolean_true_node; }
  610. ':' expr_no_commas
  611. { skip_evaluation -= $1 == boolean_true_node;
  612. $$ = build_conditional_expr ($1, $&lt;ttype&gt;2, $5); }
  613. | expr_no_commas '=' expr_no_commas
  614. { char class;
  615. $$ = build_modify_expr ($1, NOP_EXPR, $3);
  616. class = TREE_CODE_CLASS (TREE_CODE ($$));
  617. if (class == 'e' || class == '1'
  618. || class == '2' || class == '&lt;')
  619. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
  620. }
  621. | expr_no_commas ASSIGN expr_no_commas
  622. { char class;
  623. $$ = build_modify_expr ($1, $2, $3);
  624. /* This inhibits warnings in truthvalue_conversion. */
  625. class = TREE_CODE_CLASS (TREE_CODE ($$));
  626. if (class == 'e' || class == '1'
  627. || class == '2' || class == '&lt;')
  628. C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
  629. }
  630. ;
  631. primary:
  632. IDENTIFIER
  633. {
  634. $$ = lastiddecl;
  635. if (!$$ || $$ == error_mark_node)
  636. {
  637. if (yychar == YYEMPTY)
  638. yychar = YYLEX;
  639. if (yychar == '(')
  640. {
  641. tree decl;
  642. if (objc_receiver_context
  643. &amp;&amp; ! (objc_receiver_context
  644. &amp;&amp; strcmp (IDENTIFIER_POINTER ($1), &quot;super&quot;)))
  645. /* we have a message to super */
  646. $$ = get_super_receiver ();
  647. else if (objc_method_context
  648. &amp;&amp; (decl = is_ivar (objc_ivar_chain, $1)))
  649. {
  650. if (is_private (decl))
  651. $$ = error_mark_node;
  652. else
  653. $$ = build_ivar_reference ($1);
  654. }
  655. else
  656. {
  657. /* Ordinary implicit function declaration. */
  658. $$ = implicitly_declare ($1);
  659. assemble_external ($$);
  660. TREE_USED ($$) = 1;
  661. }
  662. }
  663. else if (current_function_decl == 0)
  664. {
  665. error (&quot;`%s' undeclared here (not in a function)&quot;,
  666. IDENTIFIER_POINTER ($1));
  667. $$ = error_mark_node;
  668. }
  669. else
  670. {
  671. tree decl;
  672. if (objc_receiver_context
  673. &amp;&amp; ! strcmp (IDENTIFIER_POINTER ($1), &quot;super&quot;))
  674. /* we have a message to super */
  675. $$ = get_super_receiver ();
  676. else if (objc_method_context
  677. &amp;&amp; (decl = is_ivar (objc_ivar_chain, $1)))
  678. {
  679. if (is_private (decl))
  680. $$ = error_mark_node;
  681. else
  682. $$ = build_ivar_reference ($1);
  683. }
  684. else
  685. {
  686. if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
  687. || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
  688. {
  689. error (&quot;`%s' undeclared (first use in this function)&quot;,
  690. IDENTIFIER_POINTER ($1));
  691. if (! undeclared_variable_notice)
  692. {
  693. error (&quot;(Each undeclared identifier is reported only once&quot;);
  694. error (&quot;for each function it appears in.)&quot;);
  695. undeclared_variable_notice = 1;
  696. }
  697. }
  698. $$ = error_mark_node;
  699. /* Prevent repeated error messages. */
  700. IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
  701. IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
  702. }
  703. }
  704. }
  705. else if (TREE_TYPE ($$) == error_mark_node)
  706. $$ = error_mark_node;
  707. else if (C_DECL_ANTICIPATED ($$))
  708. {
  709. /* The first time we see a build-in function used,
  710. if it has not been declared. */
  711. C_DECL_ANTICIPATED ($$) = 0;
  712. if (yychar == YYEMPTY)
  713. yychar = YYLEX;
  714. if (yychar == '(')
  715. {
  716. /* Omit the implicit declaration we
  717. would ordinarily do, so we don't lose
  718. the actual built in type.
  719. But print a diagnostic for the mismatch. */
  720. if (objc_method_context
  721. &amp;&amp; is_ivar (objc_ivar_chain, $1))
  722. error (&quot;Instance variable `%s' implicitly declared as function&quot;,
  723. IDENTIFIER_POINTER (DECL_NAME ($$)));
  724. else
  725. if (TREE_CODE ($$) != FUNCTION_DECL)
  726. error (&quot;`%s' implicitly declared as function&quot;,
  727. IDENTIFIER_POINTER (DECL_NAME ($$)));
  728. else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
  729. != TYPE_MODE (integer_type_node))
  730. &amp;&amp; (TREE_TYPE (TREE_TYPE ($$))
  731. != void_type_node))
  732. pedwarn (&quot;type mismatch in implicit declaration for built-in function `%s'&quot;,
  733. IDENTIFIER_POINTER (DECL_NAME ($$)));
  734. /* If it really returns void, change that to int. */
  735. if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
  736. TREE_TYPE ($$)
  737. = build_function_type (integer_type_node,
  738. TYPE_ARG_TYPES (TREE_TYPE ($$)));
  739. }
  740. else
  741. pedwarn (&quot;built-in function `%s' used without declaration&quot;,
  742. IDENTIFIER_POINTER (DECL_NAME ($$)));
  743. /* Do what we would ordinarily do when a fn is used. */
  744. assemble_external ($$);
  745. TREE_USED ($$) = 1;
  746. }
  747. else
  748. {
  749. assemble_external ($$);
  750. TREE_USED ($$) = 1;
  751. /* we have a definition - still check if iVariable */
  752. if (!objc_receiver_context
  753. || (objc_receiver_context
  754. &amp;&amp; strcmp (IDENTIFIER_POINTER ($1), &quot;super&quot;)))
  755. {
  756. tree decl;
  757. if (objc_method_context
  758. &amp;&amp; (decl = is_ivar (objc_ivar_chain, $1)))
  759. {
  760. if (IDENTIFIER_LOCAL_VALUE ($1))
  761. warning (&quot;local declaration of `%s' hides instance variable&quot;,
  762. IDENTIFIER_POINTER ($1));
  763. else
  764. {
  765. if (is_private (decl))
  766. $$ = error_mark_node;
  767. else
  768. $$ = build_ivar_reference ($1);
  769. }
  770. }
  771. }
  772. else /* we have a message to super */
  773. $$ = get_super_receiver ();
  774. }
  775. if (TREE_CODE ($$) == CONST_DECL)
  776. {
  777. $$ = DECL_INITIAL ($$);
  778. /* This is to prevent an enum whose value is 0
  779. from being considered a null pointer constant. */
  780. $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
  781. TREE_CONSTANT ($$) = 1;
  782. }
  783. }
  784. | CONSTANT
  785. | string
  786. { $$ = combine_strings ($1); }
  787. | '(' expr ')'
  788. { char class = TREE_CODE_CLASS (TREE_CODE ($2));
  789. if (class == 'e' || class == '1'
  790. || class == '2' || class == '&lt;')
  791. C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
  792. $$ = $2; }
  793. | '(' error ')'
  794. { $$ = error_mark_node; }
  795. | '('
  796. { if (current_function_decl == 0)
  797. {
  798. error (&quot;braced-group within expression allowed only inside a function&quot;);
  799. YYERROR;
  800. }
  801. /* We must force a BLOCK for this level
  802. so that, if it is not expanded later,
  803. there is a way to turn off the entire subtree of blocks
  804. that are contained in it. */
  805. keep_next_level ();
  806. push_iterator_stack ();
  807. push_label_level ();
  808. $&lt;ttype&gt;$ = expand_start_stmt_expr (); }
  809. compstmt ')'
  810. { tree rtl_exp;
  811. if (pedantic)
  812. pedwarn (&quot;ANSI C forbids braced-groups within expressions&quot;);
  813. pop_iterator_stack ();
  814. pop_label_level ();
  815. rtl_exp = expand_end_stmt_expr ($&lt;ttype&gt;2);
  816. /* The statements have side effects, so the group does. */
  817. TREE_SIDE_EFFECTS (rtl_exp) = 1;
  818. if (TREE_CODE ($3) == BLOCK)
  819. {
  820. /* Make a BIND_EXPR for the BLOCK already made. */
  821. $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
  822. NULL_TREE, rtl_exp, $3);
  823. /* Remove the block from the tree at this point.
  824. It gets put back at the proper place
  825. when the BIND_EXPR is expanded. */
  826. delete_block ($3);
  827. }
  828. else
  829. $$ = $3;
  830. }
  831. | primary '(' exprlist ')' %prec '.'
  832. {
  833. #ifdef MODERN_OBJC_SYNTAX
  834. if (doing_objc_thang &amp;&amp; flag_modern_objc_syntax &amp;&amp;
  835. TREE_CODE ($1) == MODERN_MESSAGE_EXPR)
  836. $$ = build_modern_message_expression($1, $3);
  837. else
  838. #endif
  839. $$ = build_function_call ($1, $3);
  840. }
  841. | primary '[' expr ']' %prec '.'
  842. { $$ = build_array_ref ($1, $3); }
  843. | CLASSNAME '.' identifier
  844. {
  845. #ifdef MODERN_OBJC_SYNTAX
  846. if (doing_objc_thang &amp;&amp; flag_modern_objc_syntax)
  847. {
  848. $1 = get_class_reference ($1);
  849. $$ = build (MODERN_MESSAGE_EXPR, TREE_TYPE ($1), $1, $3);
  850. }
  851. else
  852. #endif
  853. $$ = error_mark_node;
  854. }
  855. | primary '.' identifier
  856. {
  857. if (doing_objc_thang
  858. #ifdef MODERN_OBJC_SYNTAX
  859. &amp;&amp; flag_modern_objc_syntax
  860. #endif
  861. )
  862. {
  863. #ifdef MODERN_OBJC_SYNTAX
  864. if (looks_like_ansistyle_message_ref($1, $3))
  865. $$ = build (MODERN_MESSAGE_EXPR, TREE_TYPE ($1),
  866. $1, $3);
  867. else
  868. #endif
  869. if (is_public ($1, $3))
  870. $$ = build_component_ref ($1, $3);
  871. else
  872. $$ = error_mark_node;
  873. }
  874. else
  875. $$ = build_component_ref ($1, $3);
  876. }
  877. | primary POINTSAT identifier
  878. {
  879. tree expr = build_indirect_ref ($1, &quot;-&gt;&quot;);
  880. if (doing_objc_thang)
  881. {
  882. if (is_public (expr, $3))
  883. $$ = build_component_ref (expr, $3);
  884. else
  885. $$ = error_mark_node;
  886. }
  887. else
  888. $$ = build_component_ref (expr, $3);
  889. }
  890. | primary PLUSPLUS
  891. { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
  892. | primary MINUSMINUS
  893. { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
  894. | objcmessageexpr
  895. { $$ = build_message_expr ($1, 0); }
  896. | objcselectorexpr
  897. { $$ = build_selector_expr ($1); }
  898. | objcprotocolexpr
  899. { $$ = build_protocol_expr ($1); }
  900. | objcencodeexpr
  901. { $$ = build_encode_expr ($1); }
  902. | objc_string
  903. { $$ = build_objc_string_object ($1); }
  904. ;
  905. /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
  906. string:
  907. STRING
  908. | string STRING
  909. { $$ = chainon ($1, $2); }
  910. ;
  911. /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
  912. onto it. */
  913. objc_string:
  914. OBJC_STRING
  915. | objc_string OBJC_STRING
  916. { $$ = chainon ($1, $2); }
  917. ;
  918. old_style_parm_decls:
  919. /* empty */
  920. | datadecls
  921. | datadecls ELLIPSIS
  922. /* ... is used here to indicate a varargs function. */
  923. { c_mark_varargs ();
  924. if (pedantic)
  925. pedwarn (&quot;ANSI C does not permit use of `varargs.h'&quot;); }
  926. ;
  927. /* The following are analogous to lineno_decl, decls and decl
  928. except that they do not allow nested functions.
  929. They are used for old-style parm decls. */
  930. lineno_datadecl:
  931. save_filename save_lineno datadecl
  932. { }
  933. ;
  934. datadecls:
  935. lineno_datadecl
  936. | errstmt
  937. | datadecls lineno_datadecl
  938. | lineno_datadecl errstmt
  939. ;
  940. /* We don't allow prefix attributes here because they cause reduce/reduce
  941. conflicts: we can't know whether we're parsing a function decl with
  942. attribute suffix, or function defn with attribute prefix on first old
  943. style parm. */
  944. datadecl:
  945. typed_declspecs_no_prefix_attr setspecs initdecls ';'
  946. { current_declspecs = TREE_VALUE (declspec_stack);
  947. prefix_attributes = TREE_PURPOSE (declspec_stack);
  948. declspec_stack = TREE_CHAIN (declspec_stack);
  949. resume_momentary ($2); }
  950. | declmods_no_prefix_attr setspecs notype_initdecls ';'
  951. { current_declspecs = TREE_VALUE (declspec_stack);
  952. prefix_attributes = TREE_PURPOSE (declspec_stack);
  953. declspec_stack = TREE_CHAIN (declspec_stack);
  954. resume_momentary ($2); }
  955. | typed_declspecs_no_prefix_attr ';'
  956. { shadow_tag_warned ($1, 1);
  957. pedwarn (&quot;empty declaration&quot;); }
  958. | declmods_no_prefix_attr ';'
  959. { pedwarn (&quot;empty declaration&quot;); }
  960. ;
  961. /* This combination which saves a lineno before a decl
  962. is the normal thing to use, rather than decl itself.
  963. This is to avoid shift/reduce conflicts in contexts
  964. where statement labels are allowed. */
  965. lineno_decl:
  966. save_filename save_lineno decl
  967. { }
  968. ;
  969. decls:
  970. lineno_decl
  971. | errstmt
  972. | decls lineno_decl
  973. | lineno_decl errstmt
  974. ;
  975. /* records the type and storage class specs to use for processing
  976. the declarators that follow.
  977. Maintains a stack of outer-level values of current_declspecs,
  978. for the sake of parm declarations nested in function declarators. */
  979. setspecs: /* empty */
  980. { $$ = suspend_momentary ();
  981. pending_xref_error ();
  982. declspec_stack = tree_cons (prefix_attributes,
  983. current_declspecs,
  984. declspec_stack);
  985. split_specs_attrs ($&lt;ttype&gt;0,
  986. &amp;current_declspecs, &amp;prefix_attributes); }
  987. ;
  988. /* ??? Yuck. See after_type_declarator. */
  989. setattrs: /* empty */
  990. { prefix_attributes = chainon (prefix_attributes, $&lt;ttype&gt;0); }
  991. ;
  992. decl:
  993. typed_declspecs setspecs initdecls ';'
  994. { current_declspecs = TREE_VALUE (declspec_stack);
  995. prefix_attributes = TREE_PURPOSE (declspec_stack);
  996. declspec_stack = TREE_CHAIN (declspec_stack);
  997. resume_momentary ($2); }
  998. | declmods setspecs notype_initdecls ';'
  999. { current_declspecs = TREE_VALUE (declspec_stack);
  1000. prefix_attributes = TREE_PURPOSE (declspec_stack);
  1001. declspec_stack = TREE_CHAIN (declspec_stack);
  1002. resume_momentary ($2); }
  1003. | typed_declspecs setspecs nested_function
  1004. { current_declspecs = TREE_VALUE (declspec_stack);
  1005. prefix_attributes = TREE_PURPOSE (declspec_stack);
  1006. declspec_stack = TREE_CHAIN (declspec_stack);
  1007. resume_momentary ($2); }
  1008. | declmods setspecs notype_nested_function
  1009. { current_declspecs = TREE_VALUE (declspec_stack);
  1010. prefix_attributes = TREE_PURPOSE (declspec_stack);
  1011. declspec_stack = TREE_CHAIN (declspec_stack);
  1012. resume_momentary ($2); }
  1013. | typed_declspecs ';'
  1014. { shadow_tag ($1); }
  1015. | declmods ';'
  1016. { pedwarn (&quot;empty declaration&quot;); }
  1017. | extension decl
  1018. { pedantic = $&lt;itype&gt;1; }
  1019. ;
  1020. /* Declspecs which contain at least one type specifier or typedef name.
  1021. (Just `const' or `volatile' is not enough.)
  1022. A typedef'd name following these is taken as a name to be declared.
  1023. Declspecs have a non-NULL TREE_VALUE, attributes do not. */
  1024. typed_declspecs:
  1025. typespec reserved_declspecs
  1026. { $$ = tree_cons (NULL_TREE, $1, $2); }
  1027. | declmods typespec reserved_declspecs
  1028. { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  1029. ;
  1030. reserved_declspecs: /* empty */
  1031. { $$ = NULL_TREE; }
  1032. | reserved_declspecs typespecqual_reserved
  1033. { $$ = tree_cons (NULL_TREE, $2, $1); }
  1034. | reserved_declspecs SCSPEC
  1035. { if (extra_warnings)
  1036. warning (&quot;`%s' is not at beginning of declaration&quot;,
  1037. IDENTIFIER_POINTER ($2));
  1038. $$ = tree_cons (NULL_TREE, $2, $1); }
  1039. | reserved_declspecs attributes
  1040. { $$ = tree_cons ($2, NULL_TREE, $1); }
  1041. ;
  1042. typed_declspecs_no_prefix_attr:
  1043. typespec reserved_declspecs_no_prefix_attr
  1044. { $$ = tree_cons (NULL_TREE, $1, $2); }
  1045. | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
  1046. { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  1047. ;
  1048. reserved_declspecs_no_prefix_attr:
  1049. /* empty */
  1050. { $$ = NULL_TREE; }
  1051. | reserved_declspecs_no_prefix_attr typespecqual_reserved
  1052. { $$ = tree_cons (NULL_TREE, $2, $1); }
  1053. | reserved_declspecs_no_prefix_attr SCSPEC
  1054. { if (extra_warnings)
  1055. warning (&quot;`%s' is not at beginning of declaration&quot;,
  1056. IDENTIFIER_POINTER ($2));
  1057. $$ = tree_cons (NULL_TREE, $2, $1); }
  1058. ;
  1059. /* List of just storage classes, type modifiers, and prefix attributes.
  1060. A declaration can start with just this, but then it cannot be used
  1061. to redeclare a typedef-name.
  1062. Declspecs have a non-NULL TREE_VALUE, attributes do not. */
  1063. declmods:
  1064. declmods_no_prefix_attr
  1065. { $$ = $1; }
  1066. | attributes
  1067. { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
  1068. | declmods declmods_no_prefix_attr
  1069. { $$ = chainon ($2, $1); }
  1070. | declmods attributes
  1071. { $$ = tree_cons ($2, NULL_TREE, $1); }
  1072. ;
  1073. declmods_no_prefix_attr:
  1074. TYPE_QUAL
  1075. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
  1076. TREE_STATIC ($$) = 1; }
  1077. | SCSPEC
  1078. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  1079. | declmods_no_prefix_attr TYPE_QUAL
  1080. { $$ = tree_cons (NULL_TREE, $2, $1);
  1081. TREE_STATIC ($$) = 1; }
  1082. | declmods_no_prefix_attr SCSPEC
  1083. { if (extra_warnings &amp;&amp; TREE_STATIC ($1))
  1084. warning (&quot;`%s' is not at beginning of declaration&quot;,
  1085. IDENTIFIER_POINTER ($2));
  1086. $$ = tree_cons (NULL_TREE, $2, $1);
  1087. TREE_STATIC ($$) = TREE_STATIC ($1); }
  1088. ;
  1089. /* Used instead of declspecs where storage classes are not allowed
  1090. (that is, for typenames and structure components).
  1091. Don't accept a typedef-name if anything but a modifier precedes it. */
  1092. typed_typespecs:
  1093. typespec reserved_typespecquals
  1094. { $$ = tree_cons (NULL_TREE, $1, $2); }
  1095. | nonempty_type_quals typespec reserved_typespecquals
  1096. { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  1097. ;
  1098. reserved_typespecquals: /* empty */
  1099. { $$ = NULL_TREE; }
  1100. | reserved_typespecquals typespecqual_reserved
  1101. { $$ = tree_cons (NULL_TREE, $2, $1); }
  1102. ;
  1103. /* A typespec (but not a type qualifier).
  1104. Once we have seen one of these in a declaration,
  1105. if a typedef name appears then it is being redeclared. */
  1106. typespec: TYPESPEC
  1107. | structsp
  1108. | TYPENAME
  1109. { /* For a typedef name, record the meaning, not the name.
  1110. In case of `foo foo, bar;'. */
  1111. $$ = lookup_name ($1); }
  1112. | CLASSNAME protocolrefs
  1113. { $$ = get_static_reference ($1, $2); }
  1114. | OBJECTNAME protocolrefs
  1115. { $$ = get_object_reference ($2); }
  1116. /* Make &quot;&lt;SomeProtocol&gt;&quot; equivalent to &quot;id &lt;SomeProtocol&gt;&quot;
  1117. - <a href="mailto:nisse@lysator.liu.se">nisse@lysator.liu.se</a> */
  1118. | non_empty_protocolrefs
  1119. { $$ = get_object_reference ($1); }
  1120. | TYPEOF '(' expr ')'
  1121. { $$ = TREE_TYPE ($3); }
  1122. | TYPEOF '(' typename ')'
  1123. { $$ = groktypename ($3); }
  1124. ;
  1125. /* A typespec that is a reserved word, or a type qualifier. */
  1126. typespecqual_reserved: TYPESPEC
  1127. | TYPE_QUAL
  1128. | structsp
  1129. ;
  1130. initdecls:
  1131. initdcl
  1132. | initdecls ',' initdcl
  1133. ;
  1134. notype_initdecls:
  1135. notype_initdcl
  1136. | notype_initdecls ',' initdcl
  1137. ;
  1138. maybeasm:
  1139. /* empty */
  1140. { $$ = NULL_TREE; }
  1141. | ASM_KEYWORD '(' string ')'
  1142. { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  1143. $$ = $3;
  1144. }
  1145. ;
  1146. initdcl:
  1147. declarator maybeasm maybe_attribute '='
  1148. { $&lt;ttype&gt;$ = start_decl ($1, current_declspecs, 1,
  1149. $3, prefix_attributes);
  1150. start_init ($&lt;ttype&gt;$, $2, global_bindings_p ()); }
  1151. init
  1152. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1153. { finish_init ();
  1154. finish_decl ($&lt;ttype&gt;5, $6, $2); }
  1155. | declarator maybeasm maybe_attribute
  1156. {
  1157. #ifdef MODERN_OBJC_SYNTAX
  1158. if (flag_modern_objc_syntax &amp;&amp; objc_interface_context &amp;&amp;
  1159. looks_like_ansistyle_method_decl($1, current_declspecs))
  1160. {
  1161. build_method_decl_from_ansiproto($1,
  1162. current_declspecs, objc_interface_context);
  1163. }
  1164. else
  1165. {
  1166. #endif
  1167. tree d = start_decl ($1, current_declspecs, 0,
  1168. $3, prefix_attributes);
  1169. finish_decl (d, NULL_TREE, $2);
  1170. #ifdef MODERN_OBJC_SYNTAX
  1171. }
  1172. #endif
  1173. }
  1174. ;
  1175. notype_initdcl:
  1176. notype_declarator maybeasm maybe_attribute '='
  1177. { $&lt;ttype&gt;$ = start_decl ($1, current_declspecs, 1,
  1178. $3, prefix_attributes);
  1179. start_init ($&lt;ttype&gt;$, $2, global_bindings_p ()); }
  1180. init
  1181. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1182. { finish_init ();
  1183. decl_attributes ($&lt;ttype&gt;5, $3, prefix_attributes);
  1184. finish_decl ($&lt;ttype&gt;5, $6, $2); }
  1185. | notype_declarator maybeasm maybe_attribute
  1186. { tree d = start_decl ($1, current_declspecs, 0,
  1187. $3, prefix_attributes);
  1188. finish_decl (d, NULL_TREE, $2); }
  1189. ;
  1190. /* the * rules are dummies to accept the Apollo extended syntax
  1191. so that the header files compile. */
  1192. maybe_attribute:
  1193. /* empty */
  1194. { $$ = NULL_TREE; }
  1195. | attributes
  1196. { $$ = $1; }
  1197. ;
  1198. attributes:
  1199. attribute
  1200. { $$ = $1; }
  1201. | attributes attribute
  1202. { $$ = chainon ($1, $2); }
  1203. ;
  1204. attribute:
  1205. ATTRIBUTE '(' '(' attribute_list ')' ')'
  1206. { $$ = $4; }
  1207. ;
  1208. attribute_list:
  1209. attrib
  1210. { $$ = $1; }
  1211. | attribute_list ',' attrib
  1212. { $$ = chainon ($1, $3); }
  1213. ;
  1214. attrib:
  1215. /* empty */
  1216. { $$ = NULL_TREE; }
  1217. | any_word
  1218. { $$ = build_tree_list ($1, NULL_TREE); }
  1219. | any_word '(' IDENTIFIER ')'
  1220. { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
  1221. | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
  1222. { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
  1223. | any_word '(' exprlist ')'
  1224. { $$ = build_tree_list ($1, $3); }
  1225. ;
  1226. /* This still leaves out most reserved keywords,
  1227. shouldn't we include them? */
  1228. any_word:
  1229. identifier
  1230. | SCSPEC
  1231. | TYPESPEC
  1232. | TYPE_QUAL
  1233. ;
  1234. /* Initializers. `init' is the entry point. */
  1235. init:
  1236. expr_no_commas
  1237. | '{'
  1238. { really_start_incremental_init (NULL_TREE);
  1239. /* Note that the call to clear_momentary
  1240. is in process_init_element. */
  1241. push_momentary (); }
  1242. initlist_maybe_comma '}'
  1243. { $$ = pop_init_level (0);
  1244. if ($$ == error_mark_node
  1245. &amp;&amp; ! (yychar == STRING || yychar == CONSTANT))
  1246. pop_momentary ();
  1247. else
  1248. pop_momentary_nofree (); }
  1249. | error
  1250. { $$ = error_mark_node; }
  1251. ;
  1252. /* `initlist_maybe_comma' is the guts of an initializer in braces. */
  1253. initlist_maybe_comma:
  1254. /* empty */
  1255. { if (pedantic)
  1256. pedwarn (&quot;ANSI C forbids empty initializer braces&quot;); }
  1257. | initlist1 maybecomma
  1258. ;
  1259. initlist1:
  1260. initelt
  1261. | initlist1 ',' initelt
  1262. ;
  1263. /* `initelt' is a single element of an initializer.
  1264. It may use braces. */
  1265. initelt:
  1266. designator_list '=' initval
  1267. | designator initval
  1268. | identifier ':'
  1269. { set_init_label ($1); }
  1270. initval
  1271. | initval
  1272. ;
  1273. initval:
  1274. '{'
  1275. { push_init_level (0); }
  1276. initlist_maybe_comma '}'
  1277. { process_init_element (pop_init_level (0)); }
  1278. | expr_no_commas
  1279. { process_init_element ($1); }
  1280. | error
  1281. ;
  1282. designator_list:
  1283. designator
  1284. | designator_list designator
  1285. ;
  1286. designator:
  1287. '.' identifier
  1288. { set_init_label ($2); }
  1289. /* These are for labeled elements. The syntax for an array element
  1290. initializer conflicts with the syntax for an Objective-C message,
  1291. so don't include these productions in the Objective-C grammar. */
  1292. | objc_openbracket.expr_no_commas ELLIPSIS expr_no_commas ']' '='
  1293. { set_init_index ($1, $3); }
  1294. initelt
  1295. | objc_openbracket.expr_no_commas ']' '='
  1296. { set_init_index ($1, NULL_TREE); }
  1297. initelt
  1298. | objc_openbracket.expr_no_commas ']'
  1299. { set_init_index ($1, NULL_TREE); }
  1300. initelt
  1301. | identifier ':'
  1302. { set_init_label ($1); }
  1303. initelt
  1304. | '.' identifier '='
  1305. { set_init_label ($2); }
  1306. initelt
  1307. ;
  1308. nested_function:
  1309. declarator
  1310. { push_c_function_context ();
  1311. if (! start_function (current_declspecs, $1,
  1312. prefix_attributes, NULL_TREE, 1))
  1313. {
  1314. pop_c_function_context ();
  1315. YYERROR1;
  1316. }
  1317. reinit_parse_for_function (); }
  1318. old_style_parm_decls
  1319. { store_parm_decls (); }
  1320. /* This used to use compstmt_or_error.
  1321. That caused a bug with input `f(g) int g {}',
  1322. where the use of YYERROR1 above caused an error
  1323. which then was handled by compstmt_or_error.
  1324. There followed a repeated execution of that same rule,
  1325. which called YYERROR1 again, and so on. */
  1326. compstmt
  1327. { finish_function (1);
  1328. pop_c_function_context (); }
  1329. ;
  1330. notype_nested_function:
  1331. notype_declarator
  1332. { push_c_function_context ();
  1333. if (! start_function (current_declspecs, $1,
  1334. prefix_attributes, NULL_TREE, 1))
  1335. {
  1336. pop_c_function_context ();
  1337. YYERROR1;
  1338. }
  1339. reinit_parse_for_function (); }
  1340. old_style_parm_decls
  1341. { store_parm_decls (); }
  1342. /* This used to use compstmt_or_error.
  1343. That caused a bug with input `f(g) int g {}',
  1344. where the use of YYERROR1 above caused an error
  1345. which then was handled by compstmt_or_error.
  1346. There followed a repeated execution of that same rule,
  1347. which called YYERROR1 again, and so on. */
  1348. compstmt
  1349. { finish_function (1);
  1350. pop_c_function_context (); }
  1351. ;
  1352. /* Any kind of declarator (thus, all declarators allowed
  1353. after an explicit typespec). */
  1354. declarator:
  1355. after_type_declarator
  1356. | notype_declarator
  1357. ;
  1358. /* A declarator that is allowed only after an explicit typespec. */
  1359. after_type_declarator:
  1360. '(' after_type_declarator ')'
  1361. { $$ = $2; }
  1362. | after_type_declarator '(' parmlist_or_identifiers %prec '.'
  1363. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1364. /* | after_type_declarator '(' error ')' %prec '.'
  1365. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1366. poplevel (0, 0, 0); } */
  1367. | after_type_declarator '[' expr ']' %prec '.'
  1368. { $$ = build_nt (ARRAY_REF, $1, $3); }
  1369. | after_type_declarator '[' ']' %prec '.'
  1370. { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  1371. | '*' type_quals after_type_declarator %prec UNARY
  1372. { $$ = make_pointer_declarator ($2, $3); }
  1373. /* ??? Yuck. setattrs is a quick hack. We can't use
  1374. prefix_attributes because $1 only applies to this
  1375. declarator. We assume setspecs has already been done.
  1376. setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
  1377. attributes could be recognized here or in `attributes'). */
  1378. | attributes setattrs after_type_declarator
  1379. { $$ = $3; }
  1380. | TYPENAME
  1381. | OBJECTNAME
  1382. ;
  1383. /* Kinds of declarator that can appear in a parameter list
  1384. in addition to notype_declarator. This is like after_type_declarator
  1385. but does not allow a typedef name in parentheses as an identifier
  1386. (because it would conflict with a function with that typedef as arg). */
  1387. parm_declarator:
  1388. parm_declarator '(' parmlist_or_identifiers %prec '.'
  1389. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1390. /* | parm_declarator '(' error ')' %prec '.'
  1391. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1392. poplevel (0, 0, 0); } */
  1393. | parm_declarator '[' expr ']' %prec '.'
  1394. { $$ = build_nt (ARRAY_REF, $1, $3); }
  1395. | parm_declarator '[' ']' %prec '.'
  1396. { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  1397. | '*' type_quals parm_declarator %prec UNARY
  1398. { $$ = make_pointer_declarator ($2, $3); }
  1399. /* ??? Yuck. setattrs is a quick hack. We can't use
  1400. prefix_attributes because $1 only applies to this
  1401. declarator. We assume setspecs has already been done.
  1402. setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
  1403. attributes could be recognized here or in `attributes'). */
  1404. | attributes setattrs parm_declarator
  1405. { $$ = $3; }
  1406. | TYPENAME
  1407. | OBJECTNAME
  1408. ;
  1409. /* A declarator allowed whether or not there has been
  1410. an explicit typespec. These cannot redeclare a typedef-name. */
  1411. notype_declarator:
  1412. notype_declarator '(' parmlist_or_identifiers %prec '.'

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