1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "coretypes.h"
28 #define YYERROR_VERBOSE
38 %token <t>ENT_TYPEDEF_STRUCT
40 %token ENT_EXTERNSTATIC
56 %type <p> struct_fields
57 %type <t> type lasttype
58 %type <o> optionsopt options option optionseq optionseqopt
59 %type <s> type_option stringseq
64 | typedef_struct start
69 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
71 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
73 do_typedef ($6, $1, &lexer_line);
74 lexer_toplevel_done = 1;
78 | ENT_STRUCT options '{' struct_fields '}'
80 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
82 lexer_toplevel_done = 1;
88 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
90 note_variable ($4, adjust_field_type ($3, $2), $2,
93 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
95 note_variable ($4, create_array ($3, $5),
98 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
100 note_variable ($4, create_array (create_array ($3, $6),
108 lexer_toplevel_done = 1;
117 struct_fields: { $$ = NULL; }
118 | type optionsopt ID bitfieldopt ';' struct_fields
120 pair_p p = XNEW (struct pair);
121 p->type = adjust_field_type ($1, $2);
125 p->line = lexer_line;
128 | type optionsopt ID ARRAY ';' struct_fields
130 pair_p p = XNEW (struct pair);
131 p->type = adjust_field_type (create_array ($1, $4), $2);
135 p->line = lexer_line;
138 | type optionsopt ID ARRAY ARRAY ';' struct_fields
140 pair_p p = XNEW (struct pair);
141 p->type = create_array (create_array ($1, $5), $4);
145 p->line = lexer_line;
148 | type ':' bitfieldlen ';' struct_fields
152 bitfieldopt: /* empty */
156 bitfieldlen: NUM | ID
163 { $$ = resolve_typedef ($1, &lexer_line); }
164 | VEC_TOKEN '(' ID ',' ID ')'
165 { $$ = resolve_typedef (concat ("VEC_", $3, "_", $5, (char *)0),
168 { $$ = create_pointer ($1); }
169 | STRUCT ID '{' struct_fields '}'
170 { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
172 { $$ = find_structure ($2, 0); }
173 | UNION ID '{' struct_fields '}'
174 { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
176 { $$ = find_structure ($2, 1); }
178 { $$ = create_scalar_type ($2, strlen ($2)); }
179 | ENUM ID '{' enum_items '}'
180 { $$ = create_scalar_type ($2, strlen ($2)); }
183 enum_items: /* empty */
184 | ID '=' NUM ',' enum_items
192 optionsopt: { $$ = NULL; }
193 | options { $$ = $1; }
196 options: GTY_TOKEN '(' '(' optionseqopt ')' ')'
201 { $$ = "ptr_alias"; }
207 { $$ = create_option (NULL, $1, (void *)""); }
208 | ID '(' stringseq ')'
209 { $$ = create_option (NULL, $1, (void *)$3); }
210 | type_option '(' type ')'
211 { $$ = create_option (NULL, $1, adjust_field_type ($3, NULL)); }
212 | NESTED_PTR '(' type ',' stringseq ',' stringseq ')'
214 struct nested_ptr_data d;
216 d.type = adjust_field_type ($3, NULL);
219 $$ = create_option (NULL, "nested_ptr",
220 xmemdup (&d, sizeof (d), sizeof (d)));
229 | optionseq ',' option
236 optionseqopt: { $$ = NULL; }
237 | optionseq { $$ = $1; }
244 size_t l1 = strlen ($1);
245 size_t l2 = strlen ($2);
246 char *s = XRESIZEVEC (char, $1, l1 + l2 + 1);
247 memcpy (s + l1, $2, l2 + 1);