OSDN Git Service

* vec.h: Remove all #if IN_GENGTYPE blocks.
[pf3gnuchains/gcc-fork.git] / gcc / gengtype-yacc.y
1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3    Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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.
11
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.
16
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.  */
21
22 %{
23 #include "bconfig.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "gengtype.h"
28 #define YYERROR_VERBOSE
29 %}
30
31 %union {
32   type_p t;
33   pair_p p;
34   options_p o;
35   const char *s;
36 }
37
38 %token <t>ENT_TYPEDEF_STRUCT
39 %token <t>ENT_STRUCT
40 %token ENT_EXTERNSTATIC
41 %token GTY_TOKEN
42 %token VEC_TOKEN
43 %token UNION
44 %token STRUCT
45 %token ENUM
46 %token ALIAS
47 %token NESTED_PTR
48 %token <s>PARAM_IS
49 %token NUM
50 %token <t>SCALAR
51 %token <s>ID
52 %token <s>STRING
53 %token <s>ARRAY
54 %token <s>CHAR
55
56 %type <p> struct_fields
57 %type <t> type lasttype
58 %type <o> optionsopt options option optionseq optionseqopt
59 %type <s> type_option stringseq
60
61 %%
62
63 start: /* empty */
64        | typedef_struct start
65        | externstatic start
66        | start
67        ;
68
69 typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
70                    {
71                      new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
72                                     $4, $2);
73                      do_typedef ($6, $1, &lexer_line);
74                      lexer_toplevel_done = 1;
75                    }
76                  ';'
77                    {}
78                 | ENT_STRUCT options '{' struct_fields '}'
79                    {
80                      new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
81                                     $4, $2);
82                      lexer_toplevel_done = 1;
83                    }
84                  ';'
85                    {}
86                 ;
87
88 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
89                  {
90                    note_variable ($4, adjust_field_type ($3, $2), $2,
91                                   &lexer_line);
92                  }
93               | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
94                  {
95                    note_variable ($4, create_array ($3, $5),
96                             $2, &lexer_line);
97                  }
98               | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
99                  {
100                    note_variable ($4, create_array (create_array ($3, $6),
101                                               $5),
102                             $2, &lexer_line);
103                  }
104               ;
105
106 lasttype: type
107             {
108               lexer_toplevel_done = 1;
109               $$ = $1;
110             }
111             ;
112
113 semiequal: ';'
114            | '='
115            ;
116
117 struct_fields: { $$ = NULL; }
118                | type optionsopt ID bitfieldopt ';' struct_fields
119                   {
120                     pair_p p = XNEW (struct pair);
121                     p->type = adjust_field_type ($1, $2);
122                     p->opt = $2;
123                     p->name = $3;
124                     p->next = $6;
125                     p->line = lexer_line;
126                     $$ = p;
127                   }
128                | type optionsopt ID ARRAY ';' struct_fields
129                   {
130                     pair_p p = XNEW (struct pair);
131                     p->type = adjust_field_type (create_array ($1, $4), $2);
132                     p->opt = $2;
133                     p->name = $3;
134                     p->next = $6;
135                     p->line = lexer_line;
136                     $$ = p;
137                   }
138                | type optionsopt ID ARRAY ARRAY ';' struct_fields
139                   {
140                     pair_p p = XNEW (struct pair);
141                     p->type = create_array (create_array ($1, $5), $4);
142                     p->opt = $2;
143                     p->name = $3;
144                     p->next = $7;
145                     p->line = lexer_line;
146                     $$ = p;
147                   }
148                | type ':' bitfieldlen ';' struct_fields
149                   { $$ = $5; }
150                ;
151
152 bitfieldopt: /* empty */
153              | ':' bitfieldlen
154              ;
155
156 bitfieldlen: NUM | ID
157                 { }
158              ;
159
160 type: SCALAR
161          { $$ = $1; }
162       | ID
163          { $$ = resolve_typedef ($1, &lexer_line); }
164       | VEC_TOKEN '(' ID ',' ID ')'
165          { $$ = resolve_typedef (concat ("VEC_", $3, "_", $5, (char *)0),
166                                  &lexer_line); }
167       | type '*'
168          { $$ = create_pointer ($1); }
169       | STRUCT ID '{' struct_fields '}'
170          { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
171       | STRUCT ID
172          { $$ = find_structure ($2, 0); }
173       | UNION ID '{' struct_fields '}'
174          { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
175       | UNION ID
176          { $$ = find_structure ($2, 1); }
177       | ENUM ID
178          { $$ = create_scalar_type ($2, strlen ($2)); }
179       | ENUM ID '{' enum_items '}'
180          { $$ = create_scalar_type ($2, strlen ($2)); }
181       ;
182
183 enum_items: /* empty */
184             | ID '=' NUM ',' enum_items
185               { }
186             | ID ',' enum_items
187               { }
188             | ID enum_items
189               { }
190             ;
191
192 optionsopt: { $$ = NULL; }
193             | options { $$ = $1; }
194             ;
195
196 options: GTY_TOKEN '(' '(' optionseqopt ')' ')'
197            { $$ = $4; }
198          ;
199
200 type_option : ALIAS
201                 { $$ = "ptr_alias"; }
202               | PARAM_IS
203                 { $$ = $1; }
204               ;
205
206 option:   ID
207             { $$ = create_option (NULL, $1, (void *)""); }
208         | ID '(' stringseq ')'
209             { $$ = create_option (NULL, $1, (void *)$3); }
210         | type_option '(' type ')'
211             { $$ = create_option (NULL, $1, adjust_field_type ($3, NULL)); }
212         | NESTED_PTR '(' type ',' stringseq ',' stringseq ')'
213             {
214               struct nested_ptr_data d;
215
216               d.type = adjust_field_type ($3, NULL);
217               d.convert_to = $5;
218               d.convert_from = $7;
219               $$ = create_option (NULL, "nested_ptr",
220                                   xmemdup (&d, sizeof (d), sizeof (d)));
221             }
222         ;
223
224 optionseq: option
225               {
226                 $1->next = NULL;
227                 $$ = $1;
228               }
229             | optionseq ',' option
230               {
231                 $3->next = $1;
232                 $$ = $3;
233               }
234             ;
235
236 optionseqopt: { $$ = NULL; }
237               | optionseq { $$ = $1; }
238               ;
239
240 stringseq: STRING
241              { $$ = $1; }
242            | stringseq STRING
243              {
244                size_t l1 = strlen ($1);
245                size_t l2 = strlen ($2);
246                char *s = XRESIZEVEC (char, $1, l1 + l2 + 1);
247                memcpy (s + l1, $2, l2 + 1);
248                XDELETE ($2);
249                $$ = s;
250              }
251            ;
252 %%