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 <s>ENT_TYPEDEF_STRUCT
40 %token <s>ENT_TYPEDEF_UNION
42 %token ENT_EXTERNSTATIC
58 %type <p> struct_fields
59 %type <t> type lasttype
60 %type <o> optionsopt options optionseq
61 %type <s> type_option stringseq
66 | typedef_struct start
71 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
73 type_p t = new_structure ($1, false, &lexer_line, $4, $2);
74 do_typedef ($6, t, &lexer_line);
75 lexer_toplevel_done = 1;
78 | ENT_TYPEDEF_UNION options '{' struct_fields '}' ID
80 type_p t = new_structure ($1, true, &lexer_line, $4, $2);
81 do_typedef ($6, t, &lexer_line);
82 lexer_toplevel_done = 1;
85 | ENT_STRUCT options '{' struct_fields '}'
87 new_structure ($1, false, &lexer_line, $4, $2);
88 lexer_toplevel_done = 1;
91 | ENT_UNION options '{' struct_fields '}'
93 new_structure ($1, true, &lexer_line, $4, $2);
94 lexer_toplevel_done = 1;
99 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
101 note_variable ($4, adjust_field_type ($3, $2), $2,
104 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
106 note_variable ($4, create_array ($3, $5),
109 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
111 note_variable ($4, create_array (create_array ($3, $6),
119 lexer_toplevel_done = 1;
128 struct_fields: { $$ = NULL; }
129 | type optionsopt ID bitfieldopt ';' struct_fields
131 $$ = create_field_at ($6, $1, $3, $2, &lexer_line);
133 | type optionsopt ID ARRAY ';' struct_fields
135 $$ = create_field_at ($6, create_array ($1, $4),
136 $3, $2, &lexer_line);
138 | type optionsopt ID ARRAY ARRAY ';' struct_fields
140 type_p arr = create_array (create_array ($1, $5), $4);
141 $$ = create_field_at ($7, arr, $3, $2, &lexer_line);
143 | type ':' bitfieldlen ';' struct_fields
147 bitfieldopt: /* empty */
151 bitfieldlen: NUM | ID
156 { $$ = create_scalar_type ($1); }
158 { $$ = resolve_typedef ($1, &lexer_line); }
159 | VEC_TOKEN '(' ID ',' ID ')'
160 { $$ = resolve_typedef (concat ("VEC_", $3, "_", $5, (char *)0),
163 { $$ = create_pointer ($1); }
164 | STRUCT ID '{' struct_fields '}'
165 { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
167 { $$ = find_structure ($2, 0); }
168 | UNION ID '{' struct_fields '}'
169 { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
171 { $$ = find_structure ($2, 1); }
173 { $$ = create_scalar_type ($2); }
174 | ENUM ID '{' enum_items '}'
175 { $$ = create_scalar_type ($2); }
178 enum_items: /* empty */
179 | ID '=' NUM ',' enum_items
187 optionsopt: { $$ = NULL; }
188 | options { $$ = $1; }
191 options: GTY_TOKEN '(' '(' optionseq ')' ')'
196 { $$ = "ptr_alias"; }
201 optionseq: { $$ = NULL; }
202 | optionseq commaopt ID
203 { $$ = create_option ($1, $3, (void *)""); }
204 | optionseq commaopt ID '(' stringseq ')'
205 { $$ = create_option ($1, $3, (void *)$5); }
206 | optionseq commaopt type_option '(' type ')'
207 { $$ = create_option ($1, $3, adjust_field_type ($5, 0)); }
208 | optionseq commaopt NESTED_PTR '(' type ',' stringseq ',' stringseq ')'
209 { $$ = create_nested_ptr_option ($1, $5, $7, $9); }
211 commaopt: /* nothing */
219 size_t l1 = strlen ($1);
220 size_t l2 = strlen ($2);
221 char *s = XRESIZEVEC (char, $1, l1 + l2 + 1);
222 memcpy (s + l1, $2, l2 + 1);