1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002, 2004, 2007 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
27 #define YYERROR_VERBOSE
37 %token <s>ENT_TYPEDEF_STRUCT
39 %token <s>ENT_TYPEDEF_UNION
41 %token ENT_EXTERNSTATIC
57 %type <p> struct_fields
58 %type <t> type lasttype
59 %type <o> optionsopt options optionseq
60 %type <s> type_option stringseq
65 | typedef_struct start
70 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
72 type_p t = new_structure ($1, false, &lexer_line, $4, $2);
73 do_typedef ($6, t, &lexer_line);
74 lexer_toplevel_done = 1;
77 | ENT_TYPEDEF_UNION options '{' struct_fields '}' ID
79 type_p t = new_structure ($1, true, &lexer_line, $4, $2);
80 do_typedef ($6, t, &lexer_line);
81 lexer_toplevel_done = 1;
84 | ENT_STRUCT options '{' struct_fields '}'
86 new_structure ($1, false, &lexer_line, $4, $2);
87 lexer_toplevel_done = 1;
90 | ENT_UNION options '{' struct_fields '}'
92 new_structure ($1, true, &lexer_line, $4, $2);
93 lexer_toplevel_done = 1;
98 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
100 note_variable ($4, adjust_field_type ($3, $2), $2,
103 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
105 note_variable ($4, create_array ($3, $5),
108 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
110 note_variable ($4, create_array (create_array ($3, $6),
118 lexer_toplevel_done = 1;
127 struct_fields: { $$ = NULL; }
128 | type optionsopt ID bitfieldopt ';' struct_fields
130 $$ = create_field_at ($6, $1, $3, $2, &lexer_line);
132 | type optionsopt ID ARRAY ';' struct_fields
134 $$ = create_field_at ($6, create_array ($1, $4),
135 $3, $2, &lexer_line);
137 | type optionsopt ID ARRAY ARRAY ';' struct_fields
139 type_p arr = create_array (create_array ($1, $5), $4);
140 $$ = create_field_at ($7, arr, $3, $2, &lexer_line);
142 | type ':' bitfieldlen ';' struct_fields
146 bitfieldopt: /* empty */
150 bitfieldlen: NUM | ID
155 { $$ = create_scalar_type ($1); }
157 { $$ = resolve_typedef ($1, &lexer_line); }
158 | VEC_TOKEN '(' ID ',' ID ')'
159 { $$ = resolve_typedef (concat ("VEC_", $3, "_", $5, (char *)0),
162 { $$ = create_pointer ($1); }
163 | STRUCT ID '{' struct_fields '}'
164 { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
166 { $$ = find_structure ($2, 0); }
167 | UNION ID '{' struct_fields '}'
168 { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
170 { $$ = find_structure ($2, 1); }
172 { $$ = create_scalar_type ($2); }
173 | ENUM ID '{' enum_items '}'
174 { $$ = create_scalar_type ($2); }
177 enum_items: /* empty */
178 | ID '=' NUM ',' enum_items
186 optionsopt: { $$ = NULL; }
187 | options { $$ = $1; }
190 options: GTY_TOKEN '(' '(' optionseq ')' ')'
195 { $$ = "ptr_alias"; }
200 optionseq: { $$ = NULL; }
201 | optionseq commaopt ID
202 { $$ = create_option ($1, $3, (void *)""); }
203 | optionseq commaopt ID '(' stringseq ')'
204 { $$ = create_option ($1, $3, (void *)$5); }
205 | optionseq commaopt type_option '(' type ')'
206 { $$ = create_option ($1, $3, adjust_field_type ($5, 0)); }
207 | optionseq commaopt NESTED_PTR '(' type ',' stringseq ',' stringseq ')'
208 { $$ = create_nested_ptr_option ($1, $5, $7, $9); }
210 commaopt: /* nothing */
218 size_t l1 = strlen ($1);
219 size_t l2 = strlen ($2);
220 char *s = XRESIZEVEC (char, $1, l1 + l2 + 1);
221 memcpy (s + l1, $2, l2 + 1);