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, 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
50 %token PERCENTPERCENT
"%%"
58 %type
<p
> struct_fields yacc_ids yacc_typematch
59 %type
<t
> type lasttype
60 %type
<o
> optionsopt options option optionseq optionseqopt
61 %type
<s
> type_option stringseq
66 | typedef_struct start
71 typedef_struct: ENT_TYPEDEF_STRUCT options
'{' struct_fields
'}' ID
73 new_structure
($1->u.s.tag
, UNION_P
($1), &lexer_line
,
75 do_typedef
($6, $1, &lexer_line
);
76 lexer_toplevel_done
= 1;
80 | ENT_STRUCT options
'{' struct_fields
'}'
82 new_structure
($1->u.s.tag
, UNION_P
($1), &lexer_line
,
84 lexer_toplevel_done
= 1;
90 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
92 note_variable
($4, adjust_field_type
($3, $2), $2,
95 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
97 note_variable
($4, create_array
($3, $5),
100 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
102 note_variable
($4, create_array
(create_array
($3, $6),
110 lexer_toplevel_done
= 1;
119 yacc_union: ENT_YACCUNION options struct_fields
'}' yacc_typematch
122 note_yacc_type
($2, $3, $5, &lexer_line
);
126 yacc_typematch: /* empty */
128 | yacc_typematch PERCENT_ID yacc_ids
131 for
(p
= $3; p
->next
!= NULL
; p
= p
->next
)
141 | yacc_typematch PERCENT_ID
'<' ID
'>' yacc_ids
144 type_p newtype
= NULL
;
145 if
(strcmp
($2, "type") == 0)
146 newtype
= (type_p
) 1;
147 for
(p
= $6; p
->next
!= NULL
; p
= p
->next
)
159 yacc_ids: /* empty */
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
= (char *)$2;
174 pair_p p
= xcalloc
(1, sizeof
(*p
));
176 p
->line
= lexer_line
;
177 p
->opt
= xmalloc
(sizeof
(*(p
->opt
)));
178 p
->opt
->name
= "tag";
180 p
->opt
->info
= xasprintf
("'%s'", $2);
185 struct_fields: { $$
= NULL
; }
186 | type optionsopt ID bitfieldopt
';' struct_fields
188 pair_p p
= xmalloc
(sizeof
(*p
));
189 p
->type
= adjust_field_type
($1, $2);
193 p
->line
= lexer_line
;
196 | type optionsopt ID ARRAY
';' struct_fields
198 pair_p p
= xmalloc
(sizeof
(*p
));
199 p
->type
= adjust_field_type
(create_array
($1, $4), $2);
203 p
->line
= lexer_line
;
206 | type optionsopt ID ARRAY ARRAY
';' struct_fields
208 pair_p p
= xmalloc
(sizeof
(*p
));
209 p
->type
= create_array
(create_array
($1, $5), $4);
213 p
->line
= lexer_line
;
216 | type
':' bitfieldlen
';' struct_fields
220 bitfieldopt: /* empty */
224 bitfieldlen: NUM | ID
231 { $$
= resolve_typedef
($1, &lexer_line
); }
233 { $$
= create_pointer
($1); }
234 | STRUCT ID
'{' struct_fields
'}'
236 new_structure
($2, 0, &lexer_line
, $4, NULL
);
237 $$
= find_structure
($2, 0);
240 { $$
= find_structure
($2, 0); }
241 | UNION ID
'{' struct_fields
'}'
243 new_structure
($2, 1, &lexer_line
, $4, NULL
);
244 $$
= find_structure
($2, 1);
247 { $$
= find_structure
($2, 1); }
249 { $$
= create_scalar_type
($2, strlen
($2)); }
250 | ENUM ID
'{' enum_items
'}'
251 { $$
= create_scalar_type
($2, strlen
($2)); }
254 enum_items: /* empty */
255 | ID
'=' NUM
',' enum_items
263 optionsopt: { $$
= NULL
; }
264 | options
{ $$
= $1; }
267 options: GTY_TOKEN
'(' '(' optionseqopt
')' ')'
272 { $$
= "ptr_alias"; }
278 { $$
= create_option
($1, (void *)""); }
279 | ID
'(' stringseq
')'
280 { $$
= create_option
($1, (void *)$3); }
281 | type_option
'(' type
')'
282 { $$
= create_option
($1, adjust_field_type
($3, NULL
)); }
283 | NESTED_PTR
'(' type
',' stringseq
',' stringseq
')'
285 struct nested_ptr_data d
=
286 { adjust_field_type
($3, NULL
), $5, $7 };
287 $$
= create_option
("nested_ptr",
288 xmemdup
(&d
, sizeof
(d
), sizeof
(d
)));
297 | optionseq
',' option
304 optionseqopt: { $$
= NULL
; }
305 | optionseq
{ $$
= $1; }
312 size_t l1
= strlen
($1);
313 size_t l2
= strlen
($2);
314 char *s
= xrealloc
((char *)$1, l1
+ l2
+ 1);
315 memcpy
(s
+ l1
, $2, l2
+ 1);