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

nasa / trick / 23871410048

01 Apr 2026 09:20PM UTC coverage: 55.811% (-0.1%) from 55.922%
23871410048

Pull #2011

github

web-flow
Merge 933021c3f into 5cf9d7558
Pull Request #2011: Standardize code style using clang-format

12577 of 22535 relevant lines covered (55.81%)

310562.05 hits per line

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

53.4
/trick_source/sim_services/CheckPointAgent/input_parser.y
1
%name-prefix="CCP_"
2
%pure-parser
3
%locations
4
%parse-param {ChkPtParseContext* IP}
5
%lex-param { void* scanner }
6
%debug
7

8
%{
9

10
/*
11
   %error-verbose
12
 */
13

14
#include <iostream>
15
#include <sstream>
16
#include <stdlib.h>
17
#include <string.h>
18

19
#include "trick/ChkPtParseContext.hh"
20
#include "trick/vval.h"
21
#include "trick/value.h"
22
#include "trick/var.h"
23
#include "trick/message_proto.h"
24
#include "trick/message_type.h"
25
#include "input_parser.tab.hpp"
26

27
    using namespace std;
28

29
    int CCP_lex( YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner );
30

31
    void CCP_error( YYLTYPE* locp, ChkPtParseContext* context, const char* err) {
×
32
       message_publish(MSG_ERROR, "Checkpoint Agent input_parser PARSE-ERROR %d : %s\n", locp->first_line, err) ;
×
33
    }
×
34

35
#define scanner IP->scanner
36

37
%}
38

39
%start entries
40

41
%union {
42
        char                cval  ;
43
        char*               sval  ;
44
        long                ival  ;
45
        long long           llval ;
46
        unsigned long long  ullval ;
47
        double              fval  ;
48
        V_DATA              vval ;
49
        REF2                rval ;
50
        VALUE_LIST*         value_list ;
51
        V_TREE*             v_tree ;
52
        VAR_LIST            var_list;
53
}
54

55
%token <cval> C_CON
56
%token <sval> S_CON NAME NAM2 TYPE_NAME 
57
%token <ival> TYPE 
58
%token <llval> I_CON
59
%token <ullval> UI_CON
60
%token <fval> F_CON
61

62
%token ECHO_ON
63
%token ECHO_OFF
64
%token GET_REF
65
%token ALLOC 
66
%token ARROW
67
%token DOUBLE_DASH
68

69
%token END 0 "End of file"
70

71
%type  <vval> v_data initial_value 
72
%type  <sval> units units_string
73
%type  <ival> p_list dereference
74
%type  <rval> param reference 
75
%type  <value_list> dim_list 
76
%type  <var_list> name_list 
77
%type  <v_tree> assignment_item assignment_list 
78

79
%%
80

81
entries: { 
82
             if ( IP->mem_mgr->debug_level > 2) {
24✔
83
                  yydebug = 1 ;
×
84
             } else {
85
                  yydebug = 0 ;
24✔
86
             }
87
         }
88
         | entries allocate {
89
         }
90
         | entries trick_funcs {
91
         }
92
         | entries assignment {
93
         }
94
         | entries declaration {
95
         }
96
         | entries error {
97

98
         /* This rule prevents a premature "file" rule reduction ( before
99
          * yyerror can be called to report the syntax error), when an
100
          * unexpected token is encountered immediately following an
101
          * "entries" rule reduction.
102
          *
103
          * Note: the special "error" token is described in Section 6 of the
104
          * GNU Bison Manual.
105
          */
106

107
         } ;
108

109
declaration: TYPE name_list ';' { 
110

111
                 /*
112
                  * Declaration of intrinsic data types.
113
                  */
114

115
                 int i , ret = -1 ;
1,575✔
116

117
                 if (IP->mem_mgr->add_vars( (TRICK_TYPE)$1 , NULL , &$2 ,NULL ) != 0) {
1,575✔
118
                     std::stringstream ss;
×
119
                     ss << "Checkpoint Agent ERROR: Declaration failed." << std::endl;
×
120
                     message_publish( MSG_ERROR, ss.str().c_str() );
×
121
                     IP->bad_declaration_count ++;
×
122
                 }
123
                 for ( i = 0 ; i < $2.num_vars ; i++ ) {
3,150✔
124
                     free($2.var_declare[i].dim_list) ;
1,575✔
125
                     free($2.var_declare[i].name) ;
1,575✔
126
                 }
127
                 free($2.var_declare) ;
1,575✔
128
             }
129

130
           | NAME name_list ';' {
131

132
                 /*
133
                  * Declaration of user-defined (class or struct) data types.
134
                  */
135

136
                 int i , ret = -1 ;
129✔
137

138
                 if (IP->mem_mgr->add_vars( TRICK_STRUCTURED , $1 , &$2, NULL) != 0) {
129✔
139
                     std::stringstream ss;
×
140
                     ss << "Checkpoint Agent ERROR: Declaration failed." << std::endl;
×
141
                     message_publish( MSG_ERROR, ss.str().c_str() );
×
142
                     IP->bad_declaration_count ++;
×
143
                 }
144
                 free( $1 ) ;
129✔
145
                 for ( i = 0 ; i < $2.num_vars ; i++ ) {
258✔
146
                     free($2.var_declare[i].dim_list) ;
129✔
147
                     free($2.var_declare[i].name) ;
129✔
148
                 }
149
                 free($2.var_declare) ;
129✔
150
            }
151
          ;
152

153
name_list: p_list NAME dim_list initial_value {
154

155
               /*
156
                * name_list consists of 1 or more variable names to be declared
157
                * the first rule handles the first variable.  The next handles all
158
                * subsequent variable names.
159
                */
160

161
               $$.num_vars = 0 ;
1,704✔
162

163
               $$.var_declare = (VAR_DECLARE *)malloc(sizeof(VAR_DECLARE)) ;
1,704✔
164
               $$.var_declare[$$.num_vars].num_pointers = $1 ;
1,704✔
165
               $$.var_declare[$$.num_vars].name = $2 ;
1,704✔
166
               $$.var_declare[$$.num_vars].dim_list = $3 ;
1,704✔
167
               $$.var_declare[$$.num_vars].value = $4 ;
1,704✔
168

169
               $$.num_vars++ ;
1,704✔
170
           }
171
         | name_list ',' p_list NAME dim_list initial_value {
172

173
               $$.var_declare = (VAR_DECLARE *)realloc($$.var_declare , ($$.num_vars + 1) * sizeof(VAR_DECLARE)) ;
×
174
               $$.var_declare[$$.num_vars].num_pointers = $3 ;
×
175
               $$.var_declare[$$.num_vars].name = $4 ;
×
176
               $$.var_declare[$$.num_vars].dim_list = $5 ;
×
177
               $$.var_declare[$$.num_vars].value = $6 ;
×
178

179
               $$.num_vars++ ;
×
180

181
           }
182
         ;
183

184
p_list: {
185
        /*
186
         * p_list counts how many pointer dims there are in a variable declaration
187
         * the first rule handles no pointers, the next handles 1 or more pointers
188
         */
189
        $$ = 0 ;
1,704✔
190
        } 
191
      | p_list '*' {
192
        $$++ ;
48✔
193
        }
194
      ;
195

196
initial_value: {
197
                   /*
198
                    * initial value handles the initial value of a variable in a declaration
199
                    * the first rule handles no initial value (default to 0) the second rule
200
                    * passes on value calculated in v_data
201
                    */
202

203
                   $$.type = TRICK_LONG_LONG ;
1,704✔
204
                   $$.value.ll = 0 ;
1,704✔
205

206
               } 
207
             | '=' v_data {
208

209
                   $$ = $2 ;
×
210
             }
211
             ;
212

213
trick_funcs: ECHO_ON ';' { 
214
                 /*
215
                  * This statement turns ON input file echo. NOTE that I->echo_input
216
                  * is the SAME parameterused in the input file to turn echo on and
217
                  * off.
218
                  */
219
             }
220
           | ECHO_OFF ';' { 
221
                  /*
222
                   * This statement turns OFF input file echo. NOTE that I->echo_input
223
                   * is the SAME parameter used in the input file to turn echo on and
224
                   * off.
225
                   */
226
             }
227
           | NAME '(' v_data ')' ';' { 
228

229
                 if (strcmp("debug",$1) == 0) {
×
230
                     int debug_level = vval_int(&$3);
×
231
                     IP->mem_mgr->debug_level = debug_level;
×
232
                     std::stringstream ss;
×
233
                     ss << "Checkpoint Agent INFO: DEBUG_LEVEL set to " << debug_level << "." << std::endl;
×
234
                     message_publish( MSG_INFO, ss.str().c_str() );
×
235
                 }
236
                 free( $1 ) ;
×
237
             }
238
           | NAME '(' ')' ';' {
239
                 if (strcmp("clear_all_vars",$1) == 0) {
14✔
240
                     IP->mem_mgr->clear_all_vars();
14✔
241
                 }
242
                 free( $1 ) ;
14✔
243
             }
244
           ;
245

246
allocate: reference ALLOC '(' v_data ')' ';' { 
247
              /*
248
               * This statement handles dynamic memory allocation for
249
               * unconstrained arrays. The param rule is responsible for
250
               * collecting all the information about the parameter name and
251
               * array dimensions, this rule is responsible for calling the
252
               * ref_allocate() function, in S_source.c, to allocate the
253
               * specified memory for the specified parameter.
254
               */
255

256
               IP->mem_mgr->ref_allocate( &$1 , vval_int(&$4)) ;
×
257

258
          }
259
;
260

261
assignment: reference assignment_item ';' {
262
    int ret ;
263

264
    if ($1.ref_type != REF_INVALID) {
17,091✔
265
        if ( $1.attr->io & TRICK_CHKPNT_INPUT ) {
17,091✔
266
            ret = IP->mem_mgr->ref_assignment( &$1 , $2 ) ;
17,091✔
267

268
            if ( ret != MM_OK ) {
17,091✔
269
                std::stringstream ss;
×
270
                ss << "Checkpoint Agent ERROR: Assignment to \"";
×
271
                ss <<  $1.reference;
×
272
                ss << "\" failed because ref_assignment() failed.";
×
273
                ss << std::endl;
×
274
                message_publish(MSG_ERROR, ss.str().c_str() );
×
275
                IP->bad_assignment_count ++;
×
276
            }
277
        } else {
278
            std::stringstream ss;
×
279
            ss << "Checkpoint Agent WARNING: \"";
×
280
            ss << $1.reference;
×
281
            ss << "\" not restored because IO specification does not allow checkpoint input.";
×
282
            ss << std::endl;
×
283
            message_publish(MSG_WARNING, ss.str().c_str() );
×
284
            IP->bad_assignment_count ++;
×
285
        }
286
    } else {
287
        std::stringstream ss;
×
288
        ss << "Checkpoint Agent ERROR: Assignment to \"";
×
289
        ss <<  $1.reference;
×
290
        ss << "\" failed because it's an invalid reference.";
×
291
        ss << std::endl;
×
292
        message_publish(MSG_ERROR, ss.str().c_str() );
×
293
        IP->bad_assignment_count ++;
×
294
    }
295
    delete_v_tree($2);
17,091✔
296

297
    /* If the attributes are dynamically-allocated, reference
298
     * attributes then free them so we don't leak memory.
299
     */
300
    if ($1.attr == $1.ref_attr) {
17,091✔
301
        free($1.ref_attr);
1,905✔
302
        $1.ref_attr = NULL;
1,905✔
303
    }
304
}
305

306
assignment_item: v_data {
307
                     $$ = (V_TREE*)calloc((size_t)1, sizeof(V_TREE));
18,359✔
308
                     $$->v_data = (V_DATA*)calloc((size_t)1, sizeof(V_DATA));
18,359✔
309
                     memcpy($$->v_data, &$1, sizeof(V_DATA));
18,359✔
310
                 }
311
               | '{' assignment_list '}' {
312
                     $$ = (V_TREE*)calloc((size_t)1, sizeof(V_TREE));
1,633✔
313
                     $$->down = $2;
1,633✔
314
                 }
315
               ;
316

317

318
assignment_list: {
319
                     $$ = NULL;
×
320
                 } 
321
               | assignment_item {
322
                     $$ = $1;
1,633✔
323
                     $$->last = $$;
1,633✔
324
                 }
325
               | assignment_list ',' assignment_item {
326
                     $$ = $1;
1,268✔
327
                     $$->last->next = $3;
1,268✔
328
                     $$->last = $3;
1,268✔
329
                 }
330
               ;
331

332
reference: param units '=' { 
333
               $$ = $1 ;
17,091✔
334
               $$.units = $2 ;
17,091✔
335
           }
336
;
337

338
units: { // No Units.
339
           $$ = NULL; 
17,091✔
340
       }
341
     | '{' units_string '}' {
342
           $$ = $2; 
×
343
       }
344
     ;
345

346

347
units_string: NAME {
348
                  $$ = $1;
×
349
              }
350
            | NAME '.' NAME '.' {
351
                  size_t m_size = strlen($1) + strlen($3) + 3;
×
352
                  $$ = (char*)malloc(m_size);
×
353
                  snprintf($$, m_size, "%s.%s.", $1,$3); 
×
354
                  free($1);
×
355
                  free($3);
×
356
              }
357
            | DOUBLE_DASH {
358
                  $$ = NULL;
×
359
              }
360
            | I_CON {
361
                  if ($1 == 1) {
×
362
                      size_t m_size = 2;
×
363
                      $$ = (char*)malloc(m_size);
×
364
                      snprintf($$, m_size, "1");
×
365
                  } else {
366
                      return (MM_INVALID_UNITS);
×
367
                  }
368
              }
369
            | units_string '*' NAME {
370
                  size_t m_size = strlen($1) + strlen($3) + 2;
×
371
                  $$ = (char*)malloc(m_size) ;
×
372
                  snprintf($$, m_size, "%s*%s",$1,$3);
×
373
                  free($1);
×
374
                  free($3);
×
375
              }
376
            | units_string '/' NAME {
377
                  size_t m_size = strlen($1) + strlen($3) + 2;
×
378
                  $$ = (char*)malloc(m_size) ;
×
379
                  snprintf($$, m_size, "%s/%s",$1,$3);
×
380
                  free($1);
×
381
                  free($3);
×
382
              }
383
            ;
384

385

386
param: NAME {
387
          /* 
388
           * This rule handles anything that starts with a NAME.  That includes
389
           * parameters, input file variables, defines, enumerations, and
390
           * sizeof structure types.
391
           * This first rule will return a reference if the variable is a
392
           * parameter or a variable.
393
           */
394
           int ret;
395
           $$.reference = NULL;
17,555✔
396
           $$.num_index = 0;
17,555✔
397
           $$.units = NULL;
17,555✔
398
           $$.num_index_left = 0;
17,555✔
399
           $$.pointer_present = 0;
17,555✔
400
           $$.stl_present = 0;
17,555✔
401
           $$.ref_type = REF_INVALID;
17,555✔
402
           $$.address = NULL;
17,555✔
403
           $$.attr = NULL;
17,555✔
404
           $$.create_add_path = 0 ;
17,555✔
405
           $$.address_path = NULL ;
17,555✔
406

407
           // Get the address and attrs of the variable.
408
           if ((ret = IP->mem_mgr->ref_var( &$$, $1)) == MM_OK) {
17,555✔
409
               $$.ref_type = REF_ADDRESS;
17,519✔
410
           } else {
411
               // Is it an enumeration value?
412
               if ((ret = IP->mem_mgr->get_enumerated($1, &$$.v_data)) == MM_OK) {
36✔
413
                   $$.ref_type = REF_VALUE;
36✔
414
               } else {
415
                   message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Invalid reference: \"%s\"\n", $1);
×
416
                   $$.ref_type = REF_INVALID;
×
417
               }
418
           }
419
           if ($$.attr != NULL) {
17,555✔
420
               $$.num_index_left = $$.attr->num_index;
17,519✔
421
           }
422
           $$.reference = strdup($1) ;
17,555✔
423

424
       }
425
     | param '[' v_data ']' {
426

427
           int ret;
428
           char temp[512];
429

430
           // Update the reference to account for the index.
431
           // Note that $$ and $1 are the same thing.
432
           if ($1.ref_type != REF_INVALID) {
13,186✔
433
               if ((ret = IP->mem_mgr->ref_dim(&$$, &$3)) != MM_OK) {
13,186✔
434
                   message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Invalid Reference: \"%s[%d]\".\n", $$.reference, vval_int(&$3));
×
435
                   $$.ref_type = REF_INVALID;
×
436
               }
437
           }
438
           snprintf(temp , sizeof(temp), "%s[%d]" , $$.reference, vval_int(&$3)) ;
13,186✔
439
           $$.reference = (char*)realloc( $$.reference , strlen(temp) + 1);
13,186✔
440
           strcpy($$.reference , temp) ;
13,186✔
441

442
       }
443

444
     | param dereference NAME {
445

446
           /* This rule handles every name level after the first with a "->" or "." */
447
           int ret;
448
           char temp[512];
449

450
           if ($1.ref_type != REF_INVALID) {
16,966✔
451

452
               // If the dereference is an arrow ...
453
               if ($2 == 1) {
16,966✔
454
                   $$.num_index++;
×
455
                   $$.num_index_left--;
×
456
               }
457

458
               /* Check to see if previous parameter specified too many dimensions. */
459
               if ($$.num_index > $$.attr->num_index) {
16,966✔
460
                   message_publish(MSG_ERROR, "Checkpoint Agent ERROR. Invalid Reference: \"%s->%s\".\n", $$.reference, $3);
×
461
                   $$.ref_type = REF_INVALID;
×
462
               }
463

464
               $$.num_index = 0;
16,966✔
465

466
               if ((ret = IP->mem_mgr->ref_name(&$$, $3)) != MM_OK) {
16,966✔
467
                   message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Invalid Reference: \"%s->%s\".\n", $$.reference, $3);
×
468
                   $$.ref_type = REF_INVALID;
×
469
               }
470

471
               /* create a new reference string because previous nodes may refer to old strings */
472
               $$.num_index_left = $$.attr->num_index;
16,966✔
473

474
               if ($2 == 1) {
16,966✔
475
                   snprintf(temp ,sizeof(temp),  "%s->%s" , $$.reference, $3) ;
×
476
               } else {
477
                   snprintf(temp ,sizeof(temp),  "%s.%s" , $$.reference, $3) ;
16,966✔
478
               }
479

480
           } else {
481
               $$.ref_type = REF_INVALID;
×
482
           }
483

484
           $$.reference = (char*)realloc($$.reference, strlen(temp) + 1) ;
16,966✔
485
           strcpy($$.reference , temp) ;
16,966✔
486

487
           free($3);
16,966✔
488

489
       } ;
490

491
dereference: ARROW { 
492
                 $$ = 1 ;
×
493
             }
494
           | '.' {
495
                 $$ = 0 ;
16,966✔
496
             };
497

498
dim_list: {
499
             /*
500
              * These two rules handle C style array indexing. This rule
501
              * handles no indexes, the second rule handles one or more other
502
              * indexes. 
503
              */
504
              int i ;
505

506
              $$ = (VALUE_LIST *)malloc(sizeof(VALUE_LIST)) ;
1,704✔
507

508
              $$->num_val = 0 ;
1,704✔
509
              for ( i = 0 ; i < TRICK_MAX_INDEX ; i++ ) {
15,336✔
510
                  $$->v_data[i].type = TRICK_INTEGER ;
13,632✔
511
                  $$->v_data[i].value.i = 0 ;
13,632✔
512
              }
513

514
          }
515
          | dim_list '[' v_data ']' { 
516
 
517
              if ($$->num_val >= TRICK_MAX_INDEX ) {
1,672✔
518
                  message_publish(MSG_ERROR, "Checkpoint Agent input_parser ERROR 9\n");
×
519
                  return(MM_TOO_MANY_ARRAY_DIMENSIONS) ;
×
520
              }
521
              $$->v_data[$$->num_val].type = TRICK_INTEGER ;
1,672✔
522
              $$->v_data[$$->num_val].value.i = vval_int(&$3) ;
1,672✔
523
              $$->num_val++ ;
1,672✔
524
 
525
         };
526

527
v_data: param {
528
            
529
              if ($1.ref_type == REF_ADDRESS){  
36✔
530
                  $$.value.vp = (void*)$1.address ;
×
531
                  $$.type = TRICK_VOID_PTR ;
×
532
              } else if ( $1.ref_type == REF_VALUE ) {
36✔
533
                  $$.value.i = $1.v_data.value.i ;
36✔
534
                  $$.type = $1.v_data.type ;
36✔
535
              } else {
536
                  message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Reference type is hosed.\n");
×
537
                  message_publish(MSG_ERROR, "Please report this error to the Trick Developement Team.\n");
×
538
              }
539
          }
540

541
      | '&' param {
542

543
            $$.value.vp = (void*)$2.address ;
428✔
544
            $$.type = TRICK_VOID_PTR ;
428✔
545
          }
546

547
      | '&' param '+' v_data {
548
            if (($4.type == TRICK_LONG_LONG)) {
×
549
                $$.value.vp = (char*)$2.address + $4.value.ll ;
×
550
                $$.type = TRICK_VOID_PTR ;
×
551
            } else {
552
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: \"+\" is only supported for adding offsets to addresses.\n");
×
553
                return ( MM_ERROR);
×
554
            }
555
        }
556

557
      | C_CON { 
558

559
            $$.value.ll = (long long)$1 ;
705✔
560
            $$.type = TRICK_LONG_LONG ;
705✔
561
          }
562

563
      | I_CON { 
564

565
            $$.value.ll = $1 ;
24,857✔
566
            $$.type = TRICK_LONG_LONG ;
24,857✔
567
          }
568

569
      | UI_CON { 
570

571
            $$.value.ll = $1 ;
229✔
572
            $$.type = TRICK_LONG_LONG ;
229✔
573
          }
574

575
      | F_CON {  
576

577
            $$.value.d = $1 ;
1,629✔
578
            $$.type = TRICK_DOUBLE ;
1,629✔
579
          }
580

581
      | S_CON { 
582

583
            $$.value.cp = $1 ;
5,333✔
584
            $$.type = TRICK_STRING ;
5,333✔
585
          }
586
;
587

588
%%
589

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