2 /***************************************
5 C Cross Referencing & Documentation tool. Version 1.5g.
8 ******************/ /******************
9 Written by Andrew M. Bishop
11 This file Copyright 1995,96,97,98,99,2000,01,02,03,04 Andrew M. Bishop
12 It may be distributed under the GNU Public License, version 2, or
13 any higher version. See section COPYING of the GNU Public license
14 for conditions under which this file may be redistributed.
15 ***************************************/
22 /*+ A structure to hold the information about an object. +*/
25 char *name
; /*+ The name of the object. +*/
26 char *type
; /*+ The type of the object. +*/
27 char *qual
; /*+ The type qualifier of the object. +*/
31 #define yylex cxref_yylex
33 static int cxref_yylex
(void);
35 static void yyerror(char *s
);
37 /*+ When in a header file, some stuff can be skipped over quickly. +*/
40 /*+ A flag that is set to true when typedef is seen in a statement. +*/
43 /*+ The scope of the function / variable that is being examined. +*/
46 /*+ The variable must be LOCAL or EXTERNAL or GLOBAL, so this checks and sets that. +*/
47 #define SCOPE ( scope&(LOCAL|EXTERNAL|EXTERN_H|EXTERN_F) ? scope : scope|GLOBAL )
49 /*+ When in a function or a function definition, the behaviour is different. +*/
50 static int in_function
=0,in_funcdef
=0,in_funcbody
=0;
52 /*+ The parsing stack +*/
53 static stack first
={NULL
,NULL
,NULL
}, /*+ first value. +*/
54 *list
=NULL
, /*+ list of all values. +*/
55 *current
=&first
; /*+ current values. +*/
57 /*+ The depth of the stack +*/
58 static int depth
=0, /*+ currently in use. +*/
59 maxdepth
=0; /*+ total malloced. +*/
61 /*+ Declarations that are in the same statement share this comment. +*/
62 static char* common_comment
=NULL
;
64 /*+ When inside a struct / union / enum definition, this is the depth. +*/
65 static int in_structunion
=0;
67 /*+ When inside a struct / union definition, this is the component type. +*/
68 static char *comp_type
=NULL
;
70 /*+ To solve the problem where a type name is used as an identifier. +*/
71 static int in_type_spec
=0;
74 /*++++++++++++++++++++++++++++++++++++++
75 Reset the current level on the stack.
76 ++++++++++++++++++++++++++++++++++++++*/
78 static void reset
(void)
86 /*++++++++++++++++++++++++++++++++++++++
87 Push a level onto the stack.
88 ++++++++++++++++++++++++++++++++++++++*/
90 static void push
(void)
94 list
=(stack
*)Malloc
(8*sizeof
(struct _stack
));
98 else if
(depth
==(maxdepth
-1))
100 list
=Realloc
(list
,(maxdepth
+8)*sizeof
(struct _stack
));
105 current
=&list
[depth
];
111 /*++++++++++++++++++++++++++++++++++++++
112 Pop a level from the stack.
113 ++++++++++++++++++++++++++++++++++++++*/
115 static void pop
(void)
120 current
=&list
[depth
];
124 /*++++++++++++++++++++++++++++++++++++++
125 Reset the Parser, ready for the next file.
126 ++++++++++++++++++++++++++++++++++++++*/
128 void ResetParser
(void)
149 /* Expected conflicts: 19 shift/reduce */
151 %token IDENTIFIER TYPE_NAME LITERAL STRING_LITERAL ELLIPSES
152 %token MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
153 %token EQ_OP NE_OP PTR_OP AND_OP OR_OP DEC_OP INC_OP LE_OP GE_OP
154 %token LEFT_SHIFT RIGHT_SHIFT
156 %token TYPEDEF EXTERN STATIC AUTO REGISTER CONST VOLATILE VOID INLINE
157 %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE
158 %token STRUCT UNION ENUM
159 %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
166 /*-------------------- Top level --------------------*/
174 : top_level_declaration
175 | program top_level_declaration
178 top_level_declaration
180 { scope
=0; reset
(); common_comment
=NULL
; in_typedef
=0; GetCurrentComment
(); }
181 | function_definition
182 { scope
=0; reset
(); common_comment
=NULL
; in_typedef
=0; GetCurrentComment
(); }
183 | asm_statement
/*+ GNU Extension +*/
187 /*-------------------- Declarations --------------------*/
191 { scope
=0; reset
(); common_comment
=NULL
; in_typedef
=0; }
192 | declaration_list declaration
193 { scope
=0; reset
(); common_comment
=NULL
; in_typedef
=0;
198 : declaration_specifiers initialized_declarator_list
';'
200 | declaration_specifiers
';'
204 declaration_specifiers
205 : declaration_specifiers1
206 { if
(!in_structunion
&& !in_typedef
&& !in_function
&& !common_comment
)
207 {common_comment
=CopyString
(GetCurrentComment
()); SetCurrentComment
(common_comment
);} }
210 declaration_specifiers1
211 : storage_class_specifier
212 | storage_class_specifier declaration_specifiers1
213 { if
($1) $$
=ConcatStrings
(3,$1," ",$2); else $$
=$2; }
215 { if
(!current
->type
) current
->type
=$1; }
216 | type_specifier declaration_specifiers1
217 { if
(!current
->type
) current
->type
=$1;
218 $$
=ConcatStrings
(3,$1," ",$2); }
220 | type_qualifier declaration_specifiers1
221 { $$
=ConcatStrings
(3,$1," ",$2); }
224 /* Initialised declarator list */
226 initialized_declarator_list
227 : initialized_declarator
228 | initialized_declarator_list
',' { in_type_spec
=1; } initialized_declarator
231 initialized_declarator
232 : initialized_declarator1
234 if
((in_function
==0 || in_function
==3) && !in_funcdef
&& !in_structunion
)
236 char* specific_comment
=GetCurrentComment
();
237 if
(!common_comment
) SetCurrentComment
(specific_comment
); else
238 if
(!specific_comment
) SetCurrentComment
(common_comment
); else
239 if
(strcmp
(common_comment
,specific_comment
)) SetCurrentComment
(ConcatStrings
(3,common_comment
," ",specific_comment
)); else
240 SetCurrentComment
(common_comment
);
245 char* vname
=strstr
($1,current
->name
);
246 SeenTypedefName
(current
->name
,vname
[strlen
(current
->name
)]=='('?
-1:1);
248 SeenTypedef
(current
->name
,ConcatStrings
(3,current
->qual
,current
->type
,$1));
252 else if
(in_function
==2)
253 SeenFunctionArg
(current
->name
,ConcatStrings
(3,current
->qual
,current
->type
,$1));
256 char* vname
=strstr
($1,current
->name
);
257 if
(vname
[strlen
(current
->name
)]!='(' && IsATypeName
(current
->type
)!='f')
259 if
((in_funcbody
==0 || scope
&EXTERN_F
) && !in_structunion
&& !(in_header
==GLOBAL
&& scope
&EXTERN_H
))
260 SeenVariableDefinition
(current
->name
,ConcatStrings
(3,current
->qual
,current
->type
,$1),SCOPE
);
263 SeenScopeVariable
(current
->name
);
267 SeenFunctionProto
(current
->name
,in_funcbody
);
273 if
(in_function
==3 && !in_structunion
) in_function
=0;
277 initialized_declarator1
279 | declarator asm_label
/*+ GNU Extension +*/
280 | declarator initializer_part
281 | declarator asm_label initializer_part
/* GNU Extension */
289 : assignment_expression
291 |
'{' initializer_list
'}'
292 |
'{' initializer_list
',' '}'
297 | initializer_list
',' named_initializer
302 | component_name
':' initializer
303 |
'.' component_name
'=' initializer
304 |
'[' named_initializer_index
']' initializer
305 |
'[' named_initializer_index
']' '=' initializer
308 named_initializer_index
309 : constant_expression
310 | constant_expression ELLIPSES constant_expression
314 /* Abstract declarator */
318 | pointer direct_abstract_declarator
319 { $$
=ConcatStrings
(2,$1,$2); }
320 | direct_abstract_declarator
323 direct_abstract_declarator
324 : '(' abstract_declarator
')'
325 { $$
=ConcatStrings
(3,$1,$2,$3);
326 { int i
=0; while
($2[i
] && $2[i
]=='*') i
++; if
(!$2[i
]) in_type_spec
=0; } }
328 { $$
=ConcatStrings
(2,$1,$2); }
329 | direct_abstract_declarator
'[' ']'
330 { $$
=ConcatStrings
(3,$1,$2,$3); }
331 |
'[' constant_expression
']'
332 { $$
=ConcatStrings
(3,$1,$2,$3); }
333 | direct_abstract_declarator
'[' constant_expression
']'
334 { $$
=ConcatStrings
(4,$1,$2,$3,$4); }
336 { $$
=ConcatStrings
(2,$1,$2); }
337 | direct_abstract_declarator
'(' ')'
338 { $$
=ConcatStrings
(3,$1,$2,$3); }
339 |
'(' parameter_type_list
')'
340 { $$
=ConcatStrings
(3,$1,$2,$3); }
341 | direct_abstract_declarator
'(' parameter_type_list
')'
342 { $$
=ConcatStrings
(4,$1,$2,$3,$4); }
350 | pointer direct_declarator
351 { in_type_spec
=0; $$
=ConcatStrings
(2,$1,$2); }
356 |
'*' type_qualifier_list
357 { $$
=ConcatStrings
(3,$1," ",$2); }
359 { $$
=ConcatStrings
(2,$1,$2); }
360 |
'*' type_qualifier_list pointer
361 { $$
=ConcatStrings
(4,$1," ",$2,$3); }
367 { if
($2[0]=='*' && $2[1]==' ') { $2=&$2[1]; $2[0]='*'; }
368 $$
=ConcatStrings
(4," ",$1,$2,$3);
371 | function_direct_declarator
376 { $$
=ConcatStrings
(2," ",$1); current
->name
=$1;
377 if
(!current
->type
) current
->type
="int";
378 if
(in_funcdef
==1 && in_function
!=3 && !in_structunion
) SeenScopeVariable
($1); }
382 : direct_declarator
'[' ']'
383 { $$
=ConcatStrings
(3,$1,$2,$3); }
384 | direct_declarator
'[' { in_type_spec
=0; } constant_expression
{ in_type_spec
=1; } ']'
385 { $$
=ConcatStrings
(4,$1,$2,$4,$6); }
388 /*-------------------- Storage class and types --------------------*/
394 storage_class_specifier
399 if
(in_funcbody
) scope|
=EXTERN_F
;
400 else if
(in_header
) scope|
=EXTERN_H
;
401 else scope|
=EXTERNAL
; }
405 { $$
=NULL
; scope |
= LOCAL
; }
408 in_typedef
=1; if
(!in_header
) SeenTypedef
(NULL
,NULL
);
409 common_comment
=CopyString
(GetCurrentComment
()); }
410 | INLINE
/* GNU Extension */
411 { $$
=NULL
; scope |
= INLINED
; }
416 | type_qualifier_list type_qualifier
417 { $$
=ConcatStrings
(3,$1," ",$2); }
422 { if
(!current
->type
) current
->qual
=ConcatStrings
(3,current
->qual
,$1," "); }
424 { if
(!current
->type
) current
->qual
=ConcatStrings
(3,current
->qual
,$1," "); }
435 : enumeration_type_specifier
436 | floating_type_specifier
437 | integer_type_specifier
438 | structure_type_specifier
440 | union_type_specifier
441 | void_type_specifier
444 floating_type_specifier
448 { $$
=ConcatStrings
(3,$1," ",$2); }
450 { $$
=ConcatStrings
(3,$1," ",$2); }
453 integer_type_specifier
454 : integer_type_specifier_part
455 | integer_type_specifier_part type_qualifier
456 { $$
=ConcatStrings
(3,$1," ",$2); }
457 | integer_type_specifier integer_type_specifier_part
458 { $$
=ConcatStrings
(3,$1," ",$2); }
461 integer_type_specifier_part
479 : declaration_specifiers
481 | declaration_specifiers abstract_declarator
482 { in_type_spec
=0; $$
=ConcatStrings
(2,$1,$2); }
485 /* Enumerated types */
487 enumeration_type_specifier
488 : enumeration_type_definition
489 | enumeration_type_reference
492 enumeration_type_definition
497 if
(in_structunion
) SeenStructUnionComp
($1,in_structunion
);
498 else SeenStructUnionStart
($1);
501 enumeration_definition_list
'}'
502 { pop
(); in_structunion
--;
503 if
(!in_structunion
&& !current
->type
) current
->type
=ConcatStrings
(2,$1," {...}");
504 if
(!in_header
&& !in_structunion
&& in_typedef
) SeenStructUnionEnd
();
505 $$
=ConcatStrings
(5,$1," ",$2,$4,$5); }
506 | ENUM enumeration_tag
'{'
510 if
(in_structunion
) SeenStructUnionComp
(ConcatStrings
(3,$1," ",$2),in_structunion
);
511 else SeenStructUnionStart
(ConcatStrings
(3,$1," ",$2));
514 enumeration_definition_list
'}'
515 { pop
(); in_structunion
--;
516 if
(!in_structunion
&& !current
->type
) current
->type
=ConcatStrings
(3,$1," ",$2);
517 if
(!in_header
&& !in_structunion
) SeenStructUnionEnd
();
518 $$
=ConcatStrings
(7,$1," ",$2," ",$3,$5,$6);}
521 enumeration_definition_list
522 : enumeration_definition_list1
523 | enumeration_definition_list1
',' /* Not ANSI, but common */
526 enumeration_definition_list1
527 : enumeration_constant_definition
528 | enumeration_definition_list1
',' enumeration_constant_definition
529 { $$
=ConcatStrings
(3,$1,$2,$3); }
532 enumeration_constant_definition
533 : enumeration_constant
534 { if
(!in_header
) SeenStructUnionComp
($1,in_structunion
); }
535 | enumeration_constant
'=' assignment_expression
/* Should be constant expression */
536 { $$
=ConcatStrings
(3,$1,$2,$3); if
(!in_header
) SeenStructUnionComp
($1,in_structunion
); }
543 enumeration_type_reference
544 : ENUM enumeration_tag
545 { $$
=ConcatStrings
(3,$1," ",$2); }
555 structure_type_specifier
556 : structure_type_definition
557 | structure_type_reference
560 structure_type_definition
565 if
(in_structunion
) SeenStructUnionComp
($1,in_structunion
);
566 else SeenStructUnionStart
($1);
570 { pop
(); in_structunion
--;
571 if
(!in_structunion
&& !current
->type
) current
->type
=ConcatStrings
(2,$1," {...}");
572 if
(!in_header
&& !in_structunion
&& in_typedef
) SeenStructUnionEnd
();
573 $$
=ConcatStrings
(5,$1," ",$2,$4,$5); }
574 | STRUCT structure_tag
'{'
578 if
(in_structunion
) SeenStructUnionComp
(ConcatStrings
(3,$1," ",$2),in_structunion
);
579 else SeenStructUnionStart
(ConcatStrings
(3,$1," ",$2));
583 { pop
(); in_structunion
--;
584 if
(!in_structunion
&& !current
->type
) current
->type
=ConcatStrings
(3,$1," ",$2);
585 if
(!in_header
&& !in_structunion
) SeenStructUnionEnd
();
586 $$
=ConcatStrings
(7,$1," ",$2," ",$3,$5,$6);}
589 structure_type_reference
590 : STRUCT structure_tag
591 { $$
=ConcatStrings
(3,$1," ",$2); }
602 : union_type_definition
603 | union_type_reference
606 union_type_definition
611 if
(in_structunion
) SeenStructUnionComp
($1,in_structunion
);
612 else SeenStructUnionStart
($1);
616 { pop
(); in_structunion
--;
617 if
(!in_structunion
&& !current
->type
) current
->type
=ConcatStrings
(2,$1," {...}");
618 if
(!in_header
&& !in_structunion
&& in_typedef
) SeenStructUnionEnd
();
619 $$
=ConcatStrings
(5,$1," ",$2,$4,$5); }
620 | UNION union_tag
'{'
624 if
(in_structunion
) SeenStructUnionComp
(ConcatStrings
(3,$1," ",$2),in_structunion
);
625 else SeenStructUnionStart
(ConcatStrings
(3,$1," ",$2));
629 { pop
(); in_structunion
--;
630 if
(!in_structunion
&& !current
->type
) current
->type
=ConcatStrings
(3,$1," ",$2);
631 if
(!in_header
&& !in_structunion
) SeenStructUnionEnd
();
632 $$
=ConcatStrings
(7,$1," ",$2," ",$3,$5,$6);}
637 { $$
=ConcatStrings
(3,$1," ",$2); }
645 /* Struct or Union */
654 | field_list1 field_list2
655 { $$
=ConcatStrings
(2,$1,$2); }
660 | structure_type_definition
';'
661 { $$
= ConcatStrings
(3, $1, " ", $2);
662 if
(!in_header
) SeenStructUnionComp
($1,in_structunion
); }
663 | union_type_definition
';'
664 { $$
= ConcatStrings
(3, $1, " ", $2);
665 if
(!in_header
) SeenStructUnionComp
($1,in_structunion
); }
666 | component_declaration
669 component_declaration
672 component_declarator_list
';'
673 { $$
=ConcatStrings
(3,$1,$3,$4); reset
(); in_type_spec
=0; }
674 | type_qualifier_list type_specifier
675 { comp_type
=ConcatStrings
(3,$1," ",$2); }
676 component_declarator_list
';'
677 { $$
=ConcatStrings
(4,$1,$2,$4,$5); reset
(); in_type_spec
=0; }
678 | type_specifier type_qualifier_list
679 { comp_type
=ConcatStrings
(3,$1," ",$2); }
680 component_declarator_list
';'
681 { $$
=ConcatStrings
(4,$1,$2,$4,$5); reset
(); in_type_spec
=0; }
684 component_declarator_list
685 : component_declarator
686 { if
(!in_header
) SeenStructUnionComp
(ConcatStrings
(2,comp_type
,$1),in_structunion
); }
687 | component_declarator_list
',' component_declarator
688 { $$
=ConcatStrings
(3,$1,$2,$3);
689 if
(!in_header
) SeenStructUnionComp
(ConcatStrings
(2,comp_type
,$3),in_structunion
); }
699 { if
(in_function
==2 && !in_structunion
) { DownScope
(); pop
(); in_function
=0; } }
704 { $$
=ConcatStrings
(2,$1,$2); }
705 | declarator
':' width
706 { $$
=ConcatStrings
(3,$1,$2,$3); }
710 : assignment_expression
/* Should be expression */
718 /*-------------------- Functions --------------------*/
720 /* Function Definition */
724 { pop
(); in_funcbody
=1; in_function
=0; }
726 { in_funcbody
=in_function
=0; DownScope
(); SeenFunctionDefinition
(NULL
); }
730 : function_specifier1
731 { char *func_type
,*fname
=strstr
($1,(current
-1)->name
),*parenth
=strstr
($1,"(");
733 {parenth
[0]=0;func_type
=ConcatStrings
(3,(current
-1)->qual
,(current
-1)->type
,$1);}
737 char *argbeg
=strstr
(&parenth
[1],"("),*argend
;
739 for
(argend
=argbeg
+2;*argend
;argend
++)
741 if
(*argend
=='(') open
++;
742 if
(*argend
==')') open
--;
745 func_type
=ConcatStrings
(4,(current
-1)->qual
,(current
-1)->type
,$1,argend
);
747 SeenFunctionDefinition
(func_type
);
752 : function_declarator
753 | declaration_specifiers function_declarator
754 { $$
=ConcatStrings
(3,current
->qual
,current
->type
,$2); }
755 | function_declarator declaration_list
756 | declaration_specifiers function_declarator declaration_list
757 { $$
=ConcatStrings
(3,current
->qual
,current
->type
,$2); }
760 /* Function Declaration */
763 : function_declarator0
764 { if
(!in_structunion
) { push
(); in_function
=2; } }
768 : function_direct_declarator
769 |
'(' function_direct_declarator
')'
770 | pointer function_direct_declarator
771 { $$
=ConcatStrings
(2,$1,$2); }
772 | pointer
'(' function_direct_declarator
')'
773 { $$
=ConcatStrings
(2,$1,$3); }
776 function_direct_declarator
777 : function_declarator1
'('
778 { if
(!in_structunion
)
779 { push
(); if
(in_function
==0) UpScope
();
780 if
(in_function
==0 && !in_funcdef
) in_function
=1; if
(in_function
!=3) in_funcdef
++; } }
781 function_declarator2
')'
782 { if
(!in_structunion
)
783 { pop
(); if
(in_function
!=3) in_funcdef
--; if
(in_funcdef
==0) in_function
=3; }
784 $$
=ConcatStrings
(4,$1,$2,$4,$5); }
790 if
(!in_funcdef
&& !in_function
&& !in_funcbody
&& !in_structunion
) SeenFunctionDeclaration
(current
->name
,SCOPE
);
797 { if
(in_function
==1 && in_funcdef
==1 && !in_structunion
) SeenFunctionArg
("void","void");
798 if
(in_structunion
) $$
=NULL
; else $$
="void"; }
799 | parameter_type_list
805 { if
(in_function
==1 && in_funcdef
==1 && in_funcbody
==0 && !in_structunion
) { SeenFunctionArg
($1,NULL
); SeenScopeVariable
($1); } }
806 | identifier_list
',' IDENTIFIER
807 { if
(in_function
==1 && in_funcdef
==1 && in_funcbody
==0 && !in_structunion
) { SeenFunctionArg
($3,NULL
); SeenScopeVariable
($3); }
808 $$
=ConcatStrings
(3,$1,$2,$3); }
813 | parameter_list
',' ELLIPSES
814 { if
(in_function
==1 && in_funcdef
==1 && in_funcbody
==0 && !in_structunion
) SeenFunctionArg
($3,$3);
815 $$
=ConcatStrings
(3,$1,$2,$3); }
819 : parameter_declaration
820 { if
(in_function
==1 && in_funcdef
==1 && in_funcbody
==0 && !in_structunion
) SeenFunctionArg
(strcmp
("void",$1)?current
->name
:"void",$1);
822 | parameter_list
',' parameter_declaration
823 { if
(in_function
==1 && in_funcdef
==1 && in_funcbody
==0 && !in_structunion
) SeenFunctionArg
(current
->name
,$3);
824 in_type_spec
=0; $$
=ConcatStrings
(3,$1,$2,$3); }
827 parameter_declaration
828 : declaration_specifiers declarator
829 { in_type_spec
=0; $$
=ConcatStrings
(2,$1,$2); }
830 | declaration_specifiers
832 | declaration_specifiers abstract_declarator
833 { in_type_spec
=0; $$
=ConcatStrings
(2,$1,$2); }
836 /*-------------------- Statements --------------------*/
839 : asm_statement
/*+ GNU Extension +*/
841 | conditional_statement
842 | iterative_statement
847 | expression_statement
853 /* Compound statement */
857 { UpScope
(); reset
(); }
858 compound_statement_body
863 compound_statement_body
870 | block_item_list block_item
876 { scope
=0; reset
(); common_comment
=NULL
; in_typedef
=0; }
879 /* Conditional statements */
881 conditional_statement
887 : IF
'(' expression
')' statement ELSE statement
891 : IF
'(' expression
')' statement
894 /* Iterative statements */
903 : DO statement WHILE
'(' expression
')' ';'
907 : FOR
'(' for_expressions
')' statement
915 |
';' expression
';' expression
916 | expression
';' ';' expression
917 | expression
';' expression
';'
918 | expression
';' expression
';' expression
922 : WHILE
'(' expression
')' statement
925 /* Label Statements */
927 labeled_statement
/* Allows for no statement following a label. */
934 : CASE constant_expression
935 | CASE constant_expression ELLIPSES constant_expression
946 /* Switch statement */
949 : SWITCH
'(' expression
')' statement
952 /* Other Statements */
967 : GOTO IDENTIFIER
';'
976 | RETURN expression
';'
979 /*-------------------- Expressions --------------------*/
988 : assignment_expression
989 | comma_expression
',' assignment_expression
990 { $$
=ConcatStrings
(3,$1,$2,$3); }
995 assignment_expression
996 : conditional_expression
997 | named_label_address
998 | unary_expression assignment_op assignment_expression
999 | unary_expression assignment_op
'{' assignment_expression_list
'}'
1017 conditional_expression
1018 : logical_or_expression
1019 | logical_or_expression
'?' expression
':' conditional_expression
1020 { $$
=ConcatStrings
(5,$1,$2,$3,$4,$5); }
1021 | logical_or_expression
'?' ':' conditional_expression
/* GNU Extension */
1022 { $$
=ConcatStrings
(4,$1,$2,$3,$4); }
1027 logical_or_expression
1028 : logical_and_expression
1029 | logical_or_expression OR_OP logical_and_expression
1030 { $$
=ConcatStrings
(3,$1,$2,$3); }
1035 logical_and_expression
1036 : bitwise_or_expression
1037 | logical_and_expression AND_OP bitwise_or_expression
1038 { $$
=ConcatStrings
(3,$1,$2,$3); }
1043 bitwise_or_expression
1044 : bitwise_xor_expression
1045 | bitwise_or_expression
'|' bitwise_xor_expression
1046 { $$
=ConcatStrings
(3,$1,$2,$3); }
1051 bitwise_xor_expression
1052 : bitwise_and_expression
1053 | bitwise_xor_expression
'^' bitwise_and_expression
1054 { $$
=ConcatStrings
(3,$1,$2,$3); }
1059 bitwise_and_expression
1060 : equality_expression
1061 | bitwise_and_expression
'&' equality_expression
1062 { $$
=ConcatStrings
(3,$1,$2,$3); }
1068 : relational_expression
1069 | equality_expression equality_op relational_expression
1070 { $$
=ConcatStrings
(3,$1,$2,$3); }
1079 relational_expression
1081 | relational_expression relational_op shift_expression
1082 { $$
=ConcatStrings
(3,$1,$2,$3); }
1094 : additive_expression
1095 | shift_expression shift_op additive_expression
1096 { $$
=ConcatStrings
(3,$1,$2,$3); }
1106 : multiplicative_expression
1107 | additive_expression add_op multiplicative_expression
1108 { $$
=ConcatStrings
(3,$1,$2,$3); }
1117 multiplicative_expression
1119 | multiplicative_expression mult_op unary_expression
1120 { $$
=ConcatStrings
(3,$1,$2,$3); }
1131 : address_expression
1132 | bitwise_negation_expression
1134 | indirection_expression
1135 | logical_negation_expression
1136 | predecrement_expression
1137 | preincrement_expression
1139 | unary_minus_expression
1140 | unary_plus_expression
1141 | postfix_expression
1145 : '&' unary_expression
1148 bitwise_negation_expression
1149 : '~' unary_expression
1150 { $$
=ConcatStrings
(2,$1,$2); }
1154 : '(' type_name
')' unary_expression
1155 { $$
=ConcatStrings
(4,$1,$2,$3,$4); }
1156 |
'(' type_name
')' '{' assignment_expression_list
'}' /* GNU Extension */
1157 |
'(' type_name
')' '{' named_assignment_list
'}' /* GNU Extension */
1160 indirection_expression
1161 : '*' unary_expression
1164 logical_negation_expression
1165 : '!' unary_expression
1166 { $$
=ConcatStrings
(2,$1,$2); }
1169 predecrement_expression
1170 : DEC_OP unary_expression
1173 preincrement_expression
1174 : INC_OP unary_expression
1178 : SIZEOF
'(' type_name
')'
1179 { $$
=ConcatStrings
(4,$1,$2,$3,$4); }
1180 | SIZEOF unary_expression
1181 { $$
=ConcatStrings
(2,$1,$2); }
1184 unary_minus_expression
1185 : '-' unary_expression
1186 { $$
=ConcatStrings
(2,$1,$2); }
1189 unary_plus_expression
1190 : '+' unary_expression
1191 { $$
=ConcatStrings
(2,$1,$2); }
1197 : component_selection_expression
1199 | function_call_direct
1200 { if
(!IsAScopeVariable
($1)) SeenFunctionCall
($1); }
1201 | postdecrement_expression
1202 | postincrement_expression
1203 | subscript_expression
1204 | primary_expression
1207 component_selection_expression
1208 : direct_component_selection
1209 | indirect_component_selection
1212 direct_component_selection
1213 : postfix_expression
'.' component_name
1216 indirect_component_selection
1217 : postfix_expression PTR_OP component_name
1221 : postfix_expression
'(' ')'
1222 | postfix_expression
'(' expression_list
')'
1225 function_call_direct
1227 | name
'(' expression_list
')'
1230 postdecrement_expression
1231 : postfix_expression DEC_OP
1234 postincrement_expression
1235 : postfix_expression INC_OP
1238 subscript_expression
1239 : postfix_expression
'[' expression
']'
1244 { CheckFunctionVariableRef
($1,in_funcbody
); }
1247 | parenthesized_expression
1251 | string_literal STRING_LITERAL
1254 parenthesized_expression
1255 : '(' expression
')'
1256 { $$
=ConcatStrings
(3,$1,$2,$3); }
1257 |
'(' { push
(); } compound_statement
{ pop
(); } ')' /* GNU Extension */
1260 /* Other expressions */
1267 : assignment_expression
1268 | expression_list
',' assignment_expression
1271 /*-------------------- GNU Extensions --------------------*/
1273 /* ASM Statements */
1276 : asm_type
'(' string_literal
')' ';'
1277 | asm_type
'(' string_literal
':' asm_inout_list
')' ';'
1278 | asm_type
'(' string_literal
':' asm_inout_list
':' asm_inout_list
')' ';'
1279 | asm_type
'(' string_literal
':' asm_inout_list
':' asm_inout_list
':' asm_clobber_list
')' ';'
1291 | asm_inout_list
',' asm_inout
1295 : string_literal
'(' expression
')'
1301 | asm_clobber_list
',' string_literal
1305 : ASM
'(' string_literal
')'
1308 /* Named label address */
1311 : AND_OP named_label
1314 /* Assignment of structure / union */
1316 assignment_expression_list
1317 : assignment_expression_list_item
1318 | assignment_expression_list
',' assignment_expression_list_item
1321 assignment_expression_list_item
1323 | assignment_expression
1324 |
'{' assignment_expression_list
'}'
1328 : component_name
':' assignment_expression
1329 | component_name
':' '{' assignment_expression_list
'}'
1330 |
'.' component_name
'=' assignment_expression
1331 |
'.' component_name
'=' '{' assignment_expression_list
'}'
1334 named_assignment_list
1336 | named_assignment_list
',' named_assignment
1343 static int last_yylex
[11];
1344 static char *last_yylval
[11];
1345 static int count
=0,modcount
=0;
1347 #endif /* YYDEBUG */
1350 /*++++++++++++++++++++++++++++++++++++++
1351 Stop parsing the current file, due to an error.
1353 char *s The error message to print out.
1354 ++++++++++++++++++++++++++++++++++++++*/
1356 static void yyerror( char *s
)
1363 fprintf
(stderr
,"%s:%d: cxref: %s\n\n",parse_file
,parse_line
,s
);
1367 fprintf
(stderr
,"The previous 10, current and next 10 symbols are:\n");
1369 for
(i
=count
>10?count
-11:0,modcount
=i%
11;i
<count
-1;i
++,modcount
=i%
11)
1371 fprintf
(stderr
,"%3d | %3d : %16s : %s\n",i
+1-count
,last_yylex
[modcount
],yytname
[YYTRANSLATE
(last_yylex
[modcount
])],last_yylval
[modcount
]);
1373 fprintf
(stderr
,"%3d | %3d : %s\n",i
+1-count
,last_yylex
[modcount
],last_yylval
[modcount
]);
1377 fprintf
(stderr
," 0 | %3d : %16s : %s\n",yychar,yytname
[YYTRANSLATE
(yychar)],yylval);
1379 fprintf
(stderr
," 0 | %3d : %s\n",yychar,yylval);
1386 {fprintf
(stderr
,"END OF FILE\n");break
;}
1388 fprintf
(stderr
,"%3d | %3d : %16s : %s\n",i
+1,yychar,yytname
[YYTRANSLATE
(yychar)],yylval);
1390 fprintf
(stderr
,"%3d | %3d : %s\n",i
+1,yychar,yylval);
1394 fprintf
(stderr
,"\n");
1396 #endif /* YYDEBUG */
1398 /* Finish off the input. */
1403 while
((yychar=yylex()));
1407 /*++++++++++++++++++++++++++++++++++++++
1408 Call the lexer, the feedback from the parser to the lexer is applied here.
1410 int cxref_yylex Returns the value from the lexer, modified due to parser feedback.
1411 ++++++++++++++++++++++++++++++++++++++*/
1413 static int cxref_yylex
(void)
1415 static int last_yyl
=0;
1419 if
(in_type_spec ||
(in_structunion
&& last_yyl
=='}') || last_yyl
==TYPE_NAME ||
1420 last_yyl
==CHAR || last_yyl
==SHORT || last_yyl
==INT || last_yyl
==LONG ||
1421 last_yyl
==SIGNED || last_yyl
==UNSIGNED ||
1422 last_yyl
==FLOAT || last_yyl
==DOUBLE
)
1429 last_yylex
[modcount
]=yyl
;
1430 last_yylval
[modcount
]=yylval;
1447 printf
("#parse.y# %6d | %16s:%4d | %3d : %16s : %s\n",count
,parse_file
,parse_line
,yyl
,yytname
[YYTRANSLATE
(yyl
)],yylval);
1449 printf
("#parse.y# %6d | %16s:%4d | %3d : %s\n",count
,parse_file
,parse_line
,yyl
,yylval);
1450 #endif /* YYBISON */
1452 printf
("#parse.y# %6d | %16s:%4d | END OF FILE\n",count
,parse_file
,parse_line
);
1456 #endif /* YYDEBUG==2 */
1458 #endif /* YYDEBUG */