PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/msp430-gcc-3.2.3/gcc-3.2.3/gcc/c-parse.y

#
Happy | 3092 lines | 2777 code | 315 blank | 0 comment | 0 complexity | d1359845a6ada5af4030a0b23dc4a078 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, GPL-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 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-lex.h"
  35. #include "c-tree.h"
  36. #include "c-pragma.h"
  37. #include "flags.h"
  38. #include "output.h"
  39. #include "toplev.h"
  40. #include "ggc.h"
  41. #ifdef MULTIBYTE_CHARS
  42. #include <locale.h>
  43. #endif
  44. /* Like YYERROR but do call yyerror. */
  45. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  46. /* Cause the "yydebug" variable to be defined. */
  47. #define YYDEBUG 1
  48. /* Rename the "yyparse" function so that we can override it elsewhere. */
  49. #define yyparse yyparse_1
  50. %}
  51. %start program
  52. %union {long itype; tree ttype; enum tree_code code;
  53. const char *filename; int lineno; }
  54. /* All identifiers that are not reserved words
  55. and are not declared typedefs in the current block */
  56. %token IDENTIFIER
  57. /* All identifiers that are declared typedefs in the current block.
  58. In some contexts, they are treated just like IDENTIFIER,
  59. but they can also serve as typespecs in declarations. */
  60. %token TYPENAME
  61. /* Reserved words that specify storage class.
  62. yylval contains an IDENTIFIER_NODE which indicates which one. */
  63. %token SCSPEC
  64. /* Reserved words that specify type.
  65. yylval contains an IDENTIFIER_NODE which indicates which one. */
  66. %token TYPESPEC
  67. /* Reserved words that qualify type: "const", "volatile", or "restrict".
  68. yylval contains an IDENTIFIER_NODE which indicates which one. */
  69. %token TYPE_QUAL
  70. /* Character or numeric constants.
  71. yylval is the node for the constant. */
  72. %token CONSTANT
  73. /* String constants in raw form.
  74. yylval is a STRING_CST node. */
  75. %token STRING
  76. /* "...", used for functions with variable arglists. */
  77. %token ELLIPSIS
  78. /* the reserved words */
  79. /* SCO include files test "ASM", so use something else. */
  80. %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  81. %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
  82. %token ATTRIBUTE EXTENSION LABEL
  83. %token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
  84. %token PTR_VALUE PTR_BASE PTR_EXTENT
  85. /* function name can be a string const or a var decl. */
  86. %token STRING_FUNC_NAME VAR_FUNC_NAME
  87. /* Add precedence rules to solve dangling else s/r conflict */
  88. %nonassoc IF
  89. %nonassoc ELSE
  90. /* Define the operator tokens and their precedences.
  91. The value is an integer because, if used, it is the tree code
  92. to use in the expression made from the operator. */
  93. %right <code> ASSIGN '='
  94. %right <code> '?' ':'
  95. %left <code> OROR
  96. %left <code> ANDAND
  97. %left <code> '|'
  98. %left <code> '^'
  99. %left <code> '&'
  100. %left <code> EQCOMPARE
  101. %left <code> ARITHCOMPARE
  102. %left <code> LSHIFT RSHIFT
  103. %left <code> '+' '-'
  104. %left <code> '*' '/' '%'
  105. %right <code> UNARY PLUSPLUS MINUSMINUS
  106. %left HYPERUNARY
  107. %left <code> POINTSAT '.' '(' '['
  108. /* The Objective-C keywords. These are included in C and in
  109. Objective C, so that the token codes are the same in both. */
  110. %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
  111. %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
  112. %type <code> unop
  113. %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  114. %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
  115. %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
  116. %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
  117. %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
  118. %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
  119. %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
  120. %type <ttype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
  121. %type <ttype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
  122. %type <ttype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
  123. %type <ttype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
  124. %type <ttype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
  125. %type <ttype> declspecs_ts declspecs_nots
  126. %type <ttype> declspecs_ts_nosa declspecs_nots_nosa
  127. %type <ttype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
  128. %type <ttype> maybe_type_quals_attrs typespec_nonattr typespec_attr
  129. %type <ttype> typespec_reserved_nonattr typespec_reserved_attr
  130. %type <ttype> typespec_nonreserved_nonattr
  131. %type <ttype> SCSPEC TYPESPEC TYPE_QUAL maybe_type_qual
  132. %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
  133. %type <ttype> init maybeasm
  134. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  135. %type <ttype> maybe_attribute attributes attribute attribute_list attrib
  136. %type <ttype> any_word extension
  137. %type <ttype> compstmt compstmt_start compstmt_nostart compstmt_primary_start
  138. %type <ttype> do_stmt_start poplevel stmt label
  139. %type <ttype> c99_block_start c99_block_end
  140. %type <ttype> declarator
  141. %type <ttype> notype_declarator after_type_declarator
  142. %type <ttype> parm_declarator
  143. %type <ttype> parm_declarator_starttypename parm_declarator_nostarttypename
  144. %type <ttype> array_declarator
  145. %type <ttype> structsp_attr structsp_nonattr
  146. %type <ttype> component_decl_list component_decl_list2
  147. %type <ttype> component_decl components components_notype component_declarator
  148. %type <ttype> component_notype_declarator
  149. %type <ttype> enumlist enumerator
  150. %type <ttype> struct_head union_head enum_head
  151. %type <ttype> typename absdcl absdcl1 absdcl1_ea absdcl1_noea
  152. %type <ttype> direct_absdcl1 absdcl_maybe_attribute
  153. %type <ttype> xexpr parms parm firstparm identifiers
  154. %type <ttype> parmlist parmlist_1 parmlist_2
  155. %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
  156. %type <ttype> identifiers_or_typenames
  157. %type <itype> setspecs setspecs_fp
  158. %type <filename> save_filename
  159. %type <lineno> save_lineno
  160. %{
  161. /* Number of statements (loosely speaking) and compound statements
  162. seen so far. */
  163. static int stmt_count;
  164. static int compstmt_count;
  165. /* Input file and line number of the end of the body of last simple_if;
  166. used by the stmt-rule immediately after simple_if returns. */
  167. static const char *if_stmt_file;
  168. static int if_stmt_line;
  169. /* List of types and structure classes of the current declaration. */
  170. static tree current_declspecs = NULL_TREE;
  171. static tree prefix_attributes = NULL_TREE;
  172. /* List of all the attributes applying to the identifier currently being
  173. declared; includes prefix_attributes and possibly some more attributes
  174. just after a comma. */
  175. static tree all_prefix_attributes = NULL_TREE;
  176. /* Stack of saved values of current_declspecs, prefix_attributes and
  177. all_prefix_attributes. */
  178. static tree declspec_stack;
  179. /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
  180. should be called from the productions making use of setspecs. */
  181. #define PUSH_DECLSPEC_STACK \
  182. do { \
  183. declspec_stack = tree_cons (build_tree_list (prefix_attributes, \
  184. all_prefix_attributes), \
  185. current_declspecs, \
  186. declspec_stack); \
  187. } while (0)
  188. #define POP_DECLSPEC_STACK \
  189. do { \
  190. current_declspecs = TREE_VALUE (declspec_stack); \
  191. prefix_attributes = TREE_PURPOSE (TREE_PURPOSE (declspec_stack)); \
  192. all_prefix_attributes = TREE_VALUE (TREE_PURPOSE (declspec_stack)); \
  193. declspec_stack = TREE_CHAIN (declspec_stack); \
  194. } while (0)
  195. /* For __extension__, save/restore the warning flags which are
  196. controlled by __extension__. */
  197. #define SAVE_WARN_FLAGS() \
  198. size_int (pedantic \
  199. | (warn_pointer_arith << 1) \
  200. | (warn_traditional << 2))
  201. #define RESTORE_WARN_FLAGS(tval) \
  202. do { \
  203. int val = tree_low_cst (tval, 0); \
  204. pedantic = val & 1; \
  205. warn_pointer_arith = (val >> 1) & 1; \
  206. warn_traditional = (val >> 2) & 1; \
  207. } while (0)
  208. #define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
  209. /* Tell yyparse how to print a token's value, if yydebug is set. */
  210. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  211. static void yyprint PARAMS ((FILE *, int, YYSTYPE));
  212. static void yyerror PARAMS ((const char *));
  213. static int yylexname PARAMS ((void));
  214. static inline int _yylex PARAMS ((void));
  215. static int yylex PARAMS ((void));
  216. static void init_reswords PARAMS ((void));
  217. /* Add GC roots for variables local to this file. */
  218. void
  219. c_parse_init ()
  220. {
  221. init_reswords ();
  222. ggc_add_tree_root (&declspec_stack, 1);
  223. ggc_add_tree_root (&current_declspecs, 1);
  224. ggc_add_tree_root (&prefix_attributes, 1);
  225. ggc_add_tree_root (&all_prefix_attributes, 1);
  226. }
  227. %}
  228. %%
  229. program: /* empty */
  230. { if (pedantic)
  231. pedwarn ("ISO C forbids an empty source file");
  232. finish_file ();
  233. }
  234. | extdefs
  235. {
  236. /* In case there were missing closebraces,
  237. get us back to the global binding level. */
  238. while (! global_bindings_p ())
  239. poplevel (0, 0, 0);
  240. finish_fname_decls ();
  241. finish_file ();
  242. }
  243. ;
  244. /* the reason for the strange actions in this rule
  245. is so that notype_initdecls when reached via datadef
  246. can find a valid list of type and sc specs in $0. */
  247. extdefs:
  248. {$<ttype>$ = NULL_TREE; } extdef
  249. | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
  250. ;
  251. extdef:
  252. fndef
  253. | datadef
  254. | ASM_KEYWORD '(' expr ')' ';'
  255. { STRIP_NOPS ($3);
  256. if ((TREE_CODE ($3) == ADDR_EXPR
  257. && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
  258. || TREE_CODE ($3) == STRING_CST)
  259. assemble_asm ($3);
  260. else
  261. error ("argument of `asm' is not a constant string"); }
  262. | extension extdef
  263. { RESTORE_WARN_FLAGS ($1); }
  264. ;
  265. datadef:
  266. setspecs notype_initdecls ';'
  267. { if (pedantic)
  268. error ("ISO C forbids data definition with no type or storage class");
  269. else if (!flag_traditional)
  270. warning ("data definition has no type or storage class");
  271. POP_DECLSPEC_STACK; }
  272. | declspecs_nots setspecs notype_initdecls ';'
  273. { POP_DECLSPEC_STACK; }
  274. | declspecs_ts setspecs initdecls ';'
  275. { POP_DECLSPEC_STACK; }
  276. | declspecs ';'
  277. { shadow_tag ($1); }
  278. | error ';'
  279. | error '}'
  280. | ';'
  281. { if (pedantic)
  282. pedwarn ("ISO C does not allow extra `;' outside of a function"); }
  283. ;
  284. fndef:
  285. declspecs_ts setspecs declarator
  286. { if (! start_function (current_declspecs, $3,
  287. all_prefix_attributes))
  288. YYERROR1;
  289. }
  290. old_style_parm_decls
  291. { store_parm_decls (); }
  292. save_filename save_lineno compstmt_or_error
  293. { DECL_SOURCE_FILE (current_function_decl) = $7;
  294. DECL_SOURCE_LINE (current_function_decl) = $8;
  295. finish_function (0, 1);
  296. POP_DECLSPEC_STACK; }
  297. | declspecs_ts setspecs declarator error
  298. { POP_DECLSPEC_STACK; }
  299. | declspecs_nots setspecs notype_declarator
  300. { if (! start_function (current_declspecs, $3,
  301. all_prefix_attributes))
  302. YYERROR1;
  303. }
  304. old_style_parm_decls
  305. { store_parm_decls (); }
  306. save_filename save_lineno compstmt_or_error
  307. { DECL_SOURCE_FILE (current_function_decl) = $7;
  308. DECL_SOURCE_LINE (current_function_decl) = $8;
  309. finish_function (0, 1);
  310. POP_DECLSPEC_STACK; }
  311. | declspecs_nots setspecs notype_declarator error
  312. { POP_DECLSPEC_STACK; }
  313. | setspecs notype_declarator
  314. { if (! start_function (NULL_TREE, $2,
  315. all_prefix_attributes))
  316. YYERROR1;
  317. }
  318. old_style_parm_decls
  319. { store_parm_decls (); }
  320. save_filename save_lineno compstmt_or_error
  321. { DECL_SOURCE_FILE (current_function_decl) = $6;
  322. DECL_SOURCE_LINE (current_function_decl) = $7;
  323. finish_function (0, 1);
  324. POP_DECLSPEC_STACK; }
  325. | setspecs notype_declarator error
  326. { POP_DECLSPEC_STACK; }
  327. ;
  328. identifier:
  329. IDENTIFIER
  330. | TYPENAME
  331. ;
  332. unop: '&'
  333. { $$ = ADDR_EXPR; }
  334. | '-'
  335. { $$ = NEGATE_EXPR; }
  336. | '+'
  337. { $$ = CONVERT_EXPR;
  338. if (warn_traditional && !in_system_header)
  339. warning ("traditional C rejects the unary plus operator");
  340. }
  341. | PLUSPLUS
  342. { $$ = PREINCREMENT_EXPR; }
  343. | MINUSMINUS
  344. { $$ = PREDECREMENT_EXPR; }
  345. | '~'
  346. { $$ = BIT_NOT_EXPR; }
  347. | '!'
  348. { $$ = TRUTH_NOT_EXPR; }
  349. ;
  350. expr: nonnull_exprlist
  351. { $$ = build_compound_expr ($1); }
  352. ;
  353. exprlist:
  354. /* empty */
  355. { $$ = NULL_TREE; }
  356. | nonnull_exprlist
  357. ;
  358. nonnull_exprlist:
  359. expr_no_commas
  360. { $$ = build_tree_list (NULL_TREE, $1); }
  361. | nonnull_exprlist ',' expr_no_commas
  362. { chainon ($1, build_tree_list (NULL_TREE, $3)); }
  363. ;
  364. unary_expr:
  365. primary
  366. | '*' cast_expr %prec UNARY
  367. { $$ = build_indirect_ref ($2, "unary *"); }
  368. /* __extension__ turns off -pedantic for following primary. */
  369. | extension cast_expr %prec UNARY
  370. { $$ = $2;
  371. RESTORE_WARN_FLAGS ($1); }
  372. | unop cast_expr %prec UNARY
  373. { $$ = build_unary_op ($1, $2, 0);
  374. overflow_warning ($$); }
  375. /* Refer to the address of a label as a pointer. */
  376. | ANDAND identifier
  377. { $$ = finish_label_address_expr ($2); }
  378. /* This seems to be impossible on some machines, so let's turn it off.
  379. You can use __builtin_next_arg to find the anonymous stack args.
  380. | '&' ELLIPSIS
  381. { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
  382. $$ = error_mark_node;
  383. if (TREE_VALUE (tree_last (types)) == void_type_node)
  384. error ("`&...' used in function with fixed number of arguments");
  385. else
  386. {
  387. if (pedantic)
  388. pedwarn ("ISO C forbids `&...'");
  389. $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
  390. $$ = build_unary_op (ADDR_EXPR, $$, 0);
  391. } }
  392. */
  393. | sizeof unary_expr %prec UNARY
  394. { skip_evaluation--;
  395. if (TREE_CODE ($2) == COMPONENT_REF
  396. && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
  397. error ("`sizeof' applied to a bit-field");
  398. $$ = c_sizeof (TREE_TYPE ($2)); }
  399. | sizeof '(' typename ')' %prec HYPERUNARY
  400. { skip_evaluation--;
  401. $$ = c_sizeof (groktypename ($3)); }
  402. | alignof unary_expr %prec UNARY
  403. { skip_evaluation--;
  404. $$ = c_alignof_expr ($2); }
  405. | alignof '(' typename ')' %prec HYPERUNARY
  406. { skip_evaluation--;
  407. $$ = c_alignof (groktypename ($3)); }
  408. | REALPART cast_expr %prec UNARY
  409. { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
  410. | IMAGPART cast_expr %prec UNARY
  411. { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
  412. ;
  413. sizeof:
  414. SIZEOF { skip_evaluation++; }
  415. ;
  416. alignof:
  417. ALIGNOF { skip_evaluation++; }
  418. ;
  419. typeof:
  420. TYPEOF { skip_evaluation++; }
  421. ;
  422. cast_expr:
  423. unary_expr
  424. | '(' typename ')' cast_expr %prec UNARY
  425. { $$ = c_cast_expr ($2, $4); }
  426. ;
  427. expr_no_commas:
  428. cast_expr
  429. | expr_no_commas '+' expr_no_commas
  430. { $$ = parser_build_binary_op ($2, $1, $3); }
  431. | expr_no_commas '-' expr_no_commas
  432. { $$ = parser_build_binary_op ($2, $1, $3); }
  433. | expr_no_commas '*' expr_no_commas
  434. { $$ = parser_build_binary_op ($2, $1, $3); }
  435. | expr_no_commas '/' expr_no_commas
  436. { $$ = parser_build_binary_op ($2, $1, $3); }
  437. | expr_no_commas '%' expr_no_commas
  438. { $$ = parser_build_binary_op ($2, $1, $3); }
  439. | expr_no_commas LSHIFT expr_no_commas
  440. { $$ = parser_build_binary_op ($2, $1, $3); }
  441. | expr_no_commas RSHIFT expr_no_commas
  442. { $$ = parser_build_binary_op ($2, $1, $3); }
  443. | expr_no_commas ARITHCOMPARE expr_no_commas
  444. { $$ = parser_build_binary_op ($2, $1, $3); }
  445. | expr_no_commas EQCOMPARE expr_no_commas
  446. { $$ = parser_build_binary_op ($2, $1, $3); }
  447. | expr_no_commas '&' expr_no_commas
  448. { $$ = parser_build_binary_op ($2, $1, $3); }
  449. | expr_no_commas '|' expr_no_commas
  450. { $$ = parser_build_binary_op ($2, $1, $3); }
  451. | expr_no_commas '^' expr_no_commas
  452. { $$ = parser_build_binary_op ($2, $1, $3); }
  453. | expr_no_commas ANDAND
  454. { $1 = truthvalue_conversion (default_conversion ($1));
  455. skip_evaluation += $1 == boolean_false_node; }
  456. expr_no_commas
  457. { skip_evaluation -= $1 == boolean_false_node;
  458. $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
  459. | expr_no_commas OROR
  460. { $1 = truthvalue_conversion (default_conversion ($1));
  461. skip_evaluation += $1 == boolean_true_node; }
  462. expr_no_commas
  463. { skip_evaluation -= $1 == boolean_true_node;
  464. $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
  465. | expr_no_commas '?'
  466. { $1 = truthvalue_conversion (default_conversion ($1));
  467. skip_evaluation += $1 == boolean_false_node; }
  468. expr ':'
  469. { skip_evaluation += (($1 == boolean_true_node)
  470. - ($1 == boolean_false_node)); }
  471. expr_no_commas
  472. { skip_evaluation -= $1 == boolean_true_node;
  473. $$ = build_conditional_expr ($1, $4, $7); }
  474. | expr_no_commas '?'
  475. { if (pedantic)
  476. pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
  477. /* Make sure first operand is calculated only once. */
  478. $<ttype>2 = save_expr ($1);
  479. $1 = truthvalue_conversion (default_conversion ($<ttype>2));
  480. skip_evaluation += $1 == boolean_true_node; }
  481. ':' expr_no_commas
  482. { skip_evaluation -= $1 == boolean_true_node;
  483. $$ = build_conditional_expr ($1, $<ttype>2, $5); }
  484. | expr_no_commas '=' expr_no_commas
  485. { char class;
  486. $$ = build_modify_expr ($1, NOP_EXPR, $3);
  487. class = TREE_CODE_CLASS (TREE_CODE ($$));
  488. if (IS_EXPR_CODE_CLASS (class))
  489. C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
  490. }
  491. | expr_no_commas ASSIGN expr_no_commas
  492. { char class;
  493. $$ = build_modify_expr ($1, $2, $3);
  494. /* This inhibits warnings in truthvalue_conversion. */
  495. class = TREE_CODE_CLASS (TREE_CODE ($$));
  496. if (IS_EXPR_CODE_CLASS (class))
  497. C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
  498. }
  499. ;
  500. primary:
  501. IDENTIFIER
  502. {
  503. if (yychar == YYEMPTY)
  504. yychar = YYLEX;
  505. $$ = build_external_ref ($1, yychar == '(');
  506. }
  507. | CONSTANT
  508. | string
  509. { $$ = combine_strings ($1); }
  510. | VAR_FUNC_NAME
  511. { $$ = fname_decl (C_RID_CODE ($$), $$); }
  512. | '(' typename ')' '{'
  513. { start_init (NULL_TREE, NULL, 0);
  514. $2 = groktypename ($2);
  515. really_start_incremental_init ($2); }
  516. initlist_maybe_comma '}' %prec UNARY
  517. { tree constructor = pop_init_level (0);
  518. tree type = $2;
  519. finish_init ();
  520. if (pedantic && ! flag_isoc99)
  521. pedwarn ("ISO C89 forbids compound literals");
  522. $$ = build_compound_literal (type, constructor);
  523. }
  524. | '(' expr ')'
  525. { char class = TREE_CODE_CLASS (TREE_CODE ($2));
  526. if (IS_EXPR_CODE_CLASS (class))
  527. C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
  528. $$ = $2; }
  529. | '(' error ')'
  530. { $$ = error_mark_node; }
  531. | compstmt_primary_start compstmt_nostart ')'
  532. { tree saved_last_tree;
  533. if (pedantic)
  534. pedwarn ("ISO C forbids braced-groups within expressions");
  535. pop_label_level ();
  536. saved_last_tree = COMPOUND_BODY ($1);
  537. RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
  538. last_tree = saved_last_tree;
  539. TREE_CHAIN (last_tree) = NULL_TREE;
  540. if (!last_expr_type)
  541. last_expr_type = void_type_node;
  542. $$ = build1 (STMT_EXPR, last_expr_type, $1);
  543. TREE_SIDE_EFFECTS ($$) = 1;
  544. }
  545. | compstmt_primary_start error ')'
  546. {
  547. pop_label_level ();
  548. last_tree = COMPOUND_BODY ($1);
  549. TREE_CHAIN (last_tree) = NULL_TREE;
  550. $$ = error_mark_node;
  551. }
  552. | primary '(' exprlist ')' %prec '.'
  553. { $$ = build_function_call ($1, $3); }
  554. | VA_ARG '(' expr_no_commas ',' typename ')'
  555. { $$ = build_va_arg ($3, groktypename ($5)); }
  556. | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ',' expr_no_commas ')'
  557. {
  558. tree c;
  559. c = fold ($3);
  560. STRIP_NOPS (c);
  561. if (TREE_CODE (c) != INTEGER_CST)
  562. error ("first argument to __builtin_choose_expr not a constant");
  563. $$ = integer_zerop (c) ? $7 : $5;
  564. }
  565. | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
  566. {
  567. tree e1, e2;
  568. e1 = TYPE_MAIN_VARIANT (groktypename ($3));
  569. e2 = TYPE_MAIN_VARIANT (groktypename ($5));
  570. $$ = comptypes (e1, e2)
  571. ? build_int_2 (1, 0) : build_int_2 (0, 0);
  572. }
  573. | primary '[' expr ']' %prec '.'
  574. { $$ = build_array_ref ($1, $3); }
  575. | primary '.' identifier
  576. {
  577. $$ = build_component_ref ($1, $3);
  578. }
  579. | primary POINTSAT identifier
  580. {
  581. tree expr = build_indirect_ref ($1, "->");
  582. $$ = build_component_ref (expr, $3);
  583. }
  584. | primary PLUSPLUS
  585. { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
  586. | primary MINUSMINUS
  587. { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
  588. ;
  589. /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
  590. string:
  591. STRING
  592. | string STRING
  593. {
  594. static int last_lineno = 0;
  595. static const char *last_input_filename = 0;
  596. $$ = chainon ($1, $2);
  597. if (warn_traditional && !in_system_header
  598. && (lineno != last_lineno || !last_input_filename ||
  599. strcmp (last_input_filename, input_filename)))
  600. {
  601. warning ("traditional C rejects string concatenation");
  602. last_lineno = lineno;
  603. last_input_filename = input_filename;
  604. }
  605. }
  606. ;
  607. old_style_parm_decls:
  608. /* empty */
  609. | datadecls
  610. | datadecls ELLIPSIS
  611. /* ... is used here to indicate a varargs function. */
  612. { c_mark_varargs ();
  613. if (pedantic)
  614. pedwarn ("ISO C does not permit use of `varargs.h'"); }
  615. ;
  616. /* The following are analogous to lineno_decl, decls and decl
  617. except that they do not allow nested functions.
  618. They are used for old-style parm decls. */
  619. lineno_datadecl:
  620. save_filename save_lineno datadecl
  621. { }
  622. ;
  623. datadecls:
  624. lineno_datadecl
  625. | errstmt
  626. | datadecls lineno_datadecl
  627. | lineno_datadecl errstmt
  628. ;
  629. /* We don't allow prefix attributes here because they cause reduce/reduce
  630. conflicts: we can't know whether we're parsing a function decl with
  631. attribute suffix, or function defn with attribute prefix on first old
  632. style parm. */
  633. datadecl:
  634. declspecs_ts_nosa setspecs initdecls ';'
  635. { POP_DECLSPEC_STACK; }
  636. | declspecs_nots_nosa setspecs notype_initdecls ';'
  637. { POP_DECLSPEC_STACK; }
  638. | declspecs_ts_nosa ';'
  639. { shadow_tag_warned ($1, 1);
  640. pedwarn ("empty declaration"); }
  641. | declspecs_nots_nosa ';'
  642. { pedwarn ("empty declaration"); }
  643. ;
  644. /* This combination which saves a lineno before a decl
  645. is the normal thing to use, rather than decl itself.
  646. This is to avoid shift/reduce conflicts in contexts
  647. where statement labels are allowed. */
  648. lineno_decl:
  649. save_filename save_lineno decl
  650. { }
  651. ;
  652. /* records the type and storage class specs to use for processing
  653. the declarators that follow.
  654. Maintains a stack of outer-level values of current_declspecs,
  655. for the sake of parm declarations nested in function declarators. */
  656. setspecs: /* empty */
  657. { pending_xref_error ();
  658. PUSH_DECLSPEC_STACK;
  659. split_specs_attrs ($<ttype>0,
  660. &current_declspecs, &prefix_attributes);
  661. all_prefix_attributes = prefix_attributes; }
  662. ;
  663. /* Possibly attributes after a comma, which should reset all_prefix_attributes
  664. to prefix_attributes with these ones chained on the front. */
  665. maybe_resetattrs:
  666. maybe_attribute
  667. { all_prefix_attributes = chainon ($1, prefix_attributes); }
  668. ;
  669. decl:
  670. declspecs_ts setspecs initdecls ';'
  671. { POP_DECLSPEC_STACK; }
  672. | declspecs_nots setspecs notype_initdecls ';'
  673. { POP_DECLSPEC_STACK; }
  674. | declspecs_ts setspecs nested_function
  675. { POP_DECLSPEC_STACK; }
  676. | declspecs_nots setspecs notype_nested_function
  677. { POP_DECLSPEC_STACK; }
  678. | declspecs ';'
  679. { shadow_tag ($1); }
  680. | extension decl
  681. { RESTORE_WARN_FLAGS ($1); }
  682. ;
  683. /* A list of declaration specifiers. These are:
  684. - Storage class specifiers (SCSPEC), which for GCC currently include
  685. function specifiers ("inline").
  686. - Type specifiers (typespec_*).
  687. - Type qualifiers (TYPE_QUAL).
  688. - Attribute specifier lists (attributes).
  689. These are stored as a TREE_LIST; the head of the list is the last
  690. item in the specifier list. Each entry in the list has either a
  691. TREE_PURPOSE that is an attribute specifier list, or a TREE_VALUE that
  692. is a single other specifier or qualifier; and a TREE_CHAIN that is the
  693. rest of the list. TREE_STATIC is set on the list if something other
  694. than a storage class specifier or attribute has been seen; this is used
  695. to warn for the obsolescent usage of storage class specifiers other than
  696. at the start of the list. (Doing this properly would require function
  697. specifiers to be handled separately from storage class specifiers.)
  698. The various cases below are classified according to:
  699. (a) Whether a storage class specifier is included or not; some
  700. places in the grammar disallow storage class specifiers (_sc or _nosc).
  701. (b) Whether a type specifier has been seen; after a type specifier,
  702. a typedef name is an identifier to redeclare (_ts or _nots).
  703. (c) Whether the list starts with an attribute; in certain places,
  704. the grammar requires specifiers that don't start with an attribute
  705. (_sa or _nosa).
  706. (d) Whether the list ends with an attribute (or a specifier such that
  707. any following attribute would have been parsed as part of that specifier);
  708. this avoids shift-reduce conflicts in the parsing of attributes
  709. (_ea or _noea).
  710. TODO:
  711. (i) Distinguish between function specifiers and storage class specifiers,
  712. at least for the purpose of warnings about obsolescent usage.
  713. (ii) Halve the number of productions here by eliminating the _sc/_nosc
  714. distinction and instead checking where required that storage class
  715. specifiers aren't present. */
  716. /* Declspecs which contain at least one type specifier or typedef name.
  717. (Just `const' or `volatile' is not enough.)
  718. A typedef'd name following these is taken as a name to be declared.
  719. Declspecs have a non-NULL TREE_VALUE, attributes do not. */
  720. declspecs_nosc_nots_nosa_noea:
  721. TYPE_QUAL
  722. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
  723. TREE_STATIC ($$) = 1; }
  724. | declspecs_nosc_nots_nosa_noea TYPE_QUAL
  725. { $$ = tree_cons (NULL_TREE, $2, $1);
  726. TREE_STATIC ($$) = 1; }
  727. | declspecs_nosc_nots_nosa_ea TYPE_QUAL
  728. { $$ = tree_cons (NULL_TREE, $2, $1);
  729. TREE_STATIC ($$) = 1; }
  730. ;
  731. declspecs_nosc_nots_nosa_ea:
  732. declspecs_nosc_nots_nosa_noea attributes
  733. { $$ = tree_cons ($2, NULL_TREE, $1);
  734. TREE_STATIC ($$) = TREE_STATIC ($1); }
  735. ;
  736. declspecs_nosc_nots_sa_noea:
  737. declspecs_nosc_nots_sa_noea TYPE_QUAL
  738. { $$ = tree_cons (NULL_TREE, $2, $1);
  739. TREE_STATIC ($$) = 1; }
  740. | declspecs_nosc_nots_sa_ea TYPE_QUAL
  741. { $$ = tree_cons (NULL_TREE, $2, $1);
  742. TREE_STATIC ($$) = 1; }
  743. ;
  744. declspecs_nosc_nots_sa_ea:
  745. attributes
  746. { $$ = tree_cons ($1, NULL_TREE, NULL_TREE);
  747. TREE_STATIC ($$) = 0; }
  748. | declspecs_nosc_nots_sa_noea attributes
  749. { $$ = tree_cons ($2, NULL_TREE, $1);
  750. TREE_STATIC ($$) = TREE_STATIC ($1); }
  751. ;
  752. declspecs_nosc_ts_nosa_noea:
  753. typespec_nonattr
  754. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
  755. TREE_STATIC ($$) = 1; }
  756. | declspecs_nosc_ts_nosa_noea TYPE_QUAL
  757. { $$ = tree_cons (NULL_TREE, $2, $1);
  758. TREE_STATIC ($$) = 1; }
  759. | declspecs_nosc_ts_nosa_ea TYPE_QUAL
  760. { $$ = tree_cons (NULL_TREE, $2, $1);
  761. TREE_STATIC ($$) = 1; }
  762. | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
  763. { $$ = tree_cons (NULL_TREE, $2, $1);
  764. TREE_STATIC ($$) = 1; }
  765. | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
  766. { $$ = tree_cons (NULL_TREE, $2, $1);
  767. TREE_STATIC ($$) = 1; }
  768. | declspecs_nosc_nots_nosa_noea typespec_nonattr
  769. { $$ = tree_cons (NULL_TREE, $2, $1);
  770. TREE_STATIC ($$) = 1; }
  771. | declspecs_nosc_nots_nosa_ea typespec_nonattr
  772. { $$ = tree_cons (NULL_TREE, $2, $1);
  773. TREE_STATIC ($$) = 1; }
  774. ;
  775. declspecs_nosc_ts_nosa_ea:
  776. typespec_attr
  777. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
  778. TREE_STATIC ($$) = 1; }
  779. | declspecs_nosc_ts_nosa_noea attributes
  780. { $$ = tree_cons ($2, NULL_TREE, $1);
  781. TREE_STATIC ($$) = TREE_STATIC ($1); }
  782. | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
  783. { $$ = tree_cons (NULL_TREE, $2, $1);
  784. TREE_STATIC ($$) = 1; }
  785. | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
  786. { $$ = tree_cons (NULL_TREE, $2, $1);
  787. TREE_STATIC ($$) = 1; }
  788. | declspecs_nosc_nots_nosa_noea typespec_attr
  789. { $$ = tree_cons (NULL_TREE, $2, $1);
  790. TREE_STATIC ($$) = 1; }
  791. | declspecs_nosc_nots_nosa_ea typespec_attr
  792. { $$ = tree_cons (NULL_TREE, $2, $1);
  793. TREE_STATIC ($$) = 1; }
  794. ;
  795. declspecs_nosc_ts_sa_noea:
  796. declspecs_nosc_ts_sa_noea TYPE_QUAL
  797. { $$ = tree_cons (NULL_TREE, $2, $1);
  798. TREE_STATIC ($$) = 1; }
  799. | declspecs_nosc_ts_sa_ea TYPE_QUAL
  800. { $$ = tree_cons (NULL_TREE, $2, $1);
  801. TREE_STATIC ($$) = 1; }
  802. | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
  803. { $$ = tree_cons (NULL_TREE, $2, $1);
  804. TREE_STATIC ($$) = 1; }
  805. | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
  806. { $$ = tree_cons (NULL_TREE, $2, $1);
  807. TREE_STATIC ($$) = 1; }
  808. | declspecs_nosc_nots_sa_noea typespec_nonattr
  809. { $$ = tree_cons (NULL_TREE, $2, $1);
  810. TREE_STATIC ($$) = 1; }
  811. | declspecs_nosc_nots_sa_ea typespec_nonattr
  812. { $$ = tree_cons (NULL_TREE, $2, $1);
  813. TREE_STATIC ($$) = 1; }
  814. ;
  815. declspecs_nosc_ts_sa_ea:
  816. declspecs_nosc_ts_sa_noea attributes
  817. { $$ = tree_cons ($2, NULL_TREE, $1);
  818. TREE_STATIC ($$) = TREE_STATIC ($1); }
  819. | declspecs_nosc_ts_sa_noea typespec_reserved_attr
  820. { $$ = tree_cons (NULL_TREE, $2, $1);
  821. TREE_STATIC ($$) = 1; }
  822. | declspecs_nosc_ts_sa_ea typespec_reserved_attr
  823. { $$ = tree_cons (NULL_TREE, $2, $1);
  824. TREE_STATIC ($$) = 1; }
  825. | declspecs_nosc_nots_sa_noea typespec_attr
  826. { $$ = tree_cons (NULL_TREE, $2, $1);
  827. TREE_STATIC ($$) = 1; }
  828. | declspecs_nosc_nots_sa_ea typespec_attr
  829. { $$ = tree_cons (NULL_TREE, $2, $1);
  830. TREE_STATIC ($$) = 1; }
  831. ;
  832. declspecs_sc_nots_nosa_noea:
  833. SCSPEC
  834. { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
  835. TREE_STATIC ($$) = 0; }
  836. | declspecs_sc_nots_nosa_noea TYPE_QUAL
  837. { $$ = tree_cons (NULL_TREE, $2, $1);
  838. TREE_STATIC ($$) = 1; }
  839. | declspecs_sc_nots_nosa_ea TYPE_QUAL
  840. { $$ = tree_cons (NULL_TREE, $2, $1);
  841. TREE_STATIC ($$) = 1; }
  842. | declspecs_nosc_nots_nosa_noea SCSPEC
  843. { if (extra_warnings && TREE_STATIC ($1))
  844. warning ("`%s' is not at beginning of declaration",
  845. IDENTIFIER_POINTER ($2));
  846. $$ = tree_cons (NULL_TREE, $2, $1);
  847. TREE_STATIC ($$) = TREE_STATIC ($1); }
  848. | declspecs_nosc_nots_nosa_ea SCSPEC
  849. { if (extra_warnings && TREE_STATIC ($1))
  850. warning ("`%s' is not at beginning of declaration",
  851. IDENTIFIER_POINTER ($2));
  852. $$ = tree_cons (NULL_TREE, $2, $1);
  853. TREE_STATIC ($$) = TREE_STATIC ($1); }
  854. | declspecs_sc_nots_nosa_noea SCSPEC
  855. { if (extra_warnings && TREE_STATIC ($1))
  856. warning ("`%s' is not at beginning of declaration",
  857. IDENTIFIER_POINTER ($2));
  858. $$ = tree_cons (NULL_TREE, $2, $1);
  859. TREE_STATIC ($$) = TREE_STATIC ($1); }
  860. | declspecs_sc_nots_nosa_ea SCSPEC
  861. { if (extra_warnings && TREE_STATIC ($1))
  862. warning ("`%s' is not at beginning of declaration",
  863. IDENTIFIER_POINTER ($2));
  864. $$ = tree_cons (NULL_TREE, $2, $1);
  865. TREE_STATIC ($$) = TREE_STATIC ($1); }
  866. ;
  867. declspecs_sc_nots_nosa_ea:
  868. declspecs_sc_nots_nosa_noea attributes
  869. { $$ = tree_cons ($2, NULL_TREE, $1);
  870. TREE_STATIC ($$) = TREE_STATIC ($1); }
  871. ;
  872. declspecs_sc_nots_sa_noea:
  873. declspecs_sc_nots_sa_noea TYPE_QUAL
  874. { $$ = tree_cons (NULL_TREE, $2, $1);
  875. TREE_STATIC ($$) = 1; }
  876. | declspecs_sc_nots_sa_ea TYPE_QUAL
  877. { $$ = tree_cons (NULL_TREE, $2, $1);
  878. TREE_STATIC ($$) = 1; }
  879. | declspecs_nosc_nots_sa_noea SCSPEC
  880. { if (extra_warnings && TREE_STATIC ($1))
  881. warning ("`%s' is not at beginning of declaration",
  882. IDENTIFIER_POINTER ($2));
  883. $$ = tree_cons (NULL_TREE, $2, $1);
  884. TREE_STATIC ($$) = TREE_STATIC ($1); }
  885. | declspecs_nosc_nots_sa_ea SCSPEC
  886. { if (extra_warnings && TREE_STATIC ($1))
  887. warning ("`%s' is not at beginning of declaration",
  888. IDENTIFIER_POINTER ($2));
  889. $$ = tree_cons (NULL_TREE, $2, $1);
  890. TREE_STATIC ($$) = TREE_STATIC ($1); }
  891. | declspecs_sc_nots_sa_noea SCSPEC
  892. { if (extra_warnings && TREE_STATIC ($1))
  893. warning ("`%s' is not at beginning of declaration",
  894. IDENTIFIER_POINTER ($2));
  895. $$ = tree_cons (NULL_TREE, $2, $1);
  896. TREE_STATIC ($$) = TREE_STATIC ($1); }
  897. | declspecs_sc_nots_sa_ea SCSPEC
  898. { if (extra_warnings && TREE_STATIC ($1))
  899. warning ("`%s' is not at beginning of declaration",
  900. IDENTIFIER_POINTER ($2));
  901. $$ = tree_cons (NULL_TREE, $2, $1);
  902. TREE_STATIC ($$) = TREE_STATIC ($1); }
  903. ;
  904. declspecs_sc_nots_sa_ea:
  905. declspecs_sc_nots_sa_noea attributes
  906. { $$ = tree_cons ($2, NULL_TREE, $1);
  907. TREE_STATIC ($$) = TREE_STATIC ($1); }
  908. ;
  909. declspecs_sc_ts_nosa_noea:
  910. declspecs_sc_ts_nosa_noea TYPE_QUAL
  911. { $$ = tree_cons (NULL_TREE, $2, $1);
  912. TREE_STATIC ($$) = 1; }
  913. | declspecs_sc_ts_nosa_ea TYPE_QUAL
  914. { $$ = tree_cons (NULL_TREE, $2, $1);
  915. TREE_STATIC ($$) = 1; }
  916. | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
  917. { $$ = tree_cons (NULL_TREE, $2, $1);
  918. TREE_STATIC ($$) = 1; }
  919. | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
  920. { $$ = tree_cons (NULL_TREE, $2, $1);
  921. TREE_STATIC ($$) = 1; }
  922. | declspecs_sc_nots_nosa_noea typespec_nonattr
  923. { $$ = tree_cons (NULL_TREE, $2, $1);
  924. TREE_STATIC ($$) = 1; }
  925. | declspecs_sc_nots_nosa_ea typespec_nonattr
  926. { $$ = tree_cons (NULL_TREE, $2, $1);
  927. TREE_STATIC ($$) = 1; }
  928. | declspecs_nosc_ts_nosa_noea SCSPEC
  929. { if (extra_warnings && TREE_STATIC ($1))
  930. warning ("`%s' is not at beginning of declaration",
  931. IDENTIFIER_POINTER ($2));
  932. $$ = tree_cons (NULL_TREE, $2, $1);
  933. TREE_STATIC ($$) = TREE_STATIC ($1); }
  934. | declspecs_nosc_ts_nosa_ea SCSPEC
  935. { if (extra_warnings && TREE_STATIC ($1))
  936. warning ("`%s' is not at beginning of declaration",
  937. IDENTIFIER_POINTER ($2));
  938. $$ = tree_cons (NULL_TREE, $2, $1);
  939. TREE_STATIC ($$) = TREE_STATIC ($1); }
  940. | declspecs_sc_ts_nosa_noea SCSPEC
  941. { if (extra_warnings && TREE_STATIC ($1))
  942. warning ("`%s' is not at beginning of declaration",
  943. IDENTIFIER_POINTER ($2));
  944. $$ = tree_cons (NULL_TREE, $2, $1);
  945. TREE_STATIC ($$) = TREE_STATIC ($1); }
  946. | declspecs_sc_ts_nosa_ea SCSPEC
  947. { if (extra_warnings && TREE_STATIC ($1))
  948. warning ("`%s' is not at beginning of declaration",
  949. IDENTIFIER_POINTER ($2));
  950. $$ = tree_cons (NULL_TREE, $2, $1);
  951. TREE_STATIC ($$) = TREE_STATIC ($1); }
  952. ;
  953. declspecs_sc_ts_nosa_ea:
  954. declspecs_sc_ts_nosa_noea attributes
  955. { $$ = tree_cons ($2, NULL_TREE, $1);
  956. TREE_STATIC ($$) = TREE_STATIC ($1); }
  957. | declspecs_sc_ts_nosa_noea typespec_reserved_attr
  958. { $$ = tree_cons (NULL_TREE, $2, $1);
  959. TREE_STATIC ($$) = 1; }
  960. | declspecs_sc_ts_nosa_ea typespec_reserved_attr
  961. { $$ = tree_cons (NULL_TREE, $2, $1);
  962. TREE_STATIC ($$) = 1; }
  963. | declspecs_sc_nots_nosa_noea typespec_attr
  964. { $$ = tree_cons (NULL_TREE, $2, $1);
  965. TREE_STATIC ($$) = 1; }
  966. | declspecs_sc_nots_nosa_ea typespec_attr
  967. { $$ = tree_cons (NULL_TREE, $2, $1);
  968. TREE_STATIC ($$) = 1; }
  969. ;
  970. declspecs_sc_ts_sa_noea:
  971. declspecs_sc_ts_sa_noea TYPE_QUAL
  972. { $$ = tree_cons (NULL_TREE, $2, $1);
  973. TREE_STATIC ($$) = 1; }
  974. | declspecs_sc_ts_sa_ea TYPE_QUAL
  975. { $$ = tree_cons (NULL_TREE, $2, $1);
  976. TREE_STATIC ($$) = 1; }
  977. | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
  978. { $$ = tree_cons (NULL_TREE, $2, $1);
  979. TREE_STATIC ($$) = 1; }
  980. | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
  981. { $$ = tree_cons (NULL_TREE, $2, $1);
  982. TREE_STATIC ($$) = 1; }
  983. | declspecs_sc_nots_sa_noea typespec_nonattr
  984. { $$ = tree_cons (NULL_TREE, $2, $1);
  985. TREE_STATIC ($$) = 1; }
  986. | declspecs_sc_nots_sa_ea typespec_nonattr
  987. { $$ = tree_cons (NULL_TREE, $2, $1);
  988. TREE_STATIC ($$) = 1; }
  989. | declspecs_nosc_ts_sa_noea SCSPEC
  990. { if (extra_warnings && TREE_STATIC ($1))
  991. warning ("`%s' is not at beginning of declaration",
  992. IDENTIFIER_POINTER ($2));
  993. $$ = tree_cons (NULL_TREE, $2, $1);
  994. TREE_STATIC ($$) = TREE_STATIC ($1); }
  995. | declspecs_nosc_ts_sa_ea SCSPEC
  996. { if (extra_warnings && TREE_STATIC ($1))
  997. warning ("`%s' is not at beginning of declaration",
  998. IDENTIFIER_POINTER ($2));
  999. $$ = tree_cons (NULL_TREE, $2, $1);
  1000. TREE_STATIC ($$) = TREE_STATIC ($1); }
  1001. | declspecs_sc_ts_sa_noea SCSPEC
  1002. { if (extra_warnings && TREE_STATIC ($1))
  1003. warning ("`%s' is not at beginning of declaration",
  1004. IDENTIFIER_POINTER ($2));
  1005. $$ = tree_cons (NULL_TREE, $2, $1);
  1006. TREE_STATIC ($$) = TREE_STATIC ($1); }
  1007. | declspecs_sc_ts_sa_ea SCSPEC
  1008. { if (extra_warnings && TREE_STATIC ($1))
  1009. warning ("`%s' is not at beginning of declaration",
  1010. IDENTIFIER_POINTER ($2));
  1011. $$ = tree_cons (NULL_TREE, $2, $1);
  1012. TREE_STATIC ($$) = TREE_STATIC ($1); }
  1013. ;
  1014. declspecs_sc_ts_sa_ea:
  1015. declspecs_sc_ts_sa_noea attributes
  1016. { $$ = tree_cons ($2, NULL_TREE, $1);
  1017. TREE_STATIC ($$) = TREE_STATIC ($1); }
  1018. | declspecs_sc_ts_sa_noea typespec_reserved_attr
  1019. { $$ = tree_cons (NULL_TREE, $2, $1);
  1020. TREE_STATIC ($$) = 1; }
  1021. | declspecs_sc_ts_sa_ea typespec_reserved_attr
  1022. { $$ = tree_cons (NULL_TREE, $2, $1);
  1023. TREE_STATIC ($$) = 1; }
  1024. | declspecs_sc_nots_sa_noea typespec_attr
  1025. { $$ = tree_cons (NULL_TREE, $2, $1);
  1026. TREE_STATIC ($$) = 1; }
  1027. | declspecs_sc_nots_sa_ea typespec_attr
  1028. { $$ = tree_cons (NULL_TREE, $2, $1);
  1029. TREE_STATIC ($$) = 1; }
  1030. ;
  1031. /* Particular useful classes of declspecs. */
  1032. declspecs_ts:
  1033. declspecs_nosc_ts_nosa_noea
  1034. | declspecs_nosc_ts_nosa_ea
  1035. | declspecs_nosc_ts_sa_noea
  1036. | declspecs_nosc_ts_sa_ea
  1037. | declspecs_sc_ts_nosa_noea
  1038. | declspecs_sc_ts_nosa_ea
  1039. | declspecs_sc_ts_sa_noea
  1040. | declspecs_sc_ts_sa_ea
  1041. ;
  1042. declspecs_nots:
  1043. declspecs_nosc_nots_nosa_noea
  1044. | declspecs_nosc_nots_nosa_ea
  1045. | declspecs_nosc_nots_sa_noea
  1046. | declspecs_nosc_nots_sa_ea
  1047. | declspecs_sc_nots_nosa_noea
  1048. | declspecs_sc_nots_nosa_ea
  1049. | declspecs_sc_nots_sa_noea
  1050. | declspecs_sc_nots_sa_ea
  1051. ;
  1052. declspecs_ts_nosa:
  1053. declspecs_nosc_ts_nosa_noea
  1054. | declspecs_nosc_ts_nosa_ea
  1055. | declspecs_sc_ts_nosa_noea
  1056. | declspecs_sc_ts_nosa_ea
  1057. ;
  1058. declspecs_nots_nosa:
  1059. declspecs_nosc_nots_nosa_noea
  1060. | declspecs_nosc_nots_nosa_ea
  1061. | declspecs_sc_nots_nosa_noea
  1062. | declspecs_sc_nots_nosa_ea
  1063. ;
  1064. declspecs_nosc_ts:
  1065. declspecs_nosc_ts_nosa_noea
  1066. | declspecs_nosc_ts_nosa_ea
  1067. | declspecs_nosc_ts_sa_noea
  1068. | declspecs_nosc_ts_sa_ea
  1069. ;
  1070. declspecs_nosc_nots:
  1071. declspecs_nosc_nots_nosa_noea
  1072. | declspecs_nosc_nots_nosa_ea
  1073. | declspecs_nosc_nots_sa_noea
  1074. | declspecs_nosc_nots_sa_ea
  1075. ;
  1076. declspecs_nosc:
  1077. declspecs_nosc_ts_nosa_noea
  1078. | declspecs_nosc_ts_nosa_ea
  1079. | declspecs_nosc_ts_sa_noea
  1080. | declspecs_nosc_ts_sa_ea
  1081. | declspecs_nosc_nots_nosa_noea
  1082. | declspecs_nosc_nots_nosa_ea
  1083. | declspecs_nosc_nots_sa_noea
  1084. | declspecs_nosc_nots_sa_ea
  1085. ;
  1086. declspecs:
  1087. declspecs_nosc_nots_nosa_noea
  1088. | declspecs_nosc_nots_nosa_ea
  1089. | declspecs_nosc_nots_sa_noea
  1090. | declspecs_nosc_nots_sa_ea
  1091. | declspecs_nosc_ts_nosa_noea
  1092. | declspecs_nosc_ts_nosa_ea
  1093. | declspecs_nosc_ts_sa_noea
  1094. | declspecs_nosc_ts_sa_ea
  1095. | declspecs_sc_nots_nosa_noea
  1096. | declspecs_sc_nots_nosa_ea
  1097. | declspecs_sc_nots_sa_noea
  1098. | declspecs_sc_nots_sa_ea
  1099. | declspecs_sc_ts_nosa_noea
  1100. | declspecs_sc_ts_nosa_ea
  1101. | declspecs_sc_ts_sa_noea
  1102. | declspecs_sc_ts_sa_ea
  1103. ;
  1104. /* A (possibly empty) sequence of type qualifiers and attributes. */
  1105. maybe_type_quals_attrs:
  1106. /* empty */
  1107. { $$ = NULL_TREE; }
  1108. | declspecs_nosc_nots
  1109. { $$ = $1; }
  1110. ;
  1111. /* A type specifier (but not a type qualifier).
  1112. Once we have seen one of these in a declaration,
  1113. if a typedef name appears then it is being redeclared.
  1114. The _reserved versions start with a reserved word and may appear anywhere
  1115. in the declaration specifiers; the _nonreserved versions may only
  1116. appear before any other type specifiers, and after that are (if names)
  1117. being redeclared.
  1118. FIXME: should the _nonreserved version be restricted to names being
  1119. redeclared only? The other entries there relate only the GNU extensions
  1120. and Objective C, and are historically parsed thus, and don't make sense
  1121. after other type specifiers, but it might be cleaner to count them as
  1122. _reserved.
  1123. _attr means: specifiers that either end with attributes,
  1124. or are such that any following attributes would
  1125. be parsed as part of the specifier.
  1126. _nonattr: specifiers. */
  1127. typespec_nonattr:
  1128. typespec_reserved_nonattr
  1129. | typespec_nonreserved_nonattr
  1130. ;
  1131. typespec_attr:
  1132. typespec_reserved_attr
  1133. ;
  1134. typespec_reserved_nonattr:
  1135. TYPESPEC
  1136. { OBJC_NEED_RAW_IDENTIFIER (1); }
  1137. | structsp_nonattr
  1138. ;
  1139. typespec_reserved_attr:
  1140. structsp_attr
  1141. ;
  1142. typespec_nonreserved_nonattr:
  1143. TYPENAME
  1144. { /* For a typedef name, record the meaning, not the name.
  1145. In case of `foo foo, bar;'. */
  1146. $$ = lookup_name ($1); }
  1147. | typeof '(' expr ')'
  1148. { skip_evaluation--; $$ = TREE_TYPE ($3); }
  1149. | typeof '(' typename ')'
  1150. { skip_evaluation--; $$ = groktypename ($3); }
  1151. ;
  1152. /* typespec_nonreserved_attr does not exist. */
  1153. initdecls:
  1154. initdcl
  1155. | initdecls ',' maybe_resetattrs initdcl
  1156. ;
  1157. notype_initdecls:
  1158. notype_initdcl
  1159. | notype_initdecls ',' maybe_resetattrs notype_initdcl
  1160. ;
  1161. maybeasm:
  1162. /* empty */
  1163. { $$ = NULL_TREE; }
  1164. | ASM_KEYWORD '(' string ')'
  1165. { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  1166. $$ = $3;
  1167. }
  1168. ;
  1169. initdcl:
  1170. declarator maybeasm maybe_attribute '='
  1171. { $<ttype>$ = start_decl ($1, current_declspecs, 1,
  1172. chainon ($3, all_prefix_attributes));
  1173. start_init ($<ttype>$, $2, global_bindings_p ()); }
  1174. init
  1175. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1176. { finish_init ();
  1177. finish_decl ($<ttype>5, $6, $2); }
  1178. | declarator maybeasm maybe_attribute
  1179. { tree d = start_decl ($1, current_declspecs, 0,
  1180. chainon ($3, all_prefix_attributes));
  1181. finish_decl (d, NULL_TREE, $2);
  1182. }
  1183. ;
  1184. notype_initdcl:
  1185. notype_declarator maybeasm maybe_attribute '='
  1186. { $<ttype>$ = start_decl ($1, current_declspecs, 1,
  1187. chainon ($3, all_prefix_attributes));
  1188. start_init ($<ttype>$, $2, global_bindings_p ()); }
  1189. init
  1190. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1191. { finish_init ();
  1192. finish_decl ($<ttype>5, $6, $2); }
  1193. | notype_declarator maybeasm maybe_attribute
  1194. { tree d = start_decl ($1, current_declspecs, 0,
  1195. chainon ($3, all_prefix_attributes));
  1196. finish_decl (d, NULL_TREE, $2); }
  1197. ;
  1198. /* the * rules are dummies to accept the Apollo extended syntax
  1199. so that the header files compile. */
  1200. maybe_attribute:
  1201. /* empty */
  1202. { $$ = NULL_TREE; }
  1203. | attributes
  1204. { $$ = $1; }
  1205. ;
  1206. attributes:
  1207. attribute
  1208. { $$ = $1; }
  1209. | attributes attribute
  1210. { $$ = chainon ($1, $2); }
  1211. ;
  1212. attribute:
  1213. ATTRIBUTE '(' '(' attribute_list ')' ')'
  1214. { $$ = $4; }
  1215. ;
  1216. attribute_list:
  1217. attrib
  1218. { $$ = $1; }
  1219. | attribute_list ',' attrib
  1220. { $$ = chainon ($1, $3); }
  1221. ;
  1222. attrib:
  1223. /* empty */
  1224. { $$ = NULL_TREE; }
  1225. | any_word
  1226. { $$ = build_tree_list ($1, NULL_TREE); }
  1227. | any_word '(' IDENTIFIER ')'
  1228. { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
  1229. | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
  1230. { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
  1231. | any_word '(' exprlist ')'
  1232. { $$ = build_tree_list ($1, $3); }
  1233. ;
  1234. /* This still leaves out most reserved keywords,
  1235. shouldn't we include them? */
  1236. any_word:
  1237. identifier
  1238. | SCSPEC
  1239. | TYPESPEC
  1240. | TYPE_QUAL
  1241. ;
  1242. /* Initializers. `init' is the entry point. */
  1243. init:
  1244. expr_no_commas
  1245. | '{'
  1246. { really_start_incremental_init (NULL_TREE); }
  1247. initlist_maybe_comma '}'
  1248. { $$ = pop_init_level (0); }
  1249. | error
  1250. { $$ = error_mark_node; }
  1251. ;
  1252. /* `initlist_maybe_comma' is the guts of an initializer in braces. */
  1253. initlist_maybe_comma:
  1254. /* empty */
  1255. { if (pedantic)
  1256. pedwarn ("ISO C forbids empty initializer braces"); }
  1257. | initlist1 maybecomma
  1258. ;
  1259. initlist1:
  1260. initelt
  1261. | initlist1 ',' initelt
  1262. ;
  1263. /* `initelt' is a single element of an initializer.
  1264. It may use braces. */
  1265. initelt:
  1266. designator_list '=' initval
  1267. { if (pedantic && ! flag_isoc99)
  1268. pedwarn ("ISO C89 forbids specifying subobject to initialize"); }
  1269. | designator initval
  1270. { if (pedantic)
  1271. pedwarn ("obsolete use of designated initializer without `='"); }
  1272. | identifier ':'
  1273. { set_init_label ($1);
  1274. if (pedantic)
  1275. pedwarn ("obsolete use of designated initializer with `:'"); }
  1276. initval
  1277. {}
  1278. | initval
  1279. ;
  1280. initval:
  1281. '{'
  1282. { push_init_level (0); }
  1283. initlist_maybe_comma '}'
  1284. { process_init_element (pop_init_level (0)); }
  1285. | expr_no_commas
  1286. { process_init_element ($1); }
  1287. | error
  1288. ;
  1289. designator_list:
  1290. designator
  1291. | designator_list designator
  1292. ;
  1293. designator:
  1294. '.' identifier
  1295. { set_init_label ($2); }
  1296. /* These are for labeled elements. The syntax for an array element
  1297. initializer conflicts with the syntax for an Objective-C message,
  1298. so don't include these productions in the Objective-C grammar. */
  1299. | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
  1300. { set_init_index ($2, $4);
  1301. if (pedantic)
  1302. pedwarn ("ISO C forbids specifying range of elements to initialize"); }
  1303. | '[' expr_no_commas ']'
  1304. { set_init_index ($2, NULL_TREE); }
  1305. ;
  1306. nested_function:
  1307. declarator
  1308. { if (pedantic)
  1309. pedwarn ("ISO C forbids nested functions");
  1310. push_function_context ();
  1311. if (! start_function (current_declspecs, $1,
  1312. all_prefix_attributes))
  1313. {
  1314. pop_function_context ();
  1315. YYERROR1;
  1316. }
  1317. }
  1318. old_style_parm_decls
  1319. { store_parm_decls (); }
  1320. /* This used to use compstmt_or_error.
  1321. That caused a bug with input `f(g) int g {}',
  1322. where the use of YYERROR1 above caused an error
  1323. which then was handled by compstmt_or_error.
  1324. There followed a repeated execution of that same rule,
  1325. which called YYERROR1 again, and so on. */
  1326. save_filename save_lineno compstmt
  1327. { tree decl = current_function_decl;
  1328. DECL_SOURCE_FILE (decl) = $5;
  1329. DECL_SOURCE_LINE (decl) = $6;
  1330. finish_function (1, 1);
  1331. pop_function_context ();
  1332. add_decl_stmt (decl); }
  1333. ;
  1334. notype_nested_function:
  1335. notype_declarator
  1336. { if (pedantic)
  1337. pedwarn ("ISO C forbids nested functions");
  1338. push_function_context ();
  1339. if (! start_function (current_declspecs, $1,
  1340. all_prefix_attributes))
  1341. {
  1342. pop_function_context ();
  1343. YYERROR1;
  1344. }
  1345. }
  1346. old_style_parm_decls
  1347. { store_parm_decls (); }
  1348. /* This used to use compstmt_or_error.
  1349. That caused a bug with input `f(g) int g {}',
  1350. where the use of YYERROR1 above caused an error
  1351. which then was handled by compstmt_or_error.
  1352. There followed a repeated execution of that same rule,
  1353. which called YYERROR1 again, and so on. */
  1354. save_filename save_lineno compstmt
  1355. { tree decl = current_function_decl;
  1356. DECL_SOURCE_FILE (decl) = $5;
  1357. DECL_SOURCE_LINE (decl) = $6;
  1358. finish_function (1, 1);
  1359. pop_function_context ();
  1360. add_decl_stmt (decl); }
  1361. ;
  1362. /* Any kind of declarator (thus, all declarators allowed
  1363. after an explicit typespec). */
  1364. declarator:
  1365. after_type_declarator
  1366. | notype_declarator
  1367. ;
  1368. /* A declarator that is allowed only after an explicit typespec. */
  1369. after_type_declarator:
  1370. '(' maybe_attribute after_type_declarator ')'
  1371. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1372. | after_type_declarator '(' parmlist_or_identifiers %prec '.'
  1373. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1374. /* | after_type_declarator '(' error ')' %prec '.'
  1375. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1376. poplevel (0, 0, 0); } */
  1377. | after_type_declarator array_declarator %prec '.'
  1378. { $$ = set_array_declarator_type ($2, $1, 0); }
  1379. | '*' maybe_type_quals_attrs after_type_declarator %prec UNARY
  1380. { $$ = make_pointer_declarator ($2, $3); }
  1381. | TYPENAME
  1382. ;
  1383. /* Kinds of declarator that can appear in a parameter list
  1384. in addition to notype_declarator. This is like after_type_declarator
  1385. but does not allow a typedef name in parentheses as an identifier
  1386. (because it would conflict with a function with that typedef as arg). */
  1387. parm_declarator:
  1388. parm_declarator_starttypename
  1389. | parm_declarator_nostarttypename
  1390. ;
  1391. parm_declarator_starttypename:
  1392. parm_declarator_starttypename '(' parmlist_or_identifiers %prec '.'
  1393. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1394. /* | parm_declarator_starttypename '(' error ')' %prec '.'
  1395. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1396. poplevel (0, 0, 0); } */
  1397. | parm_declarator_starttypename array_declarator %prec '.'
  1398. { $$ = set_array_declarator_type ($2, $1, 0); }
  1399. | TYPENAME
  1400. ;
  1401. parm_declarator_nostarttypename:
  1402. parm_declarator_nostarttypename '(' parmlist_or_identifiers %prec '.'
  1403. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1404. /* | parm_declarator_nostarttypename '(' error ')' %prec '.'
  1405. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1406. poplevel (0, 0, 0); } */
  1407. | parm_declarator_nostarttypename array_declarator %prec '.'
  1408. { $$ = set_array_declarator_type ($2, $1, 0); }
  1409. | '*' maybe_type_quals_attrs parm_declarator_starttypename %prec UNARY
  1410. { $$ = make_pointer_declarator ($2, $3); }
  1411. | '*' maybe_type_quals_attrs parm_declarator_nostarttypename %prec UNARY
  1412. { $$ = make_pointer_declarator ($2, $3); }
  1413. | '(' maybe_attribute parm_declarator_nostarttypename ')'
  1414. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1415. ;
  1416. /* A declarator allowed whether or not there has been
  1417. an explicit typespec. These cannot redeclare a typedef-name. */
  1418. notype_declarator:
  1419. notype_declarator '(' parmlist_or_identifiers %prec '.'
  1420. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1421. /* | notype_declarator '(' error ')' %prec '.'
  1422. { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  1423. poplevel (0, 0, 0); } */
  1424. | '(' maybe_attribute notype_declarator ')'
  1425. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1426. | '*' maybe_type_quals_attrs notype_declarator %prec UNARY
  1427. { $$ = make_pointer_declarator ($2, $3); }
  1428. | notype_declarator array_declarator %prec '.'
  1429. { $$ = set_array_declarator_type ($2, $1, 0); }
  1430. | IDENTIFIER
  1431. ;
  1432. struct_head:
  1433. STRUCT
  1434. { $$ = NULL_TREE; }
  1435. | STRUCT attributes
  1436. { $$ = $2; }
  1437. ;
  1438. union_head:
  1439. UNION
  1440. { $$ = NULL_TREE; }
  1441. | UNION attributes
  1442. { $$ = $2; }
  1443. ;
  1444. enum_head:
  1445. ENUM
  1446. { $$ = NULL_TREE; }
  1447. | ENUM attributes
  1448. { $$ = $2; }
  1449. ;
  1450. /* structsp_attr: struct/union/enum specifiers that either
  1451. end with attributes, or are such that any following attributes would
  1452. be parsed as part of the struct/union/enum specifier.
  1453. structsp_nonattr: other struct/union/enum specifiers. */
  1454. structsp_attr:
  1455. struct_head identifier '{'
  1456. { $$ = start_struct (RECORD_TYPE, $2);
  1457. /* Start scope of tag before parsing components. */
  1458. }
  1459. component_decl_list '}' maybe_attribute
  1460. { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
  1461. | struct_head '{' component_decl_list '}' maybe_attribute
  1462. { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
  1463. $3, chainon ($1, $5));
  1464. }
  1465. | union_head identifier '{'
  1466. { $$ = start_struct (UNION_TYPE, $2); }
  1467. component_decl_list '}' maybe_attribute
  1468. { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
  1469. | union_head '{' component_decl_list '}' maybe_attribute
  1470. { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
  1471. $3, chainon ($1, $5));
  1472. }
  1473. | enum_head identifier '{'
  1474. { $$ = start_enum ($2); }
  1475. enumlist maybecomma_warn '}' maybe_attribute
  1476. { $$ = finish_enum ($<ttype>4, nreverse ($5),
  1477. chainon ($1, $8)); }
  1478. | enum_head '{'
  1479. { $$ = start_enum (NULL_TREE); }
  1480. enumlist maybecomma_warn '}' maybe_attribute
  1481. { $$ = finish_enum ($<ttype>3, nreverse ($4),
  1482. chainon ($1, $7)); }
  1483. ;
  1484. structsp_nonattr:
  1485. struct_head identifier
  1486. { $$ = xref_tag (RECORD_TYPE, $2); }
  1487. | union_head identifier
  1488. { $$ = xref_tag (UNION_TYPE, $2); }
  1489. | enum_head identifier
  1490. { $$ = xref_tag (ENUMERAL_TYPE, $2);
  1491. /* In ISO C, enumerated types can be referred to
  1492. only if already defined. */
  1493. if (pedantic && !COMPLETE_TYPE_P ($$))
  1494. pedwarn ("ISO C forbids forward references to `enum' types"); }
  1495. ;
  1496. maybecomma:
  1497. /* empty */
  1498. | ','
  1499. ;
  1500. maybecomma_warn:
  1501. /* empty */
  1502. | ','
  1503. { if (pedantic && ! flag_isoc99)
  1504. pedwarn ("comma at end of enumerator list"); }
  1505. ;
  1506. component_decl_list:
  1507. component_decl_list2
  1508. { $$ = $1; }
  1509. | component_decl_list2 component_decl
  1510. { $$ = chainon ($1, $2);
  1511. pedwarn ("no semicolon at end of struct or union"); }
  1512. ;
  1513. component_decl_list2: /* empty */
  1514. { $$ = NULL_TREE; }
  1515. | component_decl_list2 component_decl ';'
  1516. { $$ = chainon ($1, $2); }
  1517. | component_decl_list2 ';'
  1518. { if (pedantic)
  1519. pedwarn ("extra semicolon in struct or union specified"); }
  1520. ;
  1521. component_decl:
  1522. declspecs_nosc_ts setspecs components
  1523. { $$ = $3;
  1524. POP_DECLSPEC_STACK; }
  1525. | declspecs_nosc_ts setspecs save_filename save_lineno
  1526. {
  1527. /* Support for unnamed structs or unions as members of
  1528. structs or unions (which is [a] useful and [b] supports
  1529. MS P-SDK). */
  1530. if (pedantic)
  1531. pedwarn ("ISO C doesn't support unnamed structs/unions");
  1532. $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
  1533. POP_DECLSPEC_STACK; }
  1534. | declspecs_nosc_nots setspecs components_notype
  1535. { $$ = $3;
  1536. POP_DECLSPEC_STACK; }
  1537. | declspecs_nosc_nots
  1538. { if (pedantic)
  1539. pedwarn ("ISO C forbids member declarations with no members");
  1540. shadow_tag($1);
  1541. $$ = NULL_TREE; }
  1542. | error
  1543. { $$ = NULL_TREE; }
  1544. | extension component_decl
  1545. { $$ = $2;
  1546. RESTORE_WARN_FLAGS ($1); }
  1547. ;
  1548. components:
  1549. component_declarator
  1550. | components ',' maybe_resetattrs component_declarator
  1551. { $$ = chainon ($1, $4); }
  1552. ;
  1553. components_notype:
  1554. component_notype_declarator
  1555. | components_notype ',' maybe_resetattrs component_notype_declarator
  1556. { $$ = chainon ($1, $4); }
  1557. ;
  1558. component_declarator:
  1559. save_filename save_lineno declarator maybe_attribute
  1560. { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
  1561. decl_attributes (&$$, chainon ($4, all_prefix_attributes), 0); }
  1562. | save_filename save_lineno
  1563. declarator ':' expr_no_commas maybe_attribute
  1564. { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
  1565. decl_attributes (&$$, chainon ($6, all_prefix_attributes), 0); }
  1566. | save_filename save_lineno ':' expr_no_commas maybe_attribute
  1567. { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
  1568. decl_attributes (&$$, chainon ($5, all_prefix_attributes), 0); }
  1569. ;
  1570. component_notype_declarator:
  1571. save_filename save_lineno notype_declarator maybe_attribute
  1572. { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
  1573. decl_attributes (&$$, chainon ($4, all_prefix_attributes), 0); }
  1574. | save_filename save_lineno
  1575. notype_declarator ':' expr_no_commas maybe_attribute
  1576. { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
  1577. decl_attributes (&$$, chainon ($6, all_prefix_attributes), 0); }
  1578. | save_filename save_lineno ':' expr_no_commas maybe_attribute
  1579. { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
  1580. decl_attributes (&$$, chainon ($5, all_prefix_attributes), 0); }
  1581. ;
  1582. /* We chain the enumerators in reverse order.
  1583. They are put in forward order where enumlist is used.
  1584. (The order used to be significant, but no longer is so.
  1585. However, we still maintain the order, just to be clean.) */
  1586. enumlist:
  1587. enumerator
  1588. | enumlist ',' enumerator
  1589. { if ($1 == error_mark_node)
  1590. $$ = $1;
  1591. else
  1592. $$ = chainon ($3, $1); }
  1593. | error
  1594. { $$ = error_mark_node; }
  1595. ;
  1596. enumerator:
  1597. identifier
  1598. { $$ = build_enumerator ($1, NULL_TREE); }
  1599. | identifier '=' expr_no_commas
  1600. { $$ = build_enumerator ($1, $3); }
  1601. ;
  1602. typename:
  1603. declspecs_nosc
  1604. { pending_xref_error ();
  1605. $<ttype>$ = $1; }
  1606. absdcl
  1607. { $$ = build_tree_list ($<ttype>2, $3); }
  1608. ;
  1609. absdcl: /* an absolute declarator */
  1610. /* empty */
  1611. { $$ = NULL_TREE; }
  1612. | absdcl1
  1613. ;
  1614. absdcl_maybe_attribute: /* absdcl maybe_attribute, but not just attributes */
  1615. /* empty */
  1616. { $$ = build_tree_list (build_tree_list (current_declspecs,
  1617. NULL_TREE),
  1618. all_prefix_attributes); }
  1619. | absdcl1
  1620. { $$ = build_tree_list (build_tree_list (current_declspecs,
  1621. $1),
  1622. all_prefix_attributes); }
  1623. | absdcl1_noea attributes
  1624. { $$ = build_tree_list (build_tree_list (current_declspecs,
  1625. $1),
  1626. chainon ($2, all_prefix_attributes)); }
  1627. ;
  1628. absdcl1: /* a nonempty absolute declarator */
  1629. absdcl1_ea
  1630. | absdcl1_noea
  1631. ;
  1632. absdcl1_noea:
  1633. direct_absdcl1
  1634. | '*' maybe_type_quals_attrs absdcl1_noea
  1635. { $$ = make_pointer_declarator ($2, $3); }
  1636. ;
  1637. absdcl1_ea:
  1638. '*' maybe_type_quals_attrs
  1639. { $$ = make_pointer_declarator ($2, NULL_TREE); }
  1640. | '*' maybe_type_quals_attrs absdcl1_ea
  1641. { $$ = make_pointer_declarator ($2, $3); }
  1642. ;
  1643. direct_absdcl1:
  1644. '(' maybe_attribute absdcl1 ')'
  1645. { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
  1646. | direct_absdcl1 '(' parmlist
  1647. { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  1648. | direct_absdcl1 array_declarator
  1649. { $$ = set_array_declarator_type ($2, $1, 1); }
  1650. | '(' parmlist
  1651. { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
  1652. | array_declarator
  1653. { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
  1654. ;
  1655. /* The [...] part of a declarator for an array type. */
  1656. array_declarator:
  1657. '[' expr ']'
  1658. { $$ = build_array_declarator ($2, NULL_TREE, 0, 0); }
  1659. | '[' declspecs_nosc expr ']'
  1660. { $$ = build_array_declarator ($3, $2, 0, 0); }
  1661. | '[' ']'
  1662. { $$ = build_array_declarator (NULL_TREE, NULL_TREE, 0, 0); }
  1663. | '[' declspecs_nosc ']'
  1664. { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
  1665. | '[' '*' ']'
  1666. { $$ = build_array_declarator (NULL_TREE, NULL_TREE, 0, 1); }
  1667. | '[' declspecs_nosc '*' ']'
  1668. { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
  1669. | '[' SCSPEC expr ']'
  1670. { if (C_RID_CODE ($2) != RID_STATIC)
  1671. error ("storage class specifier in array declarator");
  1672. $$ = build_array_declarator ($3, NULL_TREE, 1, 0); }
  1673. | '[' SCSPEC declspecs_nosc expr ']'
  1674. { if (C_RID_CODE ($2) != RID_STATIC)
  1675. error ("storage class specifier in array declarator");
  1676. $$ = build_array_declarator ($4, $3, 1, 0); }
  1677. | '[' declspecs_nosc SCSPEC expr ']'
  1678. { if (C_RID_CODE ($3) != RID_STATIC)
  1679. error ("storage class specifier in array declarator");
  1680. $$ = build_array_declarator ($4, $2, 1, 0); }
  1681. ;
  1682. /* A nonempty series of declarations and statements (possibly followed by
  1683. some labels) that can form the body of a compound statement.
  1684. NOTE: we don't allow labels on declarations; this might seem like a
  1685. natural extension, but there would be a conflict between attributes
  1686. on the label and prefix attributes on the declaration. */
  1687. stmts_and_decls:
  1688. lineno_stmt_decl_or_labels_ending_stmt
  1689. | lineno_stmt_decl_or_labels_ending_decl
  1690. | lineno_stmt_decl_or_labels_ending_label
  1691. {
  1692. pedwarn ("deprecated use of label at end of compound statement");
  1693. }
  1694. | lineno_stmt_decl_or_labels_ending_error
  1695. ;
  1696. lineno_stmt_decl_or_labels_ending_stmt:
  1697. lineno_stmt
  1698. | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
  1699. | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
  1700. | lineno_stmt_decl_or_labels_ending_label lineno_stmt
  1701. | lineno_stmt_decl_or_labels_ending_error lineno_stmt
  1702. ;
  1703. lineno_stmt_decl_or_labels_ending_decl:
  1704. lineno_decl
  1705. | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
  1706. { if (pedantic && !flag_isoc99)
  1707. pedwarn ("ISO C89 forbids mixed declarations and code"); }
  1708. | lineno_stmt_decl_or_labels_ending_decl lineno_decl
  1709. | lineno_stmt_decl_or_labels_ending_error lineno_decl
  1710. ;
  1711. lineno_stmt_decl_or_labels_ending_label:
  1712. lineno_label
  1713. | lineno_stmt_decl_or_labels_ending_stmt lineno_label
  1714. | lineno_stmt_decl_or_labels_ending_decl lineno_label
  1715. | lineno_stmt_decl_or_labels_ending_label lineno_label
  1716. | lineno_stmt_decl_or_labels_ending_error lineno_label
  1717. ;
  1718. lineno_stmt_decl_or_labels_ending_error:
  1719. errstmt
  1720. | lineno_stmt_decl_or_labels errstmt
  1721. ;
  1722. lineno_stmt_decl_or_labels:
  1723. lineno_stmt_decl_or_labels_ending_stmt
  1724. | lineno_stmt_decl_or_labels_ending_decl
  1725. | lineno_stmt_decl_or_labels_ending_label
  1726. | lineno_stmt_decl_or_labels_ending_error
  1727. ;
  1728. errstmt: error ';'
  1729. ;
  1730. pushlevel: /* empty */
  1731. { pushlevel (0);
  1732. clear_last_expr ();
  1733. add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
  1734. }
  1735. ;
  1736. poplevel: /* empty */
  1737. { $$ = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); }
  1738. ;
  1739. /* Start and end blocks created for the new scopes of C99. */
  1740. c99_block_start: /* empty */
  1741. { if (flag_isoc99)
  1742. {
  1743. $$ = c_begin_compound_stmt ();
  1744. pushlevel (0);
  1745. clear_last_expr ();
  1746. add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
  1747. }
  1748. else
  1749. $$ = NULL_TREE;
  1750. }
  1751. ;
  1752. /* Productions using c99_block_start and c99_block_end will need to do what's
  1753. in compstmt: RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); $$ = $2; where
  1754. $1 is the value of c99_block_start and $2 of c99_block_end. */
  1755. c99_block_end: /* empty */
  1756. { if (flag_isoc99)
  1757. {
  1758. tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
  1759. $$ = poplevel (kept_level_p (), 0, 0);
  1760. SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt))
  1761. = SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt))
  1762. = $$;
  1763. }
  1764. else
  1765. $$ = NULL_TREE; }
  1766. ;
  1767. /* Read zero or more forward-declarations for labels
  1768. that nested functions can jump to. */
  1769. maybe_label_decls:
  1770. /* empty */
  1771. | label_decls
  1772. { if (pedantic)
  1773. pedwarn ("ISO C forbids label declarations"); }
  1774. ;
  1775. label_decls:
  1776. label_decl
  1777. | label_decls label_decl
  1778. ;
  1779. label_decl:
  1780. LABEL identifiers_or_typenames ';'
  1781. { tree link;
  1782. for (link = $2; link; link = TREE_CHAIN (link))
  1783. {
  1784. tree label = shadow_label (TREE_VALUE (link));
  1785. C_DECLARED_LABEL_FLAG (label) = 1;
  1786. add_decl_stmt (label);
  1787. }
  1788. }
  1789. ;
  1790. /* This is the body of a function definition.
  1791. It causes syntax errors to ignore to the next openbrace. */
  1792. compstmt_or_error:
  1793. compstmt
  1794. {}
  1795. | error compstmt
  1796. ;
  1797. compstmt_start: '{' { compstmt_count++;
  1798. $$ = c_begin_compound_stmt (); }
  1799. ;
  1800. compstmt_nostart: '}'
  1801. { $$ = convert (void_type_node, integer_zero_node); }
  1802. | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
  1803. { $$ = poplevel (kept_level_p (), 1, 0);
  1804. SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
  1805. = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
  1806. = $$; }
  1807. ;
  1808. compstmt_contents_nonempty:
  1809. stmts_and_decls
  1810. | error
  1811. ;
  1812. compstmt_primary_start:
  1813. '(' '{'
  1814. { if (current_function_decl == 0)
  1815. {
  1816. error ("braced-group within expression allowed only inside a function");
  1817. YYERROR;
  1818. }
  1819. /* We must force a BLOCK for this level
  1820. so that, if it is not expanded later,
  1821. there is a way to turn off the entire subtree of blocks
  1822. that are contained in it. */
  1823. keep_next_level ();
  1824. push_label_level ();
  1825. compstmt_count++;
  1826. $$ = add_stmt (build_stmt (COMPOUND_STMT, last_tree));
  1827. }
  1828. ;
  1829. compstmt: compstmt_start compstmt_nostart
  1830. { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
  1831. last_expr_type = NULL_TREE;
  1832. $$ = $1; }
  1833. ;
  1834. /* Value is number of statements counted as of the closeparen. */
  1835. simple_if:
  1836. if_prefix c99_block_lineno_labeled_stmt
  1837. { c_finish_then (); }
  1838. /* Make sure c_expand_end_cond is run once
  1839. for each call to c_expand_start_cond.
  1840. Otherwise a crash is likely. */
  1841. | if_prefix error
  1842. ;
  1843. if_prefix:
  1844. /* We must build the IF_STMT node before parsing its
  1845. condition so that STMT_LINENO refers to the line
  1846. containing the "if", and not the line containing
  1847. the close-parenthesis.
  1848. c_begin_if_stmt returns the IF_STMT node, which
  1849. we later pass to c_expand_start_cond to fill
  1850. in the condition and other tidbits. */
  1851. IF
  1852. { $<ttype>$ = c_begin_if_stmt (); }
  1853. '(' expr ')'
  1854. { c_expand_start_cond (truthvalue_conversion ($4),
  1855. compstmt_count,$<ttype>2);
  1856. $<itype>$ = stmt_count;
  1857. if_stmt_file = $<filename>-2;
  1858. if_stmt_line = $<lineno>-1; }
  1859. ;
  1860. /* This is a subroutine of stmt.
  1861. It is used twice, once for valid DO statements
  1862. and once for catching errors in parsing the end test. */
  1863. do_stmt_start:
  1864. DO
  1865. { stmt_count++;
  1866. compstmt_count++;
  1867. $<ttype>$
  1868. = add_stmt (build_stmt (DO_STMT, NULL_TREE,
  1869. NULL_TREE));
  1870. /* In the event that a parse error prevents
  1871. parsing the complete do-statement, set the
  1872. condition now. Otherwise, we can get crashes at
  1873. RTL-generation time. */
  1874. DO_COND ($<ttype>$) = error_mark_node; }
  1875. c99_block_lineno_labeled_stmt WHILE
  1876. { $$ = $<ttype>2;
  1877. RECHAIN_STMTS ($$, DO_BODY ($$)); }
  1878. ;
  1879. /* The forced readahead in here is because we might be at the end of a
  1880. line, and the line and file won't be bumped until yylex absorbs the
  1881. first token on the next line. */
  1882. save_filename:
  1883. { if (yychar == YYEMPTY)
  1884. yychar = YYLEX;
  1885. $$ = input_filename; }
  1886. ;
  1887. save_lineno:
  1888. { if (yychar == YYEMPTY)
  1889. yychar = YYLEX;
  1890. $$ = lineno; }
  1891. ;
  1892. lineno_labeled_stmt:
  1893. lineno_stmt
  1894. | lineno_label lineno_labeled_stmt
  1895. ;
  1896. /* Like lineno_labeled_stmt, but a block in C99. */
  1897. c99_block_lineno_labeled_stmt:
  1898. c99_block_start lineno_labeled_stmt c99_block_end
  1899. { if (flag_isoc99)
  1900. RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); }
  1901. ;
  1902. lineno_stmt:
  1903. save_filename save_lineno stmt
  1904. { if ($3)
  1905. {
  1906. STMT_LINENO ($3) = $2;
  1907. /* ??? We currently have no way of recording
  1908. the filename for a statement. This probably
  1909. matters little in practice at the moment,
  1910. but I suspect that problems will occur when
  1911. doing inlining at the tree level. */
  1912. }
  1913. }
  1914. ;
  1915. lineno_label:
  1916. save_filename save_lineno label
  1917. { if ($3)
  1918. {
  1919. STMT_LINENO ($3) = $2;
  1920. }
  1921. }
  1922. ;
  1923. select_or_iter_stmt:
  1924. simple_if ELSE
  1925. { c_expand_start_else ();
  1926. $<itype>1 = stmt_count; }
  1927. c99_block_lineno_labeled_stmt
  1928. { c_finish_else ();
  1929. c_expand_end_cond ();
  1930. if (extra_warnings && stmt_count == $<itype>1)
  1931. warning ("empty body in an else-statement"); }
  1932. | simple_if %prec IF
  1933. { c_expand_end_cond ();
  1934. /* This warning is here instead of in simple_if, because we
  1935. do not want a warning if an empty if is followed by an
  1936. else statement. Increment stmt_count so we don't
  1937. give a second error if this is a nested `if'. */
  1938. if (extra_warnings && stmt_count++ == $<itype>1)
  1939. warning_with_file_and_line (if_stmt_file, if_stmt_line,
  1940. "empty body in an if-statement"); }
  1941. /* Make sure c_expand_end_cond is run once
  1942. for each call to c_expand_start_cond.
  1943. Otherwise a crash is likely. */
  1944. | simple_if ELSE error
  1945. { c_expand_end_cond (); }
  1946. /* We must build the WHILE_STMT node before parsing its
  1947. condition so that STMT_LINENO refers to the line
  1948. containing the "while", and not the line containing
  1949. the close-parenthesis.
  1950. c_begin_while_stmt returns the WHILE_STMT node, which
  1951. we later pass to c_finish_while_stmt_cond to fill
  1952. in the condition and other tidbits. */
  1953. | WHILE
  1954. { stmt_count++;
  1955. $<ttype>$ = c_begin_while_stmt (); }
  1956. '(' expr ')'
  1957. { $4 = truthvalue_conversion ($4);
  1958. c_finish_while_stmt_cond (truthvalue_conversion ($4),
  1959. $<ttype>2);
  1960. $<ttype>$ = add_stmt ($<ttype>2); }
  1961. c99_block_lineno_labeled_stmt
  1962. { RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
  1963. | do_stmt_start
  1964. '(' expr ')' ';'
  1965. { DO_COND ($1) = truthvalue_conversion ($3); }
  1966. | do_stmt_start error
  1967. { }
  1968. | FOR
  1969. { $<ttype>$ = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
  1970. NULL_TREE, NULL_TREE);
  1971. add_stmt ($<ttype>$); }
  1972. '(' for_init_stmt
  1973. { stmt_count++;
  1974. RECHAIN_STMTS ($<ttype>2, FOR_INIT_STMT ($<ttype>2)); }
  1975. xexpr ';'
  1976. { if ($6)
  1977. FOR_COND ($<ttype>2) = truthvalue_conversion ($6); }
  1978. xexpr ')'
  1979. { FOR_EXPR ($<ttype>2) = $9; }
  1980. c99_block_lineno_labeled_stmt
  1981. { RECHAIN_STMTS ($<ttype>2, FOR_BODY ($<ttype>2)); }
  1982. | SWITCH '(' expr ')'
  1983. { stmt_count++;
  1984. $<ttype>$ = c_start_case ($3); }
  1985. c99_block_lineno_labeled_stmt
  1986. { c_finish_case (); }
  1987. ;
  1988. for_init_stmt:
  1989. xexpr ';'
  1990. { add_stmt (build_stmt (EXPR_STMT, $1)); }
  1991. | decl
  1992. { check_for_loop_decls (); }
  1993. ;
  1994. /* Parse a single real statement, not including any labels. */
  1995. stmt:
  1996. compstmt
  1997. { stmt_count++; $$ = $1; }
  1998. | expr ';'
  1999. { stmt_count++;
  2000. $$ = c_expand_expr_stmt ($1); }
  2001. | c99_block_start select_or_iter_stmt c99_block_end
  2002. { if (flag_isoc99)
  2003. RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
  2004. $$ = NULL_TREE; }
  2005. | BREAK ';'
  2006. { stmt_count++;
  2007. $$ = add_stmt (build_break_stmt ()); }
  2008. | CONTINUE ';'
  2009. { stmt_count++;
  2010. $$ = add_stmt (build_continue_stmt ()); }
  2011. | RETURN ';'
  2012. { stmt_count++;
  2013. $$ = c_expand_return (NULL_TREE); }
  2014. | RETURN expr ';'
  2015. { stmt_count++;
  2016. $$ = c_expand_return ($2); }
  2017. | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
  2018. { stmt_count++;
  2019. $$ = simple_asm_stmt ($4); }
  2020. /* This is the case with just output operands. */
  2021. | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
  2022. { stmt_count++;
  2023. $$ = build_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
  2024. /* This is the case with input operands as well. */
  2025. | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
  2026. asm_operands ')' ';'
  2027. { stmt_count++;
  2028. $$ = build_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
  2029. /* This is the case with clobbered registers as well. */
  2030. | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
  2031. asm_operands ':' asm_clobbers ')' ';'
  2032. { stmt_count++;
  2033. $$ = build_asm_stmt ($2, $4, $6, $8, $10); }
  2034. | GOTO identifier ';'
  2035. { tree decl;
  2036. stmt_count++;
  2037. decl = lookup_label ($2);
  2038. if (decl != 0)
  2039. {
  2040. TREE_USED (decl) = 1;
  2041. $$ = add_stmt (build_stmt (GOTO_STMT, decl));
  2042. }
  2043. else
  2044. $$ = NULL_TREE;
  2045. }
  2046. | GOTO '*' expr ';'
  2047. { if (pedantic)
  2048. pedwarn ("ISO C forbids `goto *expr;'");
  2049. stmt_count++;
  2050. $3 = convert (ptr_type_node, $3);
  2051. $$ = add_stmt (build_stmt (GOTO_STMT, $3)); }
  2052. | ';'
  2053. { $$ = NULL_TREE; }
  2054. ;
  2055. /* Any kind of label, including jump labels and case labels.
  2056. ANSI C accepts labels only before statements, but we allow them
  2057. also at the end of a compound statement. */
  2058. label: CASE expr_no_commas ':'
  2059. { stmt_count++;
  2060. $$ = do_case ($2, NULL_TREE); }
  2061. | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
  2062. { stmt_count++;
  2063. $$ = do_case ($2, $4); }
  2064. | DEFAULT ':'
  2065. { stmt_count++;
  2066. $$ = do_case (NULL_TREE, NULL_TREE); }
  2067. | identifier save_filename save_lineno ':' maybe_attribute
  2068. { tree label = define_label ($2, $3, $1);
  2069. stmt_count++;
  2070. if (label)
  2071. {
  2072. decl_attributes (&label, $5, 0);
  2073. $$ = add_stmt (build_stmt (LABEL_STMT, label));
  2074. }
  2075. else
  2076. $$ = NULL_TREE;
  2077. }
  2078. ;
  2079. /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
  2080. maybe_type_qual:
  2081. /* empty */
  2082. { emit_line_note (input_filename, lineno);
  2083. $$ = NULL_TREE; }
  2084. | TYPE_QUAL
  2085. { emit_line_note (input_filename, lineno); }
  2086. ;
  2087. xexpr:
  2088. /* empty */
  2089. { $$ = NULL_TREE; }
  2090. | expr
  2091. ;
  2092. /* These are the operands other than the first string and colon
  2093. in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
  2094. asm_operands: /* empty */
  2095. { $$ = NULL_TREE; }
  2096. | nonnull_asm_operands
  2097. ;
  2098. nonnull_asm_operands:
  2099. asm_operand
  2100. | nonnull_asm_operands ',' asm_operand
  2101. { $$ = chainon ($1, $3); }
  2102. ;
  2103. asm_operand:
  2104. STRING '(' expr ')'
  2105. { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
  2106. | '[' identifier ']' STRING '(' expr ')'
  2107. { $$ = build_tree_list (build_tree_list ($2, $4), $6); }
  2108. ;
  2109. asm_clobbers:
  2110. string
  2111. { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
  2112. | asm_clobbers ',' string
  2113. { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
  2114. ;
  2115. /* This is what appears inside the parens in a function declarator.
  2116. Its value is a list of ..._TYPE nodes. Attributes must appear here
  2117. to avoid a conflict with their appearance after an open parenthesis
  2118. in an abstract declarator, as in
  2119. "void bar (int (__attribute__((__mode__(SI))) int foo));". */
  2120. parmlist:
  2121. maybe_attribute
  2122. { pushlevel (0);
  2123. clear_parm_order ();
  2124. declare_parm_level (0); }
  2125. parmlist_1
  2126. { $$ = $3;
  2127. parmlist_tags_warning ();
  2128. poplevel (0, 0, 0); }
  2129. ;
  2130. parmlist_1:
  2131. parmlist_2 ')'
  2132. | parms ';'
  2133. { tree parm;
  2134. if (pedantic)
  2135. pedwarn ("ISO C forbids forward parameter declarations");
  2136. /* Mark the forward decls as such. */
  2137. for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
  2138. TREE_ASM_WRITTEN (parm) = 1;
  2139. clear_parm_order (); }
  2140. maybe_attribute
  2141. { /* Dummy action so attributes are in known place
  2142. on parser stack. */ }
  2143. parmlist_1
  2144. { $$ = $6; }
  2145. | error ')'
  2146. { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
  2147. ;
  2148. /* This is what appears inside the parens in a function declarator.
  2149. Is value is represented in the format that grokdeclarator expects. */
  2150. parmlist_2: /* empty */
  2151. { $$ = get_parm_info (0); }
  2152. | ELLIPSIS
  2153. { $$ = get_parm_info (0);
  2154. /* Gcc used to allow this as an extension. However, it does
  2155. not work for all targets, and thus has been disabled.
  2156. Also, since func (...) and func () are indistinguishable,
  2157. it caused problems with the code in expand_builtin which
  2158. tries to verify that BUILT_IN_NEXT_ARG is being used
  2159. correctly. */
  2160. error ("ISO C requires a named argument before `...'");
  2161. }
  2162. | parms
  2163. { $$ = get_parm_info (1); }
  2164. | parms ',' ELLIPSIS
  2165. { $$ = get_parm_info (0); }
  2166. ;
  2167. parms:
  2168. firstparm
  2169. { push_parm_decl ($1); }
  2170. | parms ',' parm
  2171. { push_parm_decl ($3); }
  2172. ;
  2173. /* A single parameter declaration or parameter type name,
  2174. as found in a parmlist. */
  2175. parm:
  2176. declspecs_ts setspecs parm_declarator maybe_attribute
  2177. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2178. $3),
  2179. chainon ($4, all_prefix_attributes));
  2180. POP_DECLSPEC_STACK; }
  2181. | declspecs_ts setspecs notype_declarator maybe_attribute
  2182. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2183. $3),
  2184. chainon ($4, all_prefix_attributes));
  2185. POP_DECLSPEC_STACK; }
  2186. | declspecs_ts setspecs absdcl_maybe_attribute
  2187. { $$ = $3;
  2188. POP_DECLSPEC_STACK; }
  2189. | declspecs_nots setspecs notype_declarator maybe_attribute
  2190. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2191. $3),
  2192. chainon ($4, all_prefix_attributes));
  2193. POP_DECLSPEC_STACK; }
  2194. | declspecs_nots setspecs absdcl_maybe_attribute
  2195. { $$ = $3;
  2196. POP_DECLSPEC_STACK; }
  2197. ;
  2198. /* The first parm, which must suck attributes from off the top of the parser
  2199. stack. */
  2200. firstparm:
  2201. declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
  2202. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2203. $3),
  2204. chainon ($4, all_prefix_attributes));
  2205. POP_DECLSPEC_STACK; }
  2206. | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
  2207. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2208. $3),
  2209. chainon ($4, all_prefix_attributes));
  2210. POP_DECLSPEC_STACK; }
  2211. | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
  2212. { $$ = $3;
  2213. POP_DECLSPEC_STACK; }
  2214. | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
  2215. { $$ = build_tree_list (build_tree_list (current_declspecs,
  2216. $3),
  2217. chainon ($4, all_prefix_attributes));
  2218. POP_DECLSPEC_STACK; }
  2219. | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
  2220. { $$ = $3;
  2221. POP_DECLSPEC_STACK; }
  2222. ;
  2223. setspecs_fp:
  2224. setspecs
  2225. { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
  2226. all_prefix_attributes = prefix_attributes; }
  2227. ;
  2228. /* This is used in a function definition
  2229. where either a parmlist or an identifier list is ok.
  2230. Its value is a list of ..._TYPE nodes or a list of identifiers. */
  2231. parmlist_or_identifiers:
  2232. maybe_attribute
  2233. { pushlevel (0);
  2234. clear_parm_order ();
  2235. declare_parm_level (1); }
  2236. parmlist_or_identifiers_1
  2237. { $$ = $3;
  2238. parmlist_tags_warning ();
  2239. poplevel (0, 0, 0); }
  2240. ;
  2241. parmlist_or_identifiers_1:
  2242. parmlist_1
  2243. | identifiers ')'
  2244. { tree t;
  2245. for (t = $1; t; t = TREE_CHAIN (t))
  2246. if (TREE_VALUE (t) == NULL_TREE)
  2247. error ("`...' in old-style identifier list");
  2248. $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
  2249. /* Make sure we have a parmlist after attributes. */
  2250. if ($<ttype>-1 != 0
  2251. && (TREE_CODE ($$) != TREE_LIST
  2252. || TREE_PURPOSE ($$) == 0
  2253. || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
  2254. YYERROR1;
  2255. }
  2256. ;
  2257. /* A nonempty list of identifiers. */
  2258. identifiers:
  2259. IDENTIFIER
  2260. { $$ = build_tree_list (NULL_TREE, $1); }
  2261. | identifiers ',' IDENTIFIER
  2262. { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2263. ;
  2264. /* A nonempty list of identifiers, including typenames. */
  2265. identifiers_or_typenames:
  2266. identifier
  2267. { $$ = build_tree_list (NULL_TREE, $1); }
  2268. | identifiers_or_typenames ',' identifier
  2269. { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2270. ;
  2271. extension:
  2272. EXTENSION
  2273. { $$ = SAVE_WARN_FLAGS();
  2274. pedantic = 0;
  2275. warn_pointer_arith = 0;
  2276. warn_traditional = 0; }
  2277. ;
  2278. %%
  2279. /* yylex() is a thin wrapper around c_lex(), all it does is translate
  2280. cpplib.h's token codes into yacc's token codes. */
  2281. static enum cpp_ttype last_token;
  2282. /* The reserved keyword table. */
  2283. struct resword
  2284. {
  2285. const char *word;
  2286. ENUM_BITFIELD(rid) rid : 16;
  2287. unsigned int disable : 16;
  2288. };
  2289. /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
  2290. _true_. */
  2291. #define D_TRAD 0x01 /* not in traditional C */
  2292. #define D_C89 0x02 /* not in C89 */
  2293. #define D_EXT 0x04 /* GCC extension */
  2294. #define D_EXT89 0x08 /* GCC extension incorporated in C99 */
  2295. #define D_OBJC 0x10 /* Objective C only */
  2296. static const struct resword reswords[] =
  2297. {
  2298. { "_Bool", RID_BOOL, 0 },
  2299. { "_Complex", RID_COMPLEX, 0 },
  2300. { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
  2301. { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
  2302. { "__alignof", RID_ALIGNOF, 0 },
  2303. { "__alignof__", RID_ALIGNOF, 0 },
  2304. { "__asm", RID_ASM, 0 },
  2305. { "__asm__", RID_ASM, 0 },
  2306. { "__attribute", RID_ATTRIBUTE, 0 },
  2307. { "__attribute__", RID_ATTRIBUTE, 0 },
  2308. { "__bounded", RID_BOUNDED, 0 },
  2309. { "__bounded__", RID_BOUNDED, 0 },
  2310. { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
  2311. { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
  2312. { "__builtin_va_arg", RID_VA_ARG, 0 },
  2313. { "__complex", RID_COMPLEX, 0 },
  2314. { "__complex__", RID_COMPLEX, 0 },
  2315. { "__const", RID_CONST, 0 },
  2316. { "__const__", RID_CONST, 0 },
  2317. { "__extension__", RID_EXTENSION, 0 },
  2318. { "__func__", RID_C99_FUNCTION_NAME, 0 },
  2319. { "__imag", RID_IMAGPART, 0 },
  2320. { "__imag__", RID_IMAGPART, 0 },
  2321. { "__inline", RID_INLINE, 0 },
  2322. { "__inline__", RID_INLINE, 0 },
  2323. { "__label__", RID_LABEL, 0 },
  2324. { "__ptrbase", RID_PTRBASE, 0 },
  2325. { "__ptrbase__", RID_PTRBASE, 0 },
  2326. { "__ptrextent", RID_PTREXTENT, 0 },
  2327. { "__ptrextent__", RID_PTREXTENT, 0 },
  2328. { "__ptrvalue", RID_PTRVALUE, 0 },
  2329. { "__ptrvalue__", RID_PTRVALUE, 0 },
  2330. { "__real", RID_REALPART, 0 },
  2331. { "__real__", RID_REALPART, 0 },
  2332. { "__restrict", RID_RESTRICT, 0 },
  2333. { "__restrict__", RID_RESTRICT, 0 },
  2334. { "__signed", RID_SIGNED, 0 },
  2335. { "__signed__", RID_SIGNED, 0 },
  2336. { "__typeof", RID_TYPEOF, 0 },
  2337. { "__typeof__", RID_TYPEOF, 0 },
  2338. { "__unbounded", RID_UNBOUNDED, 0 },
  2339. { "__unbounded__", RID_UNBOUNDED, 0 },
  2340. { "__volatile", RID_VOLATILE, 0 },
  2341. { "__volatile__", RID_VOLATILE, 0 },
  2342. { "asm", RID_ASM, D_EXT },
  2343. { "auto", RID_AUTO, 0 },
  2344. { "break", RID_BREAK, 0 },
  2345. { "case", RID_CASE, 0 },
  2346. { "char", RID_CHAR, 0 },
  2347. { "const", RID_CONST, D_TRAD },
  2348. { "continue", RID_CONTINUE, 0 },
  2349. { "default", RID_DEFAULT, 0 },
  2350. { "do", RID_DO, 0 },
  2351. { "double", RID_DOUBLE, 0 },
  2352. { "else", RID_ELSE, 0 },
  2353. { "enum", RID_ENUM, 0 },
  2354. { "extern", RID_EXTERN, 0 },
  2355. { "float", RID_FLOAT, 0 },
  2356. { "for", RID_FOR, 0 },
  2357. { "goto", RID_GOTO, 0 },
  2358. { "if", RID_IF, 0 },
  2359. { "inline", RID_INLINE, D_TRAD|D_EXT89 },
  2360. { "int", RID_INT, 0 },
  2361. { "long", RID_LONG, 0 },
  2362. { "register", RID_REGISTER, 0 },
  2363. { "restrict", RID_RESTRICT, D_TRAD|D_C89 },
  2364. { "return", RID_RETURN, 0 },
  2365. { "short", RID_SHORT, 0 },
  2366. { "signed", RID_SIGNED, D_TRAD },
  2367. { "sizeof", RID_SIZEOF, 0 },
  2368. { "static", RID_STATIC, 0 },
  2369. { "struct", RID_STRUCT, 0 },
  2370. { "switch", RID_SWITCH, 0 },
  2371. { "typedef", RID_TYPEDEF, 0 },
  2372. { "typeof", RID_TYPEOF, D_TRAD|D_EXT },
  2373. { "union", RID_UNION, 0 },
  2374. { "unsigned", RID_UNSIGNED, 0 },
  2375. { "void", RID_VOID, 0 },
  2376. { "volatile", RID_VOLATILE, D_TRAD },
  2377. { "while", RID_WHILE, 0 },
  2378. };
  2379. #define N_reswords (sizeof reswords / sizeof (struct resword))
  2380. /* Table mapping from RID_* constants to yacc token numbers.
  2381. Unfortunately we have to have entries for all the keywords in all
  2382. three languages. */
  2383. static const short rid_to_yy[RID_MAX] =
  2384. {
  2385. /* RID_STATIC */ SCSPEC,
  2386. /* RID_UNSIGNED */ TYPESPEC,
  2387. /* RID_LONG */ TYPESPEC,
  2388. /* RID_CONST */ TYPE_QUAL,
  2389. /* RID_EXTERN */ SCSPEC,
  2390. /* RID_REGISTER */ SCSPEC,
  2391. /* RID_TYPEDEF */ SCSPEC,
  2392. /* RID_SHORT */ TYPESPEC,
  2393. /* RID_INLINE */ SCSPEC,
  2394. /* RID_VOLATILE */ TYPE_QUAL,
  2395. /* RID_SIGNED */ TYPESPEC,
  2396. /* RID_AUTO */ SCSPEC,
  2397. /* RID_RESTRICT */ TYPE_QUAL,
  2398. /* C extensions */
  2399. /* RID_BOUNDED */ TYPE_QUAL,
  2400. /* RID_UNBOUNDED */ TYPE_QUAL,
  2401. /* RID_COMPLEX */ TYPESPEC,
  2402. /* C++ */
  2403. /* RID_FRIEND */ 0,
  2404. /* RID_VIRTUAL */ 0,
  2405. /* RID_EXPLICIT */ 0,
  2406. /* RID_EXPORT */ 0,
  2407. /* RID_MUTABLE */ 0,
  2408. /* ObjC */
  2409. /* RID_IN */ TYPE_QUAL,
  2410. /* RID_OUT */ TYPE_QUAL,
  2411. /* RID_INOUT */ TYPE_QUAL,
  2412. /* RID_BYCOPY */ TYPE_QUAL,
  2413. /* RID_BYREF */ TYPE_QUAL,
  2414. /* RID_ONEWAY */ TYPE_QUAL,
  2415. /* C */
  2416. /* RID_INT */ TYPESPEC,
  2417. /* RID_CHAR */ TYPESPEC,
  2418. /* RID_FLOAT */ TYPESPEC,
  2419. /* RID_DOUBLE */ TYPESPEC,
  2420. /* RID_VOID */ TYPESPEC,
  2421. /* RID_ENUM */ ENUM,
  2422. /* RID_STRUCT */ STRUCT,
  2423. /* RID_UNION */ UNION,
  2424. /* RID_IF */ IF,
  2425. /* RID_ELSE */ ELSE,
  2426. /* RID_WHILE */ WHILE,
  2427. /* RID_DO */ DO,
  2428. /* RID_FOR */ FOR,
  2429. /* RID_SWITCH */ SWITCH,
  2430. /* RID_CASE */ CASE,
  2431. /* RID_DEFAULT */ DEFAULT,
  2432. /* RID_BREAK */ BREAK,
  2433. /* RID_CONTINUE */ CONTINUE,
  2434. /* RID_RETURN */ RETURN,
  2435. /* RID_GOTO */ GOTO,
  2436. /* RID_SIZEOF */ SIZEOF,
  2437. /* C extensions */
  2438. /* RID_ASM */ ASM_KEYWORD,
  2439. /* RID_TYPEOF */ TYPEOF,
  2440. /* RID_ALIGNOF */ ALIGNOF,
  2441. /* RID_ATTRIBUTE */ ATTRIBUTE,
  2442. /* RID_VA_ARG */ VA_ARG,
  2443. /* RID_EXTENSION */ EXTENSION,
  2444. /* RID_IMAGPART */ IMAGPART,
  2445. /* RID_REALPART */ REALPART,
  2446. /* RID_LABEL */ LABEL,
  2447. /* RID_PTRBASE */ PTR_BASE,
  2448. /* RID_PTREXTENT */ PTR_EXTENT,
  2449. /* RID_PTRVALUE */ PTR_VALUE,
  2450. /* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
  2451. /* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
  2452. /* RID_FUNCTION_NAME */ STRING_FUNC_NAME,
  2453. /* RID_PRETTY_FUNCTION_NAME */ STRING_FUNC_NAME,
  2454. /* RID_C99_FUNCTION_NAME */ VAR_FUNC_NAME,
  2455. /* C++ */
  2456. /* RID_BOOL */ TYPESPEC,
  2457. /* RID_WCHAR */ 0,
  2458. /* RID_CLASS */ 0,
  2459. /* RID_PUBLIC */ 0,
  2460. /* RID_PRIVATE */ 0,
  2461. /* RID_PROTECTED */ 0,
  2462. /* RID_TEMPLATE */ 0,
  2463. /* RID_NULL */ 0,
  2464. /* RID_CATCH */ 0,
  2465. /* RID_DELETE */ 0,
  2466. /* RID_FALSE */ 0,
  2467. /* RID_NAMESPACE */ 0,
  2468. /* RID_NEW */ 0,
  2469. /* RID_OPERATOR */ 0,
  2470. /* RID_THIS */ 0,
  2471. /* RID_THROW */ 0,
  2472. /* RID_TRUE */ 0,
  2473. /* RID_TRY */ 0,
  2474. /* RID_TYPENAME */ 0,
  2475. /* RID_TYPEID */ 0,
  2476. /* RID_USING */ 0,
  2477. /* casts */
  2478. /* RID_CONSTCAST */ 0,
  2479. /* RID_DYNCAST */ 0,
  2480. /* RID_REINTCAST */ 0,
  2481. /* RID_STATCAST */ 0,
  2482. /* alternate spellings */
  2483. /* RID_AND */ 0,
  2484. /* RID_AND_EQ */ 0,
  2485. /* RID_NOT */ 0,
  2486. /* RID_NOT_EQ */ 0,
  2487. /* RID_OR */ 0,
  2488. /* RID_OR_EQ */ 0,
  2489. /* RID_XOR */ 0,
  2490. /* RID_XOR_EQ */ 0,
  2491. /* RID_BITAND */ 0,
  2492. /* RID_BITOR */ 0,
  2493. /* RID_COMPL */ 0,
  2494. /* Objective C */
  2495. /* RID_ID */ OBJECTNAME,
  2496. /* RID_AT_ENCODE */ ENCODE,
  2497. /* RID_AT_END */ END,
  2498. /* RID_AT_CLASS */ CLASS,
  2499. /* RID_AT_ALIAS */ ALIAS,
  2500. /* RID_AT_DEFS */ DEFS,
  2501. /* RID_AT_PRIVATE */ PRIVATE,
  2502. /* RID_AT_PROTECTED */ PROTECTED,
  2503. /* RID_AT_PUBLIC */ PUBLIC,
  2504. /* RID_AT_PROTOCOL */ PROTOCOL,
  2505. /* RID_AT_SELECTOR */ SELECTOR,
  2506. /* RID_AT_INTERFACE */ INTERFACE,
  2507. /* RID_AT_IMPLEMENTATION */ IMPLEMENTATION
  2508. };
  2509. static void
  2510. init_reswords ()
  2511. {
  2512. unsigned int i;
  2513. tree id;
  2514. int mask = (flag_isoc99 ? 0 : D_C89)
  2515. | (flag_traditional ? D_TRAD : 0)
  2516. | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
  2517. if (c_language != clk_objective_c)
  2518. mask |= D_OBJC;
  2519. /* It is not necessary to register ridpointers as a GC root, because
  2520. all the trees it points to are permanently interned in the
  2521. get_identifier hash anyway. */
  2522. ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
  2523. for (i = 0; i < N_reswords; i++)
  2524. {
  2525. /* If a keyword is disabled, do not enter it into the table
  2526. and so create a canonical spelling that isn't a keyword. */
  2527. if (reswords[i].disable & mask)
  2528. continue;
  2529. id = get_identifier (reswords[i].word);
  2530. C_RID_CODE (id) = reswords[i].rid;
  2531. C_IS_RESERVED_WORD (id) = 1;
  2532. ridpointers [(int) reswords[i].rid] = id;
  2533. }
  2534. }
  2535. #define NAME(type) cpp_type2name (type)
  2536. static void
  2537. yyerror (msgid)
  2538. const char *msgid;
  2539. {
  2540. const char *string = _(msgid);
  2541. if (last_token == CPP_EOF)
  2542. error ("%s at end of input", string);
  2543. else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
  2544. {
  2545. unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
  2546. const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
  2547. if (val <= UCHAR_MAX && ISGRAPH (val))
  2548. error ("%s before %s'%c'", string, ell, val);
  2549. else
  2550. error ("%s before %s'\\x%x'", string, ell, val);
  2551. }
  2552. else if (last_token == CPP_STRING
  2553. || last_token == CPP_WSTRING)
  2554. error ("%s before string constant", string);
  2555. else if (last_token == CPP_NUMBER)
  2556. error ("%s before numeric constant", string);
  2557. else if (last_token == CPP_NAME)
  2558. error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
  2559. else
  2560. error ("%s before '%s' token", string, NAME(last_token));
  2561. }
  2562. static int
  2563. yylexname ()
  2564. {
  2565. tree decl;
  2566. if (C_IS_RESERVED_WORD (yylval.ttype))
  2567. {
  2568. enum rid rid_code = C_RID_CODE (yylval.ttype);
  2569. {
  2570. int yycode = rid_to_yy[(int) rid_code];
  2571. if (yycode == STRING_FUNC_NAME)
  2572. {
  2573. /* __FUNCTION__ and __PRETTY_FUNCTION__ get converted
  2574. to string constants. */
  2575. const char *name = fname_string (rid_code);
  2576. yylval.ttype = build_string (strlen (name) + 1, name);
  2577. C_ARTIFICIAL_STRING_P (yylval.ttype) = 1;
  2578. last_token = CPP_STRING; /* so yyerror won't choke */
  2579. return STRING;
  2580. }
  2581. /* Return the canonical spelling for this keyword. */
  2582. yylval.ttype = ridpointers[(int) rid_code];
  2583. return yycode;
  2584. }
  2585. }
  2586. decl = lookup_name (yylval.ttype);
  2587. if (decl)
  2588. {
  2589. if (TREE_CODE (decl) == TYPE_DECL)
  2590. return TYPENAME;
  2591. }
  2592. return IDENTIFIER;
  2593. }
  2594. static inline int
  2595. _yylex ()
  2596. {
  2597. get_next:
  2598. last_token = c_lex (&yylval.ttype);
  2599. switch (last_token)
  2600. {
  2601. case CPP_EQ: return '=';
  2602. case CPP_NOT: return '!';
  2603. case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
  2604. case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
  2605. case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
  2606. case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
  2607. case CPP_MULT: yylval.code = MULT_EXPR; return '*';
  2608. case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
  2609. case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
  2610. case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
  2611. case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
  2612. case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
  2613. case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
  2614. case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
  2615. case CPP_COMPL: return '~';
  2616. case CPP_AND_AND: return ANDAND;
  2617. case CPP_OR_OR: return OROR;
  2618. case CPP_QUERY: return '?';
  2619. case CPP_OPEN_PAREN: return '(';
  2620. case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
  2621. case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
  2622. case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
  2623. case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
  2624. case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
  2625. case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
  2626. case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
  2627. case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
  2628. case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
  2629. case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
  2630. case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
  2631. case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
  2632. case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
  2633. case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
  2634. case CPP_OPEN_SQUARE: return '[';
  2635. case CPP_CLOSE_SQUARE: return ']';
  2636. case CPP_OPEN_BRACE: return '{';
  2637. case CPP_CLOSE_BRACE: return '}';
  2638. case CPP_ELLIPSIS: return ELLIPSIS;
  2639. case CPP_PLUS_PLUS: return PLUSPLUS;
  2640. case CPP_MINUS_MINUS: return MINUSMINUS;
  2641. case CPP_DEREF: return POINTSAT;
  2642. case CPP_DOT: return '.';
  2643. /* The following tokens may affect the interpretation of any
  2644. identifiers following, if doing Objective-C. */
  2645. case CPP_COLON: OBJC_NEED_RAW_IDENTIFIER (0); return ':';
  2646. case CPP_COMMA: OBJC_NEED_RAW_IDENTIFIER (0); return ',';
  2647. case CPP_CLOSE_PAREN: OBJC_NEED_RAW_IDENTIFIER (0); return ')';
  2648. case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
  2649. case CPP_EOF:
  2650. return 0;
  2651. case CPP_NAME:
  2652. return yylexname ();
  2653. case CPP_NUMBER:
  2654. case CPP_CHAR:
  2655. case CPP_WCHAR:
  2656. return CONSTANT;
  2657. case CPP_STRING:
  2658. case CPP_WSTRING:
  2659. return STRING;
  2660. /* This token is Objective-C specific. It gives the next token
  2661. special significance. */
  2662. case CPP_ATSIGN:
  2663. /* These tokens are C++ specific (and will not be generated
  2664. in C mode, but let's be cautious). */
  2665. case CPP_SCOPE:
  2666. case CPP_DEREF_STAR:
  2667. case CPP_DOT_STAR:
  2668. case CPP_MIN_EQ:
  2669. case CPP_MAX_EQ:
  2670. case CPP_MIN:
  2671. case CPP_MAX:
  2672. /* These tokens should not survive translation phase 4. */
  2673. case CPP_HASH:
  2674. case CPP_PASTE:
  2675. error ("syntax error at '%s' token", NAME(last_token));
  2676. goto get_next;
  2677. default:
  2678. abort ();
  2679. }
  2680. /* NOTREACHED */
  2681. }
  2682. static int
  2683. yylex()
  2684. {
  2685. int r;
  2686. timevar_push (TV_LEX);
  2687. r = _yylex();
  2688. timevar_pop (TV_LEX);
  2689. return r;
  2690. }
  2691. /* Sets the value of the 'yydebug' variable to VALUE.
  2692. This is a function so we don't have to have YYDEBUG defined
  2693. in order to build the compiler. */
  2694. void
  2695. c_set_yydebug (value)
  2696. int value;
  2697. {
  2698. #if YYDEBUG != 0
  2699. yydebug = value;
  2700. #else
  2701. warning ("YYDEBUG not defined");
  2702. #endif
  2703. }
  2704. /* Function used when yydebug is set, to print a token in more detail. */
  2705. static void
  2706. yyprint (file, yychar, yyl)
  2707. FILE *file;
  2708. int yychar;
  2709. YYSTYPE yyl;
  2710. {
  2711. tree t = yyl.ttype;
  2712. fprintf (file, " [%s]", NAME(last_token));
  2713. switch (yychar)
  2714. {
  2715. case IDENTIFIER:
  2716. case TYPENAME:
  2717. case OBJECTNAME:
  2718. case TYPESPEC:
  2719. case TYPE_QUAL:
  2720. case SCSPEC:
  2721. if (IDENTIFIER_POINTER (t))
  2722. fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
  2723. break;
  2724. case CONSTANT:
  2725. fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
  2726. if (TREE_CODE (t) == INTEGER_CST)
  2727. fprintf (file,
  2728. #if HOST_BITS_PER_WIDE_INT == 64
  2729. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
  2730. " 0x%x%016x",
  2731. #else
  2732. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
  2733. " 0x%lx%016lx",
  2734. #else
  2735. " 0x%llx%016llx",
  2736. #endif
  2737. #endif
  2738. #else
  2739. #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
  2740. " 0x%lx%08lx",
  2741. #else
  2742. " 0x%x%08x",
  2743. #endif
  2744. #endif
  2745. TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
  2746. break;
  2747. }
  2748. }
  2749. /* This is not the ideal place to put these, but we have to get them out
  2750. of c-lex.c because cp/lex.c has its own versions. */
  2751. /* Return something to represent absolute declarators containing a *.
  2752. TARGET is the absolute declarator that the * contains.
  2753. TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile
  2754. to apply to the pointer type, represented as identifiers, possible mixed
  2755. with attributes.
  2756. We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST,
  2757. if attributes are present) and whose type is the modifier list. */
  2758. tree
  2759. make_pointer_declarator (type_quals_attrs, target)
  2760. tree type_quals_attrs, target;
  2761. {
  2762. tree quals, attrs;
  2763. tree itarget = target;
  2764. split_specs_attrs (type_quals_attrs, &quals, &attrs);
  2765. if (attrs != NULL_TREE)
  2766. itarget = tree_cons (attrs, target, NULL_TREE);
  2767. return build1 (INDIRECT_REF, quals, itarget);
  2768. }