Updated for libbid move.
[official-gcc.git] / gcc / gengtype-yacc.y
blob292f3ef6f028ed7aacec9a342d94088f29bcc7d4
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
10 version.
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
15 for more details.
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
20 02110-1301, USA. */
23 #include "bconfig.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "gengtype.h"
28 #define YYERROR_VERBOSE
31 %union {
32 type_p t;
33 pair_p p;
34 options_p o;
35 const char *s;
38 %token <s>ENT_TYPEDEF_STRUCT
39 %token <s>ENT_STRUCT
40 %token <s>ENT_TYPEDEF_UNION
41 %token <s>ENT_UNION
42 %token ENT_EXTERNSTATIC
43 %token GTY_TOKEN
44 %token VEC_TOKEN
45 %token UNION
46 %token STRUCT
47 %token ENUM
48 %token ALIAS
49 %token NESTED_PTR
50 %token <s>PARAM_IS
51 %token NUM
52 %token <s>SCALAR
53 %token <s>ID
54 %token <s>STRING
55 %token <s>ARRAY
56 %token <s>CHAR
58 %type <p> struct_fields
59 %type <t> type lasttype
60 %type <o> optionsopt options optionseq
61 %type <s> type_option stringseq
65 start: /* empty */
66 | typedef_struct start
67 | externstatic start
68 | 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;
77 ';'
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;
84 ';'
85 | ENT_STRUCT options '{' struct_fields '}'
87 new_structure ($1, false, &lexer_line, $4, $2);
88 lexer_toplevel_done = 1;
90 ';'
91 | ENT_UNION options '{' struct_fields '}'
93 new_structure ($1, true, &lexer_line, $4, $2);
94 lexer_toplevel_done = 1;
96 ';'
99 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
101 note_variable ($4, adjust_field_type ($3, $2), $2,
102 &lexer_line);
104 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
106 note_variable ($4, create_array ($3, $5),
107 $2, &lexer_line);
109 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
111 note_variable ($4, create_array (create_array ($3, $6),
112 $5),
113 $2, &lexer_line);
117 lasttype: type
119 lexer_toplevel_done = 1;
120 $$ = $1;
124 semiequal: ';'
125 | '='
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
144 { $$ = $5; }
147 bitfieldopt: /* empty */
148 | ':' bitfieldlen
151 bitfieldlen: NUM | ID
155 type: SCALAR
156 { $$ = create_scalar_type ($1); }
157 | ID
158 { $$ = resolve_typedef ($1, &lexer_line); }
159 | VEC_TOKEN '(' ID ',' ID ')'
160 { $$ = resolve_typedef (concat ("VEC_", $3, "_", $5, (char *)0),
161 &lexer_line); }
162 | type '*'
163 { $$ = create_pointer ($1); }
164 | STRUCT ID '{' struct_fields '}'
165 { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
166 | STRUCT ID
167 { $$ = find_structure ($2, 0); }
168 | UNION ID '{' struct_fields '}'
169 { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
170 | UNION ID
171 { $$ = find_structure ($2, 1); }
172 | ENUM ID
173 { $$ = create_scalar_type ($2); }
174 | ENUM ID '{' enum_items '}'
175 { $$ = create_scalar_type ($2); }
178 enum_items: /* empty */
179 | ID '=' NUM ',' enum_items
181 | ID ',' enum_items
183 | ID enum_items
187 optionsopt: { $$ = NULL; }
188 | options { $$ = $1; }
191 options: GTY_TOKEN '(' '(' optionseq ')' ')'
192 { $$ = $4; }
195 type_option : ALIAS
196 { $$ = "ptr_alias"; }
197 | PARAM_IS
198 { $$ = $1; }
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 */
212 | ','
215 stringseq: STRING
216 { $$ = $1; }
217 | stringseq STRING
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);
223 XDELETE ($2);
224 $$ = s;