1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
28 #define YYERROR_VERBOSE
38 %token <t>ENT_TYPEDEF_STRUCT
40 %token ENT_EXTERNSTATIC
49 %token PERCENTPERCENT "%%"
57 %type <p> struct_fields yacc_ids yacc_typematch
58 %type <t> type lasttype
59 %type <o> optionsopt options option optionseq optionseqopt
65 | typedef_struct start
70 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
72 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
74 do_typedef ($6, $1, &lexer_line);
75 lexer_toplevel_done = 1;
79 | ENT_STRUCT options '{' struct_fields '}'
81 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
83 lexer_toplevel_done = 1;
89 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
91 note_variable ($4, adjust_field_type ($3, $2), $2,
94 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
96 note_variable ($4, create_array ($3, $5),
99 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
101 note_variable ($4, create_array (create_array ($3, $6),
109 lexer_toplevel_done = 1;
118 yacc_union: ENT_YACCUNION options struct_fields '}' yacc_typematch
121 note_yacc_type ($2, $3, $5, &lexer_line);
125 yacc_typematch: /* empty */
127 | yacc_typematch PERCENT_ID yacc_ids
130 for (p = $3; p->next != NULL; p = p->next)
140 | yacc_typematch PERCENT_ID '<' ID '>' yacc_ids
143 type_p newtype = NULL;
144 if (strcmp ($2, "type") == 0)
145 newtype = (type_p) 1;
146 for (p = $6; p->next != NULL; p = p->next)
158 yacc_ids: /* empty */
162 pair_p p = xcalloc (1, sizeof (*p));
164 p->line = lexer_line;
165 p->opt = xmalloc (sizeof (*(p->opt)));
166 p->opt->name = "tag";
168 p->opt->info = (char *)$2;
173 pair_p p = xcalloc (1, sizeof (*p));
175 p->line = lexer_line;
176 p->opt = xmalloc (sizeof (*(p->opt)));
177 p->opt->name = "tag";
179 p->opt->info = xasprintf ("'%s'", $2);
184 struct_fields: { $$ = NULL; }
185 | type optionsopt ID bitfieldopt ';' struct_fields
187 pair_p p = xmalloc (sizeof (*p));
188 p->type = adjust_field_type ($1, $2);
192 p->line = lexer_line;
195 | type optionsopt ID ARRAY ';' struct_fields
197 pair_p p = xmalloc (sizeof (*p));
198 p->type = adjust_field_type (create_array ($1, $4), $2);
202 p->line = lexer_line;
205 | type optionsopt ID ARRAY ARRAY ';' struct_fields
207 pair_p p = xmalloc (sizeof (*p));
208 p->type = create_array (create_array ($1, $5), $4);
212 p->line = lexer_line;
217 bitfieldopt: /* empty */
225 { $$ = resolve_typedef ($1, &lexer_line); }
227 { $$ = create_pointer ($1); }
228 | STRUCT ID '{' struct_fields '}'
230 new_structure ($2, 0, &lexer_line, $4, NULL);
231 $$ = find_structure ($2, 0);
234 { $$ = find_structure ($2, 0); }
235 | UNION ID '{' struct_fields '}'
237 new_structure ($2, 1, &lexer_line, $4, NULL);
238 $$ = find_structure ($2, 1);
241 { $$ = find_structure ($2, 1); }
243 { $$ = create_scalar_type ($2, strlen ($2)); }
244 | ENUM ID '{' enum_items '}'
245 { $$ = create_scalar_type ($2, strlen ($2)); }
248 enum_items: /* empty */
249 | ID '=' NUM ',' enum_items
257 optionsopt: { $$ = NULL; }
258 | options { $$ = $1; }
261 options: GTY_TOKEN '(' '(' optionseqopt ')' ')'
266 { $$ = "ptr_alias"; }
271 option: type_option '(' type ')'
273 options_p o = xmalloc (sizeof (*o));
275 o->info = adjust_field_type ($3, NULL);
280 options_p o = xmalloc (sizeof (*o));
282 o->info = (void *)$3;
292 | optionseq ',' option
299 optionseqopt: { $$ = NULL; }
300 | optionseq { $$ = $1; }