OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [gengtype-yacc.y] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* -*- indented-text -*- */
2
/* Process source files and output type information.
3
   Copyright (C) 2002, 2004, 2007 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 3, 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 COPYING3.  If not see
19
.  */
20
 
21
%{
22
#include "bconfig.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "gengtype.h"
27
#define YYERROR_VERBOSE
28
%}
29
 
30
%union {
31
  type_p t;
32
  pair_p p;
33
  options_p o;
34
  const char *s;
35
}
36
 
37
%token ENT_TYPEDEF_STRUCT
38
%token ENT_STRUCT
39
%token ENT_EXTERNSTATIC
40
%token ENT_YACCUNION
41
%token GTY_TOKEN
42
%token UNION
43
%token STRUCT
44
%token ENUM
45
%token ALIAS
46
%token NESTED_PTR
47
%token PARAM_IS
48
%token NUM
49
%token PERCENTPERCENT "%%"
50
%token SCALAR
51
%token ID
52
%token STRING
53
%token ARRAY
54
%token PERCENT_ID
55
%token CHAR
56
 
57
%type 

struct_fields yacc_ids yacc_typematch

58
%type  type lasttype
59
%type  optionsopt options option optionseq optionseqopt
60
%type  type_option stringseq
61
 
62
%%
63
 
64
start: /* empty */
65
       | typedef_struct start
66
       | externstatic start
67
       | yacc_union start
68
       ;
69
 
70
typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
71
                   {
72
                     new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
73
                                    $4, $2);
74
                     do_typedef ($6, $1, &lexer_line);
75
                     lexer_toplevel_done = 1;
76
                   }
77
                 ';'
78
                   {}
79
                | ENT_STRUCT options '{' struct_fields '}'
80
                   {
81
                     new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line,
82
                                    $4, $2);
83
                     lexer_toplevel_done = 1;
84
                   }
85
                 ';'
86
                   {}
87
                ;
88
 
89
externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
90
                 {
91
                   note_variable ($4, adjust_field_type ($3, $2), $2,
92
                                  &lexer_line);
93
                 }
94
              | ENT_EXTERNSTATIC options lasttype ID ARRAY semiequal
95
                 {
96
                   note_variable ($4, create_array ($3, $5),
97
                            $2, &lexer_line);
98
                 }
99
              | ENT_EXTERNSTATIC options lasttype ID ARRAY ARRAY semiequal
100
                 {
101
                   note_variable ($4, create_array (create_array ($3, $6),
102
                                              $5),
103
                            $2, &lexer_line);
104
                 }
105
              ;
106
 
107
lasttype: type
108
            {
109
              lexer_toplevel_done = 1;
110
              $$ = $1;
111
            }
112
            ;
113
 
114
semiequal: ';'
115
           | '='
116
           ;
117
 
118
yacc_union: ENT_YACCUNION options struct_fields '}' yacc_typematch
119
            PERCENTPERCENT
120
              {
121
                note_yacc_type ($2, $3, $5, &lexer_line);
122
              }
123
            ;
124
 
125
yacc_typematch: /* empty */
126
                   { $$ = NULL; }
127
                | yacc_typematch PERCENT_ID yacc_ids
128
                   {
129
                     pair_p p;
130
                     for (p = $3; p->next != NULL; p = p->next)
131
                       {
132
                         p->name = NULL;
133
                         p->type = NULL;
134
                       }
135
                     p->name = NULL;
136
                     p->type = NULL;
137
                     p->next = $1;
138
                     $$ = $3;
139
                   }
140
                | yacc_typematch PERCENT_ID '<' ID '>' yacc_ids
141
                   {
142
                     pair_p p;
143
                     type_p newtype = NULL;
144
                     if (strcmp ($2, "type") == 0)
145
                       newtype = (type_p) 1;
146
                     for (p = $6; p->next != NULL; p = p->next)
147
                       {
148
                         p->name = $4;
149
                         p->type = newtype;
150
                       }
151
                     p->name = $4;
152
                     p->next = $1;
153
                     p->type = newtype;
154
                     $$ = $6;
155
                   }
156
                ;
157
 
158
yacc_ids: /* empty */
159
        { $$ = NULL; }
160
     | yacc_ids ID
161
        {
162
          pair_p p = XCNEW (struct pair);
163
          p->next = $1;
164
          p->line = lexer_line;
165
          p->opt = XNEW (struct options);
166
          p->opt->name = "tag";
167
          p->opt->next = NULL;
168
          p->opt->info = (char *)$2;
169
          $$ = p;
170
        }
171
     | yacc_ids CHAR
172
        {
173
          pair_p p = XCNEW (struct pair);
174
          p->next = $1;
175
          p->line = lexer_line;
176
          p->opt = XNEW (struct options);
177
          p->opt->name = "tag";
178
          p->opt->next = NULL;
179
          p->opt->info = xasprintf ("'%s'", $2);
180
          $$ = p;
181
        }
182
     ;
183
 
184
struct_fields: { $$ = NULL; }
185
               | type optionsopt ID bitfieldopt ';' struct_fields
186
                  {
187
                    pair_p p = XNEW (struct pair);
188
                    p->type = adjust_field_type ($1, $2);
189
                    p->opt = $2;
190
                    p->name = $3;
191
                    p->next = $6;
192
                    p->line = lexer_line;
193
                    $$ = p;
194
                  }
195
               | type optionsopt ID ARRAY ';' struct_fields
196
                  {
197
                    pair_p p = XNEW (struct pair);
198
                    p->type = adjust_field_type (create_array ($1, $4), $2);
199
                    p->opt = $2;
200
                    p->name = $3;
201
                    p->next = $6;
202
                    p->line = lexer_line;
203
                    $$ = p;
204
                  }
205
               | type optionsopt ID ARRAY ARRAY ';' struct_fields
206
                  {
207
                    pair_p p = XNEW (struct pair);
208
                    p->type = create_array (create_array ($1, $5), $4);
209
                    p->opt = $2;
210
                    p->name = $3;
211
                    p->next = $7;
212
                    p->line = lexer_line;
213
                    $$ = p;
214
                  }
215
               | type ':' bitfieldlen ';' struct_fields
216
                  { $$ = $5; }
217
               ;
218
 
219
bitfieldopt: /* empty */
220
             | ':' bitfieldlen
221
             ;
222
 
223
bitfieldlen: NUM | ID
224
                { }
225
             ;
226
 
227
type: SCALAR
228
         { $$ = $1; }
229
      | ID
230
         { $$ = resolve_typedef ($1, &lexer_line); }
231
      | type '*'
232
         { $$ = create_pointer ($1); }
233
      | STRUCT ID '{' struct_fields '}'
234
         { $$ = new_structure ($2, 0, &lexer_line, $4, NULL); }
235
      | STRUCT ID
236
         { $$ = find_structure ($2, 0); }
237
      | UNION ID '{' struct_fields '}'
238
         { $$ = new_structure ($2, 1, &lexer_line, $4, NULL); }
239
      | UNION ID
240
         { $$ = find_structure ($2, 1); }
241
      | ENUM ID
242
         { $$ = create_scalar_type ($2, strlen ($2)); }
243
      | ENUM ID '{' enum_items '}'
244
         { $$ = create_scalar_type ($2, strlen ($2)); }
245
      ;
246
 
247
enum_items: /* empty */
248
            | ID '=' NUM ',' enum_items
249
              { }
250
            | ID ',' enum_items
251
              { }
252
            | ID enum_items
253
              { }
254
            ;
255
 
256
optionsopt: { $$ = NULL; }
257
            | options { $$ = $1; }
258
            ;
259
 
260
options: GTY_TOKEN '(' '(' optionseqopt ')' ')'
261
           { $$ = $4; }
262
         ;
263
 
264
type_option : ALIAS
265
                { $$ = "ptr_alias"; }
266
              | PARAM_IS
267
                { $$ = $1; }
268
              ;
269
 
270
option:   ID
271
            { $$ = create_option (NULL, $1, (void *)""); }
272
        | ID '(' stringseq ')'
273
            { $$ = create_option (NULL, $1, (void *)$3); }
274
        | type_option '(' type ')'
275
            { $$ = create_option (NULL, $1, adjust_field_type ($3, NULL)); }
276
        | NESTED_PTR '(' type ',' stringseq ',' stringseq ')'
277
            {
278
              struct nested_ptr_data d;
279
 
280
              d.type = adjust_field_type ($3, NULL);
281
              d.convert_to = $5;
282
              d.convert_from = $7;
283
              $$ = create_option (NULL, "nested_ptr",
284
                                  xmemdup (&d, sizeof (d), sizeof (d)));
285
            }
286
        ;
287
 
288
optionseq: option
289
              {
290
                $1->next = NULL;
291
                $$ = $1;
292
              }
293
            | optionseq ',' option
294
              {
295
                $3->next = $1;
296
                $$ = $3;
297
              }
298
            ;
299
 
300
optionseqopt: { $$ = NULL; }
301
              | optionseq { $$ = $1; }
302
              ;
303
 
304
stringseq: STRING
305
             { $$ = $1; }
306
           | stringseq STRING
307
             {
308
               size_t l1 = strlen ($1);
309
               size_t l2 = strlen ($2);
310
               char *s = XRESIZEVEC (char, $1, l1 + l2 + 1);
311
               memcpy (s + l1, $2, l2 + 1);
312
               XDELETE ($2);
313
               $$ = s;
314
             }
315
           ;
316
%%

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.