PageRenderTime 74ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/opensource.apple.com/source/libstdcxx_SUPanWheat/libstdcxx_SUPanWheat-16/libstdcxx/gcc/c-parse.y

#
Happy | 2080 lines | 1851 code | 229 blank | 0 comment | 0 complexity | 1919cf4ca55745d10137e941199b7176 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, MPL-2.0, JSON, 0BSD, LGPL-2.1, Apache-2.0, BSD-3-Clause, ISC, LGPL-2.0, WTFPL, MIT

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>c-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">c-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. /* YACC parser for C syntax and for Objective C. -*-c-*-
  25. Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  26. 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  27. This file is part of GCC.
  28. GCC is free software; you can redistribute it and/or modify it under
  29. the terms of the GNU General Public License as published by the Free
  30. Software Foundation; either version 2, or (at your option) any later
  31. version.
  32. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  33. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  34. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  35. for more details.
  36. You should have received a copy of the GNU General Public License
  37. along with GCC; see the file COPYING. If not, write to the Free
  38. Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  39. 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 13 /* shift/reduce conflicts, and no reduce/reduce conflicts. */
  48. %{
  49. #include &quot;config.h&quot;
  50. #include &quot;system.h&quot;
  51. #include &quot;coretypes.h&quot;
  52. #include &quot;tm.h&quot;
  53. #include &quot;tree.h&quot;
  54. #include &quot;langhooks.h&quot;
  55. #include &quot;input.h&quot;
  56. #include &quot;cpplib.h&quot;
  57. #include &quot;intl.h&quot;
  58. #include &quot;timevar.h&quot;
  59. #include &quot;c-pragma.h&quot; /* For YYDEBUG definition, and parse_in. */
  60. #include &quot;c-tree.h&quot;
  61. #include &quot;flags.h&quot;
  62. #include &quot;varray.h&quot;
  63. #include &quot;output.h&quot;
  64. #include &quot;toplev.h&quot;
  65. #include &quot;ggc.h&quot;
  66. #include &quot;c-common.h&quot;
  67. #define YYERROR1 { yyerror (&quot;syntax error&quot;); YYERROR; }
  68. /* Like the default stack expander, except (1) use realloc when possible,
  69. (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
  70. Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
  71. give malloced_yyvs its proper type. This is ok since all we need from
  72. it is to be able to free it. */
  73. static short *malloced_yyss;
  74. static void *malloced_yyvs;
  75. #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
  76. do { \
  77. size_t newsize; \
  78. short *newss; \
  79. YYSTYPE *newvs; \
  80. newsize = *(YYSSZ) *= 2; \
  81. if (malloced_yyss) \
  82. { \
  83. newss = really_call_realloc (*(SS), newsize * sizeof (short)); \
  84. newvs = really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
  85. } \
  86. else \
  87. { \
  88. newss = really_call_malloc (newsize * sizeof (short)); \
  89. newvs = really_call_malloc (newsize * sizeof (YYSTYPE)); \
  90. if (newss) \
  91. memcpy (newss, *(SS), (SSSIZE)); \
  92. if (newvs) \
  93. memcpy (newvs, *(VS), (VSSIZE)); \
  94. } \
  95. if (!newss || !newvs) \
  96. { \
  97. yyerror (MSG); \
  98. return 2; \
  99. } \
  100. *(SS) = newss; \
  101. *(VS) = newvs; \
  102. malloced_yyss = newss; \
  103. malloced_yyvs = (void *) newvs; \
  104. } while (0)
  105. %}
  106. %start program
  107. %union {long itype; tree ttype; void *otype; struct c_expr exprtype;
  108. struct c_arg_info *arginfotype; struct c_declarator *dtrtype;
  109. struct c_type_name *typenametype; struct c_parm *parmtype;
  110. struct c_declspecs *dsptype; struct c_typespec tstype;
  111. enum tree_code code; location_t location; }
  112. /* All identifiers that are not reserved words
  113. and are not declared typedefs in the current block */
  114. %token IDENTIFIER
  115. /* All identifiers that are declared typedefs in the current block.
  116. In some contexts, they are treated just like IDENTIFIER,
  117. but they can also serve as typespecs in declarations. */
  118. %token TYPENAME
  119. /* Reserved words that specify storage class.
  120. yylval contains an IDENTIFIER_NODE which indicates which one. */
  121. %token SCSPEC /* Storage class other than static. */
  122. %token STATIC /* Static storage class. */
  123. /* Reserved words that specify type.
  124. yylval contains an IDENTIFIER_NODE which indicates which one. */
  125. %token TYPESPEC
  126. /* Reserved words that qualify type: &quot;const&quot;, &quot;volatile&quot;, or &quot;restrict&quot;.
  127. yylval contains an IDENTIFIER_NODE which indicates which one. */
  128. %token TYPE_QUAL
  129. /* Objective-C protocol qualifiers. These acquire their magic powers
  130. only in certain contexts. */
  131. %token OBJC_TYPE_QUAL
  132. /* Character or numeric constants.
  133. yylval is the node for the constant. */
  134. %token CONSTANT
  135. /* String constants in raw form.
  136. yylval is a STRING_CST node. */
  137. %token STRING
  138. /* &quot;...&quot;, used for functions with variable arglists. */
  139. %token ELLIPSIS
  140. /* the reserved words */
  141. /* SCO include files test &quot;ASM&quot;, so use something else. */
  142. %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  143. %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
  144. %token ATTRIBUTE EXTENSION LABEL
  145. %token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
  146. %token FUNC_NAME OFFSETOF
  147. /* Add precedence rules to solve dangling else s/r conflict */
  148. %nonassoc IF
  149. %nonassoc ELSE
  150. /* Define the operator tokens and their precedences.
  151. The value is an integer because, if used, it is the tree code
  152. to use in the expression made from the operator. */
  153. %right &lt;code&gt; ASSIGN '='
  154. %right &lt;code&gt; '?' ':'
  155. %left &lt;code&gt; OROR
  156. %left &lt;code&gt; ANDAND
  157. %left &lt;code&gt; '|'
  158. %left &lt;code&gt; '^'
  159. %left &lt;code&gt; '&amp;'
  160. %left &lt;code&gt; EQCOMPARE
  161. %left &lt;code&gt; ARITHCOMPARE
  162. %left &lt;code&gt; LSHIFT RSHIFT
  163. %left &lt;code&gt; '+' '-'
  164. %left &lt;code&gt; '*' '/' '%'
  165. %right &lt;code&gt; UNARY PLUSPLUS MINUSMINUS
  166. %left HYPERUNARY
  167. %left &lt;code&gt; POINTSAT '.' '(' '['
  168. /* The Objective-C keywords. These are included in C and in
  169. Objective C, so that the token codes are the same in both. */
  170. %token AT_INTERFACE AT_IMPLEMENTATION AT_END AT_SELECTOR AT_DEFS AT_ENCODE
  171. %token CLASSNAME AT_PUBLIC AT_PRIVATE AT_PROTECTED AT_PROTOCOL
  172. %token AT_CLASS AT_ALIAS
  173. %token AT_THROW AT_TRY AT_CATCH AT_FINALLY AT_SYNCHRONIZED
  174. %token OBJC_STRING
  175. %type &lt;code&gt; unop
  176. %type &lt;ttype&gt; ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  177. %type &lt;ttype&gt; BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
  178. %type &lt;ttype&gt; identifier IDENTIFIER TYPENAME CONSTANT STRING FUNC_NAME
  179. %type &lt;ttype&gt; nonnull_exprlist exprlist
  180. %type &lt;exprtype&gt; expr expr_no_commas cast_expr unary_expr primary
  181. %type &lt;dsptype&gt; declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
  182. %type &lt;dsptype&gt; declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
  183. %type &lt;dsptype&gt; declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
  184. %type &lt;dsptype&gt; declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
  185. %type &lt;dsptype&gt; declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
  186. %type &lt;dsptype&gt; declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
  187. %type &lt;dsptype&gt; declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
  188. %type &lt;dsptype&gt; declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
  189. %type &lt;dsptype&gt; declspecs_ts declspecs_nots
  190. %type &lt;dsptype&gt; declspecs_ts_nosa declspecs_nots_nosa
  191. %type &lt;dsptype&gt; declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
  192. %type &lt;dsptype&gt; maybe_type_quals_attrs
  193. %type &lt;tstype&gt; typespec_nonattr typespec_attr
  194. %type &lt;tstype&gt; typespec_reserved_nonattr typespec_reserved_attr
  195. %type &lt;tstype&gt; typespec_nonreserved_nonattr
  196. %type &lt;ttype&gt; offsetof_member_designator
  197. %type &lt;ttype&gt; scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile
  198. %type &lt;ttype&gt; initdecls notype_initdecls initdcl notype_initdcl
  199. %type &lt;exprtype&gt; init
  200. %type &lt;ttype&gt; simple_asm_expr maybeasm asm_stmt asm_argument asm_string
  201. %type &lt;ttype&gt; asm_operands nonnull_asm_operands asm_operand asm_clobbers
  202. %type &lt;ttype&gt; maybe_attribute attributes attribute attribute_list attrib
  203. %type &lt;ttype&gt; any_word
  204. %type &lt;ttype&gt; compstmt compstmt_start compstmt_primary_start
  205. %type &lt;ttype&gt; stmt label stmt_nocomp start_break start_continue
  206. %type &lt;ttype&gt; c99_block_start c99_block_lineno_labeled_stmt
  207. %type &lt;ttype&gt; if_statement_1 if_statement_2
  208. %type &lt;dtrtype&gt; declarator
  209. %type &lt;dtrtype&gt; notype_declarator after_type_declarator
  210. %type &lt;dtrtype&gt; parm_declarator
  211. %type &lt;dtrtype&gt; parm_declarator_starttypename parm_declarator_nostarttypename
  212. %type &lt;dtrtype&gt; array_declarator
  213. %type &lt;tstype&gt; structsp_attr structsp_nonattr
  214. %type &lt;ttype&gt; component_decl_list component_decl_list2
  215. %type &lt;ttype&gt; component_decl components components_notype component_declarator
  216. %type &lt;ttype&gt; component_notype_declarator
  217. %type &lt;ttype&gt; enumlist enumerator
  218. %type &lt;ttype&gt; struct_head union_head enum_head
  219. %type &lt;typenametype&gt; typename
  220. %type &lt;dtrtype&gt; absdcl absdcl1 absdcl1_ea absdcl1_noea direct_absdcl1
  221. %type &lt;parmtype&gt; absdcl_maybe_attribute
  222. %type &lt;ttype&gt; condition xexpr for_cond_expr for_incr_expr
  223. %type &lt;parmtype&gt; parm firstparm
  224. %type &lt;ttype&gt; identifiers
  225. %type &lt;arginfotype&gt; parms parmlist parmlist_1 parmlist_2
  226. %type &lt;arginfotype&gt; parmlist_or_identifiers parmlist_or_identifiers_1
  227. %type &lt;ttype&gt; identifiers_or_typenames
  228. %type &lt;itype&gt; setspecs setspecs_fp extension
  229. %type &lt;location&gt; save_location
  230. %type &lt;otype&gt; save_obstack_position
  231. %{
  232. /* Declaration specifiers of the current declaration. */
  233. static struct c_declspecs *current_declspecs;
  234. static GTY(()) tree prefix_attributes;
  235. /* List of all the attributes applying to the identifier currently being
  236. declared; includes prefix_attributes and possibly some more attributes
  237. just after a comma. */
  238. static GTY(()) tree all_prefix_attributes;
  239. /* Structure to save declaration specifiers. */
  240. struct c_declspec_stack {
  241. /* Saved value of current_declspecs. */
  242. struct c_declspecs *current_declspecs;
  243. /* Saved value of prefix_attributes. */
  244. tree prefix_attributes;
  245. /* Saved value of all_prefix_attributes. */
  246. tree all_prefix_attributes;
  247. /* Next level of stack. */
  248. struct c_declspec_stack *next;
  249. };
  250. /* Stack of saved values of current_declspecs, prefix_attributes and
  251. all_prefix_attributes. */
  252. static struct c_declspec_stack *declspec_stack;
  253. /* INDIRECT_REF with a TREE_TYPE of the type being queried for offsetof. */
  254. static tree offsetof_base;
  255. /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
  256. should be called from the productions making use of setspecs. */
  257. #define PUSH_DECLSPEC_STACK \
  258. do { \
  259. struct c_declspec_stack *t = XOBNEW (&amp;parser_obstack, \
  260. struct c_declspec_stack); \
  261. t-&gt;current_declspecs = current_declspecs; \
  262. t-&gt;prefix_attributes = prefix_attributes; \
  263. t-&gt;all_prefix_attributes = all_prefix_attributes; \
  264. t-&gt;next = declspec_stack; \
  265. declspec_stack = t; \
  266. } while (0)
  267. #define POP_DECLSPEC_STACK \
  268. do { \
  269. current_declspecs = declspec_stack-&gt;current_declspecs; \
  270. prefix_attributes = declspec_stack-&gt;prefix_attributes; \
  271. all_prefix_attributes = declspec_stack-&gt;all_prefix_attributes; \
  272. declspec_stack = declspec_stack-&gt;next; \
  273. } while (0)
  274. /* For __extension__, save/restore the warning flags which are
  275. controlled by __extension__. */
  276. #define SAVE_EXT_FLAGS() \
  277. (pedantic \
  278. | (warn_pointer_arith &lt;&lt; 1) \
  279. | (warn_traditional &lt;&lt; 2) \
  280. | (flag_iso &lt;&lt; 3))
  281. #define RESTORE_EXT_FLAGS(val) \
  282. do { \
  283. pedantic = val &amp; 1; \
  284. warn_pointer_arith = (val &gt;&gt; 1) &amp; 1; \
  285. warn_traditional = (val &gt;&gt; 2) &amp; 1; \
  286. flag_iso = (val &gt;&gt; 3) &amp; 1; \
  287. } while (0)
  288. #define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
  289. /* Tell yyparse how to print a token's value, if yydebug is set. */
  290. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  291. static void yyprint (FILE *, int, YYSTYPE);
  292. static void yyerror (const char *);
  293. static int yylexname (void);
  294. static inline int _yylex (void);
  295. static int yylex (void);
  296. static void init_reswords (void);
  297. /* Initialization routine for this file. */
  298. void
  299. c_parse_init (void)
  300. {
  301. init_reswords ();
  302. }
  303. %}
  304. %%
  305. program: /* empty */
  306. { if (pedantic)
  307. pedwarn (&quot;ISO C forbids an empty source file&quot;);
  308. }
  309. | extdefs
  310. ;
  311. /* the reason for the strange actions in this rule
  312. is so that notype_initdecls when reached via datadef
  313. can find valid declaration specifiers in $0. */
  314. extdefs:
  315. save_obstack_position { $&lt;dsptype&gt;$ = NULL; } extdef
  316. { obstack_free (&amp;parser_obstack, $1); }
  317. | extdefs save_obstack_position
  318. { $&lt;dsptype&gt;$ = NULL; ggc_collect (); } extdef
  319. { obstack_free (&amp;parser_obstack, $2); }
  320. ;
  321. extdef:
  322. fndef
  323. | datadef
  324. | asmdef
  325. | extension extdef
  326. { RESTORE_EXT_FLAGS ($1); }
  327. ;
  328. /* Record the current position of parser_obstack before a
  329. declaration to restore it afterwards. */
  330. save_obstack_position:
  331. { $$ = obstack_alloc (&amp;parser_obstack, 0); }
  332. ;
  333. datadef:
  334. setspecs notype_initdecls ';'
  335. { pedwarn (&quot;data definition has no type or storage class&quot;);
  336. POP_DECLSPEC_STACK; }
  337. | declspecs_nots setspecs notype_initdecls ';'
  338. { POP_DECLSPEC_STACK; }
  339. | declspecs_ts setspecs initdecls ';'
  340. { POP_DECLSPEC_STACK; }
  341. | declspecs ';'
  342. { shadow_tag (finish_declspecs ($1)); }
  343. | error ';'
  344. | error '}'
  345. | ';'
  346. { if (pedantic)
  347. pedwarn (&quot;ISO C does not allow extra %&lt;;%&gt; outside of a function&quot;); }
  348. ;
  349. fndef:
  350. declspecs_ts setspecs declarator
  351. { if (!start_function (current_declspecs, $3,
  352. all_prefix_attributes))
  353. YYERROR1;
  354. }
  355. old_style_parm_decls save_location
  356. { DECL_SOURCE_LOCATION (current_function_decl) = $6;
  357. store_parm_decls (); }
  358. compstmt_or_error
  359. { finish_function ();
  360. POP_DECLSPEC_STACK; }
  361. | declspecs_ts setspecs declarator error
  362. { POP_DECLSPEC_STACK; }
  363. | declspecs_nots setspecs notype_declarator
  364. { if (!start_function (current_declspecs, $3,
  365. all_prefix_attributes))
  366. YYERROR1;
  367. }
  368. old_style_parm_decls save_location
  369. { DECL_SOURCE_LOCATION (current_function_decl) = $6;
  370. store_parm_decls (); }
  371. compstmt_or_error
  372. { finish_function ();
  373. POP_DECLSPEC_STACK; }
  374. | declspecs_nots setspecs notype_declarator error
  375. { POP_DECLSPEC_STACK; }
  376. | setspecs notype_declarator
  377. { if (!start_function (current_declspecs, $2,
  378. all_prefix_attributes))
  379. YYERROR1;
  380. }
  381. old_style_parm_decls save_location
  382. { DECL_SOURCE_LOCATION (current_function_decl) = $5;
  383. store_parm_decls (); }
  384. compstmt_or_error
  385. { finish_function ();
  386. POP_DECLSPEC_STACK; }
  387. | setspecs notype_declarator error
  388. { POP_DECLSPEC_STACK; }
  389. ;
  390. identifier:
  391. IDENTIFIER
  392. | TYPENAME
  393. ;
  394. unop: '&amp;'
  395. { $$ = ADDR_EXPR; }
  396. | '-'
  397. { $$ = NEGATE_EXPR; }
  398. | '+'
  399. { $$ = CONVERT_EXPR;
  400. if (warn_traditional &amp;&amp; !in_system_header)
  401. warning (&quot;traditional C rejects the unary plus operator&quot;);
  402. }
  403. | PLUSPLUS
  404. { $$ = PREINCREMENT_EXPR; }
  405. | MINUSMINUS
  406. { $$ = PREDECREMENT_EXPR; }
  407. | '~'
  408. { $$ = BIT_NOT_EXPR; }
  409. | '!'
  410. { $$ = TRUTH_NOT_EXPR; }
  411. ;
  412. expr: expr_no_commas
  413. | expr ',' expr_no_commas
  414. { $$.value = build_compound_expr ($1.value, $3.value);
  415. $$.original_code = COMPOUND_EXPR; }
  416. ;
  417. exprlist:
  418. /* empty */
  419. { $$ = NULL_TREE; }
  420. | nonnull_exprlist
  421. ;
  422. nonnull_exprlist:
  423. expr_no_commas
  424. { $$ = build_tree_list (NULL_TREE, $1.value); }
  425. | nonnull_exprlist ',' expr_no_commas
  426. { chainon ($1, build_tree_list (NULL_TREE, $3.value)); }
  427. ;
  428. unary_expr:
  429. primary
  430. | '*' cast_expr %prec UNARY
  431. { $$.value = build_indirect_ref ($2.value, &quot;unary *&quot;);
  432. $$.original_code = ERROR_MARK; }
  433. /* __extension__ turns off -pedantic for following primary. */
  434. | extension cast_expr %prec UNARY
  435. { $$ = $2;
  436. RESTORE_EXT_FLAGS ($1); }
  437. | unop cast_expr %prec UNARY
  438. { $$.value = build_unary_op ($1, $2.value, 0);
  439. overflow_warning ($$.value);
  440. $$.original_code = ERROR_MARK; }
  441. /* Refer to the address of a label as a pointer. */
  442. | ANDAND identifier
  443. { $$.value = finish_label_address_expr ($2);
  444. $$.original_code = ERROR_MARK; }
  445. | sizeof unary_expr %prec UNARY
  446. { skip_evaluation--;
  447. in_sizeof--;
  448. if (TREE_CODE ($2.value) == COMPONENT_REF
  449. &amp;&amp; DECL_C_BIT_FIELD (TREE_OPERAND ($2.value, 1)))
  450. error (&quot;%&lt;sizeof%&gt; applied to a bit-field&quot;);
  451. $$ = c_expr_sizeof_expr ($2); }
  452. | sizeof '(' typename ')' %prec HYPERUNARY
  453. { skip_evaluation--;
  454. in_sizeof--;
  455. $$ = c_expr_sizeof_type ($3); }
  456. | alignof unary_expr %prec UNARY
  457. { skip_evaluation--;
  458. in_alignof--;
  459. $$.value = c_alignof_expr ($2.value);
  460. $$.original_code = ERROR_MARK; }
  461. | alignof '(' typename ')' %prec HYPERUNARY
  462. { skip_evaluation--;
  463. in_alignof--;
  464. $$.value = c_alignof (groktypename ($3));
  465. $$.original_code = ERROR_MARK; }
  466. | REALPART cast_expr %prec UNARY
  467. { $$.value = build_unary_op (REALPART_EXPR, $2.value, 0);
  468. $$.original_code = ERROR_MARK; }
  469. | IMAGPART cast_expr %prec UNARY
  470. { $$.value = build_unary_op (IMAGPART_EXPR, $2.value, 0);
  471. $$.original_code = ERROR_MARK; }
  472. ;
  473. sizeof:
  474. SIZEOF { skip_evaluation++; in_sizeof++; }
  475. ;
  476. alignof:
  477. ALIGNOF { skip_evaluation++; in_alignof++; }
  478. ;
  479. typeof:
  480. TYPEOF { skip_evaluation++; in_typeof++; }
  481. ;
  482. cast_expr:
  483. unary_expr
  484. | '(' typename ')' cast_expr %prec UNARY
  485. { $$.value = c_cast_expr ($2, $4.value);
  486. $$.original_code = ERROR_MARK; }
  487. ;
  488. expr_no_commas:
  489. cast_expr
  490. | expr_no_commas '+' expr_no_commas
  491. { $$ = parser_build_binary_op ($2, $1, $3); }
  492. | expr_no_commas '-' expr_no_commas
  493. { $$ = parser_build_binary_op ($2, $1, $3); }
  494. | expr_no_commas '*' expr_no_commas
  495. { $$ = parser_build_binary_op ($2, $1, $3); }
  496. | expr_no_commas '/' expr_no_commas
  497. { $$ = parser_build_binary_op ($2, $1, $3); }
  498. | expr_no_commas '%' expr_no_commas
  499. { $$ = parser_build_binary_op ($2, $1, $3); }
  500. | expr_no_commas LSHIFT expr_no_commas
  501. { $$ = parser_build_binary_op ($2, $1, $3); }
  502. | expr_no_commas RSHIFT expr_no_commas
  503. { $$ = parser_build_binary_op ($2, $1, $3); }
  504. | expr_no_commas ARITHCOMPARE expr_no_commas
  505. { $$ = parser_build_binary_op ($2, $1, $3); }
  506. | expr_no_commas EQCOMPARE expr_no_commas
  507. { $$ = parser_build_binary_op ($2, $1, $3); }
  508. | expr_no_commas '&amp;' expr_no_commas
  509. { $$ = parser_build_binary_op ($2, $1, $3); }
  510. | expr_no_commas '|' expr_no_commas
  511. { $$ = parser_build_binary_op ($2, $1, $3); }
  512. | expr_no_commas '^' expr_no_commas
  513. { $$ = parser_build_binary_op ($2, $1, $3); }
  514. | expr_no_commas ANDAND
  515. { $1.value = lang_hooks.truthvalue_conversion
  516. (default_conversion ($1.value));
  517. skip_evaluation += $1.value == truthvalue_false_node; }
  518. expr_no_commas
  519. { skip_evaluation -= $1.value == truthvalue_false_node;
  520. $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
  521. | expr_no_commas OROR
  522. { $1.value = lang_hooks.truthvalue_conversion
  523. (default_conversion ($1.value));
  524. skip_evaluation += $1.value == truthvalue_true_node; }
  525. expr_no_commas
  526. { skip_evaluation -= $1.value == truthvalue_true_node;
  527. $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
  528. | expr_no_commas '?'
  529. { $1.value = lang_hooks.truthvalue_conversion
  530. (default_conversion ($1.value));
  531. skip_evaluation += $1.value == truthvalue_false_node; }
  532. expr ':'
  533. { skip_evaluation += (($1.value == truthvalue_true_node)
  534. - ($1.value == truthvalue_false_node)); }
  535. expr_no_commas
  536. { skip_evaluation -= $1.value == truthvalue_true_node;
  537. $$.value = build_conditional_expr ($1.value, $4.value,
  538. $7.value);
  539. $$.original_code = ERROR_MARK; }
  540. | expr_no_commas '?'
  541. { if (pedantic)
  542. pedwarn (&quot;ISO C forbids omitting the middle term of a ?: expression&quot;);
  543. /* Make sure first operand is calculated only once. */
  544. $&lt;ttype&gt;2 = save_expr (default_conversion ($1.value));
  545. $1.value = lang_hooks.truthvalue_conversion ($&lt;ttype&gt;2);
  546. skip_evaluation += $1.value == truthvalue_true_node; }
  547. ':' expr_no_commas
  548. { skip_evaluation -= $1.value == truthvalue_true_node;
  549. $$.value = build_conditional_expr ($1.value, $&lt;ttype&gt;2,
  550. $5.value);
  551. $$.original_code = ERROR_MARK; }
  552. | expr_no_commas '=' expr_no_commas
  553. { $$.value = build_modify_expr ($1.value, NOP_EXPR, $3.value);
  554. $$.original_code = MODIFY_EXPR;
  555. }
  556. | expr_no_commas ASSIGN expr_no_commas
  557. { $$.value = build_modify_expr ($1.value, $2, $3.value);
  558. TREE_NO_WARNING ($$.value) = 1;
  559. $$.original_code = ERROR_MARK;
  560. }
  561. ;
  562. primary:
  563. IDENTIFIER
  564. {
  565. if (yychar == YYEMPTY)
  566. yychar = YYLEX;
  567. $$.value = build_external_ref ($1, yychar == '(');
  568. $$.original_code = ERROR_MARK;
  569. }
  570. | CONSTANT
  571. { $$.value = $1; $$.original_code = ERROR_MARK; }
  572. | STRING
  573. { $$.value = $1; $$.original_code = STRING_CST; }
  574. | FUNC_NAME
  575. { $$.value = fname_decl (C_RID_CODE ($1), $1);
  576. $$.original_code = ERROR_MARK; }
  577. | '(' typename ')' '{'
  578. { start_init (NULL_TREE, NULL, 0);
  579. $&lt;ttype&gt;$ = groktypename ($2);
  580. if (C_TYPE_VARIABLE_SIZE ($&lt;ttype&gt;$))
  581. {
  582. error (&quot;compound literal has variable size&quot;);
  583. $&lt;ttype&gt;$ = error_mark_node;
  584. }
  585. really_start_incremental_init ($&lt;ttype&gt;$); }
  586. initlist_maybe_comma '}' %prec UNARY
  587. { struct c_expr init = pop_init_level (0);
  588. tree constructor = init.value;
  589. tree type = $&lt;ttype&gt;5;
  590. finish_init ();
  591. maybe_warn_string_init (type, init);
  592. if (pedantic &amp;&amp; !flag_isoc99)
  593. pedwarn (&quot;ISO C90 forbids compound literals&quot;);
  594. $$.value = build_compound_literal (type, constructor);
  595. $$.original_code = ERROR_MARK;
  596. }
  597. | '(' expr ')'
  598. { $$.value = $2.value;
  599. if (TREE_CODE ($$.value) == MODIFY_EXPR)
  600. TREE_NO_WARNING ($$.value) = 1;
  601. $$.original_code = ERROR_MARK; }
  602. | '(' error ')'
  603. { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
  604. | compstmt_primary_start compstmt_nostart ')'
  605. { if (pedantic)
  606. pedwarn (&quot;ISO C forbids braced-groups within expressions&quot;);
  607. $$.value = c_finish_stmt_expr ($1);
  608. $$.original_code = ERROR_MARK;
  609. }
  610. | compstmt_primary_start error ')'
  611. { c_finish_stmt_expr ($1);
  612. $$.value = error_mark_node;
  613. $$.original_code = ERROR_MARK;
  614. }
  615. | primary '(' exprlist ')' %prec '.'
  616. { $$.value = build_function_call ($1.value, $3);
  617. $$.original_code = ERROR_MARK; }
  618. | VA_ARG '(' expr_no_commas ',' typename ')'
  619. { $$.value = build_va_arg ($3.value, groktypename ($5));
  620. $$.original_code = ERROR_MARK; }
  621. | OFFSETOF '(' typename ','
  622. { tree type = groktypename ($3);
  623. if (type == error_mark_node)
  624. offsetof_base = error_mark_node;
  625. else
  626. offsetof_base = build1 (INDIRECT_REF, type, NULL);
  627. }
  628. offsetof_member_designator ')'
  629. { $$.value = fold_offsetof ($6);
  630. $$.original_code = ERROR_MARK; }
  631. | OFFSETOF '(' error ')'
  632. { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
  633. | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ','
  634. expr_no_commas ')'
  635. {
  636. tree c;
  637. c = fold ($3.value);
  638. STRIP_NOPS (c);
  639. if (TREE_CODE (c) != INTEGER_CST)
  640. error (&quot;first argument to %&lt;__builtin_choose_expr%&gt; not&quot;
  641. &quot; a constant&quot;);
  642. $$ = integer_zerop (c) ? $7 : $5;
  643. }
  644. | CHOOSE_EXPR '(' error ')'
  645. { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
  646. | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
  647. {
  648. tree e1, e2;
  649. e1 = TYPE_MAIN_VARIANT (groktypename ($3));
  650. e2 = TYPE_MAIN_VARIANT (groktypename ($5));
  651. $$.value = comptypes (e1, e2)
  652. ? build_int_cst (NULL_TREE, 1)
  653. : build_int_cst (NULL_TREE, 0);
  654. $$.original_code = ERROR_MARK;
  655. }
  656. | TYPES_COMPATIBLE_P '(' error ')'
  657. { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
  658. | primary '[' expr ']' %prec '.'
  659. { $$.value = build_array_ref ($1.value, $3.value);
  660. $$.original_code = ERROR_MARK; }
  661. | primary '.' identifier
  662. { $$.value = build_component_ref ($1.value, $3);
  663. $$.original_code = ERROR_MARK; }
  664. | primary POINTSAT identifier
  665. {
  666. tree expr = build_indirect_ref ($1.value, &quot;-&gt;&quot;);
  667. $$.value = build_component_ref (expr, $3);
  668. $$.original_code = ERROR_MARK;
  669. }
  670. | primary PLUSPLUS
  671. { $$.value = build_unary_op (POSTINCREMENT_EXPR, $1.value, 0);
  672. $$.original_code = ERROR_MARK; }
  673. | primary MINUSMINUS
  674. { $$.value = build_unary_op (POSTDECREMENT_EXPR, $1.value, 0);
  675. $$.original_code = ERROR_MARK; }
  676. ;
  677. /* This is the second argument to __builtin_offsetof. We must have one
  678. identifier, and beyond that we want to accept sub structure and sub
  679. array references. */
  680. offsetof_member_designator:
  681. identifier
  682. { $$ = build_component_ref (offsetof_base, $1); }
  683. | offsetof_member_designator '.' identifier
  684. { $$ = build_component_ref ($1, $3); }
  685. | offsetof_member_designator '[' expr ']'
  686. { $$ = build_array_ref ($1, $3.value); }
  687. ;
  688. old_style_parm_decls:
  689. /* empty */
  690. | datadecls
  691. ;
  692. /* The following are analogous to lineno_decl, decls and decl
  693. except that they do not allow nested functions.
  694. They are used for old-style parm decls. */
  695. lineno_datadecl:
  696. save_location datadecl
  697. { }
  698. ;
  699. datadecls:
  700. lineno_datadecl
  701. | errstmt
  702. | datadecls lineno_datadecl
  703. | lineno_datadecl errstmt
  704. ;
  705. /* We don't allow prefix attributes here because they cause reduce/reduce
  706. conflicts: we can't know whether we're parsing a function decl with
  707. attribute suffix, or function defn with attribute prefix on first old
  708. style parm. */
  709. datadecl:
  710. declspecs_ts_nosa setspecs initdecls ';'
  711. { POP_DECLSPEC_STACK; }
  712. | declspecs_nots_nosa setspecs notype_initdecls ';'
  713. { POP_DECLSPEC_STACK; }
  714. | declspecs_ts_nosa ';'
  715. { shadow_tag_warned (finish_declspecs ($1), 1);
  716. pedwarn (&quot;empty declaration&quot;); }
  717. | declspecs_nots_nosa ';'
  718. { pedwarn (&quot;empty declaration&quot;); }
  719. ;
  720. /* This combination which saves a lineno before a decl
  721. is the normal thing to use, rather than decl itself.
  722. This is to avoid shift/reduce conflicts in contexts
  723. where statement labels are allowed. */
  724. lineno_decl:
  725. save_location decl
  726. { }
  727. ;
  728. /* records the type and storage class specs to use for processing
  729. the declarators that follow.
  730. Maintains a stack of outer-level values of current_declspecs,
  731. for the sake of parm declarations nested in function declarators. */
  732. setspecs: /* empty */
  733. { pending_xref_error ();
  734. PUSH_DECLSPEC_STACK;
  735. if ($&lt;dsptype&gt;0)
  736. {
  737. prefix_attributes = $&lt;dsptype&gt;0-&gt;attrs;
  738. $&lt;dsptype&gt;0-&gt;attrs = NULL_TREE;
  739. current_declspecs = $&lt;dsptype&gt;0;
  740. }
  741. else
  742. {
  743. prefix_attributes = NULL_TREE;
  744. current_declspecs = build_null_declspecs ();
  745. }
  746. current_declspecs = finish_declspecs (current_declspecs);
  747. all_prefix_attributes = prefix_attributes; }
  748. ;
  749. /* Possibly attributes after a comma, which should reset all_prefix_attributes
  750. to prefix_attributes with these ones chained on the front. */
  751. maybe_resetattrs:
  752. maybe_attribute
  753. { all_prefix_attributes = chainon ($1, prefix_attributes); }
  754. ;
  755. decl:
  756. declspecs_ts setspecs initdecls ';'
  757. { POP_DECLSPEC_STACK; }
  758. | declspecs_nots setspecs notype_initdecls ';'
  759. { POP_DECLSPEC_STACK; }
  760. | declspecs_ts setspecs nested_function
  761. { POP_DECLSPEC_STACK; }
  762. | declspecs_nots setspecs notype_nested_function
  763. { POP_DECLSPEC_STACK; }
  764. | declspecs ';'
  765. { shadow_tag (finish_declspecs ($1)); }
  766. | extension decl
  767. { RESTORE_EXT_FLAGS ($1); }
  768. ;
  769. /* A list of declaration specifiers. These are:
  770. - Storage class specifiers (scspec), which for GCC currently includes
  771. function specifiers (&quot;inline&quot;).
  772. - Type specifiers (typespec_*).
  773. - Type qualifiers (TYPE_QUAL).
  774. - Attribute specifier lists (attributes).
  775. The various cases below are classified according to:
  776. (a) Whether a storage class specifier is included or not; some
  777. places in the grammar disallow storage class specifiers (_sc or _nosc).
  778. (b) Whether a type specifier has been seen; after a type specifier,
  779. a typedef name is an identifier to redeclare (_ts or _nots).
  780. (c) Whether the list starts with an attribute; in certain places,
  781. the grammar requires specifiers that don't start with an attribute
  782. (_sa or _nosa).
  783. (d) Whether the list ends with an attribute (or a specifier such that
  784. any following attribute would have been parsed as part of that specifier);
  785. this avoids shift-reduce conflicts in the parsing of attributes
  786. (_ea or _noea).
  787. TODO:
  788. (i) Distinguish between function specifiers and storage class specifiers,
  789. at least for the purpose of warnings about obsolescent usage.
  790. (ii) Halve the number of productions here by eliminating the _sc/_nosc
  791. distinction and instead checking where required that storage class
  792. specifiers aren't present. */
  793. /* Declspecs which contain at least one type specifier or typedef name.
  794. (Just `const' or `volatile' is not enough.)
  795. A typedef'd name following these is taken as a name to be declared. */
  796. declspecs_nosc_nots_nosa_noea:
  797. TYPE_QUAL
  798. { $$ = declspecs_add_qual (build_null_declspecs (), $1); }
  799. | declspecs_nosc_nots_nosa_noea TYPE_QUAL
  800. { $$ = declspecs_add_qual ($1, $2); }
  801. | declspecs_nosc_nots_nosa_ea TYPE_QUAL
  802. { $$ = declspecs_add_qual ($1, $2); }
  803. ;
  804. declspecs_nosc_nots_nosa_ea:
  805. declspecs_nosc_nots_nosa_noea attributes
  806. { $$ = declspecs_add_attrs ($1, $2); }
  807. ;
  808. declspecs_nosc_nots_sa_noea:
  809. declspecs_nosc_nots_sa_noea TYPE_QUAL
  810. { $$ = declspecs_add_qual ($1, $2); }
  811. | declspecs_nosc_nots_sa_ea TYPE_QUAL
  812. { $$ = declspecs_add_qual ($1, $2); }
  813. ;
  814. declspecs_nosc_nots_sa_ea:
  815. attributes
  816. { $$ = declspecs_add_attrs (build_null_declspecs (), $1); }
  817. | declspecs_nosc_nots_sa_noea attributes
  818. { $$ = declspecs_add_attrs ($1, $2); }
  819. ;
  820. declspecs_nosc_ts_nosa_noea:
  821. typespec_nonattr
  822. { $$ = declspecs_add_type (build_null_declspecs (), $1); }
  823. | declspecs_nosc_ts_nosa_noea TYPE_QUAL
  824. { $$ = declspecs_add_qual ($1, $2); }
  825. | declspecs_nosc_ts_nosa_ea TYPE_QUAL
  826. { $$ = declspecs_add_qual ($1, $2); }
  827. | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
  828. { $$ = declspecs_add_type ($1, $2); }
  829. | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
  830. { $$ = declspecs_add_type ($1, $2); }
  831. | declspecs_nosc_nots_nosa_noea typespec_nonattr
  832. { $$ = declspecs_add_type ($1, $2); }
  833. | declspecs_nosc_nots_nosa_ea typespec_nonattr
  834. { $$ = declspecs_add_type ($1, $2); }
  835. ;
  836. declspecs_nosc_ts_nosa_ea:
  837. typespec_attr
  838. { $$ = declspecs_add_type (build_null_declspecs (), $1); }
  839. | declspecs_nosc_ts_nosa_noea attributes
  840. { $$ = declspecs_add_attrs ($1, $2); }
  841. | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
  842. { $$ = declspecs_add_type ($1, $2); }
  843. | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
  844. { $$ = declspecs_add_type ($1, $2); }
  845. | declspecs_nosc_nots_nosa_noea typespec_attr
  846. { $$ = declspecs_add_type ($1, $2); }
  847. | declspecs_nosc_nots_nosa_ea typespec_attr
  848. { $$ = declspecs_add_type ($1, $2); }
  849. ;
  850. declspecs_nosc_ts_sa_noea:
  851. declspecs_nosc_ts_sa_noea TYPE_QUAL
  852. { $$ = declspecs_add_qual ($1, $2); }
  853. | declspecs_nosc_ts_sa_ea TYPE_QUAL
  854. { $$ = declspecs_add_qual ($1, $2); }
  855. | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
  856. { $$ = declspecs_add_type ($1, $2); }
  857. | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
  858. { $$ = declspecs_add_type ($1, $2); }
  859. | declspecs_nosc_nots_sa_noea typespec_nonattr
  860. { $$ = declspecs_add_type ($1, $2); }
  861. | declspecs_nosc_nots_sa_ea typespec_nonattr
  862. { $$ = declspecs_add_type ($1, $2); }
  863. ;
  864. declspecs_nosc_ts_sa_ea:
  865. declspecs_nosc_ts_sa_noea attributes
  866. { $$ = declspecs_add_attrs ($1, $2); }
  867. | declspecs_nosc_ts_sa_noea typespec_reserved_attr
  868. { $$ = declspecs_add_type ($1, $2); }
  869. | declspecs_nosc_ts_sa_ea typespec_reserved_attr
  870. { $$ = declspecs_add_type ($1, $2); }
  871. | declspecs_nosc_nots_sa_noea typespec_attr
  872. { $$ = declspecs_add_type ($1, $2); }
  873. | declspecs_nosc_nots_sa_ea typespec_attr
  874. { $$ = declspecs_add_type ($1, $2); }
  875. ;
  876. declspecs_sc_nots_nosa_noea:
  877. scspec
  878. { $$ = declspecs_add_scspec (build_null_declspecs (), $1); }
  879. | declspecs_sc_nots_nosa_noea TYPE_QUAL
  880. { $$ = declspecs_add_qual ($1, $2); }
  881. | declspecs_sc_nots_nosa_ea TYPE_QUAL
  882. { $$ = declspecs_add_qual ($1, $2); }
  883. | declspecs_nosc_nots_nosa_noea scspec
  884. { $$ = declspecs_add_scspec ($1, $2); }
  885. | declspecs_nosc_nots_nosa_ea scspec
  886. { $$ = declspecs_add_scspec ($1, $2); }
  887. | declspecs_sc_nots_nosa_noea scspec
  888. { $$ = declspecs_add_scspec ($1, $2); }
  889. | declspecs_sc_nots_nosa_ea scspec
  890. { $$ = declspecs_add_scspec ($1, $2); }
  891. ;
  892. declspecs_sc_nots_nosa_ea:
  893. declspecs_sc_nots_nosa_noea attributes
  894. { $$ = declspecs_add_attrs ($1, $2); }
  895. ;
  896. declspecs_sc_nots_sa_noea:
  897. declspecs_sc_nots_sa_noea TYPE_QUAL
  898. { $$ = declspecs_add_qual ($1, $2); }
  899. | declspecs_sc_nots_sa_ea TYPE_QUAL
  900. { $$ = declspecs_add_qual ($1, $2); }
  901. | declspecs_nosc_nots_sa_noea scspec
  902. { $$ = declspecs_add_scspec ($1, $2); }
  903. | declspecs_nosc_nots_sa_ea scspec
  904. { $$ = declspecs_add_scspec ($1, $2); }
  905. | declspecs_sc_nots_sa_noea scspec
  906. { $$ = declspecs_add_scspec ($1, $2); }
  907. | declspecs_sc_nots_sa_ea scspec
  908. { $$ = declspecs_add_scspec ($1, $2); }
  909. ;
  910. declspecs_sc_nots_sa_ea:
  911. declspecs_sc_nots_sa_noea attributes
  912. { $$ = declspecs_add_attrs ($1, $2); }
  913. ;
  914. declspecs_sc_ts_nosa_noea:
  915. declspecs_sc_ts_nosa_noea TYPE_QUAL
  916. { $$ = declspecs_add_qual ($1, $2); }
  917. | declspecs_sc_ts_nosa_ea TYPE_QUAL
  918. { $$ = declspecs_add_qual ($1, $2); }
  919. | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
  920. { $$ = declspecs_add_type ($1, $2); }
  921. | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
  922. { $$ = declspecs_add_type ($1, $2); }
  923. | declspecs_sc_nots_nosa_noea typespec_nonattr
  924. { $$ = declspecs_add_type ($1, $2); }
  925. | declspecs_sc_nots_nosa_ea typespec_nonattr
  926. { $$ = declspecs_add_type ($1, $2); }
  927. | declspecs_nosc_ts_nosa_noea scspec
  928. { $$ = declspecs_add_scspec ($1, $2); }
  929. | declspecs_nosc_ts_nosa_ea scspec
  930. { $$ = declspecs_add_scspec ($1, $2); }
  931. | declspecs_sc_ts_nosa_noea scspec
  932. { $$ = declspecs_add_scspec ($1, $2); }
  933. | declspecs_sc_ts_nosa_ea scspec
  934. { $$ = declspecs_add_scspec ($1, $2); }
  935. ;
  936. declspecs_sc_ts_nosa_ea:
  937. declspecs_sc_ts_nosa_noea attributes
  938. { $$ = declspecs_add_attrs ($1, $2); }
  939. | declspecs_sc_ts_nosa_noea typespec_reserved_attr
  940. { $$ = declspecs_add_type ($1, $2); }
  941. | declspecs_sc_ts_nosa_ea typespec_reserved_attr
  942. { $$ = declspecs_add_type ($1, $2); }
  943. | declspecs_sc_nots_nosa_noea typespec_attr
  944. { $$ = declspecs_add_type ($1, $2); }
  945. | declspecs_sc_nots_nosa_ea typespec_attr
  946. { $$ = declspecs_add_type ($1, $2); }
  947. ;
  948. declspecs_sc_ts_sa_noea:
  949. declspecs_sc_ts_sa_noea TYPE_QUAL
  950. { $$ = declspecs_add_qual ($1, $2); }
  951. | declspecs_sc_ts_sa_ea TYPE_QUAL
  952. { $$ = declspecs_add_qual ($1, $2); }
  953. | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
  954. { $$ = declspecs_add_type ($1, $2); }
  955. | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
  956. { $$ = declspecs_add_type ($1, $2); }
  957. | declspecs_sc_nots_sa_noea typespec_nonattr
  958. { $$ = declspecs_add_type ($1, $2); }
  959. | declspecs_sc_nots_sa_ea typespec_nonattr
  960. { $$ = declspecs_add_type ($1, $2); }
  961. | declspecs_nosc_ts_sa_noea scspec
  962. { $$ = declspecs_add_scspec ($1, $2); }
  963. | declspecs_nosc_ts_sa_ea scspec
  964. { $$ = declspecs_add_scspec ($1, $2); }
  965. | declspecs_sc_ts_sa_noea scspec
  966. { $$ = declspecs_add_scspec ($1, $2); }
  967. | declspecs_sc_ts_sa_ea scspec
  968. { $$ = declspecs_add_scspec ($1, $2); }
  969. ;
  970. declspecs_sc_ts_sa_ea:
  971. declspecs_sc_ts_sa_noea attributes
  972. { $$ = declspecs_add_attrs ($1, $2); }
  973. | declspecs_sc_ts_sa_noea typespec_reserved_attr
  974. { $$ = declspecs_add_type ($1, $2); }
  975. | declspecs_sc_ts_sa_ea typespec_reserved_attr
  976. { $$ = declspecs_add_type ($1, $2); }
  977. | declspecs_sc_nots_sa_noea typespec_attr
  978. { $$ = declspecs_add_type ($1, $2); }
  979. | declspecs_sc_nots_sa_ea typespec_attr
  980. { $$ = declspecs_add_type ($1, $2); }
  981. ;
  982. /* Particular useful classes of declspecs. */
  983. declspecs_ts:
  984. declspecs_nosc_ts_nosa_noea
  985. | declspecs_nosc_ts_nosa_ea
  986. | declspecs_nosc_ts_sa_noea
  987. | declspecs_nosc_ts_sa_ea
  988. | declspecs_sc_ts_nosa_noea
  989. | declspecs_sc_ts_nosa_ea
  990. | declspecs_sc_ts_sa_noea
  991. | declspecs_sc_ts_sa_ea
  992. ;
  993. declspecs_nots:
  994. declspecs_nosc_nots_nosa_noea
  995. | declspecs_nosc_nots_nosa_ea
  996. | declspecs_nosc_nots_sa_noea
  997. | declspecs_nosc_nots_sa_ea
  998. | declspecs_sc_nots_nosa_noea
  999. | declspecs_sc_nots_nosa_ea
  1000. | declspecs_sc_nots_sa_noea
  1001. | declspecs_sc_nots_sa_ea
  1002. ;
  1003. declspecs_ts_nosa:
  1004. declspecs_nosc_ts_nosa_noea
  1005. | declspecs_nosc_ts_nosa_ea
  1006. | declspecs_sc_ts_nosa_noea
  1007. | declspecs_sc_ts_nosa_ea
  1008. ;
  1009. declspecs_nots_nosa:
  1010. declspecs_nosc_nots_nosa_noea
  1011. | declspecs_nosc_nots_nosa_ea
  1012. | declspecs_sc_nots_nosa_noea
  1013. | declspecs_sc_nots_nosa_ea
  1014. ;
  1015. declspecs_nosc_ts:
  1016. declspecs_nosc_ts_nosa_noea
  1017. | declspecs_nosc_ts_nosa_ea
  1018. | declspecs_nosc_ts_sa_noea
  1019. | declspecs_nosc_ts_sa_ea
  1020. ;
  1021. declspecs_nosc_nots:
  1022. declspecs_nosc_nots_nosa_noea
  1023. | declspecs_nosc_nots_nosa_ea
  1024. | declspecs_nosc_nots_sa_noea
  1025. | declspecs_nosc_nots_sa_ea
  1026. ;
  1027. declspecs_nosc:
  1028. declspecs_nosc_ts_nosa_noea
  1029. | declspecs_nosc_ts_nosa_ea
  1030. | declspecs_nosc_ts_sa_noea
  1031. | declspecs_nosc_ts_sa_ea
  1032. | declspecs_nosc_nots_nosa_noea
  1033. | declspecs_nosc_nots_nosa_ea
  1034. | declspecs_nosc_nots_sa_noea
  1035. | declspecs_nosc_nots_sa_ea
  1036. ;
  1037. declspecs:
  1038. declspecs_nosc_nots_nosa_noea
  1039. | declspecs_nosc_nots_nosa_ea
  1040. | declspecs_nosc_nots_sa_noea
  1041. | declspecs_nosc_nots_sa_ea
  1042. | declspecs_nosc_ts_nosa_noea
  1043. | declspecs_nosc_ts_nosa_ea
  1044. | declspecs_nosc_ts_sa_noea
  1045. | declspecs_nosc_ts_sa_ea
  1046. | declspecs_sc_nots_nosa_noea
  1047. | declspecs_sc_nots_nosa_ea
  1048. | declspecs_sc_nots_sa_noea
  1049. | declspecs_sc_nots_sa_ea
  1050. | declspecs_sc_ts_nosa_noea
  1051. | declspecs_sc_ts_nosa_ea
  1052. | declspecs_sc_ts_sa_noea
  1053. | declspecs_sc_ts_sa_ea
  1054. ;
  1055. /* A (possibly empty) sequence of type qualifiers and attributes. */
  1056. maybe_type_quals_attrs:
  1057. /* empty */
  1058. { $$ = NULL; }
  1059. | declspecs_nosc_nots
  1060. { $$ = $1; }
  1061. ;
  1062. /* A type specifier (but not a type qualifier).
  1063. Once we have seen one of these in a declaration,
  1064. if a typedef name appears then it is being redeclared.
  1065. The _reserved versions start with a reserved word and may appear anywhere
  1066. in the declaration specifiers; the _nonreserved versions may only
  1067. appear before any other type specifiers, and after that are (if names)
  1068. being redeclared.
  1069. FIXME: should the _nonreserved version be restricted to names being
  1070. redeclared only? The other entries there relate only the GNU extensions
  1071. and Objective C, and are historically parsed thus, and don't make sense
  1072. after other type specifiers, but it might be cleaner to count them as
  1073. _reserved.
  1074. _attr means: specifiers that either end with attributes,
  1075. or are such that any following attributes would
  1076. be parsed as part of the specifier.
  1077. _nonattr: other specifiers not ending with attributes. */
  1078. typespec_nonattr:
  1079. typespec_reserved_nonattr
  1080. | typespec_nonreserved_nonattr
  1081. ;
  1082. typespec_attr:
  1083. typespec_reserved_attr
  1084. ;
  1085. typespec_reserved_nonattr:
  1086. TYPESPEC
  1087. { OBJC_NEED_RAW_IDENTIFIER (1);
  1088. $$.kind = ctsk_resword;
  1089. $$.spec = $1; }
  1090. | structsp_nonattr
  1091. ;
  1092. typespec_reserved_attr:
  1093. structsp_attr
  1094. ;
  1095. typespec_nonreserved_nonattr:
  1096. TYPENAME
  1097. { /* For a typedef name, record the meaning, not the name.
  1098. In case of `foo foo, bar;'. */
  1099. $$.kind = ctsk_typedef;
  1100. $$.spec = lookup_name ($1); }
  1101. | typeof '(' expr ')'
  1102. { skip_evaluation--;
  1103. in_typeof--;
  1104. if (TREE_CODE ($3.value) == COMPONENT_REF
  1105. &amp;&amp; DECL_C_BIT_FIELD (TREE_OPERAND ($3.value, 1)))
  1106. error (&quot;%&lt;typeof%&gt; applied to a bit-field&quot;);
  1107. $$.kind = ctsk_typeof;
  1108. $$.spec = TREE_TYPE ($3.value);
  1109. pop_maybe_used (variably_modified_type_p ($$.spec,
  1110. NULL_TREE)); }
  1111. | typeof '(' typename ')'
  1112. { skip_evaluation--;
  1113. in_typeof--;
  1114. $$.kind = ctsk_typeof;
  1115. $$.spec = groktypename ($3);
  1116. pop_maybe_used (variably_modified_type_p ($$.spec,
  1117. NULL_TREE)); }
  1118. ;
  1119. /* typespec_nonreserved_attr does not exist. */
  1120. initdecls:
  1121. initdcl
  1122. | initdecls ',' maybe_resetattrs initdcl
  1123. ;
  1124. notype_initdecls:
  1125. notype_initdcl
  1126. | notype_initdecls ',' maybe_resetattrs notype_initdcl
  1127. ;
  1128. initdcl:
  1129. declarator maybeasm maybe_attribute '='
  1130. { $&lt;ttype&gt;$ = start_decl ($1, current_declspecs, true,
  1131. chainon ($3, all_prefix_attributes));
  1132. if (!$&lt;ttype&gt;$)
  1133. $&lt;ttype&gt;$ = error_mark_node;
  1134. start_init ($&lt;ttype&gt;$, $2, global_bindings_p ()); }
  1135. init
  1136. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1137. { finish_init ();
  1138. if ($&lt;ttype&gt;5 != error_mark_node)
  1139. {
  1140. maybe_warn_string_init (TREE_TYPE ($&lt;ttype&gt;5), $6);
  1141. finish_decl ($&lt;ttype&gt;5, $6.value, $2);
  1142. }
  1143. }
  1144. | declarator maybeasm maybe_attribute
  1145. { tree d = start_decl ($1, current_declspecs, false,
  1146. chainon ($3, all_prefix_attributes));
  1147. if (d)
  1148. finish_decl (d, NULL_TREE, $2);
  1149. }
  1150. ;
  1151. notype_initdcl:
  1152. notype_declarator maybeasm maybe_attribute '='
  1153. { $&lt;ttype&gt;$ = start_decl ($1, current_declspecs, true,
  1154. chainon ($3, all_prefix_attributes));
  1155. if (!$&lt;ttype&gt;$)
  1156. $&lt;ttype&gt;$ = error_mark_node;
  1157. start_init ($&lt;ttype&gt;$, $2, global_bindings_p ()); }
  1158. init
  1159. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1160. { finish_init ();
  1161. if ($&lt;ttype&gt;5 != error_mark_node)
  1162. {
  1163. maybe_warn_string_init (TREE_TYPE ($&lt;ttype&gt;5), $6);
  1164. finish_decl ($&lt;ttype&gt;5, $6.value, $2);
  1165. }
  1166. }
  1167. | notype_declarator maybeasm maybe_attribute
  1168. { tree d = start_decl ($1, current_declspecs, false,
  1169. chainon ($3, all_prefix_attributes));
  1170. if (d)
  1171. finish_decl (d, NULL_TREE, $2); }
  1172. ;
  1173. /* the * rules are dummies to accept the Apollo extended syntax
  1174. so that the header files compile. */
  1175. maybe_attribute:
  1176. /* empty */
  1177. { $$ = NULL_TREE; }
  1178. | attributes
  1179. { $$ = $1; }
  1180. ;
  1181. attributes:
  1182. attribute
  1183. { $$ = $1; }
  1184. | attributes attribute
  1185. { $$ = chainon ($1, $2); }
  1186. ;
  1187. attribute:
  1188. ATTRIBUTE stop_string_translation
  1189. '(' '(' attribute_list ')' ')' start_string_translation
  1190. { $$ = $5; }
  1191. | ATTRIBUTE error start_string_translation
  1192. { $$ = NULL_TREE; }
  1193. ;
  1194. attribute_list:
  1195. attrib
  1196. { $$ = $1; }
  1197. | attribute_list ',' attrib
  1198. { $$ = chainon ($1, $3); }
  1199. ;
  1200. attrib:
  1201. /* empty */
  1202. { $$ = NULL_TREE; }
  1203. | any_word
  1204. { $$ = build_tree_list ($1, NULL_TREE); }
  1205. | any_word '(' IDENTIFIER ')'
  1206. { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
  1207. | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
  1208. { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
  1209. | any_word '(' exprlist ')'
  1210. { $$ = build_tree_list ($1, $3); }
  1211. ;
  1212. /* This still leaves out most reserved keywords,
  1213. shouldn't we include them? */
  1214. any_word:
  1215. identifier
  1216. | scspec
  1217. | TYPESPEC
  1218. | TYPE_QUAL
  1219. ;
  1220. scspec:
  1221. STATIC
  1222. | SCSPEC
  1223. ;
  1224. /* Initializers. `init' is the entry point. */
  1225. init:
  1226. expr_no_commas
  1227. { $$ = $1; }
  1228. | '{'
  1229. { really_start_incremental_init (NULL_TREE); }
  1230. initlist_maybe_comma '}'
  1231. { $$ = pop_init_level (0); }
  1232. | error
  1233. { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
  1234. ;
  1235. /* `initlist_maybe_comma' is the guts of an initializer in braces. */
  1236. initlist_maybe_comma:
  1237. /* empty */
  1238. { if (pedantic)
  1239. pedwarn (&quot;ISO C forbids empty initializer braces&quot;); }
  1240. | initlist1 maybecomma
  1241. ;
  1242. initlist1:
  1243. initelt
  1244. | initlist1 ',' initelt
  1245. ;
  1246. /* `initelt' is a single element of an initializer.
  1247. It may use braces. */
  1248. initelt:
  1249. designator_list '=' initval
  1250. { if (pedantic &amp;&amp; !flag_isoc99)
  1251. pedwarn (&quot;ISO C90 forbids specifying subobject to initialize&quot;); }
  1252. | array_designator initval
  1253. { if (pedantic)
  1254. pedwarn (&quot;obsolete use of designated initializer without %&lt;=%&gt;&quot;); }
  1255. | identifier ':'
  1256. { set_init_label ($1);
  1257. if (pedantic)
  1258. pedwarn (&quot;obsolete use of designated initializer with %&lt;:%&gt;&quot;); }
  1259. initval
  1260. {}
  1261. | initval
  1262. ;
  1263. initval:
  1264. '{'
  1265. { push_init_level (0); }
  1266. initlist_maybe_comma '}'
  1267. { process_init_element (pop_init_level (0)); }
  1268. | expr_no_commas
  1269. { process_init_element ($1); }
  1270. | error
  1271. ;
  1272. designator_list:
  1273. designator
  1274. | designator_list designator
  1275. ;
  1276. designator:
  1277. '.' identifier
  1278. { set_init_label ($2); }
  1279. | array_designator
  1280. ;
  1281. array_designator:
  1282. '[' expr_no_commas ELLIPSIS expr_no_commas ']'
  1283. { set_init_index ($2.value, $4.value);
  1284. if (pedantic)
  1285. pedwarn (&quot;ISO C forbids specifying range of elements to initialize&quot;); }
  1286. | '[' expr_no_commas ']'
  1287. { set_init_index ($2.value, NULL_TREE); }
  1288. ;
  1289. nested_function:
  1290. declarator
  1291. { if (pedantic)
  1292. pedwarn (&quot;ISO C forbids nested functions&quot;);
  1293. push_function_context ();
  1294. if (!start_function (current_declspecs, $1,
  1295. all_prefix_attributes))
  1296. {
  1297. pop_function_context ();
  1298. YYERROR1;
  1299. }
  1300. }
  1301. old_style_parm_decls save_location
  1302. { tree decl = current_function_decl;
  1303. DECL_SOURCE_LOCATION (decl) = $4;
  1304. store_parm_decls (); }
  1305. /* This used to use compstmt_or_error. That caused a bug with
  1306. input `f(g) int g {}', where the use of YYERROR1 above caused
  1307. an error which then was handled by compstmt_or_error. There
  1308. followed a repeated execution of that same rule, which called
  1309. YYERROR1 again, and so on. */
  1310. compstmt
  1311. { tree decl = current_function_decl;
  1312. add_stmt ($6);
  1313. finish_function ();
  1314. pop_function_context ();
  1315. add_stmt (build_stmt (DECL_EXPR, decl)); }
  1316. ;
  1317. notype_nested_function:
  1318. notype_declarator
  1319. { if (pedantic)
  1320. pedwarn (&quot;ISO C forbids nested functions&quot;);
  1321. push_function_context ();
  1322. if (!start_function (current_declspecs, $1,
  1323. all_prefix_attributes))
  1324. {
  1325. pop_function_context ();
  1326. YYERROR1;
  1327. }
  1328. }
  1329. old_style_parm_decls save_location
  1330. { tree decl = current_function_decl;
  1331. DECL_SOURCE_LOCATION (decl) = $4;
  1332. store_parm_decls (); }
  1333. /* This used to use compstmt_or_error. That caused a bug with
  1334. input `f(g) int g {}', where the use of YYERROR1 above caused
  1335. an error which then was handled by compstmt_or_error. There
  1336. followed a repeated execution of that same rule, which called
  1337. YYERROR1 again, and so on. */
  1338. compstmt
  1339. { tree decl = current_function_decl;
  1340. add_stmt ($6);
  1341. finish_function ();
  1342. pop_function_context ();
  1343. add_stmt (build_stmt (DECL_EXPR, decl)); }
  1344. ;
  1345. /* Any kind of declarator (thus, all declarators allowed
  1346. after an explicit typespec). */
  1347. declarator:
  1348. after_type_declarator
  1349. | notype_declarator
  1350. ;
  1351. /* A declarator that is allowed only after an explicit typespec. */
  1352. after_type_declarator:
  1353. '(' maybe_attribute after_type_declarator ')'
  1354. { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
  1355. | after_type_declarator '(' parmlist_or_identifiers %prec '.'
  1356. { $$ = build_function_declarator ($3, $1); }
  1357. | after_type_declarator array_declarator %prec '.'
  1358. { $$ = set_array_declarator_inner ($2, $1, false); }
  1359. | '*' maybe_type_quals_attrs after_type_declarator %prec UNARY
  1360. { $$ = make_pointer_declarator ($2, $3); }
  1361. | TYPENAME
  1362. { $$ = build_id_declarator ($1); }
  1363. ;
  1364. /* Kinds of declarator that can appear in a parameter list
  1365. in addition to notype_declarator. This is like after_type_declarator
  1366. but does not allow a typedef name in parentheses as an identifier
  1367. (because it would conflict with a function with that typedef as arg). */
  1368. parm_declarator:
  1369. parm_declarator_starttypename
  1370. | parm_declarator_nostarttypename
  1371. ;
  1372. parm_declarator_starttypename:
  1373. parm_declarator_starttypename '(' parmlist_or_identifiers %prec '.'
  1374. { $$ = build_function_declarator ($3, $1); }
  1375. | parm_declarator_starttypename array_declarator %prec '.'
  1376. { $$ = set_array_declarator_inner ($2, $1, false); }
  1377. | TYPENAME
  1378. { $$ = build_id_declarator ($1); }
  1379. ;
  1380. parm_declarator_nostarttypename:
  1381. parm_declarator_nostarttypename '(' parmlist_or_identifiers %prec '.'
  1382. { $$ = build_function_declarator ($3, $1); }
  1383. | parm_declarator_nostarttypename array_declarator %prec '.'
  1384. { $$ = set_array_declarator_inner ($2, $1, false); }
  1385. | '*' maybe_type_quals_attrs parm_declarator_starttypename %prec UNARY
  1386. { $$ = make_pointer_declarator ($2, $3)

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