PageRenderTime 28ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/osprey/kgccfe/gnu/c-parse.y

https://bitbucket.org/osunix/open64
Happy | 4011 lines | 3598 code | 413 blank | 0 comment | 0 complexity | 096dadafdb13c294c10f26603605c22d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, GPL-3.0

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

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

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