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
26 #define YYERROR_VERBOSE
36 %token <t>ENT_TYPEDEF_STRUCT
38 %token ENT_EXTERNSTATIC
40 %token GTY_TOKEN "GTY"
42 %token STRUCT "struct"
44 %token ALIAS "ptr_alias"
45 %token PARAM_IS "param_is"
47 %token PERCENTPERCENT "%%"
55 %type <p> struct_fields yacc_ids yacc_typematch
56 %type <t> type lasttype
57 %type <o> optionsopt options option optionseq optionseqopt
63 | typedef_struct start
68 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
70 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
72 do_typedef ($6, $1, &lexer_line);
73 lexer_toplevel_done = 1;
76 | ENT_STRUCT options '{' struct_fields '}'
78 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
80 lexer_toplevel_done = 1;
85 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
87 note_variable ($4, adjust_field_type ($3, $2), $2,
90 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
92 note_variable ($4, create_array ($3, $5),
95 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
97 note_variable ($4, create_array (create_array ($3, $6),
105 lexer_toplevel_done = 1;
114 yacc_union: ENT_YACCUNION options struct_fields '}' yacc_typematch
117 note_yacc_type ($2, $3, $5, &lexer_line);
121 yacc_typematch: /* empty */
123 | yacc_typematch PERCENT_ID yacc_ids
126 for (p = $3; p->next != NULL; p = p->next)
136 | yacc_typematch PERCENT_ID '<' ID '>' yacc_ids
139 type_p newtype = NULL;
140 if (strcmp ($2, "type") == 0)
141 newtype = (type_p) 1;
142 for (p = $6; p->next != NULL; p = p->next)
154 yacc_ids: /* empty */
158 pair_p p = xcalloc (1, sizeof (*p));
160 p->line = lexer_line;
161 p->opt = xmalloc (sizeof (*(p->opt)));
162 p->opt->name = "tag";
164 p->opt->info = (char *)$2;
169 pair_p p = xcalloc (1, sizeof (*p));
171 p->line = lexer_line;
172 p->opt = xmalloc (sizeof (*(p->opt)));
173 p->opt->name = "tag";
175 p->opt->info = xmalloc (3 + strlen ($2));
176 sprintf (p->opt->info, "'%s'", $2);
181 struct_fields: { $$ = NULL; }
182 | type optionsopt ID bitfieldopt ';' struct_fields
184 pair_p p = xmalloc (sizeof (*p));
185 p->type = adjust_field_type ($1, $2);
189 p->line = lexer_line;
192 | type optionsopt ID ARRAY ';' struct_fields
194 pair_p p = xmalloc (sizeof (*p));
195 p->type = adjust_field_type (create_array ($1, $4), $2);
199 p->line = lexer_line;
202 | type optionsopt ID ARRAY ARRAY ';' struct_fields
204 pair_p p = xmalloc (sizeof (*p));
205 p->type = create_array (create_array ($1, $5), $4);
209 p->line = lexer_line;
214 bitfieldopt: /* empty */
221 { $$ = resolve_typedef ($1, &lexer_line); }
223 { $$ = create_pointer ($1); }
224 | STRUCT ID '{' struct_fields '}'
226 new_structure ($2, 0, &lexer_line, $4, NULL);
227 $$ = find_structure ($2, 0);
230 { $$ = find_structure ($2, 0); }
231 | UNION ID '{' struct_fields '}'
233 new_structure ($2, 1, &lexer_line, $4, NULL);
234 $$ = find_structure ($2, 1);
237 { $$ = find_structure ($2, 1); }
239 { $$ = create_scalar_type ($2, strlen ($2)); }
240 | ENUM ID '{' enum_items '}'
241 { $$ = create_scalar_type ($2, strlen ($2)); }
244 enum_items: /* empty */
245 | ID '=' NUM ',' enum_items
253 optionsopt: { $$ = NULL; }
254 | options { $$ = $1; }
257 options: GTY_TOKEN '(' '(' optionseqopt ')' ')'
262 { $$ = "ptr_alias"; }
267 option: type_option '(' type ')'
269 options_p o = xmalloc (sizeof (*o));
276 options_p o = xmalloc (sizeof (*o));
278 o->info = (void *)$3;
288 | optionseq ',' option
295 optionseqopt: { $$ = NULL }
296 | optionseq { $$ = $1; }