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

nasa / trick / 20283694683

16 Dec 2025 09:44PM UTC coverage: 55.586% (-0.3%) from 55.934%
20283694683

push

github

web-flow
Add vs support for stl vector, deque, and array containers of supported data types (#1996)

* Added TV GUI side support for vectors

* Initial check-in for variable server to support vector.

* Added accessor functions to ATTRIBUTES to get stl container size and element at index so mm ref_dim can get element at index for a vector as getting element of an array plus bounds check for vector.

* Added support to deque and array as they be treated similar to vector.

* Updated the test due to vs vector support change.

* Added vector/deque/array of TRICK_STRUCTURED data type support.

* Updated to support vector<bool>.

* Updated to support vector/deque/array of *.

* Updated to support vector/deque/array of TRICK_ENUMERATED and display enum name for the stl enum elements for TV; also updated to show bool element as normal bool var for TV.

* Made elements of vector/array/deque to be editable from TV.

* Not to change the stl type to element when not indexing.

* Added special handling for updating vector of bool since std::vector<bool> is optimized to store bits compactly (8 bools per byte) in c++.

* Need to print NULL for the newly added ATTRIBUTES assessor function for filed attributes in io src file.

* Added var_get_stl_size command to vs sesssion and updated tv to show index range as constraint arrays for vector/deque/array when adding a var.

* Added test cases for vector/deque/array and also changed to use its own vs msg type for var_get_stl_size.

* Removed the unused function as it was changed to use clang api instead.

* Updated not to use static temp attr for working on storing vector<boo> to its ref_attr.

---------

Co-authored-by: plherrin <pherring04@gmail.com>

46 of 212 new or added lines in 8 files covered. (21.7%)

2 existing lines in 2 files now uncovered.

12508 of 22502 relevant lines covered (55.59%)

304713.82 hits per line

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

32.94
/trick_source/sim_services/MemoryManager/MemoryManager_ref_name.cpp
1
/*
2
   PURPOSE: (Construct a parse tree representation of a parameter reference name from the input file.)
3

4
   PROGRAMMERS: (((Robert W. Bailey) (LinCom) (7/95) (CR#600) (--)) ((Robert W. Bailey) (LinCom Corp) (Feb 1991) (v1.0)
5
   (Initial Release.))) */
6

7
#include <string.h>
8
#include <sstream>
9
#include <string>
10

11
#include "trick/MemoryManager.hh"
12
#include "trick/attributes.h"
13
#include "trick/reference.h"
14
#include "trick/parameter_types.h"
15
#include "trick/mm_error.h"
16
#include <stdlib.h>
17

18
//FIXME TODO make a error file
19
/////// MM_NO_ERROR 0
20
#define MM_PARAMETER_NAME 1
21
#define MM_INPUT_NOT_ALLOWED 2
22

23
// Helper function to trim whitespace from both ends of a string
NEW
24
static std::string trim(const std::string& str) {
×
NEW
25
    size_t start = str.find_first_not_of(" \t\n\r");
×
NEW
26
    if (start == std::string::npos) return "";
×
27
    
NEW
28
    size_t end = str.find_last_not_of(" \t\n\r");
×
NEW
29
    return str.substr(start, end - start + 1);
×
30
}
31

32
int Trick::MemoryManager::ref_name(REF2 * R, char *name) {
17,929✔
33

34
    int ii;
35
    char *addr;
36
    ATTRIBUTES *attr;
37

38
    attr = (ATTRIBUTES*)(R->attr->attr);
17,929✔
39

40
    if (attr == NULL) {
17,929✔
41
        // Special handling for STL containers with structured elements
42
        // ICG doesn't populate attr field for these, so we look it up at runtime
NEW
43
        if (R->attr->type == TRICK_STL && R->attr->stl_elem_type == TRICK_STRUCTURED && R->attr->stl_elem_type_name != NULL) {
×
44
            // Get element type name directly from stl_elem_type_name field
NEW
45
            std::string elem_type_name = R->attr->stl_elem_type_name;
×
46

47
            // Check if the element type is a pointer (contains '*')
NEW
48
            bool is_pointer = (elem_type_name.find('*') != std::string::npos);
×
49

50
            // If it's a pointer, strip the pointer symbols and whitespace to get the base type
NEW
51
            if (is_pointer) {
×
NEW
52
                size_t star_pos = elem_type_name.find('*');
×
NEW
53
                elem_type_name = trim(elem_type_name.substr(0, star_pos));
×
54
            }
55

56
            // Look up the element type's attributes without modifying the static structure
57
            ATTRIBUTES temp_attr;
NEW
58
            memset(&temp_attr, 0, sizeof(ATTRIBUTES));
×
59

NEW
60
            if (add_attr_info(elem_type_name, &temp_attr) == 0 && temp_attr.attr != NULL) {
×
NEW
61
                attr = (ATTRIBUTES*)temp_attr.attr;
×
62

63
                // If element is a pointer type, we need to dereference it first
NEW
64
                if (is_pointer) {
×
NEW
65
                    if (R->address == NULL) {
×
NEW
66
                        std::stringstream message;
×
67
                        message << "ref_name: Address is NULL for pointer element in STL container \""
NEW
68
                                << R->reference << "\".";
×
NEW
69
                        emitError(message.str());
×
NEW
70
                        return (MM_PARAMETER_NAME);
×
71
                    }
72
                    // Dereference the pointer to get to the actual object
NEW
73
                    R->address = *(void**)R->address;
×
NEW
74
                    if (R->address == NULL) {
×
NEW
75
                        std::stringstream message;
×
76
                        message << "ref_name: Pointer element is NULL in STL container \""
NEW
77
                                << R->reference << "\".";
×
NEW
78
                        emitError(message.str());
×
NEW
79
                        return (MM_PARAMETER_NAME);
×
80
                    }
81
                }
82
            } else {
NEW
83
                return (MM_PARAMETER_NAME);
×
NEW
84
            }
×
85
        } else {
NEW
86
            return (MM_PARAMETER_NAME);
×
87
        }
88
    }
89

90
    if (R->address == NULL) {
17,929✔
91
        std::stringstream message;
×
92
        message << "ref_name: Because the address of \"" << R->reference
×
93
                << "\" is NULL, a legitimate address can't be calculated for \""
94
                << R->reference << "." << name << "\".";
×
95
        emitError(message.str());
×
96
        return (MM_PARAMETER_NAME);
×
97
    }
98

99
    /* Find the parameter name at this level in the parameter list, 'ii' is the index to the parameter in the list. */
100
    ii = 0;
17,929✔
101
    while (strcmp(name, attr[ii].name)) {
163,741✔
102
        if (attr[ii].name[0] == '\0')
145,813✔
103
            return (MM_PARAMETER_NAME);
1✔
104
        ii++;
145,812✔
105
    }
106

107
    attr = &(attr[ii]);
17,928✔
108

109
//    R->deprecated |= (attr->mods & 0x80000000);
110

111
/* Set error_attr just in case we have an error */
112
//    R->error_attr = attr;
113

114
    /* If the variable is a static var, offset is the absolute address */
115
    if (attr->mods & 2) {
17,928✔
116
        addr = (char *) attr->offset;
10✔
117
        if ( R->create_add_path ) {
10✔
118
            DLLPOS list_pos ;
119
            ADDRESS_NODE * address_node ;
120
            list_pos = DLL_GetHeadPosition(R->address_path) ;
×
121
            while ( (list_pos != NULL) && (address_node = (ADDRESS_NODE *)DLL_GetNext(&list_pos, R->address_path)) != NULL ) {
×
122
                if ( (list_pos != NULL) && (list_pos->info != NULL) ) {
×
123
                    delete (ADDRESS_NODE *)(list_pos->info) ;
×
124
                }
125
            }
126
            DLL_RemoveAll(R->address_path) ;
×
127
            address_node = new ADDRESS_NODE ;
×
128
            address_node->operator_ = AO_ADDRESS ;
×
129
            address_node->operand.address = addr ;
×
130
            DLL_AddTail(address_node , R->address_path) ;
×
131
        }
132
    } else {
133
        addr = (char *)R->address + attr->offset;
17,918✔
134
        if ( R->create_add_path ) {
17,918✔
135
            ADDRESS_NODE * address_node ;
136

137
            if ( attr->offset != 0 ) {
2,508✔
138
                address_node = (ADDRESS_NODE *)DLL_GetAt(DLL_GetTailPosition(R->address_path), R->address_path) ;
1,664✔
139
                switch ( address_node->operator_ ) {
1,664✔
140
                    case AO_ADDRESS:
1,664✔
141
                        address_node->operand.address = (void *)((char *)address_node->operand.address +  attr->offset) ;
1,664✔
142
                        break ;
1,664✔
143
                    case AO_DEREFERENCE:
×
144
                        address_node = new ADDRESS_NODE ;
×
145
                        address_node->operator_ = AO_OFFSET ;
×
146
                        address_node->operand.offset = attr->offset ;
×
147
                        DLL_AddTail(address_node , R->address_path) ;
×
148
                        break ;
×
149
                    case AO_OFFSET:
×
150
                        address_node->operand.offset += attr->offset ;
×
151
                        break ;
×
152
                }
153
            }
154
        }
155
    }
156

157
    if (attr->mods & 1) {
17,928✔
158
            ADDRESS_NODE * address_node = new ADDRESS_NODE ;
×
159
            address_node->operator_ = AO_DEREFERENCE ;
×
160
            address_node->operand.address = NULL ;
×
161
            DLL_AddTail(address_node , R->address_path) ;
×
162

163
            addr = *(char**)addr;
×
164
    }
165

166
    /* Save the address and next attributes in the REF structure.
167
       If the attributes are dynamically-allocated, reference attributes
168
       then free them so we don't leak memory.
169
    */
170
    if (R->attr == R->ref_attr) {
17,928✔
171
        free(R->ref_attr);
14,783✔
172
        R->ref_attr = NULL;
14,783✔
173
    }
174
    R->attr = attr;
17,928✔
175
    R->address = addr;
17,928✔
176

177

178
    return (MM_OK);
17,928✔
179
}
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

© 2025 Coveralls, Inc