1 /* C global declaration parser for genksyms.
2 Copyright 1996, 1997 Linux International.
4 New implementation contributed by Richard Henderson <rth@tamu.edu>
5 Based on original work by Bjorn Ekwall <bj0rn@blox.se>
7 This file is part of the Linux modutils.
9 This program is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2 of the License, or (at your
12 option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 static int is_typedef
;
32 static char *current_name
;
33 static struct string_list
*decl_spec
;
35 static void yyerror(const char *);
38 remove_node
(struct string_list
**p
)
40 struct string_list
*node
= *p
;
46 remove_list
(struct string_list
**pb
, struct string_list
**pe
)
48 struct string_list
*b
= *pb
, *e
= *pe
;
82 %token EXPORT_SYMBOL_KEYW
85 %token ATTRIBUTE_PHRASE
88 %token EXPRESSION_PHRASE
104 | declaration_seq declaration
108 { is_typedef
= 0; is_extern
= 0; current_name
= NULL
; decl_spec
= NULL
; }
110 { free_list
(*$2, NULL
); *$2 = NULL
; }
114 EXTENSION_KEYW TYPEDEF_KEYW
{ is_typedef
= 1; } simple_declaration
116 | TYPEDEF_KEYW
{ is_typedef
= 1; } simple_declaration
119 | function_definition
122 |
error ';' { $$
= $2; }
123 |
error '}' { $$
= $2; }
127 decl_specifier_seq_opt init_declarator_list_opt
';'
128 { if
(current_name
) {
129 struct string_list
*decl
= (*$3)->next
;
131 add_symbol
(current_name
,
132 is_typedef ? SYM_TYPEDEF
: SYM_NORMAL
,
140 init_declarator_list_opt:
141 /* empty */ { $$
= NULL
; }
142 | init_declarator_list
145 init_declarator_list:
147 { struct string_list
*decl
= *$1;
149 add_symbol
(current_name
,
150 is_typedef ? SYM_TYPEDEF
: SYM_NORMAL
, decl
, is_extern
);
154 | init_declarator_list
',' init_declarator
155 { struct string_list
*decl
= *$3;
157 free_list
(*$2, NULL
);
159 add_symbol
(current_name
,
160 is_typedef ? SYM_TYPEDEF
: SYM_NORMAL
, decl
, is_extern
);
167 declarator asm_phrase_opt attribute_opt initializer_opt
168 { $$
= $4 ?
$4 : $3 ?
$3 : $2 ?
$2 : $1; }
171 /* Hang on to the specifiers so that we can reuse them. */
172 decl_specifier_seq_opt:
173 /* empty */ { decl_spec
= NULL
; }
178 decl_specifier
{ decl_spec
= *$1; }
179 | decl_specifier_seq decl_specifier
{ decl_spec
= *$2; }
183 storage_class_specifier
184 { /* Version 2 checksumming ignores storage class, as that
185 is really irrelevant to the linkage. */
192 storage_class_specifier:
196 | EXTERN_KEYW
{ is_extern
= 1; $$
= $1; }
197 | INLINE_KEYW
{ is_extern
= 0; $$
= $1; }
201 simple_type_specifier
203 | TYPEOF_KEYW
'(' decl_specifier_seq
'*' ')'
204 | TYPEOF_KEYW
'(' decl_specifier_seq
')'
206 /* References to s/u/e's defined elsewhere. Rearrange things
207 so that it is easier to expand the definition fully later. */
209 { remove_node
($1); (*$2)->tag
= SYM_STRUCT
; $$
= $2; }
211 { remove_node
($1); (*$2)->tag
= SYM_UNION
; $$
= $2; }
213 { remove_node
($1); (*$2)->tag
= SYM_ENUM
; $$
= $2; }
215 /* Full definitions of an s/u/e. Record it. */
216 | STRUCT_KEYW IDENT class_body
217 { struct string_list
*s
= *$3, *i
= *$2, *r
;
218 r
= copy_node
(i
); r
->tag
= SYM_STRUCT
;
219 r
->next
= (*$1)->next
; *$3 = r
; (*$1)->next
= NULL
;
220 add_symbol
(i
->string, SYM_STRUCT
, s
, is_extern
);
223 | UNION_KEYW IDENT class_body
224 { struct string_list
*s
= *$3, *i
= *$2, *r
;
225 r
= copy_node
(i
); r
->tag
= SYM_UNION
;
226 r
->next
= (*$1)->next
; *$3 = r
; (*$1)->next
= NULL
;
227 add_symbol
(i
->string, SYM_UNION
, s
, is_extern
);
230 | ENUM_KEYW IDENT BRACE_PHRASE
231 { struct string_list
*s
= *$3, *i
= *$2, *r
;
232 r
= copy_node
(i
); r
->tag
= SYM_ENUM
;
233 r
->next
= (*$1)->next
; *$3 = r
; (*$1)->next
= NULL
;
234 add_symbol
(i
->string, SYM_ENUM
, s
, is_extern
);
238 /* Anonymous s/u/e definitions. Nothing needs doing. */
239 | ENUM_KEYW BRACE_PHRASE
{ $$
= $2; }
240 | STRUCT_KEYW class_body
{ $$
= $2; }
241 | UNION_KEYW class_body
{ $$
= $2; }
244 simple_type_specifier:
255 | TYPE
{ (*$1)->tag
= SYM_TYPEDEF
; $$
= $1; }
259 '*' cvar_qualifier_seq_opt
260 { $$
= $2 ?
$2 : $1; }
263 cvar_qualifier_seq_opt:
264 /* empty */ { $$
= NULL
; }
270 | cvar_qualifier_seq cvar_qualifier
{ $$
= $2; }
274 CONST_KEYW | VOLATILE_KEYW | ATTRIBUTE_PHRASE
276 { /* restrict has no effect in prototypes so ignore it */
283 ptr_operator declarator
{ $$
= $2; }
289 { if
(current_name
!= NULL
) {
290 error_with_pos
("unexpected second declaration name");
293 current_name
= (*$1)->string;
297 | direct_declarator
'(' parameter_declaration_clause
')'
299 | direct_declarator
'(' error ')'
301 | direct_declarator BRACKET_PHRASE
309 /* Nested declarators differ from regular declarators in that they do
310 not record the symbols they find in the global symbol table. */
312 ptr_operator nested_declarator
{ $$
= $2; }
313 | direct_nested_declarator
316 direct_nested_declarator:
319 | direct_nested_declarator
'(' parameter_declaration_clause
')'
321 | direct_nested_declarator
'(' error ')'
323 | direct_nested_declarator BRACKET_PHRASE
325 |
'(' nested_declarator
')'
331 parameter_declaration_clause:
332 parameter_declaration_list_opt DOTS
{ $$
= $2; }
333 | parameter_declaration_list_opt
334 | parameter_declaration_list
',' DOTS
{ $$
= $3; }
337 parameter_declaration_list_opt:
338 /* empty */ { $$
= NULL
; }
339 | parameter_declaration_list
342 parameter_declaration_list:
343 parameter_declaration
344 | parameter_declaration_list
',' parameter_declaration
348 parameter_declaration:
349 decl_specifier_seq m_abstract_declarator
350 { $$
= $2 ?
$2 : $1; }
353 m_abstract_declarator:
354 ptr_operator m_abstract_declarator
355 { $$
= $2 ?
$2 : $1; }
356 | direct_m_abstract_declarator
359 direct_m_abstract_declarator:
360 /* empty */ { $$
= NULL
; }
362 { /* For version 2 checksums, we don't want to remember
363 private parameter names. */
367 /* This wasn't really a typedef name but an identifier that
373 | direct_m_abstract_declarator
'(' parameter_declaration_clause
')'
375 | direct_m_abstract_declarator
'(' error ')'
377 | direct_m_abstract_declarator BRACKET_PHRASE
379 |
'(' m_abstract_declarator
')'
386 decl_specifier_seq_opt declarator BRACE_PHRASE
387 { struct string_list
*decl
= *$2;
389 add_symbol
(current_name
, SYM_NORMAL
, decl
, is_extern
);
395 /* empty */ { $$
= NULL
; }
399 /* We never care about the contents of an initializer. */
401 '=' EXPRESSION_PHRASE
402 { remove_list
($2, &(*$1)->next
); $$
= $2; }
406 '{' member_specification_opt
'}' { $$
= $3; }
407 |
'{' error '}' { $$
= $3; }
410 member_specification_opt:
411 /* empty */ { $$
= NULL
; }
412 | member_specification
415 member_specification:
417 | member_specification member_declaration
{ $$
= $2; }
421 decl_specifier_seq_opt member_declarator_list_opt
';'
427 member_declarator_list_opt:
428 /* empty */ { $$
= NULL
; }
429 | member_declarator_list
432 member_declarator_list:
434 | member_declarator_list
',' member_declarator
{ $$
= $3; }
438 nested_declarator attribute_opt
{ $$
= $2 ?
$2 : $1; }
439 | IDENT member_bitfield_declarator
{ $$
= $2; }
440 | member_bitfield_declarator
443 member_bitfield_declarator:
444 ':' EXPRESSION_PHRASE
{ $$
= $2; }
448 /* empty */ { $$
= NULL
; }
453 ASM_PHRASE
';' { $$
= $2; }
457 /* empty */ { $$
= NULL
; }
462 EXPORT_SYMBOL_KEYW
'(' IDENT
')' ';'
463 { export_symbol
((*$3)->string); $$
= $5; }
470 yyerror(const char *e
)
472 error_with_pos
("%s", e
);