• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoni56 / c-xrefactory / 1679

25 Dec 2025 02:54PM UTC coverage: 83.741% (+0.9%) from 82.868%
1679

push

travis-ci

thoni56
[build] Split watchers into three: unittests, build, systemtests

13386 of 15985 relevant lines covered (83.74%)

17943716.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.28
src/c_parser.y
1
/*
2
  Our yacc does not support %expect, but this should be it for the C grammar
3

4
  %expect 7
5
  %expect-rr 34
6

7
../../../byacc-1.9/yacc: 7 shift/reduce conflicts, 28 reduce/reduce conflicts.
8

9
*/
10

11
%{
12

13
#define c_yylex yylex
14

15
#include "c_parser.h"
16

17
#include <stdlib.h>
18
#include <string.h>
19
#include <ctype.h>
20

21
#include "ast.h"
22
#include "commons.h"
23
#include "complete.h"
24
#include "counters.h"
25
#include "cxref.h"
26
#include "extract.h"
27
#include "filedescriptor.h"
28
#include "filetable.h"
29
#include "globals.h"
30
#include "id.h"
31
#include "list.h"
32
#include "log.h"
33
#include "options.h"
34
#include "semact.h"
35
#include "stackmemory.h"
36
#include "symbol.h"
37
#include "yylex.h"
38

39
#ifndef YYDEBUG
40
#define YYDEBUG 0
41
#endif
42
#define c_yyerror styyerror
43
#define yyErrorRecovery styyErrorRecovery
44

45
static int savedWorkMemoryIndex = 0;
46

47
%}
48

49
/* Token definitions *must* be the same in all parsers. The following
50
   is a marker, it must be the same as in the Makefile check */
51
/* START OF COMMON TOKEN DEFINITIONS */
52

53
/* ************************* SPECIALS ****************************** */
54

55
%token TYPE_NAME
56

57
/* ************************* OPERATORS ****************************** */
58
/* common */
59
%token INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
60
%token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
61
%token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
62
%token XOR_ASSIGN OR_ASSIGN
63

64
/* c-only */
65
%token PTR_OP ELLIPSIS
66

67
/* yacc-only */
68
%token YACC_PERC YACC_DPERC
69

70
/* ************************** KEYWORDS ******************************** */
71

72
%token STATIC BREAK CASE CHAR CONST CONTINUE DEFAULT DO DOUBLE ELSE
73
%token FLOAT FOR GOTO IF INT LONG RETURN SHORT SWITCH VOID VOLATILE WHILE
74

75
/* c-special */
76
%token TYPEDEF EXTERN AUTO REGISTER SIGNED UNSIGNED STRUCT UNION ENUM
77
%token SIZEOF RESTRICT _ATOMIC _BOOL _THREADLOCAL _NORETURN _STATIC_ASSERT
78
%token INLINE ASM_KEYWORD
79
/* hmm */
80
%token ANONYMOUS_MODIFIER
81

82
%token TRUE_LITERAL FALSE_LITERAL NULL_LITERAL
83

84
/* yacc-special */
85
%token TOKEN TYPE
86

87
/* gcc specials */
88
%token LABEL
89

90
/* ******************** COMPLETION SPECIAL TOKENS ******************** */
91

92
%token COMPLETE_FOR_STATEMENT1 COMPLETE_FOR_STATEMENT2
93

94
/* c-only */
95
%token COMPLETE_TYPE_NAME
96
%token COMPLETE_STRUCT_NAME COMPLETE_STRUCT_MEMBER_NAME COMPLETE_UP_FUN_PROFILE
97
%token COMPLETE_ENUM_NAME COMPLETE_LABEL_NAME COMPLETE_OTHER_NAME
98

99
/* yacc-special */
100
%token COMPLETE_YACC_LEXEM_NAME
101

102
/* ************************** CPP-TOKENS ****************************** */
103
/* c-only */
104
%token CPP_TOKENS_START
105
%token CPP_INCLUDE CPP_INCLUDE_NEXT CPP_DEFINE CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ENDIF
106
%token CPP_ELIF CPP_UNDEF
107
%token CPP_PRAGMA CPP_LINE
108
%token CPP_DEFINE0       /* macro with no argument */
109
%token CPP_TOKENS_END
110

111
%token CPP_COLLATION     /* ## in macro body */
112
%token CPP_DEFINED_OP    /* defined(xxx) in #if */
113
%token CPP_HAS_INCLUDE_OP /* __has_include(xxx) in #if */
114
%token CPP_HAS_INCLUDE_NEXT_OP /* __has_include_next(xxx) in #if */
115

116
/* ******************************************************************** */
117
/* special token signaling end of input */
118
%token EOI_TOKEN
119

120
/* ******************************************************************** */
121
%token OL_MARKER_TOKEN OL_MARKER_TOKEN1 OL_MARKER_TOKEN2
122

123
/* ******************************************************************** */
124
%token TMP_TOKEN1 TMP_TOKEN2
125

126
/* ************************ MULTI TOKENS START ************************ */
127
%token MULTI_TOKENS_START
128

129
/* commons */
130
%token IDENTIFIER CONSTANT LONG_CONSTANT
131
%token FLOAT_CONSTANT DOUBLE_CONSTANT
132
%token STRING_LITERAL CHAR_LITERAL
133
%token LINE_TOKEN
134
%token IDENT_TO_COMPLETE        /* identifier under cursor */
135

136
/* c-only */
137
%token CPP_MACRO_ARGUMENT IDENT_NO_CPP_EXPAND
138

139
/* ******************************************************************
140
 * LAST_TOKEN is to dimension the lexemEnum arrays, should always be
141
 * the last token, duh! If not, there is a token that is not explicitly
142
 * declared above. */
143

144
%token LAST_TOKEN
145

146
/* END OF COMMON TOKEN DEFINITIONS */
147
/* Token definitions *must* be the same in all parsers. The above
148
   is a marker, it must be the same as in the Makefile check */
149

150
%union {
151
#include "yystype.h"
152
}
153

154

155
%type <ast_id> IDENTIFIER identifier struct_identifier enum_identifier
156
%type <ast_id> field_identifier STRUCT UNION struct_or_union
157
%type <ast_id> user_defined_type TYPE_NAME
158
%type <ast_id> designator, designator_list
159
%type <ast_idList> designation_opt, initializer, initializer_list, eq_initializer_opt
160
%type <ast_integer> assignment_operator
161
%type <ast_integer> pointer CONSTANT _ncounter_ _nlabel_ _ngoto_ _nfork_
162
%type <ast_unsigned> storage_class_specifier type_specifier1
163
%type <ast_unsigned> type_modality_specifier Save_index
164
%type <ast_symbol> init_declarator declarator declarator2 struct_declarator
165
%type <ast_symbol> type_specifier_list type_mod_specifier_list
166
%type <ast_symbol> type_specifier_list0
167
%type <ast_symbol> top_init_declarations
168
%type <ast_symbol> declaration_specifiers init_declarations
169
%type <ast_symbol> declaration_modality_specifiers declaration_specifiers0
170
%type <ast_symbol> enumerator parameter_declaration
171
%type <ast_symbol> function_head_declaration function_definition_head
172
%type <ast_symbol> struct_declaration_list struct_declaration
173
%type <ast_symbol> struct_declarator_list
174
%type <ast_symbolList> enumerator_list enumerator_list_comma
175
%type <ast_symbol> fun_arg_init_declarations fun_arg_declaration
176
%type <ast_symbolPositionListPair> parameter_list parameter_type_list
177
%type <ast_symbolPositionListPair> parameter_identifier_list identifier_list
178
%type <ast_positionList> argument_expr_list argument_expr_list_opt
179

180
%type <ast_typeModifiers> type_specifier2
181
%type <ast_typeModifiers> struct_or_union_specifier struct_or_union_define_specifier
182
%type <ast_typeModifiers> enum_specifier enum_define_specifier
183
%type <ast_typeModifiers> type_name abstract_declarator abstract_declarator2
184

185
%type <ast_expressionType> primary_expr postfix_expr unary_expr cast_expr compound_literal
186
%type <ast_expressionType> multiplicative_expr additive_expr shift_expr
187
%type <ast_expressionType> relational_expr equality_expr and_expr exclusive_or_expr
188
%type <ast_expressionType> inclusive_or_expr logical_and_expr logical_or_expr
189
%type <ast_expressionType> conditional_expr assignment_expr expr maybe_expr
190

191
%type <ast_position> STRING_LITERAL '(' ',' ')' '{' '}' compound_statement
192

193
%start file
194
%%
195

196
primary_expr
197
    : IDENTIFIER            {
198
        Symbol *symbol = $1.data->symbol;
4,101,569✔
199
        if (symbol != NULL && symbol->type == TypeDefault) {
4,101,569✔
200
            assert(symbol->storage != StorageTypedef);
3,791,638✔
201
            $$.data.typeModifier = symbol->typeModifier;
3,791,638✔
202
            assert(options.mode);
203
            $$.data.reference = handleFoundSymbolReference(symbol, $1.data->position, UsageUsed, NO_FILE_NUMBER);
204
        } else {
205
            /* implicit function declaration */
206
            TypeModifier *modifier;
207
            Symbol *newSymbol;
208
            Symbol *definitionSymbol;
309,931✔
209

309,931✔
210
            modifier = newTypeModifier(TypeInt, NULL, NULL);
211
            $$.data.typeModifier = newFunctionTypeModifier(NULL, NULL, modifier);
309,931✔
212

309,931✔
213
            newSymbol = newSymbolAsType($1.data->name, $1.data->name, $1.data->position, $$.data.typeModifier);
214
            newSymbol->storage = StorageExtern;
309,931✔
215

309,931✔
216
            definitionSymbol = addNewSymbolDefinition(symbolTable, inputFileName, newSymbol, StorageExtern, UsageUsed);
217
            $$.data.reference = handleFoundSymbolReference(definitionSymbol, $1.data->position, UsageUsed, NO_FILE_NUMBER);
218
        }
4,101,569✔
219
    }
76,383✔
220
    | CHAR_LITERAL          { $$.data.typeModifier = newSimpleTypeModifier(TypeInt); $$.data.reference = NULL;}
241✔
221
    | TRUE_LITERAL          { $$.data.typeModifier = newSimpleTypeModifier(TypeBoolean); $$.data.reference = NULL;}
×
222
    | FALSE_LITERAL         { $$.data.typeModifier = newSimpleTypeModifier(TypeBoolean); $$.data.reference = NULL;}
3,801,308✔
223
    | NULL_LITERAL          { $$.data.typeModifier = newSimpleTypeModifier(TypeNull); $$.data.reference = NULL;}
×
224
    | CONSTANT              { $$.data.typeModifier = newSimpleTypeModifier(TypeInt); $$.data.reference = NULL;}
163,320✔
225
    | LONG_CONSTANT         { $$.data.typeModifier = newSimpleTypeModifier(TypeLong); $$.data.reference = NULL;}
164,347✔
226
    | FLOAT_CONSTANT        { $$.data.typeModifier = newSimpleTypeModifier(TypeFloat); $$.data.reference = NULL;}
164,347✔
227
    | DOUBLE_CONSTANT       { $$.data.typeModifier = newSimpleTypeModifier(TypeDouble); $$.data.reference = NULL;}
164,347✔
228
    | string_literals       {
164,347✔
229
        TypeModifier *modifier;
230
        modifier = newSimpleTypeModifier(TypeChar);
164,347✔
231
        $$.data.typeModifier = newPointerTypeModifier(modifier);
1,505,175✔
232
        $$.data.reference = NULL;
233
    }
1,505,175✔
234
    | '(' expr ')'          {
16,203✔
235
        $$.data = $2.data;
16,203✔
236
    }
237
    | '(' compound_statement ')'            {       /* GNU's shit */
×
238
        $$.data.typeModifier = &errorModifier;
312,981✔
239
        $$.data.reference = NULL;
240
    }
241
    | COMPLETE_OTHER_NAME      { assert(0); /* token never used */ }
242
    ;
243

244
string_literals
245
    : STRING_LITERAL
246
    | STRING_LITERAL string_literals
247
    ;
312,981✔
248

6,681✔
249
postfix_expr
6,644✔
250
    : primary_expr                              /*& { $$.data = $1.data; } &*/
312,981✔
251
    | postfix_expr '[' expr ']'                 {
252
        if ($1.data.typeModifier->type==TypePointer || $1.data.typeModifier->type==TypeArray) $$.data.typeModifier=$1.data.typeModifier->next;
312,981✔
253
        else if ($3.data.typeModifier->type==TypePointer || $3.data.typeModifier->type==TypeArray) $$.data.typeModifier=$3.data.typeModifier->next;
576,481✔
254
        else $$.data.typeModifier = &errorModifier;
255
        $$.data.reference = NULL;
256
        assert($$.data.typeModifier);
257
    }
258
/*
259
  Replaced by optional arguments in "postfix_expr '(' argument_expr_list_opt ')' ...
260
    | postfix_expr '(' ')'                      {
261
        if ($1.d.typeModifier->kind==TypeFunction) {
262
            $$.d.typeModifier=$1.d.typeModifier->next;
263
            handleInvocationParamPositions($1.d.reference, &$2.d, NULL, &$3.d, 0);
264
        } else {
265
            $$.d.typeModifier = &s_errorModifier;
266
        }
267
        $$.d.reference = NULL;
576,481✔
268
        assert($$.d.typeModifier);
576,481✔
269
    }
270
*/
576,481✔
271
    | postfix_expr
514,701✔
272
            {
514,701✔
273
                $<typeModifier>$ = upLevelFunctionCompletionType;
505,790✔
274
                upLevelFunctionCompletionType = $1.data.typeModifier;
505,790✔
275
            }
27,373✔
276
      '(' argument_expr_list_opt ')'    {
277
        upLevelFunctionCompletionType = $<typeModifier>2;
478,417✔
278
        if ($1.data.typeModifier->type==TypeFunction) {
279
            $$.data.typeModifier=$1.data.typeModifier->next;
280
            if ($4.data == NULL) {
8,911✔
281
                handleInvocationParamPositions($1.data.reference, $3.data, NULL, $5.data, 0);
282
            } else {
514,701✔
283
                handleInvocationParamPositions($1.data.reference, $3.data, $4.data->next, $5.data, 1);
284
            }
514,701✔
285
        } else {
138,935✔
286
            $$.data.typeModifier = &errorModifier;
138,924✔
287
        }
138,924✔
288
        $$.data.reference = NULL;
289
        assert($$.data.typeModifier);
138,924✔
290
    }
525,976✔
291
    | postfix_expr {setDirectStructureCompletionType($1.data.typeModifier);} '.' field_identifier        {
525,954✔
292
        Symbol *rec=NULL;
525,954✔
293
        $$.data.reference = findStructureFieldFromType($1.data.typeModifier, $4.data, &rec);
516,597✔
294
        assert(rec);
516,597✔
295
        $$.data.typeModifier = rec->typeModifier;
9,357✔
296
        assert($$.data.typeModifier);
297
    }
525,954✔
298
    | postfix_expr {setIndirectStructureCompletionType($1.data.typeModifier);} PTR_OP field_identifier   {
42,938✔
299
        Symbol *rec=NULL;
42,938✔
300
        $$.data.reference = NULL;
301
        if ($1.data.typeModifier->type==TypePointer || $1.data.typeModifier->type==TypeArray) {
42,938✔
302
            $$.data.reference = findStructureFieldFromType($1.data.typeModifier->next, $4.data, &rec);
3,184✔
303
            assert(rec);
3,184✔
304
            $$.data.typeModifier = rec->typeModifier;
305
        } else $$.data.typeModifier = &errorModifier;
3,184✔
306
        assert($$.data.typeModifier);
7,024✔
307
    }
308
    | postfix_expr INC_OP                       {
309
        $$.data.typeModifier = $1.data.typeModifier;
310
        setReferenceUsage($1.data.reference, UsageAddrUsed);
311
    }
8,974✔
312
    | postfix_expr DEC_OP                       {
1,950✔
313
        $$.data.typeModifier = $1.data.typeModifier;
1,950✔
314
        setReferenceUsage($1.data.reference, UsageAddrUsed);
315
    }
7,024✔
316
    | compound_literal
7,024✔
317
    ;
318

7,024✔
319
compound_literal                /* Added in C99 */
14✔
320
    : '(' type_name ')' '{' initializer_list optional_comma '}'     {
14✔
321
        IdList *idList;
14✔
322
        for (idList = $5.data; idList != NULL; idList = idList->next) {
323
            Symbol *rec=NULL;
14✔
324
            (void) findStructureFieldFromType($2.data, &idList->id, &rec);
×
325
        }
326
        $$.data.typeModifier = $2.data;
327
        $$.data.reference = NULL;
328
    }
329
    /* GNU extension: empty compound literal */
330
    | '(' type_name ')' '{' '}'     {
331
        $$.data.typeModifier = $2.data;
332
        $$.data.reference = NULL;
×
333
    }
×
334
    ;
27,680✔
335

336
optional_comma
337
    :
27,680✔
338
    | ','
339
    ;
27,680✔
340

487,021✔
341
field_identifier
342
    : identifier                /*& { $$.data = $1.data; } &*/
487,021✔
343
    | COMPLETE_STRUCT_MEMBER_NAME     { assert(0); /* token never used */ }
491,227✔
344
    ;
345

346
argument_expr_list_opt
491,227✔
347
    :                                           {
348
        $$.data = NULL;
491,227✔
349
    }
705,326✔
350
    |   argument_expr_list          {
705,326✔
351
            $$.data = newPositionList(noPosition, $1.data);
352
        }
705,326✔
353
    ;
×
354

×
355
argument_expr_list
1,299✔
356
    : assignment_expr                           {
357
        $$.data = NULL;
358
    }
359
    | argument_expr_list ',' assignment_expr    {
1,299✔
360
        $$.data = $1.data;
1,299✔
361
        appendPositionToList(&$$.data, $2.data);
362
    }
1,299✔
363
    | COMPLETE_UP_FUN_PROFILE                          {/* never used */}
1,172✔
364
    | argument_expr_list ',' COMPLETE_UP_FUN_PROFILE   {/* never used */}
1,172✔
365
    ;
366

1,172✔
367
unary_expr
499,224✔
368
    : postfix_expr                  /*& { $$.data = $1.data; } &*/
499,224✔
369
    | INC_OP unary_expr             {
370
        $$.data.typeModifier = $2.data.typeModifier;
499,224✔
371
        setReferenceUsage($2.data.reference, UsageAddrUsed);
78,149✔
372
    }
78,149✔
373
    | DEC_OP unary_expr             {
78,149✔
374
        $$.data.typeModifier = $2.data.typeModifier;
375
        setReferenceUsage($2.data.reference, UsageAddrUsed);
78,149✔
376
    }
84,604✔
377
    | unary_operator cast_expr      {
1,441✔
378
        $$.data.typeModifier = $2.data.typeModifier;
84,604✔
379
        $$.data.reference = NULL;
380
    }
84,604✔
381
    | '&' cast_expr                 {
28,121✔
382
        $$.data.typeModifier = newPointerTypeModifier($2.data.typeModifier);
28,121✔
383
        setReferenceUsage($2.data.reference, UsageAddrUsed);
384
        $$.data.reference = NULL;
28,121✔
385
    }
56,174✔
386
    | '*' cast_expr                 {
56,174✔
387
        if ($2.data.typeModifier->type==TypePointer || $2.data.typeModifier->type==TypeArray) $$.data.typeModifier=$2.data.typeModifier->next;
388
        else $$.data.typeModifier = &errorModifier;
56,174✔
389
        assert($$.data.typeModifier);
×
390
        $$.data.reference = NULL;
×
391
    }
392
    | SIZEOF unary_expr             {
×
393
        $$.data.typeModifier = newSimpleTypeModifier(TypeInt);
298,907✔
394
        $$.data.reference = NULL;
395
    }
396
    | SIZEOF '(' type_name ')'      {
397
        $$.data.typeModifier = newSimpleTypeModifier(TypeInt);
398
        $$.data.reference = NULL;
399
    }
400
    /* yet another GCC ext. */
401
    | AND_OP identifier     {
402
        labelReference($2.data, UsageLvalUsed);
403
    }
404
    ;
298,907✔
405

298,907✔
406
unary_operator
407
    : '+'
298,907✔
408
    | '-'
199,578✔
409
    | '~'
410
    | '!'
411
    ;
412

199,578✔
413
cast_expr
199,578✔
414
    : unary_expr                        /*& { $$.data = $1.data; } &*/
415
    | '(' type_name ')' cast_expr       {
199,578✔
416
        $$.data.typeModifier = $2.data;
58,798✔
417
        $$.data.reference = $4.data.reference;
58,798✔
418
    }
419
    ;
58,798✔
420

2,000✔
421
multiplicative_expr
2,000✔
422
    : cast_expr                         /*& { $$.data = $1.data; } &*/
423
    | multiplicative_expr '*' cast_expr {
2,000✔
424
        $$.data.typeModifier = &defaultIntModifier;
280,359✔
425
        $$.data.reference = NULL;
426
    }
427
    | multiplicative_expr '/' cast_expr {
428
        $$.data.typeModifier = &defaultIntModifier;
280,359✔
429
        $$.data.reference = NULL;
279,881✔
430
    }
280,359✔
431
    | multiplicative_expr '%' cast_expr {
432
        $$.data.typeModifier = &defaultIntModifier;
280,359✔
433
        $$.data.reference = NULL;
170,658✔
434
    }
151,294✔
435
    ;
170,658✔
436

437
additive_expr
170,658✔
438
    : multiplicative_expr                       /*& { $$.data = $1.data; } &*/
172,682✔
439
    | additive_expr '+' multiplicative_expr     {
440
        if ($3.data.typeModifier->type==TypePointer || $3.data.typeModifier->type==TypeArray) $$.data.typeModifier = $3.data.typeModifier;
441
        else $$.data.typeModifier = $1.data.typeModifier;
442
        $$.data.reference = NULL;
172,682✔
443
    }
172,682✔
444
    | additive_expr '-' multiplicative_expr     {
445
        if ($3.data.typeModifier->type==TypePointer || $3.data.typeModifier->type==TypeArray) $$.data.typeModifier = $3.data.typeModifier;
172,682✔
446
        else $$.data.typeModifier = $1.data.typeModifier;
115,643✔
447
        $$.data.reference = NULL;
115,643✔
448
    }
449
    ;
115,643✔
450

105,281✔
451
shift_expr
452
    : additive_expr                             /*& { $$.data = $1.data; } &*/
453
    | shift_expr LEFT_OP additive_expr          {
454
        $$.data.typeModifier = &defaultIntModifier;
105,281✔
455
        $$.data.reference = NULL;
105,281✔
456
    }
457
    | shift_expr RIGHT_OP additive_expr         {
105,281✔
458
        $$.data.typeModifier = &defaultIntModifier;
58,101✔
459
        $$.data.reference = NULL;
58,101✔
460
    }
461
    ;
58,101✔
462

17,721✔
463
relational_expr
17,721✔
464
    : shift_expr                                /*& { $$.data = $1.data; } &*/
465
    | relational_expr '<' shift_expr            {
17,721✔
466
        $$.data.typeModifier = &defaultIntModifier;
29,774✔
467
        $$.data.reference = NULL;
29,774✔
468
    }
469
    | relational_expr '>' shift_expr            {
29,774✔
470
        $$.data.typeModifier = &defaultIntModifier;
69,622✔
471
        $$.data.reference = NULL;
472
    }
473
    | relational_expr LE_OP shift_expr          {
474
        $$.data.typeModifier = &defaultIntModifier;
69,622✔
475
        $$.data.reference = NULL;
69,622✔
476
    }
477
    | relational_expr GE_OP shift_expr          {
69,622✔
478
        $$.data.typeModifier = &defaultIntModifier;
28,668✔
479
        $$.data.reference = NULL;
28,668✔
480
    }
481
    ;
28,668✔
482

101,146✔
483
equality_expr
484
    : relational_expr                           /*& { $$.data = $1.data; } &*/
485
    | equality_expr EQ_OP relational_expr       {
486
        $$.data.typeModifier = &defaultIntModifier;
101,146✔
487
        $$.data.reference = NULL;
101,146✔
488
    }
489
    | equality_expr NE_OP relational_expr       {
101,146✔
490
        $$.data.typeModifier = &defaultIntModifier;
23,534✔
491
        $$.data.reference = NULL;
492
    }
493
    ;
494

23,534✔
495
and_expr
23,534✔
496
    : equality_expr                             /*& { $$.data = $1.data; } &*/
497
    | and_expr '&' equality_expr                {
23,534✔
498
        $$.data.typeModifier = &defaultIntModifier;
92,496✔
499
        $$.data.reference = NULL;
500
    }
501
    ;
502

92,496✔
503
exclusive_or_expr
92,496✔
504
    : and_expr                                  /*& { $$.data = $1.data; } &*/
505
    | exclusive_or_expr '^' and_expr            {
92,496✔
506
        $$.data.typeModifier = &defaultIntModifier;
46,707✔
507
        $$.data.reference = NULL;
508
    }
509
    ;
510

46,707✔
511
inclusive_or_expr
46,707✔
512
    : exclusive_or_expr                         /*& { $$.data = $1.data; } &*/
513
    | inclusive_or_expr '|' exclusive_or_expr   {
46,707✔
514
        $$.data.typeModifier = &defaultIntModifier;
85,787✔
515
        $$.data.reference = NULL;
516
    }
517
    ;
518

85,787✔
519
logical_and_expr
85,787✔
520
    : inclusive_or_expr                         /*& { $$.data = $1.data; } &*/
521
    | logical_and_expr AND_OP inclusive_or_expr {
85,787✔
522
        $$.data.typeModifier = &defaultIntModifier;
53,739✔
523
        $$.data.reference = NULL;
524
    }
525
    ;
526

53,739✔
527
logical_or_expr
53,739✔
528
    : logical_and_expr                          /*& { $$.data = $1.data; } &*/
529
    | logical_or_expr OR_OP logical_and_expr    {
53,739✔
530
        $$.data.typeModifier = &defaultIntModifier;
89✔
531
        $$.data.reference = NULL;
89✔
532
    }
89✔
533
    ;
534

89✔
535
conditional_expr
493,407✔
536
    : logical_or_expr                                           /*& { $$.data = $1.data; } &*/
537
    | logical_or_expr '?' logical_or_expr ':' conditional_expr  {
538
        $$.data.typeModifier = $3.data.typeModifier;
539
        $$.data.reference = NULL;
493,784✔
540
    }
377✔
541
    /* GNU Conditional operator (a?:b meaning if a then a else b) */
377✔
542
    | logical_or_expr '?' ':' conditional_expr  {
377✔
543
        $$.data.typeModifier = $4.data.typeModifier;
347✔
544
        $$.data.reference = NULL;
545
    }
30✔
546
    ;
547

548
assignment_expr
493,030✔
549
    : conditional_expr                                  /*& { $$.data = $1.data; } &*/
409,899✔
550
    | unary_expr assignment_operator assignment_expr    {
551
        if ($1.data.reference != NULL && options.serverOperation == OLO_EXTRACT) {
83,131✔
552
            Reference *r = duplicateReferenceInCxMemory($1.data.reference);
553
            $1.data.reference->usage = UsageNone;
554
            if ($2.data == '=') {
493,407✔
555
                setReferenceUsage(r, UsageLvalUsed);
556
            } else {
493,407✔
557
                setReferenceUsage(r, UsageAddrUsed);
481,036✔
558
            }
559
        } else {
481,036✔
560
            if ($2.data == '=') {
481,036✔
561
                setReferenceUsage($1.data.reference, UsageLvalUsed);
4,891✔
562
            } else {
1,372✔
563
                setReferenceUsage($1.data.reference, UsageAddrUsed);
49✔
564
            }
54,725✔
565
        }
9,690✔
566
        $$.data = $1.data;    /* $$.d.r will be used for FOR completions ! */
2,932✔
567
    }
3,300✔
568
    ;
958✔
569

1,949✔
570
assignment_operator
3,542✔
571
    : '='                   {$$.data = '=';}
56,982✔
572
    | MUL_ASSIGN            {$$.data = MUL_ASSIGN;}
573
    | DIV_ASSIGN            {$$.data = DIV_ASSIGN;}
574
    | MOD_ASSIGN            {$$.data = MOD_ASSIGN;}
575
    | ADD_ASSIGN            {$$.data = ADD_ASSIGN;}
56,982✔
576
    | SUB_ASSIGN            {$$.data = SUB_ASSIGN;}
56,982✔
577
    | LEFT_ASSIGN           {$$.data = LEFT_ASSIGN;}
578
    | RIGHT_ASSIGN          {$$.data = RIGHT_ASSIGN;}
56,982✔
579
    | AND_ASSIGN            {$$.data = AND_ASSIGN;}
11,833,024✔
580
    | XOR_ASSIGN            {$$.data = XOR_ASSIGN;}
581
    | OR_ASSIGN             {$$.data = OR_ASSIGN;}
582
    ;
583

584
expr
585
    : assignment_expr                           /*& { $$.data = $1.data; } &*/
586
    | expr ',' assignment_expr                  {
11,833,024✔
587
        $$.data.typeModifier = $3.data.typeModifier;
588
        $$.data.reference = NULL;
11,833,024✔
589
    }
76✔
590
    ;
591

76✔
592
constant_expr
76✔
593
    : conditional_expr
313,324✔
594
    ;
3,664✔
595

191✔
596
Save_index
597
    :    {
598
        $$.data = savedWorkMemoryIndex;
191✔
599
    }
191✔
600
    ;
601

602
declaration
191✔
603
    : Save_index declaration_specifiers ';'     { savedWorkMemoryIndex = $1.data; }
245,587✔
604
    | Save_index init_declarations ';'          { savedWorkMemoryIndex = $1.data; }
605
    | Save_index static_assert_declaration ';'  { savedWorkMemoryIndex = $1.data; }
606
    | error
607
        {
608
#if YYDEBUG
609
            char buffer[1000];
610
            sprintf(buffer, "DEBUG: error parsing declaration, near '%s'", yytext);
611
            yyerror(buffer);
245,587✔
612
#endif
245,587✔
613
        }
614
    ;
245,587✔
615

44,797✔
616
static_assert_declaration
44,797✔
617
    : _STATIC_ASSERT '(' constant_expr ',' STRING_LITERAL ')'
618
    | _STATIC_ASSERT '(' constant_expr ')'
44,797✔
619
    ;
72,421✔
620

72,421✔
621
init_declarations
622
    : declaration_specifiers init_declarator eq_initializer_opt {
623
        $$.data = $1.data;
72,421✔
624
        addNewDeclaration(symbolTable, $1.data, $2.data, $3.data, StorageAuto);
72,421✔
625
    }
626
    | init_declarations ',' init_declarator eq_initializer_opt  {
627
        $$.data = $1.data;
72,421✔
628
        addNewDeclaration(symbolTable, $1.data, $3.data, $4.data, StorageAuto);
4,680,688✔
629
    }
630
    | error                                             {
631
        /* $$.d = &s_errorSymbol; */
632
        $$.data = typeSpecifier2(&errorModifier);
633
#if YYDEBUG
634
        char buffer[1000];
635
        sprintf(buffer, "DEBUG: error parsing init_declarations, near '%s'", yytext);
636
        yyerror(buffer);
637
#endif
4,680,688✔
638
    }
4,680,688✔
639
    ;
4,412,934✔
640

641
declaration_specifiers
267,754✔
642
    : declaration_modality_specifiers
4,680,688✔
643
    | declaration_specifiers0
644
    ;
4,680,688✔
645

2,868,906✔
646
user_defined_type
647
    : TYPE_NAME                                             {
648
        int usage;
2,868,906✔
649
        $$.data = $1.data;
650
        assert(options.mode);
2,868,906✔
651
        assert($1.data);
5,328,049✔
652
        assert($1.data->symbol);
653
        if (nestingLevel() == 0)
5,328,049✔
654
            usage = USAGE_TOP_LEVEL_USED;
758,692✔
655
        else
656
            usage = UsageUsed;
758,692✔
657
        handleFoundSymbolReference($1.data->symbol, $1.data->position,usage,NO_FILE_NUMBER);
905,753✔
658
    }
905,753✔
659
    ;
660

905,753✔
661
declaration_specifiers0
3,711,671✔
662
    : user_defined_type                                     {
3,711,671✔
663
        assert($1.data);
664
        assert($1.data->symbol);
3,711,671✔
665
        $$.data = typeSpecifier2($1.data->symbol->typeModifier);
343,348✔
666
    }
343,348✔
667
    | type_specifier1                                       {
668
        $$.data  = typeSpecifier1($1.data);
343,348✔
669
    }
156✔
670
    | type_specifier2                                       {
156✔
671
        $$.data  = typeSpecifier2($1.data);
672
    }
156✔
673
    | declaration_modality_specifiers  user_defined_type    {
1,640,746✔
674
        assert($2.data);
1,640,746✔
675
        assert($2.data->symbol);
676
        $$.data = $1.data;
1,640,746✔
677
        declTypeSpecifier2($1.data,$2.data->symbol->typeModifier);
×
678
    }
×
679
    | declaration_modality_specifiers type_specifier1       {
680
        $$.data = $1.data;
×
681
        declTypeSpecifier1($1.data,$2.data);
1✔
682
    }
1✔
683
    | declaration_modality_specifiers type_specifier2       {
684
        $$.data = $1.data;
1✔
685
        declTypeSpecifier2($1.data,$2.data);
12✔
686
    }
687
    | declaration_specifiers0 type_modality_specifier       {
12✔
688
        $$.data = $1.data;
×
689
        declTypeSpecifier1($1.data,$2.data);
690
    }
×
691
    | declaration_specifiers0 type_specifier1               {
×
692
        $$.data = $1.data;
693
        declTypeSpecifier1($1.data,$2.data);
×
694
    }
3,369,013✔
695
    | declaration_specifiers0 type_specifier2               {
696
        $$.data = $1.data;
697
        declTypeSpecifier2($1.data,$2.data);
3,369,013✔
698
    }
3,369,013✔
699
    | declaration_specifiers0 storage_class_specifier       {
700
        $$.data = $1.data;
3,369,013✔
701
        $$.data->storage = $2.data;
54✔
702
    }
54✔
703
    | declaration_specifiers0 function_specifier            {
704
        $$.data = $1.data;
54✔
705
    }
1,591,736✔
706
    | COMPLETE_TYPE_NAME                                       {
707
        assert(0);
1,591,736✔
708
    }
86,431✔
709
    | declaration_modality_specifiers COMPLETE_TYPE_NAME       {
710
        assert(0); /* token never used */
86,431✔
711
    }
1,995✔
712
    ;
713

1,995✔
714
declaration_modality_specifiers
223,492✔
715
    : storage_class_specifier                               {
716
        $$.data  = typeSpecifier1(TypeDefault);
223,492✔
717
        $$.data->storage = $1.data;
4,653,915✔
718
    }
719
    | declaration_modality_specifiers storage_class_specifier       {
720
        $$.data = $1.data;
721
        $$.data->storage = $2.data;
722
    }
723
    | type_modality_specifier                               {
724
        $$.data  = typeSpecifier1($1.data);
725
    }
726
    | declaration_modality_specifiers type_modality_specifier       {
727
        declTypeSpecifier1($1.data, $2.data);
4,653,915✔
728
    }
729
    | function_specifier                                    {
4,653,915✔
730
        $$.data = typeSpecifier1(TypeDefault);
178,532✔
731
    }
732
    | declaration_modality_specifiers function_specifier            {
178,532✔
733
        $$.data = $1.data;
817,818✔
734
    }
735
    ;
736

737

738
/* a gcc extension ? */
739
asm_opt
817,818✔
740
    :
817,818✔
741
    |   ASM_KEYWORD '(' string_literals ')'
2,247,056✔
742
    ;
299,950✔
743

23✔
744
eq_initializer_opt
3✔
745
    :                   {
4,218✔
746
        $$.data = NULL;
1,787,400✔
747
    }
748
    | '=' initializer   {
1,787,400✔
749
        $$.data = $2.data;
1,787,400✔
750
    }
676,475✔
751
    ;
12,355✔
752

7,906✔
753
init_declarator
24,292✔
754
    : declarator asm_opt /* eq_initializer_opt   { $$.d = $1.d; } */
1,837,219✔
755
    ;
756

757
storage_class_specifier
758
    : TYPEDEF       { $$.data = StorageTypedef; }
759
    | EXTERN        { $$.data = StorageExtern; }
760
    | STATIC        { $$.data = StorageStatic; }
761
    | _THREADLOCAL  { $$.data = StorageThreadLocal; }
1,837,219✔
762
    | AUTO          { $$.data = StorageAuto; }
1,837,219✔
763
    | REGISTER      { $$.data = StorageAuto; }
107,236✔
764
    ;
4,621,972✔
765

1,339,256✔
766
type_modality_specifier
27,908✔
767
    : CONST         { $$.data = TypeDefault; }
620,287✔
768
    | RESTRICT      { $$.data = TypeDefault; }
823,013✔
769
    | VOLATILE      { $$.data = TypeDefault; }
1,653,024✔
770
    | _ATOMIC       { $$.data = TypeDefault; }
1,326,479✔
771
    | ANONYMOUS_MODIFIER   { $$.data = TypeDefault; }
209✔
772
    ;
535,091✔
773

774
type_modality_specifier_opt
775
    :
776
    | type_modality_specifier
777
    ;
778

779
type_specifier1
780
    : CHAR      { $$.data = TypeChar; }
781
    | SHORT     { $$.data = TmodShort; }
782
    | INT       { $$.data = TypeInt; }
783
    | LONG      { $$.data = TmodLong; }
784
    | SIGNED    { $$.data = TmodSigned; }
785
    | UNSIGNED  { $$.data = TmodUnsigned; }
786
    | FLOAT     { $$.data = TypeFloat; }
535,091✔
787
    | DOUBLE    { $$.data = TypeDouble; }
503,054✔
788
    | VOID      { $$.data = TypeVoid; }
789
    | _BOOL     { $$.data = TypeBoolean; }
32,037✔
790
    ;
535,091✔
791

792
type_specifier2
535,091✔
793
    : struct_or_union_specifier     /*& { $$.data = $1.data; } &*/
370,311✔
794
    | enum_specifier                /*& { $$.data = $1.data; } &*/
370,311✔
795
    ;
796

370,311✔
797
function_specifier
8✔
798
    : INLINE
799
    | _NORETURN
8✔
800
    ;
261,582✔
801

802
struct_or_union_specifier
803
    : struct_or_union struct_identifier                             {
261,582✔
804
        int usage;
805
        if (nestingLevel() == 0)
261,582✔
806
            usage = USAGE_TOP_LEVEL_USED;
108,737✔
807
        else
808
            usage = UsageUsed;
108,737✔
809
        $$.data = simpleStructOrUnionSpecifier($1.data, $2.data, usage);
×
810
    }
811
    | struct_or_union_define_specifier '{' struct_declaration_list '}'{
812
        assert($1.data && $1.data->typeSymbol);
×
813
        $$.data = $1.data;
×
814
        specializeStructOrUnionDef($$.data->typeSymbol, $3.data);
800,362✔
815
    }
816
    | struct_or_union_define_specifier '{' '}'                      {
800,362✔
817
        $$.data = $1.data;
800,362✔
818
    }
105,048✔
819
    ;
2,223,628✔
820

821
struct_or_union_define_specifier
822
    : struct_or_union struct_identifier                             {
823
        $$.data = simpleStructOrUnionSpecifier($1.data, $2.data, UsageDefined);
2,223,628✔
824
    }
220✔
825
    | struct_or_union                                               {
2,223,408✔
826
        $$.data = createNewAnonymousStructOrUnion($1.data);
×
827
    }
828
    ;
2,223,408✔
829

830
struct_identifier
831
    : identifier            /*& { $$.data = $1.data; } &*/
2,223,628✔
832
    | COMPLETE_STRUCT_NAME     { assert(0); /* token never used */ }
2,593,059✔
833
    ;
834

835
struct_or_union
5,213,309✔
836
    : STRUCT        { $$.data = $1.data; }
2,620,250✔
837
    | UNION         { $$.data = $1.data; }
838
    ;
2,593,059✔
839

2,593,059✔
840
struct_declaration_list
841
    : struct_declaration                                /*& { $$.data = $1.data; } &*/
2,593,059✔
842
    | struct_declaration_list struct_declaration        {
×
843
        if ($1.data == &errorSymbol || $1.data->type==TypeError) {
×
844
            $$.data = $2.data;
×
845
        } else if ($2.data == &errorSymbol || $1.data->type==TypeError)  {
846
            $$.data = $1.data;
×
847
        } else {
880✔
848
            $$.data = $1.data;
849
            LIST_APPEND(Symbol, $$.data, $2.data);
850
        }
880✔
851
    }
880✔
852
    ;
853

854
struct_declaration
880✔
855
    : Save_index type_specifier_list struct_declarator_list ';'     {
2,593,059✔
856
        assert($2.data && $3.data);
857
        for (Symbol *symbol=$3.data; symbol!=NULL; symbol=symbol->next) {
858
            completeDeclarator($2.data, symbol);
2,593,059✔
859
        }
860
        $$.data = $3.data;
2,593,059✔
861
        savedWorkMemoryIndex = $1.data;
27,191✔
862
    }
863
    | Save_index static_assert_declaration ';'  {
27,191✔
864
        /* static_assert in struct - just ignore it */
13,408✔
865
        $$.data = NULL;
866
        savedWorkMemoryIndex = $1.data;
867
    }
13,408✔
868
    | error                                             {
869
        $$.data = newSymbolAsCopyOf(&errorSymbol);
13,408✔
870
#if YYDEBUG
22✔
871
        char buffer[1000];
872
        sprintf(buffer, "DEBUG: error parsing struct_declaration near '%s'", yytext);
22✔
873
        yyerror(buffer);
330,263✔
874
#endif
875
    }
876
    ;
877

878
struct_declarator_list
879
    : struct_declarator                                 {
330,263✔
880
        $$.data = $1.data;
329,319✔
881
        assert($$.data->next == NULL);
882
    }
944✔
883
    | struct_declarator_list ',' struct_declarator      {
330,263✔
884
        $$.data = $1.data;
885
        assert($3.data->next == NULL);
330,263✔
886
        LIST_APPEND(Symbol, $$.data, $3.data);
85,059✔
887
    }
85,059✔
888
    ;
85,059✔
889

85,059✔
890
struct_declarator
891
    : /* gcc extension allow empty field */ {
892
        $$.data = createEmptyField();
85,059✔
893
    }
66,719✔
894
    | ':' constant_expr             {
895
        $$.data = createEmptyField();
66,719✔
896
    }
85,059✔
897
    | declarator                    /*& { $$.data = $1.data; } &*/
898
    | declarator ':' constant_expr  /*& { $$.data = $1.data; } &*/
899
    ;
85,059✔
900

901
enum_specifier
85,059✔
902
    : ENUM enum_identifier                                  {
×
903
        Usage usage;
904
        if (nestingLevel() == 0)
905
            usage = USAGE_TOP_LEVEL_USED;
×
906
        else
×
907
            usage = UsageUsed;
151,778✔
908
        $$.data = simpleEnumSpecifier($2.data, usage);
909
    }
910
    | enum_define_specifier '{' enumerator_list_comma '}'       {
911
        assert($1.data && $1.data->type == TypeEnum && $1.data->typeSymbol);
912
        $$.data = $1.data;
913
        if ($$.data->typeSymbol->enums==NULL) {
914
            $$.data->typeSymbol->enums = $3.data;
915
            addToFrame(setToNull, &($$.data->typeSymbol->enums));
151,778✔
916
        }
917
    }
151,778✔
918
    | ENUM '{' enumerator_list_comma '}'                        {
2,750,459✔
919
        $$.data = createNewAnonymousEnum($3.data);
920
    }
2,750,459✔
921
    ;
2,393,151✔
922

923
enum_define_specifier
924
    : ENUM enum_identifier                                  {
2,393,151✔
925
        $$.data = simpleEnumSpecifier($2.data, UsageDefined);
2,393,151✔
926
    }
927
    ;
2,393,151✔
928

509,036✔
929
enum_identifier
509,036✔
930
    : identifier            /*& { $$.data = $1.data; } &*/
931
    | COMPLETE_ENUM_NAME       { assert(0); /* token never used */ }
509,036✔
932
    ;
50✔
933

934
enumerator_list_comma
935
    : enumerator_list               /*& { $$.data = $1.data; } &*/
50✔
936
    | enumerator_list ','           /*& { $$.data = $1.data; } &*/
50✔
937
    ;
938

939
enumerator_list
×
940
    : enumerator                            {
5,325,367✔
941
        $$.data = createDefinitionList($1.data);
942
    }
943
    | enumerator_list ',' enumerator        {
944
        $$.data = $1.data;
5,325,367✔
945
        LIST_APPEND(SymbolList, $$.data, createDefinitionList($3.data));
5,325,367✔
946
    }
947
    ;
5,325,367✔
948

15,417,306✔
949
enumerator
950
    : identifier                            {
951
        $$.data = createSimpleDefinition(StorageConstant,TypeInt,$1.data);
15,417,306✔
952
        addNewSymbolDefinition(symbolTable, inputFileName, $$.data, StorageConstant, UsageDefined);
953
    }
15,417,306✔
954
    | identifier '=' constant_expr          {
206,257✔
955
        $$.data = createSimpleDefinition(StorageConstant,TypeInt,$1.data);
206,257✔
956
        addNewSymbolDefinition(symbolTable, inputFileName, $$.data, StorageConstant, UsageDefined);
957
    }
206,257✔
958
    | error                                 {
32,903✔
959
        $$.data = newSymbolAsCopyOf(&errorSymbol);
32,903✔
960
#if YYDEBUG
961
        char buffer[1000];
32,903✔
962
        sprintf(buffer, "DEBUG: error parsing enumerator near '%s'", yytext);
352,698✔
963
        yyerror(buffer);
352,698✔
964
#endif
965
    }
352,698✔
966
    | COMPLETE_OTHER_NAME      { assert(0); /* token never used */ }
1,108✔
967
    ;
1,108✔
968

1,108✔
969
declarator
1,108✔
970
    : declarator2                                       /*& { $$.data = $1.data; } &*/
1,108✔
971
    | pointer declarator2                               {
972
        $$.data = $2.data;
1,108✔
973
        assert($$.data->npointers == 0);
4,124,662✔
974
        $$.data->npointers = $1.data;
4,124,662✔
975
    }
4,124,662✔
976
    ;
4,124,662✔
977

4,124,662✔
978
declarator2
4,124,662✔
979
    : identifier                                        {
980
        $$.data = newSymbol($1.data->name, $1.data->position);
4,124,662✔
981
    }
346✔
982
    | '(' declarator ')'                                {
346✔
983
        $$.data = $2.data;
346✔
984
        unpackPointers($$.data);
346✔
985
    }
346✔
986
    | declarator2 '[' ']'                               {
987
        assert($1.data);
×
988
        $$.data = $1.data;
4,843,879✔
989
        addComposedTypeToSymbol($$.data, TypeArray);
990
    }
991
    | declarator2 '[' constant_expr ']'                 {
4,843,879✔
992
        assert($1.data);
993
        $$.data = $1.data;
4,843,879✔
994
        addComposedTypeToSymbol($$.data, TypeArray);
685,901✔
995
    }
996
    | declarator2 '(' ')'                               {
685,901✔
997
        TypeModifier *modifier;
376,649✔
998
        assert($1.data);
999
        $$.data = $1.data;
376,649✔
1000
        modifier = addComposedTypeToSymbol($$.data, TypeFunction);
16,733✔
1001
        initFunctionTypeModifier(modifier, NULL);
1002
        handleDeclaratorParamPositions($1.data, $2.data, NULL, $3.data, false, false);
16,733✔
1003
    }
821,885✔
1004
    | declarator2 '(' parameter_type_list ')'           {
1005
        TypeModifier *modifier;
1006
        assert($1.data);
821,885✔
1007
        $$.data = $1.data;
1008
        modifier = addComposedTypeToSymbol($$.data, TypeFunction);
821,885✔
1009
        initFunctionTypeModifier(modifier, $3.data.symbol);
×
1010
        bool isVoid = $3.data.symbol->typeModifier->type == TypeVoid;
1011
        handleDeclaratorParamPositions($1.data, $2.data, $3.data.positionList, $4.data, true, isVoid);
×
1012
    }
872,843✔
1013
    | declarator2 '(' parameter_identifier_list ')'     {
1014
        TypeModifier *modifier;
1015
        assert($1.data);
1016
        $$.data = $1.data;
1017
        modifier = addComposedTypeToSymbol($$.data, TypeFunction);
1018
        initFunctionTypeModifier(modifier, $3.data.symbol);
1019
        handleDeclaratorParamPositions($1.data, $2.data, $3.data.positionList, $4.data, true, false);
1020
    }
1021
    | COMPLETE_OTHER_NAME      { assert(0); /* token never used */ }
1022
    ;
1023

1024
pointer
1025
    : '*'                                   {
1026
        $$.data = 1;
1027
    }
1028
    | '*' type_mod_specifier_list               {
1029
        $$.data = 1;
1030
    }
1031
    | '*' pointer                           {
1032
        $$.data = $2.data+1;
1033
    }
1034
    | '*' type_mod_specifier_list pointer       {
1035
        $$.data = $3.data+1;
1036
    }
1037
    ;
872,843✔
1038

1039
type_mod_specifier_list
872,843✔
1040
    : type_modality_specifier                                   {
1,339,130✔
1041
        $$.data  = typeSpecifier1($1.data);
1042
    }
1,339,130✔
1043
    | type_mod_specifier_list type_modality_specifier           {
261,856✔
1044
        declTypeSpecifier1($1.data, $2.data);
1045
    }
261,856✔
1046
    ;
33,186✔
1047

33,186✔
1048
/*
1049
type_specifier_list
33,186✔
1050
    : type_specifier1                                   {
62,492✔
1051
        $$.d  = typeSpecifier1($1.d);
62,492✔
1052
    }
1053
    | type_specifier2                                   {
62,492✔
1054
        $$.d  = typeSpecifier2($1.d);
23,555✔
1055
    }
23,555✔
1056
    | type_specifier_list type_specifier1               {
1057
        declTypeSpecifier1($1.d, $2.d);
23,555✔
1058
    }
19✔
1059
    | type_specifier_list type_specifier2               {
19✔
1060
        declTypeSpecifier2($1.d, $2.d);
1061
    }
19✔
1062
    ;
274,515✔
1063
*/
274,515✔
1064

1065
type_specifier_list
274,515✔
1066
    : type_mod_specifier_list                       /*& { $$.data = $1.data; } &*/
×
1067
    | type_specifier_list0                          /*& { $$.data = $1.data; } &*/
×
1068
    ;
1069

×
1070
type_specifier_list0
×
1071
    : user_defined_type                                     {
1072
        assert($1.data);
×
1073
        assert($1.data->symbol);
×
1074
        assert($1.data->symbol);
1075
        $$.data = typeSpecifier2($1.data->symbol->typeModifier);
×
1076
    }
1✔
1077
    | type_specifier1                                       {
1078
        $$.data  = typeSpecifier1($1.data);
1079
    }
1080
    | type_specifier2                                       {
1081
        $$.data  = typeSpecifier2($1.data);
1✔
1082
    }
1083
    | type_mod_specifier_list user_defined_type             {
1✔
1084
        assert($2.data);
1✔
1085
        assert($2.data->symbol);
1✔
1086
        assert($2.data->symbol);
1087
        $$.data = $1.data;
1✔
1088
        declTypeSpecifier2($1.data,$2.data->symbol->typeModifier);
1089
    }
1✔
1090
    | type_mod_specifier_list type_specifier1       {
1,448✔
1091
        $$.data = $1.data;
1092
        declTypeSpecifier1($1.data,$2.data);
1093
    }
1094
    | type_mod_specifier_list type_specifier2       {
1,448✔
1095
        $$.data = $1.data;
1,448✔
1096
        declTypeSpecifier2($1.data,$2.data);
1,448✔
1097
    }
1098
    | type_specifier_list0 type_modality_specifier      {
1,448✔
1099
        $$.data = $1.data;
209✔
1100
        declTypeSpecifier1($1.data,$2.data);
209✔
1101
    }
209✔
1102
    | type_specifier_list0 type_specifier1              {
209✔
1103
        $$.data = $1.data;
1104
        declTypeSpecifier1($1.data,$2.data);
×
1105
    }
61,699✔
1106
    | type_specifier_list0 type_specifier2              {
1107
        $$.data = $1.data;
1108
        declTypeSpecifier2($1.data,$2.data);
1109
    }
1110
    | COMPLETE_TYPE_NAME                                       {
61,699✔
1111
        assert(0);
1112
    }
61,699✔
1113
    | type_mod_specifier_list COMPLETE_TYPE_NAME       {
61,699✔
1114
        assert(0); /* token never used */
61,699✔
1115
    }
1116
    ;
61,699✔
1117

1118
parameter_identifier_list
61,699✔
1119
    : identifier_list                           /*& { $$.data = $1.data; } &*/
4,124,681✔
1120
    | identifier_list ',' ELLIPSIS               {
1121
        Symbol *symbol;
1122
        Position pos = makePosition(-1, 0, 0);
4,124,681✔
1123

4,124,681✔
1124
        symbol = newSymbol("", pos);
1125
        symbol->type = TypeElipsis;
4,124,681✔
1126
        $$.data = $1.data;
4,028,368✔
1127

4,028,368✔
1128
        LIST_APPEND(Symbol, $$.data.symbol, symbol);
1129
        appendPositionToList(&$$.data.positionList, $2.data);
4,028,368✔
1130
    }
7,680,495✔
1131
    ;
1132

1133
identifier_list
1134
    : IDENTIFIER                                {
7,680,495✔
1135
        Symbol *symbol;
7,680,495✔
1136
        symbol = newSymbol($1.data->name, $1.data->position);
1137
        $$.data.symbol = symbol;
7,680,495✔
1138
        $$.data.positionList = NULL;
466,386✔
1139
    }
1140
    | identifier_list ',' identifier            {
466,386✔
1141
        Symbol *symbol;
6,168✔
1142
        symbol = newSymbol($3.data->name, $3.data->position);
1143
        $$.data = $1.data;
1144
        LIST_APPEND(Symbol, $$.data.symbol, symbol);
6,168✔
1145
        appendPositionToList(&$$.data.positionList, $2.data);
6,168✔
1146
    }
1147
    | COMPLETE_OTHER_NAME      { assert(0); /* token never used */ }
1148
    ;
6,168✔
1149

618,128✔
1150
parameter_type_list
1151
    : parameter_list                    /*& { $$.data = $1.data; } &*/
1152
    | parameter_list ',' ELLIPSIS                {
618,128✔
1153
        Symbol *symbol;
1154
        Position position = makePosition(-1, 0, 0);
618,128✔
1155

210,400✔
1156
        symbol = newSymbol("", position);
1157
        symbol->type = TypeElipsis;
210,400✔
1158
        $$.data = $1.data;
202,504✔
1159

1160
        LIST_APPEND(Symbol, $$.data.symbol, symbol);
1161
        appendPositionToList(&$$.data.positionList, $2.data);
1162
    }
202,504✔
1163
    ;
210,415✔
1164

1165
parameter_list
202,504✔
1166
    : parameter_declaration                         {
7,872✔
1167
        $$.data.symbol = $1.data;
1168
        $$.data.positionList = NULL;
7,872✔
1169
    }
152✔
1170
    | parameter_list ',' parameter_declaration      {
152✔
1171
        $$.data = $1.data;
304✔
1172
        LIST_APPEND(Symbol, $1.data.symbol, $3.data);
1173
        appendPositionToList(&$$.data.positionList, $2.data);
152✔
1174
    }
128✔
1175
    ;
1176

1177

128✔
1178
parameter_declaration
1179
    : declaration_specifiers declarator         {
128✔
1180
        completeDeclarator($1.data, $2.data);
904✔
1181
        $$.data = $2.data;
1182
    }
904✔
1183
    | type_name                                 {
6,992✔
1184
        $$.data = newSymbolAsType(NULL, NULL, noPosition, $1.data);
1185
    }
6,992✔
1186
    | error                                     {
50✔
1187
        $$.data = newSymbolAsCopyOf(&errorSymbol);
50✔
1188
#if YYDEBUG
1189
        char buffer[1000];
50✔
1190
        sprintf(buffer, "DEBUG: error parsing parameter_declaration near '%s'", yytext);
171✔
1191
        yyerror(buffer);
171✔
1192
#endif
1193
    }
171✔
1194
    ;
×
1195

1196
type_name
×
1197
    : declaration_specifiers                        {
×
1198
        $$.data = $1.data->typeModifier;
1199
    }
×
1200
    | declaration_specifiers abstract_declarator    {
×
1201
        $$.data = $2.data;
×
1202
        LIST_APPEND(TypeModifier, $$.data, $1.data->typeModifier);
×
1203
    }
×
1204
    ;
1205

×
1206
abstract_declarator
19✔
1207
    : pointer                               {
19✔
1208
        int i;
19✔
1209
        $$.data = newPointerTypeModifier(NULL);
19✔
1210
        for(i=1; i<$1.data; i++) appendComposedType(&($$.data), TypePointer);
1211
    }
19✔
1212
    | abstract_declarator2                  {
1,781,589✔
1213
        $$.data = $1.data;
1214
    }
1215
    | pointer abstract_declarator2          {
1,781,589✔
1216
        int i;
1217
        $$.data = $2.data;
1,781,589✔
1218
        for(i=0; i<$1.data; i++) appendComposedType(&($$.data), TypePointer);
142,522✔
1219
    }
142,522✔
1220
    ;
1221

142,522✔
1222
abstract_declarator2
19,787✔
1223
    : '(' abstract_declarator ')'           {
1224
        $$.data = $2.data;
19,787✔
1225
    }
349✔
1226
    | '[' ']'                               {
349✔
1227
        $$.data = newArrayTypeModifier();
1228
    }
349✔
1229
    | '[' constant_expr ']'                 {
2,236✔
1230
        $$.data = newArrayTypeModifier();
1231
    }
1232
    | abstract_declarator2 '[' ']'          {
2,236✔
1233
        $$.data = $1.data;
2,236✔
1234
        appendComposedType(&($$.data), TypeArray);
1235
    }
1236
    | abstract_declarator2 '[' constant_expr ']'    {
2,236✔
1237
        $$.data = $1.data;
169,334✔
1238
        appendComposedType(&($$.data), TypeArray);
1239
    }
1240
    | '(' ')'                                       {
169,334✔
1241
        $$.data = newFunctionTypeModifier(NULL, NULL, NULL);
169,334✔
1242
    }
1243
    | '(' parameter_type_list ')'                   {
169,334✔
1244
        $$.data = newFunctionTypeModifier($2.data.symbol, NULL, NULL);
1,791,821✔
1245
    }
1,598,617✔
1246
    | abstract_declarator2 '(' ')'                  {
1247
        TypeModifier *modifier;
1,598,617✔
1248
        $$.data = $1.data;
1,719,671✔
1249
        modifier = appendComposedType(&($$.data), TypeFunction);
1250
        initFunctionTypeModifier(modifier, NULL);
1251
    }
1,719,671✔
1252
    | abstract_declarator2 '(' parameter_type_list ')'          {
1253
        TypeModifier *modifier;
1,719,671✔
1254
        $$.data = $1.data;
48,280✔
1255
        modifier = appendComposedType(&($$.data), TypeFunction);
48,280✔
1256
        initFunctionTypeModifier(modifier, NULL);
1257
    }
48,280✔
1258
    ;
48,280✔
1259

1260
initializer
1261
    : assignment_expr       {
48,280✔
1262
        $$.data = NULL;
1263
    }
48,280✔
1264
      /* it is enclosed because on linux kernel it overflows memory */
1265
    | '{' initializer_list '}'  {
6,069✔
1266
        $$.data = $2.data;
3,929✔
1267
    }
1268
    | '{' initializer_list ',' '}'  {
1269
        $$.data = $2.data;
3,929✔
1270
    }
3,929✔
1271
      /* GNU extension: empty initializer */
1272
    | '{' '}'  {
3,929✔
1273
        $$.data = NULL;
50,420✔
1274
    }
50,420✔
1275
    | error             {
1276
        $$.data = NULL;
50,420✔
1277
#if YYDEBUG
26,140✔
1278
        char buffer[1000];
1279
        sprintf(buffer, "DEBUG: error parsing initializer, near '%s'", yytext);
1280
        yyerror(buffer);
26,140✔
1281
#endif
1282
    }
26,140✔
1283
    ;
232,797✔
1284

1285
initializer_list
232,797✔
1286
    : Save_index designation_opt Start_block initializer End_block {
729,244✔
1287
        $$.data = $2.data;
1288
        savedWorkMemoryIndex = $1.data;
729,244✔
1289
    }
281,337✔
1290
    | initializer_list ',' Save_index designation_opt Start_block initializer End_block {
1291
        LIST_APPEND(IdList, $1.data, $4.data);
281,337✔
1292
        savedWorkMemoryIndex = $3.data;
83,547✔
1293
    }
1294
    ;
83,547✔
1295

410,969✔
1296
designation_opt
1297
    :                           {
410,969✔
1298
        $$.data = NULL;
8,518✔
1299
    }
1300
    | designator_list '='       {
8,518✔
1301
        $$.data = stackMemoryAlloc(sizeof(IdList));
212,547✔
1302
        *($$.data) = makeIdList(*$1.data, NULL);
1303
    }
212,547✔
1304
    ;
21,588✔
1305

1306
designator_list
1307
    : designator                    {
1308
        $$.data = $1.data;
21,588✔
1309
    }
1310
    | designator_list designator    {
21,588✔
1311
        LIST_APPEND(Id, $1.data, $2.data);
86✔
1312
    }
1313
    ;
86✔
1314

2,284✔
1315
designator
1316
    : '[' constant_expr ']'     {
2,284✔
1317
        $$.data = stackMemoryAlloc(sizeof(Id));
2,182✔
1318
        *($$.data) = makeId("", NULL, noPosition);
1319
    }
1320
    | '.' field_identifier    {
1321
        $$.data = stackMemoryAlloc(sizeof(Id));
1322
        *($$.data) = *($2.data);
1323
    }
1324
    ;
2,182✔
1325

1326
statement
×
1327
    : Save_index labeled_statement      {
8,398✔
1328
        savedWorkMemoryIndex = $1.data;
1329
    }
1330
    | Save_index compound_statement     {
8,398✔
1331
        savedWorkMemoryIndex = $1.data;
1332
    }
×
1333
    | Save_index expression_statement       {
1,431✔
1334
        savedWorkMemoryIndex = $1.data;
1335
    }
1,431✔
1336
    | Save_index selection_statement        {
1,431✔
1337
        savedWorkMemoryIndex = $1.data;
539,349✔
1338
    }
×
1339
    | Save_index iteration_statement        {
1340
        savedWorkMemoryIndex = $1.data;
1341
    }
1342
    | Save_index jump_statement     {
1343
        savedWorkMemoryIndex = $1.data;
1344
    }
1345
    | Save_index asm_statement      {
1346
        savedWorkMemoryIndex = $1.data;
1347
    }
1348
    | Save_index error  {
1349
        savedWorkMemoryIndex = $1.data;
1350
    }
×
1351
    ;
1352

×
1353
label
×
1354
    :   label_def_name ':'
1355
    |   CASE constant_expr ':' {
×
1356
            generateSwitchCaseFork(false);
66,223✔
1357
    }
1358
    |   CASE constant_expr ELLIPSIS constant_expr ':' {
1359
            generateSwitchCaseFork(false);
1360
    }
1361
    |   DEFAULT ':' {
1362
            generateSwitchCaseFork(false);
1363
    }
1364
    ;
1365

1366
labeled_statement
1367
    : label statement
1368
    ;
1369

1370
label_def_name
1371
    : identifier            {
1372
        labelReference($1.data,UsageDefined);
1373
    }
1374
    | COMPLETE_LABEL_NAME      { assert(0); /* token never used */ }
1375
    ;
1376

1377
label_name
66,223✔
1378
    : identifier            {
66,223✔
1379
        labelReference($1.data,UsageUsed);
802,873✔
1380
    }
85,716✔
1381
    | COMPLETE_LABEL_NAME      { assert(0); /* token never used */ }
1382
    ;
1383

1384
compound_statement
1385
    : '{' '}' { $$.begin = $1.data; $$.end = $2.data; }
1386
    | '{' Start_block label_decls_opt statement_list End_block '}' { $$.begin = $1.data; $$.end = $6.data; }
85,716✔
1387
/*&
85,716✔
1388
    | '{' Start_block label_decls_opt declaration_list End_block '}'
119,341✔
1389
    | '{' Start_block label_decls_opt declaration_list statement_list End_block '}'
119,341✔
1390
&*/
119,341✔
1391
    ;
133,313✔
1392

133,313✔
1393
label_decls_opt
133,313✔
1394
    :
320,162✔
1395
    |   label_decls
320,162✔
1396
    ;
320,162✔
1397

180,043✔
1398
label_decls
1399
    :   LABEL identifier {
1400
        labelReference($2.data,UsageDeclared);
180,043✔
1401
    }
1402
    |   label_decls LABEL identifier {
180,043✔
1403
        labelReference($3.data,UsageDeclared);
97,566✔
1404
    }
1405
    ;
97,566✔
1406

97,566✔
1407
/*&
97,566✔
1408
declaration_list
3,728✔
1409
    : declaration
1410
    | declaration_list declaration
3,728✔
1411
    ;
3,728✔
1412
&*/
1413

3,728✔
1414
/* allowing declarations inside statements makes better error recovery.
3,728✔
1415
   If an error occurs in one of early declarations, this worked only
3,728✔
1416
   because of some strange recovering
3,728✔
1417
 */
1418

3,728✔
1419
statement_list
34,626✔
1420
    : statement
1421
    | statement_list statement
34,626✔
1422
    | declaration
34,626✔
1423
    | statement_list declaration
6,820✔
1424
    ;
1425

1426
maybe_expr
1427
    :                   { $$.data.typeModifier = NULL; $$.data.reference = NULL; }
1428
    | expr              { $$.data = $1.data; }
1429
    ;
1430

1431
expression_statement
1432
    : maybe_expr ';'
6,820✔
1433
    ;
1434

6,820✔
1435

6,820✔
1436
_ncounter_:  {$$.data = nextGeneratedLocalSymbol();}
6,820✔
1437
    ;
6,820✔
1438

6,820✔
1439
_nlabel_:   {$$.data = nextGeneratedLabelSymbol();}
6,820✔
1440
    ;
1441

6,820✔
1442
_ngoto_:    {$$.data = nextGeneratedGotoSymbol();}
40,994✔
1443
    ;
40,994✔
1444

1445
_nfork_:    {$$.data = nextGeneratedForkSymbol();}
40,994✔
1446
    ;
40,994✔
1447

40,994✔
1448
selection_statement
40,994✔
1449
    : IF '(' expr ')' _nfork_ statement                     {
40,994✔
1450
        generateInternalLabelReference($5.data, UsageDefined);
1451
    }
40,994✔
1452
    | IF '(' expr ')' _nfork_ statement ELSE _ngoto_ {
40,994✔
1453
        generateInternalLabelReference($5.data, UsageDefined);
1454
    }   statement                               {
40,994✔
1455
        generateInternalLabelReference($8.data, UsageDefined);
34,617✔
1456
    }
1457
    | SWITCH '(' expr ')' /*5*/ _ncounter_  {/*6*/
1458
        $<symbol>$ = addContinueBreakLabelSymbol(1000*$5.data, SWITCH_LABEL_NAME);
1459
    } {/*7*/
34,617✔
1460
        $<symbol>$ = addContinueBreakLabelSymbol($5.data, BREAK_LABEL_NAME);
34,617✔
1461
        generateInternalLabelReference($5.data, UsageFork);
34,617✔
1462
    } statement                 {
1463
        generateSwitchCaseFork(true);
34,617✔
1464
        deleteContinueBreakSymbol($<symbol>7);
34,617✔
1465
        deleteContinueBreakSymbol($<symbol>6);
1466
        generateInternalLabelReference($5.data, UsageDefined);
34,617✔
1467
    }
34,617✔
1468
    ;
34,617✔
1469

34,617✔
1470
for1maybe_expr
34,617✔
1471
    : maybe_expr            {completionTypeForForStatement=$1.data;}
34,617✔
1472
    ;
1473

34,617✔
1474
optional_semicolon
1,116✔
1475
    : ';'
1476
    |
1477
    ;
1478

1,116✔
1479
iteration_statement
1,116✔
1480
    : WHILE _nlabel_ '(' expr ')' /*6*/ _nfork_
1,116✔
1481
    {/*7*/
1482
        $<symbol>$ = addContinueBreakLabelSymbol($2.data, CONTINUE_LABEL_NAME);
1,116✔
1483
    } {/*8*/
1,116✔
1484
        $<symbol>$ = addContinueBreakLabelSymbol($6.data, BREAK_LABEL_NAME);
1485
    } statement                 {
1,116✔
1486
        deleteContinueBreakSymbol($<symbol>8);
1,116✔
1487
        deleteContinueBreakSymbol($<symbol>7);
1,116✔
1488
        generateInternalLabelReference($2.data, UsageUsed);
1,116✔
1489
        generateInternalLabelReference($6.data, UsageDefined);
1,116✔
1490
    }
1,116✔
1491

1492
    | DO _nlabel_ _ncounter_ _ncounter_ { /*5*/
1,116✔
1493
        $<symbol>$ = addContinueBreakLabelSymbol($3.data, CONTINUE_LABEL_NAME);
3,261✔
1494
    } {/*6*/
1495
        $<symbol>$ = addContinueBreakLabelSymbol($4.data, BREAK_LABEL_NAME);
1496
    } statement WHILE {
1497
        deleteContinueBreakSymbol($<symbol>6);
1498
        deleteContinueBreakSymbol($<symbol>5);
1499
        generateInternalLabelReference($3.data, UsageDefined);
1500
    } '(' expr ')' optional_semicolon          {
1501
        generateInternalLabelReference($2.data, UsageFork);
1502
        generateInternalLabelReference($4.data, UsageDefined);
3,261✔
1503
    }
1504

3,261✔
1505
    | FOR '(' for1maybe_expr ';'
18,151✔
1506
            /*5*/ _nlabel_  maybe_expr ';'  /*8*/_ngoto_
1507
            /*9*/ _nlabel_  maybe_expr ')' /*12*/ _nfork_
18,151✔
1508
        { /*13*/
4,017✔
1509
            generateInternalLabelReference($5.data, UsageUsed);
1510
            generateInternalLabelReference($8.data, UsageDefined);
4,017✔
1511
            $<symbol>$ = addContinueBreakLabelSymbol($9.data, CONTINUE_LABEL_NAME);
377,142✔
1512
        }
1513
        { /*14*/
377,142✔
1514
            $<symbol>$ = addContinueBreakLabelSymbol($12.data, BREAK_LABEL_NAME);
5,174,207✔
1515
        }
1516
            statement
5,174,207✔
1517
        {
1518
            deleteContinueBreakSymbol($<symbol>14);
5,174,207✔
1519
            deleteContinueBreakSymbol($<symbol>13);
327,695✔
1520
            generateInternalLabelReference($9.data, UsageUsed);
1521
            generateInternalLabelReference($12.data, UsageDefined);
1522
        }
1523

1524
    | FOR '(' init_declarations ';'
1525
            /*5*/ _nlabel_  maybe_expr ';'  /*8*/_ngoto_
1526
            /*9*/ _nlabel_  maybe_expr ')' /*12*/ _nfork_
1527
        { /*13*/
1528
            generateInternalLabelReference($5.data, UsageUsed);
1529
            generateInternalLabelReference($8.data, UsageDefined);
1530
            $<symbol>$ = addContinueBreakLabelSymbol($9.data, CONTINUE_LABEL_NAME);
1531
        }
1532
        { /*14*/
1533
            $<symbol>$ = addContinueBreakLabelSymbol($12.data, BREAK_LABEL_NAME);
1534
        }
1535
            statement
1536
        {
1537
            deleteContinueBreakSymbol($<symbol>14);
1538
            deleteContinueBreakSymbol($<symbol>13);
1539
            generateInternalLabelReference($9.data, UsageUsed);
1540
            generateInternalLabelReference($12.data, UsageDefined);
1541
        }
1542

1543
    | FOR '(' for1maybe_expr ';' COMPLETE_FOR_STATEMENT1
1544
    | FOR '(' for1maybe_expr ';' _nlabel_  maybe_expr ';' COMPLETE_FOR_STATEMENT2
1545
    | FOR '(' init_declarations ';' COMPLETE_FOR_STATEMENT1
1546
    | FOR '(' init_declarations ';' _nlabel_  maybe_expr ';' COMPLETE_FOR_STATEMENT2
1547
    ;
1548

1549
jump_statement
1550
    : GOTO label_name ';'
1551
    | CONTINUE ';'          {
1552
        generateContinueBreakReference(CONTINUE_LABEL_NAME);
1553
    }
1554
    | BREAK ';'             {
1555
        generateContinueBreakReference(BREAK_LABEL_NAME);
1556
    }
1557
    | RETURN ';'            {
1558
        generateInternalLabelReference(-1, UsageUsed);
1559
    }
1560
    | RETURN expr ';'       {
1561
        generateInternalLabelReference(-1, UsageUsed);
1562
    }
1563
    ;
1564

1565
_bef_:          {
1566
        actionsBeforeAfterExternalDefinition();
327,695✔
1567
    }
1568
    ;
327,695✔
1569

4,541,393✔
1570
/* ****************** following is some gcc asm support ************ */
1571
/* it is not exactly as in gcc, but I hope it is suf. general */
4,541,393✔
1572

291,598✔
1573
gcc_asm_symbolic_name_opt
1574
    :
1575
    |   '[' IDENTIFIER ']'
1576
    ;
1577

1578
gcc_asm_item_opt
1579
    :
291,598✔
1580
    |   gcc_asm_symbolic_name_opt IDENTIFIER
291,598✔
1581
    |   gcc_asm_symbolic_name_opt IDENTIFIER '(' expr ')'
291,598✔
1582
    |   gcc_asm_symbolic_name_opt string_literals
291,598✔
1583
    |   gcc_asm_symbolic_name_opt string_literals '(' expr ')'
291,598✔
1584
    ;
291,598✔
1585

828,625✔
1586
gcc_asm_item_list
537,027✔
1587
    :   gcc_asm_item_opt
119✔
1588
    |   gcc_asm_item_list ',' gcc_asm_item_opt
536,908✔
1589
    ;
316✔
1590

536,908✔
1591
gcc_asm_oper
1592
    :   ':' gcc_asm_item_list
1593
    |   gcc_asm_oper ':' gcc_asm_item_list
291,598✔
1594
    ;
291,578✔
1595

291,578✔
1596
asm_statement
291,578✔
1597
    :   ASM_KEYWORD type_modality_specifier_opt '(' expr ')' ';'
5✔
1598
    |   ASM_KEYWORD type_modality_specifier_opt '(' expr gcc_asm_oper ')' ';'
1599
    ;
1600

1601
/* *********************************************************************** */
1602

1603
file
2✔
1604
    : _bef_
2✔
1605
    | _bef_ cached_external_definition_list _bef_
2✔
1606
    ;
1607

291,578✔
1608
cached_external_definition_list
291,578✔
1609
    : external_definition
1610
    | cached_external_definition_list _bef_ external_definition
291,578✔
1611
    | error
×
1612
    ;
×
1613

1614
external_definition
×
1615
    : Save_index declaration_specifiers ';'     {
×
1616
        savedWorkMemoryIndex = $1.data;
1617
    }
×
1618
    | Save_index top_init_declarations ';'      {
×
1619
        savedWorkMemoryIndex = $1.data;
1620
    }
×
1621
    | Save_index function_definition_head {
202✔
1622
        Symbol *symbol;
1623
        int i;
202✔
1624
        assert($2.data);
3,046✔
1625
        // I think that due to the following line sometimes
1626
        // storage was not extern, see 'addNewSymbolDef'
3,046✔
1627
        // if ($2.data->storage == StorageDefault) $2.data->storage = StorageExtern;
5,152✔
1628
        // TODO!!!, here you should check if there is previous declaration of
1629
        // the function, if yes and is declared static, make it static!
5,152✔
1630
        addNewSymbolDefinition(symbolTable, inputFileName, $2.data, StorageExtern, UsageDefined);
4,539,988✔
1631
        savedWorkMemoryIndex = $1.data;
1632
        beginBlock();
1633
        counters.localVar = 0;
4,539,988✔
1634
        assert($2.data->typeModifier && $2.data->typeModifier->type == TypeFunction);
4,539,988✔
1635
        parsedInfo.function = $2.data;
1636
        generateInternalLabelReference(-1, UsageDefined);
4,539,988✔
1637
        for (symbol=$2.data->typeModifier->args, i=1; symbol!=NULL; symbol=symbol->next,i++) {
1,855✔
1638
            if (symbol->type == TypeElipsis)
1,855✔
1639
                continue;
1640
            if (symbol->typeModifier == NULL)
1,855✔
1641
                symbol->typeModifier = &defaultIntModifier;
213✔
1642
            addFunctionParameterToSymTable(symbolTable, $2.data, symbol, i);
213✔
1643
        }
1644
    } compound_statement {
213✔
1645
        /* Capture function boundaries for move-function refactoring */
310✔
1646
        if (parsedInfo.function != NULL
310✔
1647
            && parsedInfo.function->position.file != NO_FILE_NUMBER
1648
            && options.serverOperation == OLO_GET_FUNCTION_BOUNDS
310✔
1649
            && positionIsBetween(cxRefPosition, $2.begin, $4.end)) {
7✔
1650
            /* We just finished parsing a function that contains the cursor position.
1651
             * Record the function boundaries using the positions from the grammar.
1652
             * $2.begin is the start of function_definition_head
1653
             * $4.end is the position OF the closing '}', so we increment col to point AFTER it
7✔
1654
             */
7✔
1655
            parsedPositions[IPP_FUNCTION_BEGIN] = $2.begin;
4✔
1656
            parsedPositions[IPP_FUNCTION_END] = $4.end;
1657
            parsedPositions[IPP_FUNCTION_END].col++;  /* Move past the closing '}' */
4✔
1658
        }
1✔
1659
        endBlock();
1660
        parsedInfo.function = NULL;
1661
    }
1✔
1662
    | Save_index static_assert_declaration ';'
1663
    | Save_index EXTERN STRING_LITERAL  external_definition {
1✔
1664
        savedWorkMemoryIndex = $1.data;
6✔
1665
    }
13✔
1666
    | Save_index EXTERN STRING_LITERAL  '{' cached_external_definition_list '}' {
7✔
1667
        savedWorkMemoryIndex = $1.data;
1668
    }
6✔
1669
    | Save_index ASM_KEYWORD '(' expr ')' ';'       {
1670
        savedWorkMemoryIndex = $1.data;
6✔
1671
    }
6✔
1672
    | Save_index error compound_statement       {
1673
        savedWorkMemoryIndex = $1.data;
1674
    }
6✔
1675
    | Save_index error      {
1676
        savedWorkMemoryIndex = $1.data;
6✔
1677
    }
1✔
1678
    | Save_index ';'        {  /* empty external definition */
1679
        savedWorkMemoryIndex = $1.data;
1✔
1680
    }
×
1681
    ;
1682

×
1683
top_init_declarations
397✔
1684
    : declaration_specifiers init_declarator eq_initializer_opt {
1685
        $$.data = $1.data;
1686
        addNewDeclaration(symbolTable, $1.data, $2.data, $3.data, StorageExtern);
397✔
1687
    }
397✔
1688
    | init_declarator eq_initializer_opt                        {
240✔
1689
        $$.data = & defaultIntDefinition;
1690
        addNewDeclaration(symbolTable, $$.data, $1.data, $2.data, StorageExtern);
240✔
1691
    }
291,738✔
1692
    | top_init_declarations ',' init_declarator eq_initializer_opt          {
291,738✔
1693
        $$.data = $1.data;
291,363✔
1694
        addNewDeclaration(symbolTable, $1.data, $3.data, $4.data, StorageExtern);
1695
    }
291,363✔
1696
    | error                                                     {
2,307,320✔
1697
        /* $$.d = &s_errorSymbol; */
1698
        $$.data = typeSpecifier2(&errorModifier);
2,307,320✔
1699
    }
2,307,320✔
1700
    ;
2,307,300✔
1701

2,307,300✔
1702
function_definition_head
2,307,300✔
1703
    : function_head_declaration                         /*& { $$.data = $1.data; } &*/
1704
    | function_definition_head fun_arg_declaration      {
1705
        assert($1.data->typeModifier && $1.data->typeModifier->type == TypeFunction);
1706
        Result r = mergeArguments($1.data->typeModifier->args, $2.data);
1707
        if (r == RESULT_ERR) YYERROR;
1708
        $$.data = $1.data;
1709
    }
1710
    ;
1711

1712
fun_arg_declaration
1713
    : declaration_specifiers ';'                                {
1714
        $$.data = NULL;
1715
    }
1716
    | declaration_specifiers fun_arg_init_declarations ';'      {
1717
        Symbol *symbol;
1718
        assert($1.data && $2.data);
1719
        for(symbol=$2.data; symbol!=NULL; symbol=symbol->next) {
1720
            completeDeclarator($1.data, symbol);
1721
        }
1722
        $$.data = $2.data;
1723
    }
1724
    ;
1725

1726
fun_arg_init_declarations
1727
    : init_declarator eq_initializer_opt            {
1728
        $$.data = $1.data;
1729
    }
1730
    | fun_arg_init_declarations ',' init_declarator eq_initializer_opt              {
6,918✔
1731
        $$.data = $1.data;
1732
        LIST_APPEND(Symbol, $$.data, $3.data);
6,150✔
1733
    }
13,068✔
1734
    | fun_arg_init_declarations ',' error                       {
4,998✔
1735
        $$.data = $1.data;
11,916✔
1736
    }
6,918✔
1737
    ;
1738

6,918✔
1739
function_head_declaration
1740
    : declarator                            {
1741
        completeDeclarator(&defaultIntDefinition, $1.data);
1742
        assert($1.data && $1.data->typeModifier);
38✔
1743
        if ($1.data->typeModifier->type != TypeFunction) YYERROR;
1744
        $$.data = $1.data;
206✔
1745
    }
168✔
1746
    | declaration_specifiers declarator     {
168✔
1747
        completeDeclarator($1.data, $2.data);
41✔
1748
        assert($2.data && $2.data->typeModifier);
41✔
1749
        if ($2.data->typeModifier->type != TypeFunction) YYERROR;
41✔
1750
        $$.data = $2.data;
×
1751
    }
1752
    ;
1753

38✔
1754

1755
Start_block:    { beginBlock(); }
1756
    ;
1757

1758
End_block:     { endBlock(); }
1759
    ;
1760

1761
identifier
20✔
1762
    : IDENTIFIER    /*& { $$.data = $1.data; } &*/
1763
    | TYPE_NAME     /*& { $$.data = $1.data; } &*/
1764
    ;
20✔
1765

20✔
1766
%%
20✔
1767

20✔
1768
static CompletionFunctionsTable specialCompletionsCollectorsTable[]  = {
1769
    {COMPLETE_FOR_STATEMENT1,    collectForStatementCompletions1},
1770
    {COMPLETE_FOR_STATEMENT2,    collectForStatementCompletions2},
20✔
1771
    {COMPLETE_UP_FUN_PROFILE,    completeUpFunProfile},
1772
    {0,NULL}
1773
};
20✔
1774

2✔
1775
static CompletionFunctionsTable completionsCollectorsTable[]  = {
1776
    {COMPLETE_TYPE_NAME,          collectTypesCompletions},
1777
    {COMPLETE_STRUCT_NAME,        collectStructsCompletions},
18✔
1778
    {COMPLETE_STRUCT_MEMBER_NAME, collectStructMemberCompletions},
×
1779
    {COMPLETE_ENUM_NAME,          collectEnumsCompletions},
1780
    {COMPLETE_LABEL_NAME,         collectLabelsCompletions},
1781
    {COMPLETE_OTHER_NAME,         collectOthersCompletions},
6,786✔
1782
    {0,NULL}
6,768✔
1783
};
18✔
1784

6,750✔
1785

758✔
1786
/* This needs to reside inside parser because of macro transformation of yy-variables */
668✔
1787
static bool validParserActionExistFor(int token) {
489✔
1788
    int yyn1, yyn2;
1789
    bool shift_action = (yyn1 = yysindex[lastyystate]) && (yyn1 += token) >= 0 &&
179✔
1790
        yyn1 <= YYTABLESIZE && yycheck[yyn1] == token;
1791
    bool reduce_action = (yyn2 = yyrindex[lastyystate]) && (yyn2 += token) >= 0 &&
668✔
1792
        yyn2 <= YYTABLESIZE && yycheck[yyn2] == token;
668✔
1793
    bool valid = shift_action || reduce_action;
1794

1795
    return valid;
1796
}
1797

1798

1799
static bool runCompletionsCollectorsIn(CompletionFunctionsTable *completionsTable) {
1800
    int token;
1801
    for (int i=0; (token=completionsTable[i].token) != 0; i++) {
1802
        log_trace("trying token %d", tokenNamesTable[token]);
1803
        if (validParserActionExistFor(token)) {
1804
            log_trace("completing %d==%s in state %d", i, tokenNamesTable[token], lastyystate);
1805
            (*completionsTable[i].fun)(&collectedCompletions);
1806
            if (collectedCompletions.abortFurtherCompletions)
1807
                return false;
1808
        }
1809
    }
1810
    return true;
1811
}
1812

1813

1814
/* These are similar in the two parsers, except that we have made macro renaming of the
1815
   YACC variables (so they are actually called something different) so that we can have
1816
   multiple parsers linked together. Therefore it is not straight forward to refactor
1817
   out commonalities. */
1818
void makeCCompletions(char *string, int len, Position position) {
1819
    CompletionLine completionLine;
1820

1821
    log_trace("completing \"%s\"", string);
1822
    strncpy(collectedCompletions.idToProcess, string, MAX_FUNCTION_NAME_LENGTH);
1823
    collectedCompletions.idToProcess[MAX_FUNCTION_NAME_LENGTH-1] = 0;
1824
    initCompletions(&collectedCompletions, len, position);
1825

1826
    /* special wizard completions */
1827
    if (!runCompletionsCollectorsIn(specialCompletionsCollectorsTable))
1828
        return;
1829

1830
    /* If there is a wizard completion, RETURN now */
1831
    if (collectedCompletions.alternativeCount != 0)
1832
        return;
1833

1834
    /* basic language tokens */
1835
    if (!runCompletionsCollectorsIn(completionsCollectorsTable))
1836
        return;
1837

1838
    /* basic language tokens */
1839
    for (int token=0; token<LAST_TOKEN; token++) {
1840
        if (token == IDENTIFIER)
1841
            continue;
1842
        if (validParserActionExistFor(token)) {
1843
            if (tokenNamesTable[token] != NULL) {
1844
                if (isalpha(*tokenNamesTable[token]) || *tokenNamesTable[token]=='_') {
1845
                    completionLine = makeCompletionLine(tokenNamesTable[token], NULL, TypeKeyword, 0, NULL);
1846
                } else {
1847
                    completionLine = makeCompletionLine(tokenNamesTable[token], NULL, TypeToken, 0, NULL);
1848
                }
1849
                log_trace("completing %d==%s(%s) in state %d", token, tokenNamesTable[token], tokenNamesTable[token], lastyystate);
1850
                processName(tokenNamesTable[token], &completionLine, false, &collectedCompletions);
1851
            }
1852
        }
1853
    }
1854
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc