PageRenderTime 174ms CodeModel.GetById 41ms RepoModel.GetById 13ms app.codeStats 1ms

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

#
Happy | 3092 lines | 2777 code | 315 blank | 0 comment | 0 complexity | d1359845a6ada5af4030a0b23dc4a078 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, GPL-2.0

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

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

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