PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/nesc-1.3.3/src/c-parse.y

#
Happy | 2733 lines | 2399 code | 334 blank | 0 comment | 0 complexity | d11b16b7fd7d509d396725c43e92373a MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-2.0, BSD-3-Clause, CC-BY-SA-3.0

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

  1. /* This file is part of the nesC compiler.
  2. This file is derived from the RC and the GNU C Compiler. It is thus
  3. Copyright (C) 1987, 88, 89, 92-7, 1998 Free Software Foundation, Inc.
  4. Copyright (C) 2000-2001 The Regents of the University of California.
  5. Changes for nesC are
  6. Copyright (C) 2002 Intel Corporation
  7. The attached "nesC" software is provided to you under the terms and
  8. conditions of the GNU General Public License Version 2 as published by the
  9. Free Software Foundation.
  10. nesC is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with nesC; see the file COPYING. If not, write to
  16. the Free Software Foundation, 59 Temple Place - Suite 330,
  17. Boston, MA 02111-1307, USA. */
  18. /* This is a version of c-parse.y with two conflicts and supporting the gcc3
  19. attribute syntax. It is a partial merge of the gcc 3 grammar */
  20. /* This file defines the grammar of C */
  21. /* To whomever it may concern: I have heard that such a thing was once
  22. written by AT&T, but I have never seen it. */
  23. %pure_parser
  24. %expect 12
  25. %{
  26. #include <stdio.h>
  27. #include <errno.h>
  28. #include <setjmp.h>
  29. #include "parser.h"
  30. #include "c-parse.h"
  31. #include "c-lex.h"
  32. #include "c-lex-int.h"
  33. #include "semantics.h"
  34. #include "expr.h"
  35. #include "stmt.h"
  36. #include "init.h"
  37. #include "nesc-semantics.h"
  38. #include "nesc-interface.h"
  39. #include "nesc-component.h"
  40. #include "nesc-configuration.h"
  41. #include "nesc-module.h"
  42. #include "nesc-env.h"
  43. #include "nesc-c.h"
  44. #include "nesc-attributes.h"
  45. #include "nesc-task.h"
  46. #include "nesc-cpp.h"
  47. #include "attributes.h"
  48. #include "machine.h"
  49. int yyparse(void) deletes;
  50. void yyerror();
  51. /* Like YYERROR but do call yyerror. */
  52. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  53. /* Cause the `yydebug' variable to be defined. */
  54. #define YYDEBUG 1
  55. %}
  56. %start dispatch
  57. /* All identifiers that are not reserved words
  58. and are not declared typedefs in the current block */
  59. %token IDENTIFIER
  60. /* All identifiers that are declared typedefs in the current block.
  61. In some contexts, they are treated just like IDENTIFIER,
  62. but they can also serve as typespecs in declarations. */
  63. %token TYPENAME
  64. /* An identifier that is declared as a component reference in the
  65. current block, and which is going to be used to refer to a typedef
  66. from the component via the component-ref '.' identifier syntax
  67. (detected in the lexer) */
  68. %token COMPONENTREF
  69. /* Reserved words that specify storage class.
  70. yylval contains an IDENTIFIER_NODE which indicates which one. */
  71. %token <u.itoken> SCSPEC
  72. /* Reserved words that specify type.
  73. yylval contains an IDENTIFIER_NODE which indicates which one. */
  74. %token <u.itoken> TYPESPEC
  75. /* Reserved words that qualify types/functions: "const" or "volatile",
  76. "deletes".
  77. yylval contains an IDENTIFIER_NODE which indicates which one. */
  78. %token <u.itoken> TYPE_QUAL FN_QUAL
  79. /* Character or numeric constants.
  80. yylval is the node for the constant. */
  81. %token CONSTANT
  82. /* String constants in raw form. */
  83. %token STRING MAGIC_STRING
  84. /* "...", used for functions with variable arglists. */
  85. %token <u.itoken> ELLIPSIS
  86. /* the reserved words */
  87. /* SCO include files test "ASM", so use something else. */
  88. %token <u.itoken> SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  89. %token <u.itoken> BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
  90. %token <u.itoken> ATTRIBUTE EXTENSION LABEL
  91. %token <u.itoken> REALPART IMAGPART VA_ARG OFFSETOF
  92. /* Add precedence rules to solve dangling else s/r conflict */
  93. %nonassoc IF
  94. %nonassoc ELSE
  95. /* Define the operator tokens and their precedences.
  96. The value is an integer because, if used, it is the tree code
  97. to use in the expression made from the operator. */
  98. %right <u.itoken> ASSIGN '='
  99. %right <u.itoken> '?' ':'
  100. %left <u.itoken> OROR
  101. %left <u.itoken> ANDAND
  102. %left <u.itoken> '|'
  103. %left <u.itoken> '^'
  104. %left <u.itoken> '&'
  105. %left <u.itoken> EQCOMPARE
  106. %left <u.itoken> ARITHCOMPARE '<' '>'
  107. %left <u.itoken> LSHIFT RSHIFT
  108. %left <u.itoken> '+' '-'
  109. %left <u.itoken> '*' '/' '%'
  110. %right <u.itoken> PLUSPLUS MINUSMINUS
  111. %left <u.itoken> POINTSAT '.' '(' '['
  112. %type <u.asm_operand> asm_operand asm_operands nonnull_asm_operands
  113. %type <u.asm_stmt> maybeasm
  114. %type <u.attribute> maybe_attribute attributes attribute attribute_list
  115. %type <u.attribute> nesc_attributes nattrib
  116. %type <u.gcc_attribute> attrib target_attribute
  117. %type <u.nesc_attribute> nastart
  118. %type <u.constant> CONSTANT
  119. %type <u.decl> datadecl datadecls datadef decl decls extdef extdefs fndef
  120. %type <u.decl> initdecls initdecls_ notype_initdecls notype_initdecls_ fndef2
  121. %type <u.decl> nested_function notype_nested_function old_style_parm_decls
  122. %type <u.decl> initdcl component_decl_list component_decl_list2 component_decl
  123. %type <u.decl> components component_declarator enumerator enumlist
  124. %type <u.decl> components_notype component_notype_declarator
  125. %type <u.decl> parmlist parmlist_1 parmlist_2 parms parm
  126. %type <u.decl> parmlist_or_identifiers identifiers notype_initdcl
  127. %type <u.decl> parmlist_or_identifiers_1 old_parameter just_datadef
  128. %type <u.declarator> declarator after_type_declarator notype_declarator
  129. %type <u.declarator> absdcl absdcl1 absdcl1_noea absdcl1_ea direct_absdcl1
  130. %type <u.declarator> parm_declarator
  131. %type <u.nested> array_declarator fn_declarator array_or_fn_declarator
  132. %type <u.nested> absfn_declarator array_or_absfn_declarator
  133. %type <u.expr> cast_expr expr expr_no_commas exprlist init initlist_maybe_comma
  134. %type <u.expr> initlist1 initelt nonnull_exprlist primary string
  135. %type <u.expr> nonnull_exprlist_ initval restricted_expr
  136. %type <u.designator> designator_list designator
  137. %type <u.expr> unary_expr xexpr function_call
  138. %type <u.expr> generic_type typelist
  139. %type <u.id_label> id_label maybe_label_decls label_decls label_decl
  140. %type <u.id_label> identifiers_or_typenames
  141. %type <idtoken> identifier type_parm
  142. %type <idtoken> IDENTIFIER TYPENAME MAGIC_STRING COMPONENTREF
  143. %type <u.iexpr> if_prefix
  144. %type <u.istmt> stmt_or_labels simple_if stmt_or_label
  145. %type <u.itoken> unop extension '~' '!' compstmt_start '{' ';'
  146. %type <u.itoken> sizeof alignof
  147. %type <u.label> label
  148. %type <u.stmt> stmts xstmts compstmt_or_error compstmt
  149. %type <u.stmt> labeled_stmt stmt stmt_or_error atomic_stmt
  150. %type <u.cstmt> do_stmt_start
  151. %type <u.string> asm_clobbers STRING
  152. %type <u.telement> declspecs_nosc_nots_nosa_noea
  153. %type <u.telement> declspecs_nosc_nots_nosa_ea
  154. %type <u.telement> declspecs_nosc_nots_sa_noea
  155. %type <u.telement> declspecs_nosc_nots_sa_ea
  156. %type <u.telement> declspecs_nosc_ts_nosa_noea
  157. %type <u.telement> declspecs_nosc_ts_nosa_ea
  158. %type <u.telement> declspecs_nosc_ts_sa_noea
  159. %type <u.telement> declspecs_nosc_ts_sa_ea
  160. %type <u.telement> declspecs_sc_nots_nosa_noea
  161. %type <u.telement> declspecs_sc_nots_nosa_ea
  162. %type <u.telement> declspecs_sc_nots_sa_noea
  163. %type <u.telement> declspecs_sc_nots_sa_ea
  164. %type <u.telement> declspecs_sc_ts_nosa_noea
  165. %type <u.telement> declspecs_sc_ts_nosa_ea
  166. %type <u.telement> declspecs_sc_ts_sa_noea
  167. %type <u.telement> declspecs_sc_ts_sa_ea
  168. %type <u.telement> declspecs_ts
  169. %type <u.telement> declspecs_nots
  170. %type <u.telement> declspecs_ts_nosa
  171. %type <u.telement> declspecs_nots_nosa
  172. %type <u.telement> declspecs_nosc_ts
  173. %type <u.telement> declspecs_nosc_nots
  174. %type <u.telement> declspecs_nosc
  175. %type <u.telement> declspecs
  176. %type <u.telement> scspec type_qual type_spec eattributes
  177. %type <u.telement> type_spec_attr type_spec_nonattr
  178. %type <u.telement> type_spec_nonreserved_nonattr type_spec_reserved_attr
  179. %type <u.telement> type_spec_reserved_nonattr
  180. %type <u.telement> structdef structuse
  181. %type <u.telement> maybe_type_qual maybe_type_quals_attrs fn_qual fn_quals
  182. %type <u.type> typename
  183. %type <u.word> idword any_word tag
  184. %type <u.fields> fieldlist
  185. %type <u.itoken> structkind
  186. /* the dispatching (fake) tokens */
  187. %token <u.itoken> DISPATCH_C DISPATCH_NESC DISPATCH_PARM DISPATCH_TYPE
  188. /* nesC reserved words */
  189. %token <u.itoken> ATOMIC USES INTERFACE COMPONENTS PROVIDES MODULE
  190. %token <u.itoken> INCLUDES CONFIGURATION AS TASTNIOP IMPLEMENTATION CALL
  191. %token <u.itoken> SIGNAL POST GENERIC NEW NX_STRUCT NX_UNION
  192. /* words reserved for nesC's future. Some may never be used... */
  193. %token <u.itoken> ABSTRACT COMPONENT EXTENDS
  194. %token <idtoken> TARGET_ATTRIBUTE0 TARGET_ATTRIBUTE1 TARGET_DEF
  195. %type <u.itoken> callkind
  196. %type <u.decl> datadef_list
  197. %type <u.decl> parameters parameters1
  198. %type <u.decl> requires provides requires_or_provides requires_or_provides_list
  199. %type <u.decl> requires_or_provides_list_
  200. %type <u.decl> parameterised_interface_list parameterised_interface
  201. %type <u.decl> parameterised_interfaces
  202. %type <u.decl> interface_parms interface_parm_list interface_parm
  203. %type <u.decl> component_parms
  204. %type <u.decl> template_parms template_parmlist template_parm
  205. %type <u.decl> target_def
  206. %type <u.iref> interface_ref interface_type
  207. %type <u.cref> component_ref component_ref2 component_list cuses
  208. %type <u.conn> connection
  209. %type <u.decl> configuration_decl configuration_decls
  210. %type <u.ep> endpoint
  211. %type <u.pid> parameterised_identifier
  212. %type <u.impl> iconfiguration imodule
  213. %type <abstract> generic
  214. %type <u.expr> generic_arglist generic_arg generic_args
  215. %{
  216. /* Region in which to allocate parse structures. Idea: the AST user can set
  217. this to different regions at appropriate junctures depending on what's
  218. being done with the AST */
  219. region parse_region;
  220. /* We'll see this a LOT below */
  221. #define pr parse_region
  222. /* Number of statements (loosely speaking) and compound statements
  223. seen so far. */
  224. static int stmt_count;
  225. static int compstmt_count;
  226. #ifdef RC_ADJUST
  227. static size_t rc_adjust_yystype(void *x, int by)
  228. {
  229. struct yystype *p = x;
  230. RC_ADJUST_PREAMBLE;
  231. RC_ADJUST(p->u.ptr, by);
  232. RC_ADJUST(p->idtoken.location.filename, by);
  233. RC_ADJUST(p->idtoken.id.data, by);
  234. RC_ADJUST(p->idtoken.decl, by);
  235. return sizeof *p;
  236. }
  237. static void rc_update_yystype(struct yystype *old, struct yystype *new)
  238. {
  239. regionid base = regionidof(old);
  240. RC_UPDATE(base, old->u.ptr, new->u.ptr);
  241. RC_UPDATE(base, old->idtoken.location.filename, new->idtoken.location.filename);
  242. RC_UPDATE(base, old->idtoken.id.data, new->idtoken.id.data);
  243. RC_UPDATE(base, old->idtoken.decl, new->idtoken.decl);
  244. }
  245. #endif
  246. /* A stack of declspecs and attributes for use during parsing */
  247. typedef struct spec_stack *spec_stack;
  248. struct spec_stack {
  249. type_element parentptr declspecs;
  250. attribute parentptr attributes;
  251. spec_stack sameregion next;
  252. };
  253. struct parse_state
  254. {
  255. /* Stack of saved values of current_declspecs and prefix_attributes. */
  256. /* In an ideal world, we would be able to eliminate most rc ops for
  257. declspec_stack and ds_region assignments. Seems tricky though. */
  258. spec_stack declspec_stack;
  259. region ds_region;
  260. /* List of types and structure classes of the current declaration. */
  261. type_element declspecs;
  262. attribute attributes;
  263. /* >0 if currently parsing an expression that will not be evaluated (argument
  264. to alignof, sizeof. Currently not typeof though that could be considered
  265. a bug) */
  266. int unevaluated_expression;
  267. } pstate;
  268. bool unevaluated_expression(void)
  269. {
  270. return pstate.unevaluated_expression != 0;
  271. }
  272. /* Pop top entry of declspec_stack back into current_declspecs,
  273. prefix_attributes */
  274. static void pop_declspec_stack(void) deletes
  275. {
  276. pstate.declspecs = pstate.declspec_stack->declspecs;
  277. pstate.attributes = pstate.declspec_stack->attributes;
  278. pstate.declspec_stack = pstate.declspec_stack->next;
  279. }
  280. static void push_declspec_stack(void)
  281. {
  282. spec_stack news;
  283. news = ralloc(pstate.ds_region, struct spec_stack);
  284. news->declspecs = pstate.declspecs;
  285. news->attributes = pstate.attributes;
  286. news->next = pstate.declspec_stack;
  287. pstate.declspec_stack = news;
  288. }
  289. static node parse_tree;
  290. node parse(void) deletes
  291. {
  292. int result, old_errorcount = errorcount;
  293. struct parse_state old_pstate = pstate;
  294. pstate.declspecs = NULL;
  295. pstate.attributes = NULL;
  296. pstate.unevaluated_expression = 0;
  297. pstate.declspec_stack = NULL;
  298. pstate.ds_region = newsubregion(parse_region);
  299. parse_tree = NULL;
  300. result = yyparse();
  301. if (result)
  302. parse_tree = NULL;
  303. deleteregion_ptr(&pstate.ds_region);
  304. if (result != 0 && errorcount == old_errorcount)
  305. fprintf(stderr, "Errors detected in input file (your bison.simple is out of date)");
  306. pstate = old_pstate;
  307. return parse_tree;
  308. }
  309. static void set_nesc_ast(void *tree)
  310. {
  311. nesc_declaration cdecl = current.container;
  312. nesc_decl nd = CAST(nesc_decl, tree);
  313. nd->cdecl = cdecl;
  314. cdecl->ast = nd;
  315. }
  316. static void set_nesc_parse_tree(void *tree)
  317. {
  318. set_nesc_ast(tree);
  319. parse_tree = CAST(node, tree);
  320. }
  321. static void set_nesc_impl(implementation impl)
  322. {
  323. nesc_declaration cdecl = current.container;
  324. CAST(component, cdecl->ast)->implementation = impl;
  325. parse_tree = CAST(node, cdecl->ast);
  326. }
  327. void refuse_asm(asm_stmt s)
  328. {
  329. if (s)
  330. error_with_location(s->location, "unexpected asm statement");
  331. }
  332. /* Merge the attributes in front of a declaration (but which aren't part
  333. of the declspecs) with the attributes after the declaration.
  334. We're pretending they all came after */
  335. attribute prefix_attr(attribute post_attr)
  336. {
  337. return attribute_chain(pstate.attributes, post_attr);
  338. }
  339. /* Simple build functions */
  340. declaration make_data_decl(type_element modifiers, declaration decls)
  341. {
  342. location l = modifiers ? modifiers->location : decls->location;
  343. data_decl dd = new_data_decl(parse_region, l, modifiers, decls);
  344. pop_declspec_stack();
  345. if (decls == NULL && current.spec_section != spec_normal)
  346. error("provides/uses must be followed by a command, event or interface");
  347. return CAST(declaration, dd);
  348. }
  349. declaration make_error_decl(void)
  350. {
  351. return new_error_decl(pr, dummy_location);
  352. }
  353. declaration make_extension_decl(int old_pedantic, location l, declaration d)
  354. {
  355. pedantic = old_pedantic;
  356. return CAST(declaration, new_extension_decl(pr, l, d));
  357. }
  358. word make_cword(location l, const char *s)
  359. {
  360. return new_word(pr, l, str2cstring(pr, s));
  361. }
  362. declarator make_qualified_declarator(location l, declarator d, type_element quals)
  363. {
  364. if (quals)
  365. return CAST(declarator, new_qualified_declarator(pr, l, d, quals));
  366. else
  367. return d;
  368. }
  369. declarator make_pointer_declarator(location l, declarator d, type_element quals)
  370. {
  371. d = make_qualified_declarator(l, d, quals);
  372. return CAST(declarator, new_pointer_declarator(pr, l, d));
  373. }
  374. declarator make_identifier_declarator(location l, cstring id)
  375. {
  376. return CAST(declarator, new_identifier_declarator(pr, l, id));
  377. }
  378. statement make_error_stmt(void)
  379. {
  380. return new_error_stmt(pr, dummy_location);
  381. }
  382. /* Tell yyparse how to print a token's value, if yydebug is set. */
  383. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  384. void yyprint();
  385. %}
  386. %%
  387. dispatch:
  388. DISPATCH_NESC interface { }
  389. | DISPATCH_NESC component { }
  390. | DISPATCH_C extdefs {
  391. declaration cdecls = declaration_reverse($2);
  392. parse_tree = CAST(node, cdecls); }
  393. | DISPATCH_C { parse_tree = NULL; }
  394. | DISPATCH_PARM parm { parse_tree = CAST(node, $2); }
  395. | DISPATCH_PARM error { parse_tree = CAST(node, make_error_decl()); }
  396. | DISPATCH_TYPE typename { parse_tree = CAST(node, $2); }
  397. | DISPATCH_TYPE error { parse_tree = NULL; }
  398. ;
  399. ncheader:
  400. { end_macro_saving(); } includes_list
  401. | extdefs
  402. {
  403. end_macro_saving();
  404. add_cdecls(declaration_reverse($1));
  405. }
  406. ;
  407. includes_list:
  408. includes_list includes
  409. | /* empty */
  410. ;
  411. includes:
  412. INCLUDES include_list ';' { }
  413. ;
  414. include_list:
  415. identifier
  416. { require_c($1.location, $1.id.data); }
  417. | include_list ',' identifier
  418. { require_c($3.location, $3.id.data); }
  419. ;
  420. interface:
  421. ncheader
  422. INTERFACE idword
  423. {
  424. start_nesc_entity(l_interface, $3);
  425. }
  426. interface_parms nesc_attributes
  427. {
  428. handle_nescdecl_attributes($6, current.container);
  429. }
  430. '{' datadef_list '}'
  431. {
  432. interface intf = new_interface(pr, $2.location, $3, $6, declaration_reverse($9));
  433. set_nesc_parse_tree(intf);
  434. if (intf->cdecl->abstract)
  435. poplevel();
  436. }
  437. ;
  438. interface_parms:
  439. /* empty */ { $$ = NULL; }
  440. | '<' interface_parm_list '>'
  441. {
  442. nesc_declaration intf = current.container;
  443. intf->parameters = $2;
  444. intf->parameter_env = current.env;
  445. $$ = $2;
  446. /* Template intfs need a new level for the actual intf */
  447. pushlevel(FALSE);
  448. /* The interface env counts as global */
  449. current.env->global_level = TRUE;
  450. intf->env = current.env;
  451. intf->abstract = TRUE;
  452. }
  453. ;
  454. interface_parm_list:
  455. interface_parm
  456. | interface_parm_list ',' interface_parm
  457. { $$ = declaration_chain($1, $3); }
  458. ;
  459. interface_parm:
  460. type_parm nesc_attributes
  461. { $$ = declare_type_parameter($1.location, $1.id, $2, NULL); }
  462. ;
  463. type_parm:
  464. IDENTIFIER { $$ = $1; }
  465. ;
  466. datadef_list:
  467. datadef_list just_datadef { $$ = declaration_chain($2, $1); }
  468. | just_datadef ;
  469. parameters:
  470. '[' { pushlevel(TRUE); } parameters1
  471. { /* poplevel done in users of parameters */ $$ = $3; } ;
  472. parameters1:
  473. parms ']'
  474. {
  475. $$ = declaration_reverse($1);
  476. check_interface_parameter_types($$);
  477. }
  478. | error ']' { $$ = make_error_decl(); }
  479. ;
  480. component:
  481. ncheader module
  482. | ncheader configuration
  483. | ncheader binary_component
  484. ;
  485. module:
  486. generic MODULE idword
  487. {
  488. start_nesc_entity(l_component, $3);
  489. current.container->abstract = $1;
  490. }
  491. component_parms nesc_attributes
  492. {
  493. handle_nescdecl_attributes($6, current.container);
  494. }
  495. '{' requires_or_provides_list '}'
  496. imodule
  497. {
  498. declaration intfs =
  499. declaration_chain(declaration_reverse($9), all_tasks);
  500. set_nesc_parse_tree(new_component(pr, $2.location, $3, $6, $1, $5, intfs, $11));
  501. }
  502. ;
  503. configuration:
  504. generic CONFIGURATION idword
  505. {
  506. start_nesc_entity(l_component, $3);
  507. current.container->abstract = $1;
  508. current.container->configuration = TRUE;
  509. }
  510. component_parms nesc_attributes
  511. {
  512. handle_nescdecl_attributes($6, current.container);
  513. }
  514. '{' requires_or_provides_list '}'
  515. {
  516. set_nesc_ast(new_component(pr, $2.location, $3, $6, $1, $5, declaration_reverse($9), NULL));
  517. }
  518. iconfiguration
  519. {
  520. set_nesc_impl($12);
  521. }
  522. ;
  523. binary_component:
  524. COMPONENT idword
  525. {
  526. start_nesc_entity(l_component, $2);
  527. }
  528. nesc_attributes
  529. {
  530. handle_nescdecl_attributes($4, current.container);
  531. }
  532. '{' requires_or_provides_list '}'
  533. {
  534. binary_component dummy = new_binary_component(pr, $1.location, start_implementation());
  535. component c = new_component(pr, $1.location, $2, $4, FALSE, NULL, declaration_reverse($7), CAST(implementation, dummy));
  536. set_nesc_parse_tree(c);
  537. }
  538. ;
  539. generic: GENERIC { $$ = TRUE; }
  540. | /* empty */ { $$ = FALSE; }
  541. ;
  542. component_parms:
  543. /* empty */
  544. {
  545. if (current.container->abstract)
  546. error("generic components require a parameter list");
  547. /* We don't create the extra environment level for this
  548. generic component as nothing actually requires its
  549. existence */
  550. $$ = NULL;
  551. }
  552. | '(' template_parms ')'
  553. {
  554. nesc_declaration comp = current.container;
  555. if (!comp->abstract)
  556. error("only generic components can have a parameter list");
  557. comp->parameters = $2;
  558. comp->parameter_env = current.env;
  559. $$ = $2;
  560. /* generic components need a new level for the
  561. specification */
  562. pushlevel(FALSE);
  563. current.env->global_level = TRUE;
  564. comp->env = current.env;
  565. }
  566. ;
  567. template_parms:
  568. /* empty */ { $$ = NULL; }
  569. | template_parmlist
  570. ;
  571. template_parmlist:
  572. template_parm
  573. | template_parmlist ',' template_parm
  574. { $$ = declaration_chain($1, $3); }
  575. ;
  576. /* A declaration of a template parameter, i.e., a regular
  577. parameter-like declaration (name required).
  578. The 'typedef t' syntax for declaring a type argument is detected
  579. inside declare_template_parameter */
  580. template_parm:
  581. declspecs_ts xreferror after_type_declarator maybe_attribute
  582. { $$ = declare_template_parameter($3, $1, $4); }
  583. | declspecs_ts xreferror notype_declarator maybe_attribute
  584. { $$ = declare_template_parameter($3, $1, $4); }
  585. | declspecs_nots xreferror notype_declarator maybe_attribute
  586. { $$ = declare_template_parameter($3, $1, $4); }
  587. | declspecs_ts xreferror
  588. { $$ = declare_template_parameter(NULL, $1, NULL); }
  589. ;
  590. requires_or_provides_list:
  591. requires_or_provides_list_
  592. { current.spec_section = spec_normal; }
  593. ;
  594. requires_or_provides_list_:
  595. requires_or_provides_list_ requires_or_provides
  596. { $$ = declaration_chain($2, $1); }
  597. | /* empty */ { $$ = NULL; }
  598. ;
  599. requires_or_provides:
  600. requires
  601. | provides
  602. | { current.spec_section = spec_normal; } just_datadef { $$ = $2; }
  603. ;
  604. requires:
  605. USES { current.spec_section = spec_uses; }
  606. parameterised_interface_list
  607. { $$ = CAST(declaration, new_rp_interface(pr, $1.location, TRUE, declaration_reverse($3))); } ;
  608. provides:
  609. PROVIDES { current.spec_section = spec_provides; }
  610. parameterised_interface_list
  611. { $$ = CAST(declaration, new_rp_interface(pr, $1.location, FALSE, declaration_reverse($3))); } ;
  612. parameterised_interface_list:
  613. parameterised_interface
  614. | '{' parameterised_interfaces '}' { $$ = $2; }
  615. ;
  616. parameterised_interfaces:
  617. parameterised_interfaces parameterised_interface
  618. { $$ = declaration_chain($2, $1); }
  619. | parameterised_interface
  620. ;
  621. parameterised_interface:
  622. just_datadef
  623. | interface_ref nesc_attributes ';'
  624. {
  625. declare_interface_ref($1, NULL, current.env, $2);
  626. $$ = CAST(declaration, $1);
  627. }
  628. | interface_ref parameters nesc_attributes ';'
  629. {
  630. $1->gparms = $2;
  631. poplevel();
  632. declare_interface_ref($1, $2, current.env, $3);
  633. $$ = CAST(declaration, $1);
  634. }
  635. ;
  636. interface_ref:
  637. interface_type
  638. | interface_type AS idword { $$ = $1; $$->word2 = $3; }
  639. ;
  640. interface_type:
  641. INTERFACE idword
  642. {
  643. preload(l_interface, $1.location, $2->cstring.data);
  644. $$ = new_interface_ref(pr, $1.location, $2, NULL, NULL, NULL, NULL, NULL);
  645. }
  646. | INTERFACE idword
  647. {
  648. preload(l_interface, $1.location, $2->cstring.data);
  649. }
  650. '<' typelist '>'
  651. { $$ = new_interface_ref(pr, $1.location, $2, $5, NULL, NULL, NULL, NULL); }
  652. ;
  653. typelist:
  654. generic_type
  655. | typelist ',' generic_type { $$ = expression_chain($1, $3); }
  656. ;
  657. iconfiguration:
  658. IMPLEMENTATION { $<u.env>$ = start_implementation(); }
  659. '{'
  660. configuration_decls
  661. '}'
  662. { $$ = CAST(implementation, new_configuration(pr, $1.location, $<u.env>2, declaration_reverse($4)));
  663. }
  664. ;
  665. cuses: COMPONENTS component_list ';' { $$ = $2; }
  666. ;
  667. component_list:
  668. component_list ',' component_ref { $$ = component_ref_chain($3, $1); }
  669. | component_ref
  670. ;
  671. component_ref:
  672. component_ref2 { $$ = require_component($1, NULL); }
  673. | component_ref2 AS idword { $$ = require_component($1, $3); }
  674. ;
  675. component_ref2:
  676. idword { $$ = new_component_ref(pr, $1->location, $1, NULL,
  677. FALSE, NULL); }
  678. | NEW idword '(' generic_args ')'
  679. { $$ = new_component_ref(pr, $1.location, $2, NULL,
  680. TRUE, $4); }
  681. ;
  682. generic_args:
  683. /* empty */ { $$ = NULL; }
  684. | generic_arglist
  685. ;
  686. generic_arglist:
  687. generic_arg
  688. | generic_arglist ',' generic_arg { $$ = expression_chain($1, $3); }
  689. ;
  690. generic_arg:
  691. expr_no_commas
  692. { $$ = $1; $$->type = default_conversion_for_assignment($$); }
  693. | generic_type
  694. ;
  695. generic_type:
  696. typename { $$ = make_type_argument($1); }
  697. ;
  698. configuration_decls:
  699. configuration_decls configuration_decl { $$ = declaration_chain($2, $1); }
  700. | /* empty */ { $$ = NULL; }
  701. ;
  702. configuration_decl:
  703. connection { $$ = CAST(declaration, $1); }
  704. | just_datadef
  705. | cuses { $$ = CAST(declaration, $1); }
  706. ;
  707. connection:
  708. endpoint '=' endpoint ';'
  709. { $$ = CAST(connection, new_eq_connection(pr, $2.location, $1, $3)); }
  710. | endpoint POINTSAT endpoint ';'
  711. { $$ = CAST(connection, new_rp_connection(pr, $2.location, $3, $1)); }
  712. | endpoint TASTNIOP endpoint ';'
  713. { $$ = CAST(connection, new_rp_connection(pr, $2.location, $1, $3)); }
  714. ;
  715. endpoint:
  716. endpoint '.' parameterised_identifier
  717. { $$ = $1;
  718. $$->ids = parameterised_identifier_chain($$->ids, $3);
  719. }
  720. | parameterised_identifier
  721. { $$ = new_endpoint(parse_region, $1->location, $1); }
  722. ;
  723. parameterised_identifier:
  724. idword
  725. { $$ = new_parameterised_identifier(pr, $1->location, $1, NULL); }
  726. | idword '[' nonnull_exprlist ']'
  727. { $$ = new_parameterised_identifier(pr, $1->location, $1, $3); }
  728. ;
  729. imodule: IMPLEMENTATION { $<u.env>$ = start_implementation(); all_tasks = NULL; } '{' extdefs '}'
  730. {
  731. $$ = CAST(implementation, new_module(pr, $1.location, $<u.env>2, declaration_reverse($4)));
  732. } ;
  733. /* the reason for the strange actions in this rule
  734. is so that notype_initdecls when reached via datadef
  735. can find a valid list of type and sc specs in $0. */
  736. extdefs:
  737. { $<u.telement>$ = NULL; } extdef { $$ = $2; }
  738. | extdefs { $<u.telement>$ = NULL; } extdef
  739. { $$ = declaration_chain($3, $1); }
  740. ;
  741. extdef:
  742. fndef
  743. | datadef
  744. | ASM_KEYWORD '(' expr ')' ';'
  745. {
  746. $$ = CAST(declaration, new_asm_decl
  747. (pr, $1.location,
  748. new_asm_stmt(pr, $1.location, $3, NULL, NULL, NULL, NULL))); }
  749. | extension extdef
  750. { $$ = make_extension_decl($1.i, $1.location, $2); }
  751. ;
  752. datadef:
  753. setspecs notype_initdecls ';'
  754. { if (pedantic)
  755. error("ANSI C forbids data definition with no type or storage class");
  756. else if (!flag_traditional)
  757. warning("data definition has no type or storage class");
  758. $$ = make_data_decl(NULL, $2); }
  759. | just_datadef
  760. ;
  761. just_datadef:
  762. declspecs_nots setspecs notype_initdecls ';'
  763. { $$ = make_data_decl($1, $3); }
  764. | declspecs_ts setspecs initdecls ';'
  765. { $$ = make_data_decl($1, $3); }
  766. | declspecs setspecs ';'
  767. { shadow_tag($1);
  768. $$ = make_data_decl($1, NULL); }
  769. | error ';' { $$ = make_error_decl(); }
  770. | error '}' { $$ = make_error_decl(); }
  771. | ';'
  772. { if (pedantic)
  773. pedwarn("ANSI C does not allow extra `;' outside of a function");
  774. $$ = NULL; }
  775. | target_def
  776. ;
  777. target_def:
  778. TARGET_DEF identifier '=' expr ';'
  779. { $$ = target->keilc_definition($1.location, $1.id, $2.id, $4); }
  780. ;
  781. fndef:
  782. declspecs_ts setspecs declarator fndef2 { $$ = $4; }
  783. | declspecs_nots setspecs notype_declarator fndef2 { $$ = $4; }
  784. | setspecs notype_declarator fndef2 { $$ = $3; }
  785. ;
  786. fndef2: maybeasm maybe_attribute
  787. {
  788. /* maybeasm is only here to avoid a s/r conflict */
  789. refuse_asm($1);
  790. /* $0 refers to the declarator that precedes fndef2
  791. in fndef (we can't just save it in an action, as that
  792. causes s/r and r/r conflicts) */
  793. if (!start_function(pstate.declspecs, $<u.declarator>0, $2, 0))
  794. YYERROR1;
  795. }
  796. old_style_parm_decls
  797. { store_parm_decls(declaration_reverse($4)); }
  798. compstmt_or_error
  799. { $$ = finish_function($6);
  800. pop_declspec_stack(); }
  801. ;
  802. identifier:
  803. IDENTIFIER
  804. | TYPENAME
  805. ;
  806. id_label:
  807. identifier { $$ = new_id_label(pr, $1.location, $1.id); }
  808. ;
  809. idword:
  810. identifier { $$ = new_word(pr, $1.location, $1.id); }
  811. ;
  812. unop: '&'
  813. { $$ = $1; $$.i = kind_address_of; }
  814. | '-'
  815. { $$ = $1; $$.i = kind_unary_minus; }
  816. | '+'
  817. { $$ = $1; $$.i = kind_unary_plus; }
  818. | PLUSPLUS
  819. { $$ = $1; $$.i = kind_preincrement; }
  820. | MINUSMINUS
  821. { $$ = $1; $$.i = kind_predecrement; }
  822. | '~'
  823. { $$ = $1; $$.i = kind_bitnot; }
  824. | '!'
  825. { $$ = $1; $$.i = kind_not; }
  826. | REALPART
  827. { $$ = $1; $$.i = kind_realpart; }
  828. | IMAGPART
  829. { $$ = $1; $$.i = kind_imagpart; }
  830. ;
  831. expr: nonnull_exprlist
  832. { if ($1->next)
  833. $$ = make_comma($1->location, $1);
  834. else
  835. $$ = $1; }
  836. ;
  837. exprlist:
  838. /* empty */
  839. { $$ = NULL; }
  840. | nonnull_exprlist
  841. ;
  842. nonnull_exprlist:
  843. nonnull_exprlist_
  844. { $$ = expression_reverse($1); }
  845. ;
  846. nonnull_exprlist_:
  847. expr_no_commas
  848. { $$ = $1; }
  849. | nonnull_exprlist_ ',' expr_no_commas
  850. { $$ = expression_chain($3, $1); }
  851. ;
  852. callkind:
  853. CALL { $$.i = command_call; }
  854. | SIGNAL { $$.i = event_signal; }
  855. | POST { $$.i = post_task; }
  856. ;
  857. unary_expr:
  858. primary
  859. | callkind function_call
  860. {
  861. function_call fc = CAST(function_call, $2);
  862. type calltype = fc->arg1->type;
  863. bool noerror = fc->type != error_type;
  864. $$ = $2;
  865. fc->call_kind = $1.i;
  866. switch ($1.i)
  867. {
  868. case command_call:
  869. if (noerror && !type_command(calltype))
  870. error("only commands can be called");
  871. break;
  872. case event_signal:
  873. if (noerror && !type_event(calltype))
  874. error("only events can be signaled");
  875. break;
  876. case post_task:
  877. fc->type = unsigned_char_type;
  878. if (noerror)
  879. {
  880. if (!type_task(calltype))
  881. error("only tasks can be posted");
  882. else if (flag_use_scheduler)
  883. /* If requested, replace post/task by references to
  884. an interface */
  885. handle_post(fc);
  886. }
  887. break;
  888. }
  889. }
  890. | '*' cast_expr
  891. { $$ = make_dereference($1.location, $2); }
  892. /* __extension__ turns off -pedantic for following primary. */
  893. | extension cast_expr
  894. { $$ = make_extension_expr($1.location, $2);
  895. pedantic = $1.i; }
  896. | unop cast_expr
  897. { $$ = make_unary($1.location, $1.i, $2);
  898. #if 0
  899. overflow_warning($$);
  900. #endif
  901. }
  902. /* Refer to the address of a label as a pointer. */
  903. | ANDAND id_label
  904. {
  905. $$ = CAST(expression, make_label_address($1.location, $2));
  906. use_label($2);
  907. }
  908. | sizeof unary_expr
  909. {
  910. #if 0
  911. if (TREE_CODE ($2) == COMPONENT_REF
  912. && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
  913. error("`sizeof' applied to a bit-field");
  914. $$ = c_sizeof (TREE_TYPE ($2));
  915. #endif
  916. $$ = make_sizeof_expr($1.location, $2);
  917. pstate.unevaluated_expression--; }
  918. | sizeof '(' typename ')'
  919. { $$ = make_sizeof_type($1.location, $3);
  920. pstate.unevaluated_expression--; }
  921. | alignof unary_expr
  922. { $$ = make_alignof_expr($1.location, $2);
  923. pstate.unevaluated_expression--; }
  924. | alignof '(' typename ')'
  925. { $$ = make_alignof_type($1.location, $3);
  926. pstate.unevaluated_expression--; }
  927. ;
  928. sizeof:
  929. SIZEOF { pstate.unevaluated_expression++; $$ = $1; }
  930. ;
  931. alignof:
  932. ALIGNOF { pstate.unevaluated_expression++; $$ = $1; }
  933. ;
  934. cast_expr:
  935. unary_expr
  936. | '(' typename ')' cast_expr
  937. { $$ = make_cast($1.location, $2, $4); }
  938. | '(' typename ')' '{'
  939. {
  940. start_init(NULL, NULL);
  941. really_start_incremental_init($2->type);
  942. }
  943. initlist_maybe_comma '}'
  944. {
  945. expression constructor = make_init_list($4.location, $6);
  946. finish_init();
  947. if (pedantic)
  948. pedwarn("ANSI C forbids constructor expressions");
  949. $$ = make_cast_list($1.location, $2, constructor);
  950. }
  951. ;
  952. expr_no_commas:
  953. cast_expr
  954. | expr_no_commas '+' expr_no_commas
  955. { $$ = make_binary($2.location, kind_plus, $1, $3); }
  956. | expr_no_commas '-' expr_no_commas
  957. { $$ = make_binary($2.location, kind_minus, $1, $3); }
  958. | expr_no_commas '*' expr_no_commas
  959. { $$ = make_binary($2.location, kind_times, $1, $3); }
  960. | expr_no_commas '/' expr_no_commas
  961. { $$ = make_binary($2.location, kind_divide, $1, $3); }
  962. | expr_no_commas '%' expr_no_commas
  963. { $$ = make_binary($2.location, kind_modulo, $1, $3); }
  964. | expr_no_commas LSHIFT expr_no_commas
  965. { $$ = make_binary($2.location, kind_lshift, $1, $3); }
  966. | expr_no_commas RSHIFT expr_no_commas
  967. { $$ = make_binary($2.location, kind_rshift, $1, $3); }
  968. | expr_no_commas ARITHCOMPARE expr_no_commas
  969. { $$ = make_binary($2.location, $2.i, $1, $3); }
  970. | expr_no_commas '<' expr_no_commas
  971. { $$ = make_binary($2.location, kind_lt, $1, $3); }
  972. | expr_no_commas '>' expr_no_commas
  973. { $$ = make_binary($2.location, kind_gt, $1, $3); }
  974. | expr_no_commas EQCOMPARE expr_no_commas
  975. { $$ = make_binary($2.location, $2.i, $1, $3); }
  976. | expr_no_commas '&' expr_no_commas
  977. { $$ = make_binary($2.location, kind_bitand, $1, $3); }
  978. | expr_no_commas '|' expr_no_commas
  979. { $$ = make_binary($2.location, kind_bitor, $1, $3); }
  980. | expr_no_commas '^' expr_no_commas
  981. { $$ = make_binary($2.location, kind_bitxor, $1, $3); }
  982. | expr_no_commas ANDAND expr_no_commas
  983. { $$ = make_binary($2.location, kind_andand, $1, $3); }
  984. | expr_no_commas OROR expr_no_commas
  985. { $$ = make_binary($2.location, kind_oror, $1, $3); }
  986. | expr_no_commas '?' expr ':' expr_no_commas
  987. { $$ = make_conditional($2.location, $1, $3, $5); }
  988. | expr_no_commas '?'
  989. { if (pedantic)
  990. pedwarn("ANSI C forbids omitting the middle term of a ?: expression");
  991. }
  992. ':' expr_no_commas
  993. { $$ = make_conditional($2.location, $1, NULL, $5); }
  994. | expr_no_commas '=' expr_no_commas
  995. { $$ = make_assign($2.location, kind_assign, $1, $3); }
  996. | expr_no_commas ASSIGN expr_no_commas
  997. { $$ = make_assign($2.location, $2.i, $1, $3); }
  998. ;
  999. primary:
  1000. IDENTIFIER
  1001. {
  1002. if (yychar == YYEMPTY)
  1003. yychar = YYLEX;
  1004. $$ = make_identifier($1.location, $1.id, yychar == '(');
  1005. }
  1006. | CONSTANT { $$ = CAST(expression, $1); }
  1007. | string { $$ = $1; }
  1008. | '(' expr ')'
  1009. { $$ = $2; $$->parens = TRUE; }
  1010. | '(' error ')'
  1011. { $$ = make_error_expr(); }
  1012. | '('
  1013. { if (current.function_decl == 0)
  1014. {
  1015. error("braced-group within expression allowed only inside a function");
  1016. YYERROR;
  1017. }
  1018. push_label_level();
  1019. }
  1020. compstmt ')'
  1021. {
  1022. pop_label_level();
  1023. if (pedantic)
  1024. pedwarn("ANSI C forbids braced-groups within expressions");
  1025. $$ = make_compound_expr($1.location, $3);
  1026. }
  1027. | function_call
  1028. {
  1029. /* Magic functions may rewrite this to something else */
  1030. if (is_function_call($1))
  1031. {
  1032. function_call fc = CAST(function_call, $1);
  1033. type calltype = fc->arg1->type;
  1034. if (type_command(calltype))
  1035. error("commands must be called with call");
  1036. else if (type_event(calltype))
  1037. error("events must be signaled with signal");
  1038. else if (type_task(calltype))
  1039. error("tasks must be posted with post");
  1040. }
  1041. $$ = $1;
  1042. }
  1043. | VA_ARG '(' expr_no_commas ',' typename ')'
  1044. { $$ = make_va_arg($1.location, $3, $5); }
  1045. | OFFSETOF '(' typename ',' fieldlist ')'
  1046. { $$ = make_offsetof($1.location, $3, $5); }
  1047. | primary '[' nonnull_exprlist ']'
  1048. { $$ = make_array_ref($2.location, $1, $3); }
  1049. | primary '.' identifier
  1050. { $$ = make_field_ref($2.location, $1, $3.id); }
  1051. | primary POINTSAT identifier
  1052. { $$ = make_field_ref($2.location, make_dereference($2.location, $1),
  1053. $3.id); }
  1054. | primary PLUSPLUS
  1055. { $$ = make_postincrement($2.location, $1); }
  1056. | primary MINUSMINUS
  1057. { $$ = make_postdecrement($2.location, $1); }
  1058. ;
  1059. fieldlist:
  1060. identifier { $$ = dd_new_list(pr); dd_add_last(pr, $$, $1.id.data); }
  1061. | fieldlist '.' identifier { $$ = $1; dd_add_last(pr, $$, $3.id.data); }
  1062. ;
  1063. function_call:
  1064. primary '(' exprlist ')'
  1065. { $$ = make_function_call($2.location, $1, $3); }
  1066. ;
  1067. string: STRING { $$ = CAST(expression, $1); }
  1068. | MAGIC_STRING { $$ = make_identifier($1.location, $1.id, FALSE); }
  1069. ;
  1070. old_style_parm_decls:
  1071. /* empty */ { $$ = NULL; }
  1072. | datadecls
  1073. | datadecls ELLIPSIS
  1074. /* ... is used here to indicate a varargs function. */
  1075. { if (pedantic)
  1076. pedwarn("ANSI C does not permit use of `varargs.h'");
  1077. $$ = declaration_chain(CAST(declaration, new_ellipsis_decl(pr, $2.location)), $1);
  1078. }
  1079. ;
  1080. /* The following are analogous to decls and decl
  1081. except that they do not allow nested functions.
  1082. They are used for old-style parm decls. */
  1083. datadecls:
  1084. datadecl
  1085. | datadecls datadecl { $$ = declaration_chain($2, $1); }
  1086. ;
  1087. /* We don't allow prefix attributes here because they cause reduce/reduce
  1088. conflicts: we can't know whether we're parsing a function decl with
  1089. attribute suffix, or function defn with attribute prefix on first old
  1090. style parm. */
  1091. datadecl:
  1092. declspecs_ts_nosa setspecs initdecls ';'
  1093. { $$ = make_data_decl($1, $3); }
  1094. | declspecs_nots_nosa setspecs notype_initdecls ';'
  1095. { $$ = make_data_decl($1, $3); }
  1096. | declspecs_ts_nosa setspecs ';'
  1097. { shadow_tag_warned($1, 1);
  1098. $$ = make_data_decl($1, NULL);
  1099. pedwarn("empty declaration"); }
  1100. | declspecs_nots_nosa ';'
  1101. { pedwarn("empty declaration");
  1102. $$ = NULL; }
  1103. ;
  1104. /* This combination which saves a lineno before a decl
  1105. is the normal thing to use, rather than decl itself.
  1106. This is to avoid shift/reduce conflicts in contexts
  1107. where statement labels are allowed. */
  1108. decls:
  1109. decl
  1110. | errstmt { $$ = make_error_decl(); }
  1111. | decls decl { $$ = declaration_chain($2, $1); }
  1112. | decl errstmt { $$ = make_error_decl(); }
  1113. ;
  1114. /* records the type and storage class specs to use for processing
  1115. the declarators that follow.
  1116. Maintains a stack of outer-level values of pstate.declspecs,
  1117. for the sake of parm declarations nested in function declarators. */
  1118. setspecs: /* empty */
  1119. {
  1120. push_declspec_stack();
  1121. pending_xref_error();
  1122. pstate.declspecs = $<u.telement>0;
  1123. pstate.attributes = NULL;
  1124. }
  1125. ;
  1126. /* Possibly attributes after a comma, which should be saved in
  1127. pstate.attributes */
  1128. maybe_resetattrs:
  1129. maybe_attribute
  1130. { pstate.attributes = $1; }
  1131. ;
  1132. decl:
  1133. declspecs_ts setspecs initdecls ';'
  1134. { $$ = make_data_decl($1, $3); }
  1135. | declspecs_nots setspecs notype_initdecls ';'
  1136. { $$ = make_data_decl($1, $3); }
  1137. | declspecs_ts setspecs nested_function
  1138. { $$ = $3;
  1139. pop_declspec_stack(); }
  1140. | declspecs_nots setspecs notype_nested_function
  1141. { $$ = $3;
  1142. pop_declspec_stack(); }
  1143. | declspecs setspecs ';'
  1144. { shadow_tag($1);
  1145. $$ = make_data_decl($1, NULL); }
  1146. | extension decl
  1147. { $$ = make_extension_decl($1.i, $1.location, $2); }
  1148. ;
  1149. /* declspecs borrowed from gcc 3. I think it's really ugly, but I guess
  1150. they (and therefore I) am stuck with this brokenness.
  1151. The only redeeming feature is that it's cleaner than gcc 2
  1152. */
  1153. /* A list of declaration specifiers. These are:
  1154. - Storage class specifiers (SCSPEC), which for GCC currently include
  1155. function specifiers ("inline").
  1156. - Type specifiers (type_spec_*).
  1157. - Type qualifiers (TYPE_QUAL).
  1158. - Attribute specifier lists (attributes).
  1159. These are stored as a TREE_LIST; the head of the list is the last
  1160. item in the specifier list. Each entry in the list has either a
  1161. TREE_PURPOSE that is an attribute specifier list, or a TREE_VALUE that
  1162. is a single other specifier or qualifier; and a TREE_CHAIN that is the
  1163. rest of the list. TREE_STATIC is set on the list if something other
  1164. than a storage class specifier or attribute has been seen; this is used
  1165. to warn for the obsolescent usage of storage class specifiers other than
  1166. at the start of the list. (Doing this properly would require function
  1167. specifiers to be handled separately from storage class specifiers.)
  1168. The various cases below are classified according to:
  1169. (a) Whether a storage class specifier is included or not; some
  1170. places in the grammar disallow storage class specifiers (_sc or _nosc).
  1171. (b) Whether a type specifier has been seen; after a type specifier,
  1172. a typedef name is an identifier to redeclare (_ts or _nots).
  1173. (c) Whether the list starts with an attribute; in certain places,
  1174. the grammar requires specifiers that don't start with an attribute
  1175. (_sa or _nosa).
  1176. (d) Whether the list ends with an attribute (or a specifier such that
  1177. any following attribute would have been parsed as part of that specifier);
  1178. this avoids shift-reduce conflicts in the parsing of attributes
  1179. (_ea or _noea).
  1180. TODO:
  1181. (i) Distinguish between function specifiers and storage class specifiers,
  1182. at least for the purpose of warnings about obsolescent usage.
  1183. (ii) Halve the number of productions here by eliminating the _sc/_nosc
  1184. distinction and instead checking where required that storage class
  1185. specifiers aren't present. */
  1186. declspecs_nosc_nots_nosa_noea:
  1187. type_qual
  1188. | declspecs_nosc_nots_nosa_noea type_qual
  1189. { $$ = type_element_chain($1, $2); }
  1190. | declspecs_nosc_nots_nosa_ea type_qual
  1191. { $$ = type_element_chain($1, $2); }
  1192. ;
  1193. declspecs_nosc_nots_nosa_ea:
  1194. declspecs_nosc_nots_nosa_noea eattributes
  1195. { $$ = type_element_chain($1, $2); }
  1196. ;
  1197. declspecs_nosc_nots_sa_noea:
  1198. declspecs_nosc_nots_sa_noea type_qual
  1199. { $$ = type_element_chain($1, $2); }
  1200. | declspecs_nosc_nots_sa_ea type_qual
  1201. { $$ = type_element_chain($1, $2); }
  1202. ;
  1203. declspecs_nosc_nots_sa_ea:
  1204. eattributes
  1205. | declspecs_nosc_nots_sa_noea eattributes
  1206. ;
  1207. declspecs_nosc_ts_nosa_noea:
  1208. type_spec_nonattr
  1209. | declspecs_nosc_ts_nosa_noea type_qual
  1210. { $$ = type_element_chain($1, $2); }
  1211. | declspecs_nosc_ts_nosa_ea type_qual
  1212. { $$ = type_element_chain($1, $2); }
  1213. | declspecs_nosc_ts_nosa_noea type_spec_reserved_nonattr
  1214. { $$ = type_element_chain($1, $2); }
  1215. | declspecs_nosc_ts_nosa_ea type_spec_reserved_nonattr
  1216. { $$ = type_element_chain($1, $2); }
  1217. | declspecs_nosc_nots_nosa_noea type_spec_nonattr
  1218. { $$ = type_element_chain($1, $2); }
  1219. | declspecs_nosc_nots_nosa_ea type_spec_nonattr
  1220. { $$ = type_element_chain($1, $2); }
  1221. ;
  1222. declspecs_nosc_ts_nosa_ea:
  1223. type_spec_attr
  1224. | declspecs_nosc_ts_nosa_noea eattributes
  1225. { $$ = type_element_chain($1, $2); }
  1226. | declspecs_nosc_ts_nosa_noea type_spec_reserved_attr
  1227. { $$ = type_element_chain($1, $2); }
  1228. | declspecs_nosc_ts_nosa_ea type_spec_reserved_attr
  1229. { $$ = type_element_chain($1, $2); }
  1230. | declspecs_nosc_nots_nosa_noea type_spec_attr
  1231. { $$ = type_element_chain($1, $2); }
  1232. | declspecs_nosc_nots_nosa_ea type_spec_attr
  1233. { $$ = type_element_chain($1, $2); }
  1234. ;
  1235. declspecs_nosc_ts_sa_noea:
  1236. declspecs_nosc_ts_sa_noea type_qual
  1237. { $$ = type_element_chain($1, $2); }
  1238. | declspecs_nosc_ts_sa_ea type_qual
  1239. { $$ = type_element_chain($1, $2); }
  1240. | declspecs_nosc_ts_sa_noea type_spec_reserved_nonattr
  1241. { $$ = type_element_chain($1, $2); }
  1242. | declspecs_nosc_ts_sa_ea type_spec_reserved_nonattr
  1243. { $$ = type_element_chain($1, $2); }
  1244. | declspecs_nosc_nots_sa_noea type_spec_nonattr
  1245. { $$ = type_element_chain($1, $2); }
  1246. | declspecs_nosc_nots_sa_ea type_spec_nonattr
  1247. { $$ = type_element_chain($1, $2); }
  1248. ;
  1249. declspecs_nosc_ts_sa_ea:
  1250. declspecs_nosc_ts_sa_noea eattributes
  1251. { $$ = type_element_chain($1, $2); }
  1252. | declspecs_nosc_ts_sa_noea type_spec_reserved_attr
  1253. { $$ = type_element_chain($1, $2); }
  1254. | declspecs_nosc_ts_sa_ea type_spec_reserved_attr
  1255. { $$ = type_element_chain($1, $2); }
  1256. | declspecs_nosc_nots_sa_noea type_spec_attr
  1257. { $$ = type_element_chain($1, $2); }
  1258. | declspecs_nosc_nots_sa_ea type_spec_attr
  1259. { $$ = type_element_chain($1, $2); }
  1260. ;
  1261. declspecs_sc_nots_nosa_noea:
  1262. scspec
  1263. | declspecs_sc_nots_nosa_noea type_qual
  1264. { $$ = type_element_chain($1, $2); }
  1265. | declspecs_sc_nots_nosa_ea type_qual
  1266. { $$ = type_element_chain($1, $2); }
  1267. | declspecs_nosc_nots_nosa_noea scspec
  1268. { $$ = type_element_chain($1, $2); }
  1269. | declspecs_nosc_nots_nosa_ea scspec
  1270. { $$ = type_element_chain($1, $2); }
  1271. | declspecs_sc_nots_nosa_noea scspec
  1272. { $$ = type_element_chain($1, $2); }
  1273. | declspecs_sc_nots_nosa_ea scspec
  1274. { $$ = type_element_chain($1, $2); }
  1275. ;
  1276. declspecs_sc_nots_nosa_ea:
  1277. declspecs_sc_nots_nosa_noea eattributes
  1278. { $$ = type_element_chain($1, $2); }
  1279. ;
  1280. declspecs_sc_nots_sa_noea:
  1281. declspecs_sc_nots_sa_noea type_qual
  1282. { $$ = type_element_chain($1, $2); }
  1283. | declspecs_sc_nots_sa_ea type_qual
  1284. { $$ = type_element_chain($1, $2); }
  1285. | declspecs_nosc_nots_sa_noea scspec
  1286. { $$ = type_element_chain($1, $2); }
  1287. | declspecs_nosc_nots_sa_ea scspec
  1288. { $$ = type_element_chain($1, $2); }
  1289. | declspecs_sc_nots_sa_noea scspec
  1290. { $$ = type_element_chain($1, $2); }
  1291. | declspecs_sc_nots_sa_ea scspec
  1292. { $$ = type_element_chain($1, $2); }
  1293. ;
  1294. declspecs_sc_nots_sa_ea:
  1295. declspecs_sc_nots_sa_noea eattributes
  1296. { $$ = type_element_chain($1, $2); }
  1297. ;
  1298. declspecs_sc_ts_nosa_noea:
  1299. declspecs_sc_ts_nosa_noea type_qual
  1300. { $$ = type_element_chain($1, $2); }
  1301. | declspecs_sc_ts_nosa_ea type_qual
  1302. { $$ = type_element_chain($1, $2); }
  1303. | declspecs_sc_ts_nosa_noea type_spec_reserved_nonattr
  1304. { $$ = type_element_chain($1, $2); }
  1305. | declspecs_sc_ts_nosa_ea type_spec_reserved_nonattr
  1306. { $$ = type_element_chain($1, $2); }
  1307. | declspecs_sc_nots_nosa_noea type_spec_nonattr
  1308. { $$ = type_element_chain($1, $2); }
  1309. | declspecs_sc_nots_nosa_ea type_spec_nonattr
  1310. { $$ = type_element_chain($1, $2); }
  1311. | declspecs_nosc_ts_nosa_noea scspec
  1312. { $$ = type_element_chain($1, $2); }
  1313. | declspecs_nosc_ts_nosa_ea scspec
  1314. { $$ = type_element_chain($1, $2); }
  1315. | declspecs_sc_ts_nosa_noea scspec
  1316. { $$ = type_element_chain($1, $2); }
  1317. | declspecs_sc_ts_nosa_ea scspec
  1318. { $$ = type_element_chain($1, $2); }
  1319. ;
  1320. declspecs_sc_ts_nosa_ea:
  1321. declspecs_sc_ts_nosa_noea eattributes
  1322. { $$ = type_element_chain($1, $2); }
  1323. | declspecs_sc_ts_nosa_noea type_spec_reserved_attr
  1324. { $$ = type_element_chain($1, $2); }
  1325. | declspecs_sc_ts_nosa_ea type_spec_reserved_attr
  1326. { $$ = type_element_chain($1, $2); }
  1327. | declspecs_sc_nots_nosa_noea type_spec_attr
  1328. { $$ = type_element_chain($1, $2); }
  1329. | declspecs_sc_nots_nosa_ea type_spec_attr
  1330. { $$ = type_element_chain($1, $2); }
  1331. ;
  1332. declspecs_sc_ts_sa_noea:
  1333. declspecs_sc_ts_sa_noea type_qual
  1334. { $$ = type_element_chain($1, $2); }
  1335. | declspecs_sc_ts_sa_ea type_qual
  1336. { $$ = type_element_chain($1, $2); }
  1337. | declspecs_sc_ts_sa_noea type_spec_reserved_nonattr
  1338. { $$ = type_element_chain($1, $2); }
  1339. | declspecs_sc_ts_sa_ea type_spec_reserved_nonattr
  1340. { $$ = type_element_chain($1, $2); }
  1341. | declspecs_sc_nots_sa_noea type_spec_nonattr
  1342. { $$ = type_element_chain($1, $2); }
  1343. | declspecs_sc_nots_sa_ea type_spec_nonattr
  1344. { $$ = type_element_chain($1, $2); }
  1345. | declspecs_nosc_ts_sa_noea scspec
  1346. { $$ = type_element_chain($1, $2); }
  1347. | declspecs_nosc_ts_sa_ea scspec
  1348. { $$ = type_element_chain($1, $2); }
  1349. | declspecs_sc_ts_sa_noea scspec
  1350. { $$ = type_element_chain($1, $2); }
  1351. | declspecs_sc_ts_sa_ea scspec
  1352. { $$ = type_element_chain($1, $2); }
  1353. ;
  1354. declspecs_sc_ts_sa_ea:
  1355. declspecs_sc_ts_sa_noea eattributes
  1356. { $$ = type_element_chain($1, $2); }
  1357. | declspecs_sc_ts_sa_noea type_spec_reserved_attr
  1358. { $$ = type_element_chain($1, $2); }
  1359. | declspecs_sc_ts_sa_ea type_spec_reserved_attr
  1360. { $$ = type_element_chain($1, $2); }
  1361. | declspecs_sc_nots_sa_noea type_spec_attr
  1362. { $$ = type_element_chain($1, $2); }
  1363. | declspecs_sc_nots_sa_ea type_spec_attr
  1364. { $$ = type_element_chain($1, $2); }
  1365. ;
  1366. /* Particular useful classes of declspecs. */
  1367. declspecs_ts:
  1368. declspecs_nosc_ts_nosa_noea
  1369. | declspecs_nosc_ts_nosa_ea
  1370. | declspecs_nosc_ts_sa_noea
  1371. | declspecs_nosc_ts_sa_ea
  1372. | declspecs_sc_ts_nosa_noea
  1373. | declspecs_sc_ts_nosa_ea
  1374. | declspecs_sc_ts_sa_noea
  1375. | declspecs_sc_ts_sa_ea
  1376. ;
  1377. declspecs_nots:
  1378. declspecs_nosc_nots_nosa_noea
  1379. | declspecs_nosc_nots_nosa_ea
  1380. | declspecs_nosc_nots_sa_noea
  1381. | declspecs_nosc_nots_sa_ea
  1382. | declspecs_sc_nots_nosa_noea
  1383. | declspecs_sc_nots_nosa_ea
  1384. | declspecs_sc_nots_sa_noea
  1385. | declspecs_sc_nots_sa_ea
  1386. ;
  1387. declspecs_ts_nosa:
  1388. declspecs_nosc_ts_nosa_noea
  1389. | declspecs_nosc_ts_nosa_ea
  1390. | declspecs_sc_ts_nosa_noea
  1391. | declspecs_sc_ts_nosa_ea
  1392. ;
  1393. declspecs_nots_nosa:
  1394. declspecs_nosc_nots_nosa_noea
  1395. | declspecs_nosc_nots_nosa_ea
  1396. | declspecs_sc_nots_nosa_noea
  1397. | declspecs_sc_nots_nosa_ea
  1398. ;
  1399. declspecs_nosc_ts:
  1400. declspecs_nosc_ts_nosa_noea
  1401. | declspecs_nosc_ts_nosa_ea
  1402. | declspecs_nosc_ts_sa_noea
  1403. | declspecs_nosc_ts_sa_ea
  1404. ;
  1405. declspecs_nosc_nots:
  1406. declspecs_nosc_nots_nosa_noea
  1407. | declspecs_nosc_nots_nosa_ea
  1408. | declspecs_nosc_nots_sa_noea
  1409. | declspecs_nosc_nots_sa_ea
  1410. ;
  1411. declspecs_nosc:
  1412. declspecs_nosc_ts
  1413. | declspecs_nosc_nots
  1414. ;
  1415. declspecs:
  1416. declspecs_ts
  1417. | declspecs_nots
  1418. ;
  1419. /* A (possibly empty) sequence of type qualifiers and attributes. */
  1420. maybe_type_quals_attrs:
  1421. /* empty */
  1422. { $$ = NULL; }
  1423. | declspecs_nosc_nots
  1424. ;
  1425. /* A type specifier (but not a type qualifier).
  1426. Once we have seen one of these in a declaration,
  1427. if a typedef name appears then it is being redeclared.
  1428. The _reserved versions start with a reserved word and may appear anywhere
  1429. in the declaration specifiers; the _nonreserved versions may only
  1430. appear before any other type specifiers, and after that are (if names)
  1431. being redeclared.
  1432. FIXME: should the _nonreserved version be restricted to names being
  1433. redeclared only? The other entries there relate only the GNU extensions
  1434. and Objective C, and are historically parsed thus, and don't make sense
  1435. after other type specifiers, but it might be cleaner to count them as
  1436. _reserved.
  1437. _attr means: specifiers that either end with attributes,
  1438. or are such that any following attributes would
  1439. be parsed as part of the specifier.
  1440. _nonattr: specifiers. */
  1441. type_spec_nonattr:
  1442. type_spec_reserved_nonattr
  1443. | type_spec_nonreserved_nonattr
  1444. ;
  1445. type_spec_attr:
  1446. type_spec_reserved_attr
  1447. ;
  1448. type_spec_reserved_nonattr:
  1449. type_spec
  1450. | structuse
  1451. ;
  1452. type_spec_reserved_attr:
  1453. structdef
  1454. ;
  1455. type_spec_nonreserved_nonattr:
  1456. TYPENAME
  1457. { /* For a typedef name, record the meaning, not the name.
  1458. In case of `foo foo, bar;'. */
  1459. $$ = CAST(type_element, new_typename(pr, $1.location, $1.decl)); }
  1460. | COMPONENTREF '.' identifier
  1461. {
  1462. /* reference to a typedef from a component. */
  1463. $$ = CAST(type_element, new_component_typeref(pr, $1.location, $3.decl, $1.id));
  1464. }
  1465. | TYPEOF '(' expr ')'
  1466. { $$ = CAST(type_element, new_typeof_expr(pr, $1.location, $3)); }
  1467. | TYPEOF '(' typename ')'
  1468. { $$ = CAST(type_element, new_typeof_type(pr, $1.location, $3)); }
  1469. ;
  1470. /* type_spec_nonreserved_attr does not exist. */
  1471. initdecls:
  1472. initdecls_ { $$ = declaration_reverse($1); }
  1473. ;
  1474. notype_initdecls:
  1475. notype_initdecls_ { $$ = declaration_reverse($1); }
  1476. ;
  1477. initdecls_:
  1478. initdcl
  1479. | initdecls_ ',' maybe_resetattrs initdcl
  1480. { $$ = declaration_chain($4, $1); }
  1481. ;
  1482. notype_initdecls_:
  1483. notype_initdcl { $$ = $1; }
  1484. | notype_initdecls_ ',' maybe_resetattrs initdcl
  1485. { $$ = declaration_chain($4, $1); }
  1486. ;
  1487. maybeasm:
  1488. /* empty */
  1489. { $$ = NULL; }
  1490. | ASM_KEYWORD '(' STRING ')'
  1491. { $$ = new_asm_stmt(pr, $1.location, CAST(expression, $3),
  1492. NULL, NULL, NULL, NULL); }
  1493. ;
  1494. initdcl:
  1495. declarator maybeasm maybe_attribute '='
  1496. { $<u.decl>$ = start_decl($1, $2, pstate.declspecs, 1,

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