EnumSet*.class: Regenerate
[official-gcc.git] / gcc / gengtype-yacc.y
blob235ec546bf52cd6c22cfeb94ed48ff8c387494c8
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
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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 #include "bconfig.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "gengtype.h"
27 #define YYERROR_VERBOSE
30 %union {
31 type_p t;
32 pair_p p;
33 options_p o;
34 const char *s;
37 %token <s>ENT_TYPEDEF_STRUCT
38 %token <s>ENT_STRUCT
39 %token <s>ENT_TYPEDEF_UNION
40 %token <s>ENT_UNION
41 %token ENT_EXTERNSTATIC
42 %token GTY_TOKEN
43 %token VEC_TOKEN
44 %token UNION
45 %token STRUCT
46 %token ENUM
47 %token ALIAS
48 %token NESTED_PTR
49 %token <s>PARAM_IS
50 %token NUM
51 %token <s>SCALAR
52 %token <s>ID
53 %token <s>STRING
54 %token <s>ARRAY
55 %token <s>CHAR
57 %type <p> struct_fields
58 %type <t> type lasttype
59 %type <o> optionsopt options optionseq
60 %type <s> type_option stringseq
64 start: /* empty */
65 | typedef_struct start
66 | externstatic start
67 | 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;
76 ';'
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;
83 ';'
84 | ENT_STRUCT options '{' struct_fields '}'
86 new_structure ($1, false, &lexer_line, $4, $2);
87 lexer_toplevel_done = 1;
89 ';'
90 | ENT_UNION options '{' struct_fields '}'
92 new_structure ($1, true, &lexer_line, $4, $2);
93 lexer_toplevel_done = 1;
95 ';'
98 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
100 note_variable ($4, adjust_field_type ($3, $2), $2,
101 &lexer_line);
103 | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
105 note_variable ($4, create_array ($3, $5),
106 $2, &lexer_line);
108 | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
110 note_variable ($4, create_array (create_array ($3, $6),
111 $5),
112 $2, &lexer_line);
116 lasttype: type
118 lexer_toplevel_done = 1;
119 $$ = $1;
123 semiequal: ';'
124 | '='
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
143 { $$ = $5; }
146 bitfieldopt: /* empty */
147 | ':' bitfieldlen
150 bitfieldlen: NUM | ID
154 type: SCALAR
155 { $$ = create_scalar_type ($1); }
156 | ID
157 { $$ = resolve_typedef ($1, &lexer_line); }
158 | VEC_TOKEN '(' ID ',' ID ')'
159 { $$ = resolve_typedef (concat ("VEC_", $3, "_", $5, (char *)0),
160 &lexer_line); }
161 | type '*'
162 { $$ = create_pointer ($1); }
163 | STRUCT ID '{' struct_fields '}'
164 { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
165 | STRUCT ID
166 { $$ = find_structure ($2, 0); }
167 | UNION ID '{' struct_fields '}'
168 { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
169 | UNION ID
170 { $$ = find_structure ($2, 1); }
171 | ENUM ID
172 { $$ = create_scalar_type ($2); }
173 | ENUM ID '{' enum_items '}'
174 { $$ = create_scalar_type ($2); }
177 enum_items: /* empty */
178 | ID '=' NUM ',' enum_items
180 | ID ',' enum_items
182 | ID enum_items
186 optionsopt: { $$ = NULL; }
187 | options { $$ = $1; }
190 options: GTY_TOKEN '(' '(' optionseq ')' ')'
191 { $$ = $4; }
194 type_option : ALIAS
195 { $$ = "ptr_alias"; }
196 | PARAM_IS
197 { $$ = $1; }
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 */
211 | ','
214 stringseq: STRING
215 { $$ = $1; }
216 | stringseq STRING
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);
222 XDELETE ($2);
223 $$ = s;