PageRenderTime 65ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/gcc/c-parse.y

https://github.com/acassis/xap-gcc
Happy | 3132 lines | 2808 code | 324 blank | 0 comment | 0 complexity | 75e13aa4d238329138d6b3add519f117 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0

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

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

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