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
67 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
69 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
71 do_typedef ($6, $1, &lexer_line);
72 lexer_toplevel_done = 1;
75 | ENT_STRUCT options '{' struct_fields '}'
77 new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
79 lexer_toplevel_done = 1;
83 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
85 note_variable ($4, adjust_field_type ($3, $2), $2,
88 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
90 note_variable ($4, create_array ($3, $5),
93 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
95 note_variable ($4, create_array (create_array ($3, $6),
102 lexer_toplevel_done = 1;
110 yacc_union: ENT_YACCUNION options struct_fields '}' yacc_typematch PERCENTPERCENT
112 note_yacc_type ($2, $3, $5, &lexer_line);
115 yacc_typematch: /* empty */
117 | yacc_typematch PERCENT_ID yacc_ids
120 for (p = $3; p->next != NULL; p = p->next)
130 | yacc_typematch PERCENT_ID '<' ID '>' yacc_ids
133 type_p newtype = NULL;
134 if (strcmp ($2, "type") == 0)
135 newtype = (type_p) 1;
136 for (p = $6; p->next != NULL; p = p->next)
148 yacc_ids: /* empty */
152 pair_p p = xcalloc (1, sizeof (*p));
154 p->line = lexer_line;
155 p->opt = xmalloc (sizeof (*(p->opt)));
156 p->opt->name = "tag";
158 p->opt->info = (char *)$2;
163 pair_p p = xcalloc (1, sizeof (*p));
165 p->line = lexer_line;
166 p->opt = xmalloc (sizeof (*(p->opt)));
167 p->opt->name = "tag";
169 p->opt->info = xmalloc (3 + strlen ($2));
170 sprintf (p->opt->info, "'%s'", $2);
174 struct_fields: { $$ = NULL; }
175 | type optionsopt ID bitfieldopt ';' struct_fields
177 pair_p p = xmalloc (sizeof (*p));
178 p->type = adjust_field_type ($1, $2);
182 p->line = lexer_line;
185 | type optionsopt ID ARRAY ';' struct_fields
187 pair_p p = xmalloc (sizeof (*p));
188 p->type = adjust_field_type (create_array ($1, $4), $2);
192 p->line = lexer_line;
195 | type optionsopt ID ARRAY ARRAY ';' struct_fields
197 pair_p p = xmalloc (sizeof (*p));
198 p->type = create_array (create_array ($1, $5), $4);
202 p->line = lexer_line;
206 bitfieldopt: /* empty */
212 { $$ = resolve_typedef ($1, &lexer_line); }
214 { $$ = create_pointer ($1); }
215 | STRUCT ID '{' struct_fields '}'
217 new_structure ($2, 0, &lexer_line, $4, NULL);
218 $$ = find_structure ($2, 0);
221 { $$ = find_structure ($2, 0); }
222 | UNION ID '{' struct_fields '}'
224 new_structure ($2, 1, &lexer_line, $4, NULL);
225 $$ = find_structure ($2, 1);
228 { $$ = find_structure ($2, 1); }
230 { $$ = create_scalar_type ($2, strlen ($2)); }
231 | ENUM ID '{' enum_items '}'
232 { $$ = create_scalar_type ($2, strlen ($2)); }
234 enum_items: /* empty */
235 | ID '=' NUM ',' enum_items
243 optionsopt: { $$ = NULL; }
244 | options { $$ = $1; }
246 options: GTY_TOKEN '(' '(' optionseqopt ')' ')' { $$ = $4; }
249 { $$ = "ptr_alias"; }
253 option: type_option '(' type ')'
255 options_p o = xmalloc (sizeof (*o));
262 options_p o = xmalloc (sizeof (*o));
264 o->info = (void *)$3;
273 | optionseq ',' option
279 optionseqopt: { $$ = NULL }
280 | optionseq { $$ = $1; }