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

nasa / trick / 15004044467

13 May 2025 06:29PM UTC coverage: 55.958% (+0.03%) from 55.933%
15004044467

Pull #1877

github

web-flow
Merge d70b5de90 into ff58ed109
Pull Request #1877: Resolved comments being parsed inside strings

12332 of 22038 relevant lines covered (55.96%)

264644.69 hits per line

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

78.79
/trick_source/sim_services/MemoryManager/MemoryManager_add_attr_info.cpp
1
#include <iostream>
2
#include <sstream>
3
#include <algorithm>
4
#include <dlfcn.h>
5

6
#ifdef __GNUC__
7
#include <cxxabi.h>
8
#endif
9

10
#include "trick/SimObject.hh"
11
#include "trick/MemoryManager.hh"
12

13
/**
14
 *
15
 */
16
int Trick::MemoryManager::add_attr_info( const std::string & user_type_string , ATTRIBUTES * attr , const char * file_name , unsigned int line_num ) {
32,528✔
17

18
    std::string user_type_name ;
65,056✔
19
    std::string sub_attr_name ;
65,056✔
20
    std::string enum_attr_name ;
65,056✔
21
    std::string sub_attr_init_name ;
65,056✔
22
    std::string size_func_name ;
65,056✔
23
    size_t spos ;
24
    ATTRIBUTES* sub_attr = NULL ;
32,528✔
25
    ENUM_ATTR* enum_attr = NULL ;
32,528✔
26
    void (*init_sub_attr)(void) = NULL ;
32,528✔
27
    size_t (*size_func)(void) = NULL ;
32,528✔
28
    unsigned int ii ;
29
    std::set<std::string>::iterator it ;
32,528✔
30

31
    /** @par Design Details: */
32

33
    user_type_name = user_type_string ;
32,528✔
34

35
    // Check if the type is a primitive type.  If so, we don't need to continue
36
    it = primitive_types.find(user_type_string) ;
32,528✔
37
    if ( it != primitive_types.end() ) {
32,528✔
38
        return 0 ;
×
39
    }
40

41
    // The user type name may start as const Foo<int>::Bar[4].  We need to convert that to Foo_int___Bar
42
    // remove const from the typename if it exists
43
    spos = user_type_name.find("const ") ;
32,528✔
44
    if ( spos != std::string::npos ) {
32,528✔
45
        user_type_name.erase( spos , spos + 6) ;
×
46
    }
47
    // remove any brackets
48
/*
49
    spos = user_type_name.find("[") ;
50
    if ( spos != std::string::npos ) {
51
        user_type_name.erase( spos ) ;
52
    }
53
*/
54
    // replace ":<>,*[]" with '_'
55
    std::replace( user_type_name.begin(), user_type_name.end(), ':', '_') ;
32,528✔
56
    std::replace( user_type_name.begin(), user_type_name.end(), '<', '_') ;
32,528✔
57
    std::replace( user_type_name.begin(), user_type_name.end(), '>', '_') ;
32,528✔
58
    std::replace( user_type_name.begin(), user_type_name.end(), ',', '_') ;
32,528✔
59
    std::replace( user_type_name.begin(), user_type_name.end(), '*', '_') ;
32,528✔
60
    std::replace( user_type_name.begin(), user_type_name.end(), '[', '_') ;
32,528✔
61
    std::replace( user_type_name.begin(), user_type_name.end(), ']', '_') ;
32,528✔
62
    // remove spaces
63
    user_type_name.erase(std::remove_if(user_type_name.begin(), user_type_name.end(), (int(*)(int))std::isspace), user_type_name.end()) ;
32,528✔
64

65
    // Attempt to find an io_src_sizeof function for the named user type.
66
    size_func_name = "io_src_sizeof_" + user_type_name ;
32,528✔
67
    for ( ii = 0 ; ii < dlhandles.size() && size_func == NULL ; ii++ ) {
65,056✔
68
        size_func     = (size_t (*)(void))dlsym( dlhandles[ii] , size_func_name.c_str()) ;
32,528✔
69
        if ( size_func != NULL ) {
32,528✔
70
            attr->size = (*size_func)() ;
32,528✔
71
        }
72
    }
73

74
    if ( size_func == NULL)  {
32,528✔
75
        std::stringstream message;
×
76
        message << "(" << file_name << ":" << line_num
×
77
            << "): Couldn't find an io_src_sizeof_ function for type "
78
            << user_type_string.c_str() << "[" << size_func_name.c_str() << "()].";
×
79
        emitWarning(message.str());
×
80
    }
81

82
    // Attempt to find an attributes list for the named user type.
83
    sub_attr_name = "attr" + user_type_name ;
32,528✔
84
    for ( ii = 0 ; ii < dlhandles.size() && sub_attr == NULL ; ii++ ) {
65,056✔
85
        sub_attr      = (ATTRIBUTES *)dlsym( dlhandles[ii] , sub_attr_name.c_str()) ;
32,528✔
86
    }
87

88
    if (sub_attr != NULL) {  // If attributes for the named type were found ...
32,528✔
89

90
        // Set type and attr of the ATTRIBUTES structure that we're populating.
91
        attr->type = TRICK_STRUCTURED ;
28,072✔
92
        attr->attr = sub_attr;
28,072✔
93

94
        // Attempt to find the initialization function for the attributes that we just found.
95
        sub_attr_init_name = "init_attr" + user_type_name + "_c_intf" ;
28,072✔
96

97
        for ( ii = 0 ; ii < dlhandles.size() && init_sub_attr == NULL ; ii++ ) {
56,144✔
98
            init_sub_attr = (void (*)(void))dlsym( dlhandles[ii] , sub_attr_init_name.c_str()) ;
28,072✔
99
        }
100

101
        if ( init_sub_attr != NULL ) {     // If the initialization function was found,
28,072✔
102
            (*init_sub_attr)() ;           // then call it.
28,072✔
103
        } else {
104
            std::stringstream message;
×
105
            message << " ATTRIBUTES init routine for type \""
106
                    << user_type_name.c_str() << "\" not found.";
×
107
            emitWarning(message.str());
×
108
            return(1) ;
×
109
        }
110

111
    } else { // The named user type isn't a structure type. Maybe it's an enumeration type.
112

113
        // Check to see whether the user type name is in the enumeration_map.
114
        ENUMERATION_MAP::iterator curr_pos = enumeration_map.find( user_type_name);
4,456✔
115

116
        // If it's not in the enumeration map then
117
        if (curr_pos == enumeration_map.end()) {
4,456✔
118

119
            // Construct the name of the enumeration attributes.
120
            enum_attr_name = "enum" + user_type_name ;
2,179✔
121

122
            // Attempt to find enumeration attributes for the named user type.
123
            for ( ii = 0 ; ii < dlhandles.size() && enum_attr == NULL ; ii++ ) {
4,358✔
124
                enum_attr = (ENUM_ATTR *)dlsym( dlhandles[ii] , enum_attr_name.c_str()) ;
2,179✔
125
            }
126

127
            // If enumeration attributes for the named type were found then
128
            if ( enum_attr != NULL ) {
2,179✔
129

130
                // Put them in the enumeration map.
131
                enumeration_map[ user_type_name] = enum_attr;
2,179✔
132

133
            // otherwise ...
134
            } else {
135
                std::stringstream message;
×
136
                message << "ATTRIBUTES for type \"" << user_type_name.c_str() << "\" not found.";
×
137
                emitWarning(message.str());
×
138
                return(1) ;
×
139
            }
140
        } else {
141
            enum_attr = curr_pos->second;
2,277✔
142
        }
143

144
        // Set the type information in the ATTRIBUTES structure that we are populating.
145
        attr->type = TRICK_ENUMERATED ;
4,456✔
146
        attr->attr = enum_attr;
4,456✔
147
    }
148
    return(0) ;
32,528✔
149
}
150

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