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

nasa / trick / 21192220067

21 Jan 2026 12:15AM UTC coverage: 55.577% (-0.003%) from 55.58%
21192220067

Pull #2028

github

web-flow
Merge f43251a11 into 771012348
Pull Request #2028: Fixed the condition for stl only case so char* or char[] size calculation gets to normal handling

1 of 3 new or added lines in 1 file covered. (33.33%)

125 existing lines in 5 files now uncovered.

12506 of 22502 relevant lines covered (55.58%)

296541.91 hits per line

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

53.17
/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) {
23✔
83
                  yydebug = 1 ;
×
84
             } else {
85
                  yydebug = 0 ;
23✔
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,480✔
116

117
                 if (IP->mem_mgr->add_vars( (TRICK_TYPE)$1 , NULL , &$2 ,NULL ) != 0) {
1,480✔
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++ ) {
2,960✔
124
                     free($2.var_declare[i].dim_list) ;
1,480✔
125
                     free($2.var_declare[i].name) ;
1,480✔
126
                 }
127
                 free($2.var_declare) ;
1,480✔
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 ;
120✔
137

138
                 if (IP->mem_mgr->add_vars( TRICK_STRUCTURED , $1 , &$2, NULL) != 0) {
120✔
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 ) ;
120✔
145
                 for ( i = 0 ; i < $2.num_vars ; i++ ) {
240✔
146
                     free($2.var_declare[i].dim_list) ;
120✔
147
                     free($2.var_declare[i].name) ;
120✔
148
                 }
149
                 free($2.var_declare) ;
120✔
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,600✔
162

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

169
               $$.num_vars++ ;
1,600✔
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,600✔
190
        } 
191
      | p_list '*' {
192
        $$++ ;
44✔
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,600✔
204
                   $$.value.ll = 0 ;
1,600✔
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) {
13✔
240
                     IP->mem_mgr->clear_all_vars();
13✔
241
                 }
242
                 free( $1 ) ;
13✔
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) {
15,568✔
265
        if ( $1.attr->io & TRICK_CHKPNT_INPUT ) {
15,568✔
266
            ret = IP->mem_mgr->ref_assignment( &$1 , $2 ) ;
15,568✔
267

268
            if ( ret != MM_OK ) {
15,568✔
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);
15,568✔
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) {
15,568✔
301
        free($1.ref_attr);
1,766✔
302
        $1.ref_attr = NULL;
1,766✔
303
    }
304
}
305

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

317

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

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

338
units: { // No Units.
339
           $$ = NULL; 
15,568✔
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;
16,025✔
396
           $$.num_index = 0;
16,025✔
397
           $$.units = NULL;
16,025✔
398
           $$.num_index_left = 0;
16,025✔
399
           $$.pointer_present = 0;
16,025✔
400
           $$.ref_type = REF_INVALID;
16,025✔
401
           $$.address = NULL;
16,025✔
402
           $$.attr = NULL;
16,025✔
403
           $$.create_add_path = 0 ;
16,025✔
404
           $$.address_path = NULL ;
16,025✔
405

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

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

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

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

441
       }
442

443
     | param dereference NAME {
444

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

449
           if ($1.ref_type != REF_INVALID) {
15,420✔
450

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

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

463
               $$.num_index = 0;
15,420✔
464

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

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

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

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

483
           $$.reference = (char*)realloc($$.reference, strlen(temp) + 1) ;
15,420✔
484
           strcpy($$.reference , temp) ;
15,420✔
485

486
           free($3);
15,420✔
487

488
       } ;
489

490
dereference: ARROW { 
UNCOV
491
                 $$ = 1 ;
×
492
             }
493
           | '.' {
494
                 $$ = 0 ;
15,420✔
495
             };
496

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

505
              $$ = (VALUE_LIST *)malloc(sizeof(VALUE_LIST)) ;
1,600✔
506

507
              $$->num_val = 0 ;
1,600✔
508
              for ( i = 0 ; i < TRICK_MAX_INDEX ; i++ ) {
14,400✔
509
                  $$->v_data[i].type = TRICK_INTEGER ;
12,800✔
510
                  $$->v_data[i].value.i = 0 ;
12,800✔
511
              }
512

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

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

540
      | '&' param {
541

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

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

556
      | C_CON { 
557

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

562
      | I_CON { 
563

564
            $$.value.ll = $1 ;
22,718✔
565
            $$.type = TRICK_LONG_LONG ;
22,718✔
566
          }
567

568
      | UI_CON { 
569

570
            $$.value.ll = $1 ;
208✔
571
            $$.type = TRICK_LONG_LONG ;
208✔
572
          }
573

574
      | F_CON {  
575

576
            $$.value.d = $1 ;
1,486✔
577
            $$.type = TRICK_DOUBLE ;
1,486✔
578
          }
579

580
      | S_CON { 
581

582
            $$.value.cp = $1 ;
4,845✔
583
            $$.type = TRICK_STRING ;
4,845✔
584
          }
585
;
586

587
%%
588

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