PageRenderTime 67ms CodeModel.GetById 22ms 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
  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 %prec '.'
  1430. { $$ = set_array_declarator_type ($2, $1, 0); }
  1431. | '*' maybe_type_quals_attrs parm_declarator_starttypename %prec UNARY
  1432. { $$ = make_pointer_declarator ($2, $3); }
  1433. | '*' maybe_type_quals_attrs parm_declarator_nostarttypename %prec UNARY
  1434. { $$ = make_pointer_declarator ($2, $3); }
  1435. | '(' maybe_attribute parm_declarator_nostarttypename ')'
  1436. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1437. ;
  1438. /* A declarator allowed whether or not there has been
  1439. an explicit typespec. These cannot redeclare a typedef-name. */
  1440. notype_declarator:
  1441. notype_declarator '(' parmlist_or_identifiers %prec '.'
  1442. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1443. /* | notype_declarator '(' error ')' %prec '.'
  1444. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1445. poplevel (0, 0, 0); } */
  1446. | '(' maybe_attribute notype_declarator ')'
  1447. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1448. | '*' maybe_type_quals_attrs notype_declarator %prec UNARY
  1449. { $$ = make_pointer_declarator ($2, $3); }
  1450. | notype_declarator array_declarator %prec '.'
  1451. { $$ = set_array_declarator_type ($2, $1, 0); }
  1452. | IDENTIFIER
  1453. ;
  1454. struct_head:
  1455. STRUCT
  1456. { $$ = NULL_TREE; }
  1457. | STRUCT attributes
  1458. { $$ = $2; }
  1459. ;
  1460. union_head:
  1461. UNION
  1462. { $$ = NULL_TREE; }
  1463. | UNION attributes
  1464. { $$ = $2; }
  1465. ;
  1466. enum_head:
  1467. ENUM
  1468. { $$ = NULL_TREE; }
  1469. | ENUM attributes
  1470. { $$ = $2; }
  1471. ;
  1472. /* structsp_attr: struct/union/enum specifiers that either
  1473. end with attributes, or are such that any following attributes would
  1474. be parsed as part of the struct/union/enum specifier.
  1475. structsp_nonattr: other struct/union/enum specifiers. */
  1476. structsp_attr:
  1477. struct_head identifier '{'
  1478. { $$ = start_struct (RECORD_TYPE, $2);
  1479. /* Start scope of tag before parsing components. */
  1480. }
  1481. component_decl_list '}' maybe_attribute
  1482. { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
  1483. | struct_head '{' component_decl_list '}' maybe_attribute
  1484. { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
  1485. $3, chainon ($1, $5));
  1486. }
  1487. | union_head identifier '{'
  1488. { $$ = start_struct (UNION_TYPE, $2); }
  1489. component_decl_list '}' maybe_attribute
  1490. { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
  1491. | union_head '{' component_decl_list '}' maybe_attribute
  1492. { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
  1493. $3, chainon ($1, $5));
  1494. }
  1495. | enum_head identifier '{'
  1496. { $$ = start_enum ($2); }
  1497. enumlist maybecomma_warn '}' maybe_attribute
  1498. { $$ = finish_enum ($<ttype>4, nreverse ($5),
  1499. chainon ($1, $8)); }
  1500. | enum_head '{'
  1501. { $$ = start_enum (NULL_TREE); }
  1502. enumlist maybecomma_warn '}' maybe_attribute
  1503. { $$ = finish_enum ($<ttype>3, nreverse ($4),
  1504. chainon ($1, $7)); }
  1505. ;
  1506. structsp_nonattr:
  1507. struct_head identifier
  1508. { $$ = xref_tag (RECORD_TYPE, $2); }
  1509. | union_head identifier
  1510. { $$ = xref_tag (UNION_TYPE, $2); }
  1511. | enum_head identifier
  1512. { $$ = xref_tag (ENUMERAL_TYPE, $2);
  1513. /* In ISO C, enumerated types can be referred to
  1514. only if already defined. */
  1515. if (pedantic && !COMPLETE_TYPE_P ($$))
  1516. pedwarn ("ISO C forbids forward references to `enum' types"); }
  1517. ;
  1518. maybecomma:
  1519. /* empty */
  1520. | ','
  1521. ;
  1522. maybecomma_warn:
  1523. /* empty */
  1524. | ','
  1525. { if (pedantic && ! flag_isoc99)
  1526. pedwarn ("comma at end of enumerator list"); }
  1527. ;
  1528. component_decl_list:
  1529. component_decl_list2
  1530. { $$ = $1; }
  1531. | component_decl_list2 component_decl
  1532. { $$ = chainon ($1, $2);
  1533. pedwarn ("no semicolon at end of struct or union"); }
  1534. ;
  1535. component_decl_list2: /* empty */
  1536. { $$ = NULL_TREE; }
  1537. | component_decl_list2 component_decl ';'
  1538. { $$ = chainon ($1, $2); }
  1539. | component_decl_list2 ';'
  1540. { if (pedantic)
  1541. pedwarn ("extra semicolon in struct or union specified"); }
  1542. ;
  1543. component_decl:
  1544. declspecs_nosc_ts setspecs components
  1545. { $$ = $3;
  1546. POP_DECLSPEC_STACK; }
  1547. | declspecs_nosc_ts setspecs save_filename save_lineno
  1548. {
  1549. /* Support for unnamed structs or unions as members of
  1550. structs or unions (which is [a] useful and [b] supports
  1551. MS P-SDK). */
  1552. if (pedantic)
  1553. pedwarn ("ISO C doesn't support unnamed structs/unions");
  1554. $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
  1555. POP_DECLSPEC_STACK; }
  1556. | declspecs_nosc_nots setspecs components_notype
  1557. { $$ = $3;
  1558. POP_DECLSPEC_STACK; }
  1559. | declspecs_nosc_nots
  1560. { if (pedantic)
  1561. pedwarn ("ISO C forbids member declarations with no members");
  1562. shadow_tag($1);
  1563. $$ = NULL_TREE; }
  1564. | error
  1565. { $$ = NULL_TREE; }
  1566. | extension component_decl
  1567. { $$ = $2;
  1568. RESTORE_EXT_FLAGS ($1); }
  1569. ;
  1570. components:
  1571. component_declarator
  1572. | components ',' maybe_resetattrs component_declarator
  1573. { $$ = chainon ($1, $4); }
  1574. ;
  1575. components_notype:
  1576. component_notype_declarator
  1577. | components_notype ',' maybe_resetattrs component_notype_declarator
  1578. { $$ = chainon ($1, $4); }
  1579. ;
  1580. component_declarator:
  1581. save_filename save_lineno declarator maybe_attribute
  1582. { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
  1583. decl_attributes (&$$, chainon ($4, all_prefix_attributes), 0); }
  1584. | save_filename save_lineno
  1585. declarator ':' expr_no_commas maybe_attribute
  1586. { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
  1587. decl_attributes (&$$, chainon ($6, all_prefix_attributes), 0); }
  1588. | save_filename save_lineno ':' expr_no_commas maybe_attribute
  1589. { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
  1590. decl_attributes (&$$, chainon ($5, all_prefix_attributes), 0); }
  1591. ;
  1592. component_notype_declarator:
  1593. save_filename save_lineno notype_declarator maybe_attribute
  1594. { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
  1595. decl_attributes (&$$, chainon ($4, all_prefix_attributes), 0); }
  1596. | save_filename save_lineno
  1597. notype_declarator ':' expr_no_commas maybe_attribute
  1598. { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
  1599. decl_attributes (&$$, chainon ($6, all_prefix_attributes), 0); }
  1600. | save_filename save_lineno ':' expr_no_commas maybe_attribute
  1601. { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
  1602. decl_attributes (&$$, chainon ($5, all_prefix_attributes), 0); }
  1603. ;
  1604. /* We chain the enumerators in reverse order.
  1605. They are put in forward order where enumlist is used.
  1606. (The order used to be significant, but no longer is so.
  1607. However, we still maintain the order, just to be clean.) */
  1608. enumlist:
  1609. enumerator
  1610. | enumlist ',' enumerator
  1611. { if ($1 == error_mark_node)
  1612. $$ = $1;
  1613. else
  1614. $$ = chainon ($3, $1); }
  1615. | error
  1616. { $$ = error_mark_node; }
  1617. ;
  1618. enumerator:
  1619. identifier
  1620. { $$ = build_enumerator ($1, NULL_TREE); }
  1621. | identifier '=' expr_no_commas
  1622. { $$ = build_enumerator ($1, $3); }
  1623. ;
  1624. typename:
  1625. declspecs_nosc
  1626. { pending_xref_error ();
  1627. $<ttype>$ = $1; }
  1628. absdcl
  1629. { $$ = build_tree_list ($<ttype>2, $3); }
  1630. ;
  1631. absdcl: /* an absolute declarator */
  1632. /* empty */
  1633. { $$ = NULL_TREE; }
  1634. | absdcl1
  1635. ;
  1636. absdcl_maybe_attribute: /* absdcl maybe_attribute, but not just attributes */
  1637. /* empty */
  1638. { $$ = build_tree_list (build_tree_list (current_declspecs,
  1639. NULL_TREE),
  1640. all_prefix_attributes); }
  1641. | absdcl1
  1642. { $$ = build_tree_list (build_tree_list (current_declspecs,
  1643. $1),
  1644. all_prefix_attributes); }
  1645. | absdcl1_noea attributes
  1646. { $$ = build_tree_list (build_tree_list (current_declspecs,
  1647. $1),
  1648. chainon ($2, all_prefix_attributes)); }
  1649. ;
  1650. absdcl1: /* a nonempty absolute declarator */
  1651. absdcl1_ea
  1652. | absdcl1_noea
  1653. ;
  1654. absdcl1_noea:
  1655. direct_absdcl1
  1656. | '*' maybe_type_quals_attrs absdcl1_noea
  1657. { $$ = make_pointer_declarator ($2, $3); }
  1658. ;
  1659. absdcl1_ea:
  1660. '*' maybe_type_quals_attrs
  1661. { $$ = make_pointer_declarator ($2, NULL_TREE); }
  1662. | '*' maybe_type_quals_attrs absdcl1_ea
  1663. { $$ = make_pointer_declarator ($2, $3); }
  1664. ;
  1665. direct_absdcl1:
  1666. '(' maybe_attribute absdcl1 ')'
  1667. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1668. | direct_absdcl1 '(' parmlist
  1669. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1670. | direct_absdcl1 array_declarator
  1671. { $$ = set_array_declarator_type ($2, $1, 1); }
  1672. | '(' parmlist
  1673. { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
  1674. | array_declarator
  1675. { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
  1676. ;
  1677. /* The [...] part of a declarator for an array type. */
  1678. array_declarator:
  1679. '[' maybe_type_quals_attrs expr ']'
  1680. { $$ = build_array_declarator ($3, $2, 0, 0); }
  1681. | '[' maybe_type_quals_attrs ']'
  1682. { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
  1683. | '[' maybe_type_quals_attrs '*' ']'
  1684. { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
  1685. | '[' STATIC maybe_type_quals_attrs expr ']'
  1686. { $$ = build_array_declarator ($4, $3, 1, 0); }
  1687. /* declspecs_nosc_nots is a synonym for type_quals_attrs. */
  1688. | '[' declspecs_nosc_nots STATIC expr ']'
  1689. { $$ = build_array_declarator ($4, $2, 1, 0); }
  1690. ;
  1691. /* A nonempty series of declarations and statements (possibly followed by
  1692. some labels) that can form the body of a compound statement.
  1693. NOTE: we don't allow labels on declarations; this might seem like a
  1694. natural extension, but there would be a conflict between attributes
  1695. on the label and prefix attributes on the declaration. */
  1696. stmts_and_decls:
  1697. lineno_stmt_decl_or_labels_ending_stmt
  1698. | lineno_stmt_decl_or_labels_ending_decl
  1699. | lineno_stmt_decl_or_labels_ending_label
  1700. {
  1701. pedwarn ("deprecated use of label at end of compound statement");
  1702. }
  1703. | lineno_stmt_decl_or_labels_ending_error
  1704. ;
  1705. lineno_stmt_decl_or_labels_ending_stmt:
  1706. lineno_stmt
  1707. | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
  1708. | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
  1709. | lineno_stmt_decl_or_labels_ending_label lineno_stmt
  1710. | lineno_stmt_decl_or_labels_ending_error lineno_stmt
  1711. ;
  1712. lineno_stmt_decl_or_labels_ending_decl:
  1713. lineno_decl
  1714. | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
  1715. { if (pedantic && !flag_isoc99)
  1716. pedwarn ("ISO C89 forbids mixed declarations and code"); }
  1717. | lineno_stmt_decl_or_labels_ending_decl lineno_decl
  1718. | lineno_stmt_decl_or_labels_ending_error lineno_decl
  1719. ;
  1720. lineno_stmt_decl_or_labels_ending_label:
  1721. lineno_label
  1722. | lineno_stmt_decl_or_labels_ending_stmt lineno_label
  1723. | lineno_stmt_decl_or_labels_ending_decl lineno_label
  1724. | lineno_stmt_decl_or_labels_ending_label lineno_label
  1725. | lineno_stmt_decl_or_labels_ending_error lineno_label
  1726. ;
  1727. lineno_stmt_decl_or_labels_ending_error:
  1728. errstmt
  1729. | lineno_stmt_decl_or_labels errstmt
  1730. ;
  1731. lineno_stmt_decl_or_labels:
  1732. lineno_stmt_decl_or_labels_ending_stmt
  1733. | lineno_stmt_decl_or_labels_ending_decl
  1734. | lineno_stmt_decl_or_labels_ending_label
  1735. | lineno_stmt_decl_or_labels_ending_error
  1736. ;
  1737. errstmt: error ';'
  1738. ;
  1739. pushlevel: /* empty */
  1740. { pushlevel (0);
  1741. clear_last_expr ();
  1742. add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
  1743. }
  1744. ;
  1745. poplevel: /* empty */
  1746. { $$ = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); }
  1747. ;
  1748. /* Start and end blocks created for the new scopes of C99. */
  1749. c99_block_start: /* empty */
  1750. { if (flag_isoc99)
  1751. {
  1752. $$ = c_begin_compound_stmt ();
  1753. pushlevel (0);
  1754. clear_last_expr ();
  1755. add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
  1756. }
  1757. else
  1758. $$ = NULL_TREE;
  1759. }
  1760. ;
  1761. /* Productions using c99_block_start and c99_block_end will need to do what's
  1762. in compstmt: RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); $$ = $2; where
  1763. $1 is the value of c99_block_start and $2 of c99_block_end. */
  1764. c99_block_end: /* empty */
  1765. { if (flag_isoc99)
  1766. {
  1767. tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
  1768. $$ = poplevel (kept_level_p (), 0, 0);
  1769. SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt))
  1770. = SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt))
  1771. = $$;
  1772. }
  1773. else
  1774. $$ = NULL_TREE; }
  1775. ;
  1776. /* Read zero or more forward-declarations for labels
  1777. that nested functions can jump to. */
  1778. maybe_label_decls:
  1779. /* empty */
  1780. | label_decls
  1781. { if (pedantic)
  1782. pedwarn ("ISO C forbids label declarations"); }
  1783. ;
  1784. label_decls:
  1785. label_decl
  1786. | label_decls label_decl
  1787. ;
  1788. label_decl:
  1789. LABEL identifiers_or_typenames ';'
  1790. { tree link;
  1791. for (link = $2; link; link = TREE_CHAIN (link))
  1792. {
  1793. tree label = shadow_label (TREE_VALUE (link));
  1794. C_DECLARED_LABEL_FLAG (label) = 1;
  1795. add_decl_stmt (label);
  1796. }
  1797. }
  1798. ;
  1799. /* This is the body of a function definition.
  1800. It causes syntax errors to ignore to the next openbrace. */
  1801. compstmt_or_error:
  1802. compstmt
  1803. {}
  1804. | error compstmt
  1805. ;
  1806. compstmt_start: '{' { compstmt_count++;
  1807. $$ = c_begin_compound_stmt (); }
  1808. ;
  1809. compstmt_nostart: '}'
  1810. { $$ = convert (void_type_node, integer_zero_node); }
  1811. | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
  1812. { $$ = poplevel (kept_level_p (), 1, 0);
  1813. SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
  1814. = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
  1815. = $$; }
  1816. ;
  1817. compstmt_contents_nonempty:
  1818. stmts_and_decls
  1819. | error
  1820. ;
  1821. compstmt_primary_start:
  1822. '(' '{'
  1823. { if (current_function_decl == 0)
  1824. {
  1825. error ("braced-group within expression allowed only inside a function");
  1826. YYERROR;
  1827. }
  1828. /* We must force a BLOCK for this level
  1829. so that, if it is not expanded later,
  1830. there is a way to turn off the entire subtree of blocks
  1831. that are contained in it. */
  1832. keep_next_level ();
  1833. push_label_level ();
  1834. compstmt_count++;
  1835. $$ = add_stmt (build_stmt (COMPOUND_STMT, last_tree));
  1836. }
  1837. ;
  1838. compstmt: compstmt_start compstmt_nostart
  1839. { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
  1840. last_expr_type = NULL_TREE;
  1841. $$ = $1; }
  1842. ;
  1843. /* Value is number of statements counted as of the closeparen. */
  1844. simple_if:
  1845. if_prefix c99_block_lineno_labeled_stmt
  1846. { c_finish_then (); }
  1847. /* Make sure c_expand_end_cond is run once
  1848. for each call to c_expand_start_cond.
  1849. Otherwise a crash is likely. */
  1850. | if_prefix error
  1851. ;
  1852. if_prefix:
  1853. /* We must build the IF_STMT node before parsing its
  1854. condition so that STMT_LINENO refers to the line
  1855. containing the "if", and not the line containing
  1856. the close-parenthesis.
  1857. c_begin_if_stmt returns the IF_STMT node, which
  1858. we later pass to c_expand_start_cond to fill
  1859. in the condition and other tidbits. */
  1860. IF
  1861. { $<ttype>$ = c_begin_if_stmt (); }
  1862. '(' expr ')'
  1863. { c_expand_start_cond (c_common_truthvalue_conversion ($4),
  1864. compstmt_count,$<ttype>2);
  1865. $<itype>$ = stmt_count;
  1866. if_stmt_file = $<filename>-2;
  1867. if_stmt_line = $<lineno>-1; }
  1868. ;
  1869. /* This is a subroutine of stmt.
  1870. It is used twice, once for valid DO statements
  1871. and once for catching errors in parsing the end test. */
  1872. do_stmt_start:
  1873. DO
  1874. { stmt_count++;
  1875. compstmt_count++;
  1876. $<ttype>$
  1877. = add_stmt (build_stmt (DO_STMT, NULL_TREE,
  1878. NULL_TREE));
  1879. /* In the event that a parse error prevents
  1880. parsing the complete do-statement, set the
  1881. condition now. Otherwise, we can get crashes at
  1882. RTL-generation time. */
  1883. DO_COND ($<ttype>$) = error_mark_node; }
  1884. c99_block_lineno_labeled_stmt WHILE
  1885. { $$ = $<ttype>2;
  1886. RECHAIN_STMTS ($$, DO_BODY ($$)); }
  1887. ;
  1888. /* The forced readahead in here is because we might be at the end of a
  1889. line, and the line and file won't be bumped until yylex absorbs the
  1890. first token on the next line. */
  1891. save_filename:
  1892. { if (yychar == YYEMPTY)
  1893. yychar = YYLEX;
  1894. $$ = input_filename; }
  1895. ;
  1896. save_lineno:
  1897. { if (yychar == YYEMPTY)
  1898. yychar = YYLEX;
  1899. $$ = lineno; }
  1900. ;
  1901. lineno_labeled_stmt:
  1902. lineno_stmt
  1903. | lineno_label lineno_labeled_stmt
  1904. ;
  1905. /* Like lineno_labeled_stmt, but a block in C99. */
  1906. c99_block_lineno_labeled_stmt:
  1907. c99_block_start lineno_labeled_stmt c99_block_end
  1908. { if (flag_isoc99)
  1909. RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); }
  1910. ;
  1911. lineno_stmt:
  1912. save_filename save_lineno stmt
  1913. { if ($3)
  1914. {
  1915. STMT_LINENO ($3) = $2;
  1916. /* ??? We currently have no way of recording
  1917. the filename for a statement. This probably
  1918. matters little in practice at the moment,
  1919. but I suspect that problems will occur when
  1920. doing inlining at the tree level. */
  1921. }
  1922. }
  1923. ;
  1924. lineno_label:
  1925. save_filename save_lineno label
  1926. { if ($3)
  1927. {
  1928. STMT_LINENO ($3) = $2;
  1929. }
  1930. }
  1931. ;
  1932. select_or_iter_stmt:
  1933. simple_if ELSE
  1934. { c_expand_start_else ();
  1935. $<itype>1 = stmt_count; }
  1936. c99_block_lineno_labeled_stmt
  1937. { c_finish_else ();
  1938. c_expand_end_cond ();
  1939. if (extra_warnings && stmt_count == $<itype>1)
  1940. warning ("empty body in an else-statement"); }
  1941. | simple_if %prec IF
  1942. { c_expand_end_cond ();
  1943. /* This warning is here instead of in simple_if, because we
  1944. do not want a warning if an empty if is followed by an
  1945. else statement. Increment stmt_count so we don't
  1946. give a second error if this is a nested `if'. */
  1947. if (extra_warnings && stmt_count++ == $<itype>1)
  1948. warning_with_file_and_line (if_stmt_file, if_stmt_line,
  1949. "empty body in an if-statement"); }
  1950. /* Make sure c_expand_end_cond is run once
  1951. for each call to c_expand_start_cond.
  1952. Otherwise a crash is likely. */
  1953. | simple_if ELSE error
  1954. { c_expand_end_cond (); }
  1955. /* We must build the WHILE_STMT node before parsing its
  1956. condition so that STMT_LINENO refers to the line
  1957. containing the "while", and not the line containing
  1958. the close-parenthesis.
  1959. c_begin_while_stmt returns the WHILE_STMT node, which
  1960. we later pass to c_finish_while_stmt_cond to fill
  1961. in the condition and other tidbits. */
  1962. | WHILE
  1963. { stmt_count++;
  1964. $<ttype>$ = c_begin_while_stmt (); }
  1965. '(' expr ')'
  1966. { $4 = c_common_truthvalue_conversion ($4);
  1967. c_finish_while_stmt_cond
  1968. (c_common_truthvalue_conversion ($4), $<ttype>2);
  1969. $<ttype>$ = add_stmt ($<ttype>2); }
  1970. c99_block_lineno_labeled_stmt
  1971. { RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
  1972. | do_stmt_start
  1973. '(' expr ')' ';'
  1974. { DO_COND ($1) = c_common_truthvalue_conversion ($3); }
  1975. | do_stmt_start error
  1976. { }
  1977. | FOR
  1978. { $<ttype>$ = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
  1979. NULL_TREE, NULL_TREE);
  1980. add_stmt ($<ttype>$); }
  1981. '(' for_init_stmt
  1982. { stmt_count++;
  1983. RECHAIN_STMTS ($<ttype>2, FOR_INIT_STMT ($<ttype>2)); }
  1984. xexpr ';'
  1985. { if ($6)
  1986. FOR_COND ($<ttype>2)
  1987. = c_common_truthvalue_conversion ($6); }
  1988. xexpr ')'
  1989. { FOR_EXPR ($<ttype>2) = $9; }
  1990. c99_block_lineno_labeled_stmt
  1991. { RECHAIN_STMTS ($<ttype>2, FOR_BODY ($<ttype>2)); }
  1992. | SWITCH '(' expr ')'
  1993. { stmt_count++;
  1994. $<ttype>$ = c_start_case ($3); }
  1995. c99_block_lineno_labeled_stmt
  1996. { c_finish_case (); }
  1997. ;
  1998. for_init_stmt:
  1999. xexpr ';'
  2000. { add_stmt (build_stmt (EXPR_STMT, $1)); }
  2001. | decl
  2002. { check_for_loop_decls (); }
  2003. ;
  2004. /* Parse a single real statement, not including any labels. */
  2005. stmt:
  2006. compstmt
  2007. { stmt_count++; $$ = $1; }
  2008. | expr ';'
  2009. { stmt_count++;
  2010. $$ = c_expand_expr_stmt ($1); }
  2011. | c99_block_start select_or_iter_stmt c99_block_end
  2012. { if (flag_isoc99)
  2013. RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
  2014. $$ = NULL_TREE; }
  2015. | BREAK ';'
  2016. { stmt_count++;
  2017. $$ = add_stmt (build_break_stmt ()); }
  2018. | CONTINUE ';'
  2019. { stmt_count++;
  2020. $$ = add_stmt (build_continue_stmt ()); }
  2021. | RETURN ';'
  2022. { stmt_count++;
  2023. $$ = c_expand_return (NULL_TREE); }
  2024. | RETURN expr ';'
  2025. { stmt_count++;
  2026. $$ = c_expand_return ($2); }
  2027. | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
  2028. { stmt_count++;
  2029. $$ = simple_asm_stmt ($4); }
  2030. /* This is the case with just output operands. */
  2031. | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
  2032. { stmt_count++;
  2033. $$ = build_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
  2034. /* This is the case with input operands as well. */
  2035. | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
  2036. asm_operands ')' ';'
  2037. { stmt_count++;
  2038. $$ = build_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
  2039. /* This is the case with clobbered registers as well. */
  2040. | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
  2041. asm_operands ':' asm_clobbers ')' ';'
  2042. { stmt_count++;
  2043. $$ = build_asm_stmt ($2, $4, $6, $8, $10); }
  2044. | GOTO identifier ';'
  2045. { tree decl;
  2046. stmt_count++;
  2047. decl = lookup_label ($2);
  2048. if (decl != 0)
  2049. {
  2050. TREE_USED (decl) = 1;
  2051. $$ = add_stmt (build_stmt (GOTO_STMT, decl));
  2052. }
  2053. else
  2054. $$ = NULL_TREE;
  2055. }
  2056. | GOTO '*' expr ';'
  2057. { if (pedantic)
  2058. pedwarn ("ISO C forbids `goto *expr;'");
  2059. stmt_count++;
  2060. $3 = convert (ptr_type_node, $3);
  2061. $$ = add_stmt (build_stmt (GOTO_STMT, $3)); }
  2062. | ';'
  2063. { $$ = NULL_TREE; }
  2064. ;
  2065. /* Any kind of label, including jump labels and case labels.
  2066. ANSI C accepts labels only before statements, but we allow them
  2067. also at the end of a compound statement. */
  2068. label: CASE expr_no_commas ':'
  2069. { stmt_count++;
  2070. $$ = do_case ($2, NULL_TREE); }
  2071. | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
  2072. { stmt_count++;
  2073. $$ = do_case ($2, $4); }
  2074. | DEFAULT ':'
  2075. { stmt_count++;
  2076. $$ = do_case (NULL_TREE, NULL_TREE); }
  2077. | identifier save_filename save_lineno ':' maybe_attribute
  2078. { tree label = define_label ($2, $3, $1);
  2079. stmt_count++;
  2080. if (label)
  2081. {
  2082. decl_attributes (&label, $5, 0);
  2083. $$ = add_stmt (build_stmt (LABEL_STMT, label));
  2084. }
  2085. else
  2086. $$ = NULL_TREE;
  2087. }
  2088. ;
  2089. /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
  2090. maybe_type_qual:
  2091. /* empty */
  2092. { emit_line_note (input_filename, lineno);
  2093. $$ = NULL_TREE; }
  2094. | TYPE_QUAL
  2095. { emit_line_note (input_filename, lineno); }
  2096. ;
  2097. xexpr:
  2098. /* empty */
  2099. { $$ = NULL_TREE; }
  2100. | expr
  2101. ;
  2102. /* These are the operands other than the first string and colon
  2103. in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
  2104. asm_operands: /* empty */
  2105. { $$ = NULL_TREE; }
  2106. | nonnull_asm_operands
  2107. ;
  2108. nonnull_asm_operands:
  2109. asm_operand
  2110. | nonnull_asm_operands ',' asm_operand
  2111. { $$ = chainon ($1, $3); }
  2112. ;
  2113. asm_operand:
  2114. STRING '(' expr ')'
  2115. { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
  2116. | '[' identifier ']' STRING '(' expr ')'
  2117. { $2 = build_string (IDENTIFIER_LENGTH ($2),
  2118. IDENTIFIER_POINTER ($2));
  2119. $$ = build_tree_list (build_tree_list ($2, $4), $6); }
  2120. ;
  2121. asm_clobbers:
  2122. STRING
  2123. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  2124. | asm_clobbers ',' STRING
  2125. { $$ = tree_cons (NULL_TREE, $3, $1); }
  2126. ;
  2127. /* This is what appears inside the parens in a function declarator.
  2128. Its value is a list of ..._TYPE nodes. Attributes must appear here
  2129. to avoid a conflict with their appearance after an open parenthesis
  2130. in an abstract declarator, as in
  2131. "void bar (int (__attribute__((__mode__(SI))) int foo));". */
  2132. parmlist:
  2133. maybe_attribute
  2134. { pushlevel (0);
  2135. clear_parm_order ();
  2136. declare_parm_level (0); }
  2137. parmlist_1
  2138. { $$ = $3;
  2139. parmlist_tags_warning ();
  2140. poplevel (0, 0, 0); }
  2141. ;
  2142. parmlist_1:
  2143. parmlist_2 ')'
  2144. | parms ';'
  2145. { tree parm;
  2146. if (pedantic)
  2147. pedwarn ("ISO C forbids forward parameter declarations");
  2148. /* Mark the forward decls as such. */
  2149. for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
  2150. TREE_ASM_WRITTEN (parm) = 1;
  2151. clear_parm_order (); }
  2152. maybe_attribute
  2153. { /* Dummy action so attributes are in known place
  2154. on parser stack. */ }
  2155. parmlist_1
  2156. { $$ = $6; }
  2157. | error ')'
  2158. { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
  2159. ;
  2160. /* This is what appears inside the parens in a function declarator.
  2161. Is value is represented in the format that grokdeclarator expects. */
  2162. parmlist_2: /* empty */
  2163. { $$ = get_parm_info (0); }
  2164. | ELLIPSIS
  2165. { $$ = get_parm_info (0);
  2166. /* Gcc used to allow this as an extension. However, it does
  2167. not work for all targets, and thus has been disabled.
  2168. Also, since func (...) and func () are indistinguishable,
  2169. it caused problems with the code in expand_builtin which
  2170. tries to verify that BUILT_IN_NEXT_ARG is being used
  2171. correctly. */
  2172. error ("ISO C requires a named argument before `...'");
  2173. }
  2174. | parms
  2175. { $$ = get_parm_info (1);
  2176. parsing_iso_function_signature = true;
  2177. }
  2178. | parms ',' ELLIPSIS
  2179. { $$ = get_parm_info (0); }
  2180. ;
  2181. parms:
  2182. firstparm
  2183. { push_parm_decl ($1); }
  2184. | parms ',' parm
  2185. { push_parm_decl ($3); }
  2186. ;
  2187. /* A single parameter declaration or parameter type name,
  2188. as found in a parmlist. */
  2189. parm:
  2190. declspecs_ts setspecs parm_declarator maybe_attribute
  2191. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2192. $3),
  2193. chainon ($4, all_prefix_attributes));
  2194. POP_DECLSPEC_STACK; }
  2195. | declspecs_ts setspecs notype_declarator maybe_attribute
  2196. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2197. $3),
  2198. chainon ($4, all_prefix_attributes));
  2199. POP_DECLSPEC_STACK; }
  2200. | declspecs_ts setspecs absdcl_maybe_attribute
  2201. { $$ = $3;
  2202. POP_DECLSPEC_STACK; }
  2203. | declspecs_nots setspecs notype_declarator maybe_attribute
  2204. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2205. $3),
  2206. chainon ($4, all_prefix_attributes));
  2207. POP_DECLSPEC_STACK; }
  2208. | declspecs_nots setspecs absdcl_maybe_attribute
  2209. { $$ = $3;
  2210. POP_DECLSPEC_STACK; }
  2211. ;
  2212. /* The first parm, which must suck attributes from off the top of the parser
  2213. stack. */
  2214. firstparm:
  2215. declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
  2216. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2217. $3),
  2218. chainon ($4, all_prefix_attributes));
  2219. POP_DECLSPEC_STACK; }
  2220. | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
  2221. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2222. $3),
  2223. chainon ($4, all_prefix_attributes));
  2224. POP_DECLSPEC_STACK; }
  2225. | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
  2226. { $$ = $3;
  2227. POP_DECLSPEC_STACK; }
  2228. | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
  2229. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2230. $3),
  2231. chainon ($4, all_prefix_attributes));
  2232. POP_DECLSPEC_STACK; }
  2233. | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
  2234. { $$ = $3;
  2235. POP_DECLSPEC_STACK; }
  2236. ;
  2237. setspecs_fp:
  2238. setspecs
  2239. { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
  2240. all_prefix_attributes = prefix_attributes; }
  2241. ;
  2242. /* This is used in a function definition
  2243. where either a parmlist or an identifier list is ok.
  2244. Its value is a list of ..._TYPE nodes or a list of identifiers. */
  2245. parmlist_or_identifiers:
  2246. maybe_attribute
  2247. { pushlevel (0);
  2248. clear_parm_order ();
  2249. declare_parm_level (1); }
  2250. parmlist_or_identifiers_1
  2251. { $$ = $3;
  2252. parmlist_tags_warning ();
  2253. poplevel (0, 0, 0); }
  2254. ;
  2255. parmlist_or_identifiers_1:
  2256. parmlist_1
  2257. | identifiers ')'
  2258. { tree t;
  2259. for (t = $1; t; t = TREE_CHAIN (t))
  2260. if (TREE_VALUE (t) == NULL_TREE)
  2261. error ("`...' in old-style identifier list");
  2262. $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
  2263. /* Make sure we have a parmlist after attributes. */
  2264. if ($<ttype>-1 != 0
  2265. && (TREE_CODE ($$) != TREE_LIST
  2266. || TREE_PURPOSE ($$) == 0
  2267. || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
  2268. YYERROR1;
  2269. }
  2270. ;
  2271. /* A nonempty list of identifiers. */
  2272. identifiers:
  2273. IDENTIFIER
  2274. { $$ = build_tree_list (NULL_TREE, $1); }
  2275. | identifiers ',' IDENTIFIER
  2276. { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2277. ;
  2278. /* A nonempty list of identifiers, including typenames. */
  2279. identifiers_or_typenames:
  2280. identifier
  2281. { $$ = build_tree_list (NULL_TREE, $1); }
  2282. | identifiers_or_typenames ',' identifier
  2283. { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2284. ;
  2285. extension:
  2286. EXTENSION
  2287. { $$ = SAVE_EXT_FLAGS();
  2288. pedantic = 0;
  2289. warn_pointer_arith = 0;
  2290. warn_traditional = 0;
  2291. flag_iso = 0; }
  2292. ;
  2293. %%
  2294. /* yylex() is a thin wrapper around c_lex(), all it does is translate
  2295. cpplib.h's token codes into yacc's token codes. */
  2296. static enum cpp_ttype last_token;
  2297. /* The reserved keyword table. */
  2298. struct resword
  2299. {
  2300. const char *word;
  2301. ENUM_BITFIELD(rid) rid : 16;
  2302. unsigned int disable : 16;
  2303. };
  2304. /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
  2305. _true_. */
  2306. #define D_C89 0x01 /* not in C89 */
  2307. #define D_EXT 0x02 /* GCC extension */
  2308. #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
  2309. #define D_OBJC 0x08 /* Objective C only */
  2310. static const struct resword reswords[] =
  2311. {
  2312. { "_Bool", RID_BOOL, 0 },
  2313. { "_Complex", RID_COMPLEX, 0 },
  2314. { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
  2315. { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
  2316. { "__alignof", RID_ALIGNOF, 0 },
  2317. { "__alignof__", RID_ALIGNOF, 0 },
  2318. { "__asm", RID_ASM, 0 },
  2319. { "__asm__", RID_ASM, 0 },
  2320. { "__attribute", RID_ATTRIBUTE, 0 },
  2321. { "__attribute__", RID_ATTRIBUTE, 0 },
  2322. { "__bounded", RID_BOUNDED, 0 },
  2323. { "__bounded__", RID_BOUNDED, 0 },
  2324. { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
  2325. { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
  2326. { "__builtin_va_arg", RID_VA_ARG, 0 },
  2327. { "__complex", RID_COMPLEX, 0 },
  2328. { "__complex__", RID_COMPLEX, 0 },
  2329. { "__const", RID_CONST, 0 },
  2330. { "__const__", RID_CONST, 0 },
  2331. { "__extension__", RID_EXTENSION, 0 },
  2332. { "__func__", RID_C99_FUNCTION_NAME, 0 },
  2333. { "__imag", RID_IMAGPART, 0 },
  2334. { "__imag__", RID_IMAGPART, 0 },
  2335. { "__inline", RID_INLINE, 0 },
  2336. { "__inline__", RID_INLINE, 0 },
  2337. { "__label__", RID_LABEL, 0 },
  2338. { "__ptrbase", RID_PTRBASE, 0 },
  2339. { "__ptrbase__", RID_PTRBASE, 0 },
  2340. { "__ptrextent", RID_PTREXTENT, 0 },
  2341. { "__ptrextent__", RID_PTREXTENT, 0 },
  2342. { "__ptrvalue", RID_PTRVALUE, 0 },
  2343. { "__ptrvalue__", RID_PTRVALUE, 0 },
  2344. { "__real", RID_REALPART, 0 },
  2345. { "__real__", RID_REALPART, 0 },
  2346. { "__restrict", RID_RESTRICT, 0 },
  2347. { "__restrict__", RID_RESTRICT, 0 },
  2348. { "__signed", RID_SIGNED, 0 },
  2349. { "__signed__", RID_SIGNED, 0 },
  2350. { "__thread", RID_THREAD, 0 },
  2351. { "__typeof", RID_TYPEOF, 0 },
  2352. { "__typeof__", RID_TYPEOF, 0 },
  2353. { "__unbounded", RID_UNBOUNDED, 0 },
  2354. { "__unbounded__", RID_UNBOUNDED, 0 },
  2355. { "__volatile", RID_VOLATILE, 0 },
  2356. { "__volatile__", RID_VOLATILE, 0 },
  2357. { "asm", RID_ASM, D_EXT },
  2358. { "auto", RID_AUTO, 0 },
  2359. { "break", RID_BREAK, 0 },
  2360. { "case", RID_CASE, 0 },
  2361. { "char", RID_CHAR, 0 },
  2362. { "const", RID_CONST, 0 },
  2363. { "continue", RID_CONTINUE, 0 },
  2364. { "default", RID_DEFAULT, 0 },
  2365. { "do", RID_DO, 0 },
  2366. { "double", RID_DOUBLE, 0 },
  2367. { "else", RID_ELSE, 0 },
  2368. { "enum", RID_ENUM, 0 },
  2369. { "extern", RID_EXTERN, 0 },
  2370. { "float", RID_FLOAT, 0 },
  2371. { "for", RID_FOR, 0 },
  2372. { "goto", RID_GOTO, 0 },
  2373. { "if", RID_IF, 0 },
  2374. { "inline", RID_INLINE, D_EXT89 },
  2375. { "int", RID_INT, 0 },
  2376. { "long", RID_LONG, 0 },
  2377. { "register", RID_REGISTER, 0 },
  2378. { "restrict", RID_RESTRICT, D_C89 },
  2379. { "return", RID_RETURN, 0 },
  2380. { "short", RID_SHORT, 0 },
  2381. { "signed", RID_SIGNED, 0 },
  2382. { "sizeof", RID_SIZEOF, 0 },
  2383. { "static", RID_STATIC, 0 },
  2384. { "struct", RID_STRUCT, 0 },
  2385. { "switch", RID_SWITCH, 0 },
  2386. { "typedef", RID_TYPEDEF, 0 },
  2387. { "typeof", RID_TYPEOF, D_EXT },
  2388. { "union", RID_UNION, 0 },
  2389. { "unsigned", RID_UNSIGNED, 0 },
  2390. { "void", RID_VOID, 0 },
  2391. { "volatile", RID_VOLATILE, 0 },
  2392. { "while", RID_WHILE, 0 },
  2393. };
  2394. #define N_reswords (sizeof reswords / sizeof (struct resword))
  2395. /* Table mapping from RID_* constants to yacc token numbers.
  2396. Unfortunately we have to have entries for all the keywords in all
  2397. three languages. */
  2398. static const short rid_to_yy[RID_MAX] =
  2399. {
  2400. /* RID_STATIC */ STATIC,
  2401. /* RID_UNSIGNED */ TYPESPEC,
  2402. /* RID_LONG */ TYPESPEC,
  2403. /* RID_CONST */ TYPE_QUAL,
  2404. /* RID_EXTERN */ SCSPEC,
  2405. /* RID_REGISTER */ SCSPEC,
  2406. /* RID_TYPEDEF */ SCSPEC,
  2407. /* RID_SHORT */ TYPESPEC,
  2408. /* RID_INLINE */ SCSPEC,
  2409. /* RID_VOLATILE */ TYPE_QUAL,
  2410. /* RID_SIGNED */ TYPESPEC,
  2411. /* RID_AUTO */ SCSPEC,
  2412. /* RID_RESTRICT */ TYPE_QUAL,
  2413. /* C extensions */
  2414. /* RID_BOUNDED */ TYPE_QUAL,
  2415. /* RID_UNBOUNDED */ TYPE_QUAL,
  2416. /* RID_COMPLEX */ TYPESPEC,
  2417. /* RID_THREAD */ SCSPEC,
  2418. /* C++ */
  2419. /* RID_FRIEND */ 0,
  2420. /* RID_VIRTUAL */ 0,
  2421. /* RID_EXPLICIT */ 0,
  2422. /* RID_EXPORT */ 0,
  2423. /* RID_MUTABLE */ 0,
  2424. /* ObjC */
  2425. /* RID_IN */ TYPE_QUAL,
  2426. /* RID_OUT */ TYPE_QUAL,
  2427. /* RID_INOUT */ TYPE_QUAL,
  2428. /* RID_BYCOPY */ TYPE_QUAL,
  2429. /* RID_BYREF */ TYPE_QUAL,
  2430. /* RID_ONEWAY */ TYPE_QUAL,
  2431. /* C */
  2432. /* RID_INT */ TYPESPEC,
  2433. /* RID_CHAR */ TYPESPEC,
  2434. /* RID_FLOAT */ TYPESPEC,
  2435. /* RID_DOUBLE */ TYPESPEC,
  2436. /* RID_VOID */ TYPESPEC,
  2437. /* RID_ENUM */ ENUM,
  2438. /* RID_STRUCT */ STRUCT,
  2439. /* RID_UNION */ UNION,
  2440. /* RID_IF */ IF,
  2441. /* RID_ELSE */ ELSE,
  2442. /* RID_WHILE */ WHILE,
  2443. /* RID_DO */ DO,
  2444. /* RID_FOR */ FOR,
  2445. /* RID_SWITCH */ SWITCH,
  2446. /* RID_CASE */ CASE,
  2447. /* RID_DEFAULT */ DEFAULT,
  2448. /* RID_BREAK */ BREAK,
  2449. /* RID_CONTINUE */ CONTINUE,
  2450. /* RID_RETURN */ RETURN,
  2451. /* RID_GOTO */ GOTO,
  2452. /* RID_SIZEOF */ SIZEOF,
  2453. /* C extensions */
  2454. /* RID_ASM */ ASM_KEYWORD,
  2455. /* RID_TYPEOF */ TYPEOF,
  2456. /* RID_ALIGNOF */ ALIGNOF,
  2457. /* RID_ATTRIBUTE */ ATTRIBUTE,
  2458. /* RID_VA_ARG */ VA_ARG,
  2459. /* RID_EXTENSION */ EXTENSION,
  2460. /* RID_IMAGPART */ IMAGPART,
  2461. /* RID_REALPART */ REALPART,
  2462. /* RID_LABEL */ LABEL,
  2463. /* RID_PTRBASE */ PTR_BASE,
  2464. /* RID_PTREXTENT */ PTR_EXTENT,
  2465. /* RID_PTRVALUE */ PTR_VALUE,
  2466. /* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
  2467. /* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
  2468. /* RID_FUNCTION_NAME */ STRING_FUNC_NAME,
  2469. /* RID_PRETTY_FUNCTION_NAME */ STRING_FUNC_NAME,
  2470. /* RID_C99_FUNCTION_NAME */ VAR_FUNC_NAME,
  2471. /* C++ */
  2472. /* RID_BOOL */ TYPESPEC,
  2473. /* RID_WCHAR */ 0,
  2474. /* RID_CLASS */ 0,
  2475. /* RID_PUBLIC */ 0,
  2476. /* RID_PRIVATE */ 0,
  2477. /* RID_PROTECTED */ 0,
  2478. /* RID_TEMPLATE */ 0,
  2479. /* RID_NULL */ 0,
  2480. /* RID_CATCH */ 0,
  2481. /* RID_DELETE */ 0,
  2482. /* RID_FALSE */ 0,
  2483. /* RID_NAMESPACE */ 0,
  2484. /* RID_NEW */ 0,
  2485. /* RID_OPERATOR */ 0,
  2486. /* RID_THIS */ 0,
  2487. /* RID_THROW */ 0,
  2488. /* RID_TRUE */ 0,
  2489. /* RID_TRY */ 0,
  2490. /* RID_TYPENAME */ 0,
  2491. /* RID_TYPEID */ 0,
  2492. /* RID_USING */ 0,
  2493. /* casts */
  2494. /* RID_CONSTCAST */ 0,
  2495. /* RID_DYNCAST */ 0,
  2496. /* RID_REINTCAST */ 0,
  2497. /* RID_STATCAST */ 0,
  2498. /* Objective C */
  2499. /* RID_ID */ OBJECTNAME,
  2500. /* RID_AT_ENCODE */ ENCODE,
  2501. /* RID_AT_END */ END,
  2502. /* RID_AT_CLASS */ CLASS,
  2503. /* RID_AT_ALIAS */ ALIAS,
  2504. /* RID_AT_DEFS */ DEFS,
  2505. /* RID_AT_PRIVATE */ PRIVATE,
  2506. /* RID_AT_PROTECTED */ PROTECTED,
  2507. /* RID_AT_PUBLIC */ PUBLIC,
  2508. /* RID_AT_PROTOCOL */ PROTOCOL,
  2509. /* RID_AT_SELECTOR */ SELECTOR,
  2510. /* RID_AT_INTERFACE */ INTERFACE,
  2511. /* RID_AT_IMPLEMENTATION */ IMPLEMENTATION
  2512. };
  2513. static void
  2514. init_reswords ()
  2515. {
  2516. unsigned int i;
  2517. tree id;
  2518. int mask = (flag_isoc99 ? 0 : D_C89)
  2519. | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
  2520. if (!flag_objc)
  2521. mask |= D_OBJC;
  2522. /* It is not necessary to register ridpointers as a GC root, because
  2523. all the trees it points to are permanently interned in the
  2524. get_identifier hash anyway. */
  2525. ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
  2526. for (i = 0; i < N_reswords; i++)
  2527. {
  2528. /* If a keyword is disabled, do not enter it into the table
  2529. and so create a canonical spelling that isn't a keyword. */
  2530. if (reswords[i].disable & mask)
  2531. continue;
  2532. id = get_identifier (reswords[i].word);
  2533. C_RID_CODE (id) = reswords[i].rid;
  2534. C_IS_RESERVED_WORD (id) = 1;
  2535. ridpointers [(int) reswords[i].rid] = id;
  2536. }
  2537. }
  2538. #define NAME(type) cpp_type2name (type)
  2539. static void
  2540. yyerror (msgid)
  2541. const char *msgid;
  2542. {
  2543. const char *string = _(msgid);
  2544. if (last_token == CPP_EOF)
  2545. error ("%s at end of input", string);
  2546. else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
  2547. {
  2548. unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
  2549. const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
  2550. if (val <= UCHAR_MAX && ISGRAPH (val))
  2551. error ("%s before %s'%c'", string, ell, val);
  2552. else
  2553. error ("%s before %s'\\x%x'", string, ell, val);
  2554. }
  2555. else if (last_token == CPP_STRING
  2556. || last_token == CPP_WSTRING)
  2557. error ("%s before string constant", string);
  2558. else if (last_token == CPP_NUMBER)
  2559. error ("%s before numeric constant", string);
  2560. else if (last_token == CPP_NAME)
  2561. error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
  2562. else
  2563. error ("%s before '%s' token", string, NAME(last_token));
  2564. }
  2565. static int
  2566. yylexname ()
  2567. {
  2568. tree decl;
  2569. if (C_IS_RESERVED_WORD (yylval.ttype))
  2570. {
  2571. enum rid rid_code = C_RID_CODE (yylval.ttype);
  2572. {
  2573. int yycode = rid_to_yy[(int) rid_code];
  2574. if (yycode == STRING_FUNC_NAME)
  2575. {
  2576. /* __FUNCTION__ and __PRETTY_FUNCTION__ get converted
  2577. to string constants. */
  2578. const char *name = fname_string (rid_code);
  2579. yylval.ttype = build_string (strlen (name) + 1, name);
  2580. C_ARTIFICIAL_STRING_P (yylval.ttype) = 1;
  2581. last_token = CPP_STRING; /* so yyerror won't choke */
  2582. return STRING;
  2583. }
  2584. /* Return the canonical spelling for this keyword. */
  2585. yylval.ttype = ridpointers[(int) rid_code];
  2586. return yycode;
  2587. }
  2588. }
  2589. decl = lookup_name (yylval.ttype);
  2590. if (decl)
  2591. {
  2592. if (TREE_CODE (decl) == TYPE_DECL)
  2593. return TYPENAME;
  2594. }
  2595. return IDENTIFIER;
  2596. }
  2597. /* Concatenate strings before returning them to the parser. This isn't quite
  2598. as good as having it done in the lexer, but it's better than nothing. */
  2599. static int
  2600. yylexstring ()
  2601. {
  2602. enum cpp_ttype next_type;
  2603. tree orig = yylval.ttype;
  2604. next_type = c_lex (&yylval.ttype);
  2605. if (next_type == CPP_STRING
  2606. || next_type == CPP_WSTRING
  2607. || (next_type == CPP_NAME && yylexname () == STRING))
  2608. {
  2609. varray_type strings;
  2610. static int last_lineno = 0;
  2611. static const char *last_input_filename = 0;
  2612. if (warn_traditional && !in_system_header
  2613. && (lineno != last_lineno || !last_input_filename ||
  2614. strcmp (last_input_filename, input_filename)))
  2615. {
  2616. warning ("traditional C rejects string concatenation");
  2617. last_lineno = lineno;
  2618. last_input_filename = input_filename;
  2619. }
  2620. VARRAY_TREE_INIT (strings, 32, "strings");
  2621. VARRAY_PUSH_TREE (strings, orig);
  2622. do
  2623. {
  2624. VARRAY_PUSH_TREE (strings, yylval.ttype);
  2625. next_type = c_lex (&yylval.ttype);
  2626. }
  2627. while (next_type == CPP_STRING
  2628. || next_type == CPP_WSTRING
  2629. || (next_type == CPP_NAME && yylexname () == STRING));
  2630. yylval.ttype = combine_strings (strings);
  2631. }
  2632. else
  2633. yylval.ttype = orig;
  2634. /* We will have always read one token too many. */
  2635. _cpp_backup_tokens (parse_in, 1);
  2636. return STRING;
  2637. }
  2638. static inline int
  2639. _yylex ()
  2640. {
  2641. get_next:
  2642. last_token = c_lex (&yylval.ttype);
  2643. switch (last_token)
  2644. {
  2645. case CPP_EQ: return '=';
  2646. case CPP_NOT: return '!';
  2647. case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
  2648. case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
  2649. case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
  2650. case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
  2651. case CPP_MULT: yylval.code = MULT_EXPR; return '*';
  2652. case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
  2653. case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
  2654. case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
  2655. case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
  2656. case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
  2657. case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
  2658. case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
  2659. case CPP_COMPL: return '~';
  2660. case CPP_AND_AND: return ANDAND;
  2661. case CPP_OR_OR: return OROR;
  2662. case CPP_QUERY: return '?';
  2663. case CPP_OPEN_PAREN: return '(';
  2664. case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
  2665. case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
  2666. case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
  2667. case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
  2668. case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
  2669. case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
  2670. case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
  2671. case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
  2672. case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
  2673. case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
  2674. case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
  2675. case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
  2676. case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
  2677. case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
  2678. case CPP_OPEN_SQUARE: return '[';
  2679. case CPP_CLOSE_SQUARE: return ']';
  2680. case CPP_OPEN_BRACE: return '{';
  2681. case CPP_CLOSE_BRACE: return '}';
  2682. case CPP_ELLIPSIS: return ELLIPSIS;
  2683. case CPP_PLUS_PLUS: return PLUSPLUS;
  2684. case CPP_MINUS_MINUS: return MINUSMINUS;
  2685. case CPP_DEREF: return POINTSAT;
  2686. case CPP_DOT: return '.';
  2687. /* The following tokens may affect the interpretation of any
  2688. identifiers following, if doing Objective-C. */
  2689. case CPP_COLON: OBJC_NEED_RAW_IDENTIFIER (0); return ':';
  2690. case CPP_COMMA: OBJC_NEED_RAW_IDENTIFIER (0); return ',';
  2691. case CPP_CLOSE_PAREN: OBJC_NEED_RAW_IDENTIFIER (0); return ')';
  2692. case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
  2693. case CPP_EOF:
  2694. return 0;
  2695. case CPP_NAME:
  2696. {
  2697. int ret = yylexname ();
  2698. if (ret == STRING)
  2699. return yylexstring ();
  2700. else
  2701. return ret;
  2702. }
  2703. case CPP_NUMBER:
  2704. case CPP_CHAR:
  2705. case CPP_WCHAR:
  2706. return CONSTANT;
  2707. case CPP_STRING:
  2708. case CPP_WSTRING:
  2709. return yylexstring ();
  2710. /* This token is Objective-C specific. It gives the next token
  2711. special significance. */
  2712. case CPP_ATSIGN:
  2713. /* These tokens are C++ specific (and will not be generated
  2714. in C mode, but let's be cautious). */
  2715. case CPP_SCOPE:
  2716. case CPP_DEREF_STAR:
  2717. case CPP_DOT_STAR:
  2718. case CPP_MIN_EQ:
  2719. case CPP_MAX_EQ:
  2720. case CPP_MIN:
  2721. case CPP_MAX:
  2722. /* These tokens should not survive translation phase 4. */
  2723. case CPP_HASH:
  2724. case CPP_PASTE:
  2725. error ("syntax error at '%s' token", NAME(last_token));
  2726. goto get_next;
  2727. default:
  2728. abort ();
  2729. }
  2730. /* NOTREACHED */
  2731. }
  2732. static int
  2733. yylex()
  2734. {
  2735. int r;
  2736. timevar_push (TV_LEX);
  2737. r = _yylex();
  2738. timevar_pop (TV_LEX);
  2739. return r;
  2740. }
  2741. /* Function used when yydebug is set, to print a token in more detail. */
  2742. static void
  2743. yyprint (file, yychar, yyl)
  2744. FILE *file;
  2745. int yychar;
  2746. YYSTYPE yyl;
  2747. {
  2748. tree t = yyl.ttype;
  2749. fprintf (file, " [%s]", NAME(last_token));
  2750. switch (yychar)
  2751. {
  2752. case IDENTIFIER:
  2753. case TYPENAME:
  2754. case OBJECTNAME:
  2755. case TYPESPEC:
  2756. case TYPE_QUAL:
  2757. case SCSPEC:
  2758. case STATIC:
  2759. if (IDENTIFIER_POINTER (t))
  2760. fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
  2761. break;
  2762. case CONSTANT:
  2763. fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
  2764. if (TREE_CODE (t) == INTEGER_CST)
  2765. fprintf (file,
  2766. #if HOST_BITS_PER_WIDE_INT == 64
  2767. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
  2768. " 0x%x%016x",
  2769. #else
  2770. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
  2771. " 0x%lx%016lx",
  2772. #else
  2773. " 0x%llx%016llx",
  2774. #endif
  2775. #endif
  2776. #else
  2777. #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
  2778. " 0x%lx%08lx",
  2779. #else
  2780. " 0x%x%08x",
  2781. #endif
  2782. #endif
  2783. TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
  2784. break;
  2785. }
  2786. }
  2787. /* This is not the ideal place to put these, but we have to get them out
  2788. of c-lex.c because cp/lex.c has its own versions. */
  2789. /* Free malloced parser stacks if necessary. */
  2790. void
  2791. free_parser_stacks ()
  2792. {
  2793. if (malloced_yyss)
  2794. {
  2795. free (malloced_yyss);
  2796. free (malloced_yyvs);
  2797. }
  2798. }
  2799. #include "gt-c-parse.h"