PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/gcc-3.4.0/gcc/c-parse.y

http://yaxx.googlecode.com/
Happy | 2143 lines | 1912 code | 231 blank | 0 comment | 0 complexity | 8aa8ecb8726929a58c9af851d0b7eef5 MD5 | raw file
Possible License(s): AGPL-1.0

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

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

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