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

tudasc / TypeART / 13904693014

17 Mar 2025 04:28PM UTC coverage: 88.901% (+0.03%) from 88.875%
13904693014

Pull #165

github

web-flow
Merge f658553a1 into c6563269e
Pull Request #165: LLVM 19 Support

19 of 20 new or added lines in 1 file covered. (95.0%)

5 existing lines in 2 files now uncovered.

4205 of 4730 relevant lines covered (88.9%)

241738.37 hits per line

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

93.33
/lib/typelib/TypeDB.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2025 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#include "TypeDB.h"
14

15
#include "TypeIO.h"
16
#include "support/Logger.h"
17
#include "typelib/TypeInterface.h"
18

19
#include <ccomplex>
20
#include <complex>
21
#include <cstddef>
22
#include <iostream>
23
#include <string_view>
24
#include <utility>
25

26
namespace typeart {
27

28
namespace builtins {
29

30
namespace {
31
inline constexpr auto size_complex_float       = sizeof(std::complex<float>);
32
inline constexpr auto size_complex_double      = sizeof(std::complex<double>);
33
inline constexpr auto size_complex_long_double = sizeof(std::complex<long double>);
34
}  // namespace
35

36
#define FOR_EACH_TYPEART_BUILTIN(X)                             \
37
  X(TYPEART_UNKNOWN_TYPE, "typeart_unknown_type", 0)            \
38
  X(TYPEART_POINTER, "ptr", sizeof(void*))                      \
39
  X(TYPEART_VTABLE_POINTER, "vtable_ptr", sizeof(void*))        \
40
  X(TYPEART_VOID, "void*", sizeof(void*))                       \
41
  X(TYPEART_NULLPOINTER, "nullptr_t", sizeof(void*))            \
42
  X(TYPEART_BOOL, "bool", sizeof(bool))                         \
43
  X(TYPEART_CHAR_8, "char", sizeof(char))                       \
44
  X(TYPEART_UCHAR_8, "unsigned char", sizeof(unsigned char))    \
45
  X(TYPEART_UTF_CHAR_8, "char8_t", sizeof(char))                \
46
  X(TYPEART_UTF_CHAR_16, "char16_t", sizeof(char16_t))          \
47
  X(TYPEART_UTF_CHAR_32, "char32_t", sizeof(char32_t))          \
48
  X(TYPEART_INT_8, "int8_t", sizeof(int8_t))                    \
49
  X(TYPEART_INT_16, "short", sizeof(int16_t))                   \
50
  X(TYPEART_INT_32, "int", sizeof(int32_t))                     \
51
  X(TYPEART_INT_64, "long int", sizeof(int64_t))                \
52
  X(TYPEART_INT_128, "int128_t", 16)                            \
53
  X(TYPEART_UINT_8, "uint8_t", sizeof(uint8_t))                 \
54
  X(TYPEART_UINT_16, "unsigned short", sizeof(uint16_t))        \
55
  X(TYPEART_UINT_32, "unsigned int", sizeof(uint32_t))          \
56
  X(TYPEART_UINT_64, "unsigned long int", sizeof(uint64_t))     \
57
  X(TYPEART_UINT_128, "uint128_t", 16)                          \
58
  X(TYPEART_FLOAT_8, "float8_t", 1)                             \
59
  X(TYPEART_FLOAT_16, "float16_t", 2)                           \
60
  X(TYPEART_FLOAT_32, "float", sizeof(float))                   \
61
  X(TYPEART_FLOAT_64, "double", sizeof(double))                 \
62
  X(TYPEART_FLOAT_128, "long double", sizeof(long double))      \
63
  X(TYPEART_COMPLEX_64, "float complex", size_complex_float)    \
64
  X(TYPEART_COMPLEX_128, "double complex", size_complex_double) \
65
  X(TYPEART_COMPLEX_256, "long double complex", size_complex_long_double)
66

67
#define TYPENAME(enum_name, str_name, size) std::string{str_name},
68
#define SIZE(enum_name, str_name, size)     (size),
69
BuiltInQuery::BuiltInQuery() : names{FOR_EACH_TYPEART_BUILTIN(TYPENAME)}, sizes{FOR_EACH_TYPEART_BUILTIN(SIZE)} {
3,899✔
70
}
3,899✔
71
#undef SIZE
72
#undef TYPENAME
73

74
}  // namespace builtins
1,955✔
75

76
std::pair<std::unique_ptr<TypeDatabase>, std::error_code> make_database(std::string_view file) {
24✔
77
  auto type_db = std::make_unique<TypeDB>();
24✔
78
  auto loaded  = io::load(type_db.get(), file.data());
24✔
79
  if (!loaded) {
24✔
80
    LOG_DEBUG("Database file not found: " << file)
81
  }
12✔
82
  return {std::move(type_db), loaded.getError()};
24✔
83
}
24✔
84

85
using namespace builtins;
86

87
const std::string unknown_struck_name{"typeart_unknown_struct"};
3,629✔
88

89
void TypeDB::clear() {
2,168✔
90
  struct_info_vec.clear();
2,168✔
91
  typeid_to_list_index.clear();
2,168✔
92
  // reverseTypeMap.clear();
93
}
2,168✔
94

95
bool TypeDB::isBuiltinType(int type_id) const {
1,093,292✔
96
  return BuiltInQuery::is_builtin_type(type_id);
1,093,292✔
97
}
98

99
bool TypeDB::isReservedType(int type_id) const {
459,968✔
100
  return BuiltInQuery::is_reserved_type(type_id);
459,968✔
101
}
102

103
bool TypeDB::isStructType(int type_id) const {
52,401✔
104
  return BuiltInQuery::is_userdef_type(type_id);
52,401✔
105
}
106

107
bool TypeDB::isUnknown(int type_id) const {
80✔
108
  return BuiltInQuery::is_unknown_type(type_id);
80✔
109
}
110

111
bool TypeDB::isPointerType(int type_id) const {
×
112
  return type_id == TYPEART_VOID || type_id == TYPEART_POINTER;
×
113
}
114

115
bool TypeDB::isUserDefinedType(int type_id) const {
527✔
116
  const auto* structInfo = getStructInfo(type_id);
527✔
117
  LOG_DEBUG(structInfo->name << " " << static_cast<int>(structInfo->flag) << " "
118
                             << (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::USER_DEFINED)))
119
  return (structInfo != nullptr) &&
1,054✔
120
         (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::USER_DEFINED));
527✔
121
}
122

123
bool TypeDB::isVectorType(int type_id) const {
42✔
124
  const auto* structInfo = getStructInfo(type_id);
42✔
125
  LOG_DEBUG(structInfo->name << " " << static_cast<int>(structInfo->flag) << " "
126
                             << (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::LLVM_VECTOR)))
127
  return (structInfo != nullptr) &&
84✔
128
         (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::LLVM_VECTOR));
42✔
129
}
130

131
bool TypeDB::isValid(int type_id) const {
232,459✔
132
  if (isBuiltinType(type_id)) {
232,459✔
133
    return true;
201,702✔
134
  }
135
  return typeid_to_list_index.find(type_id) != typeid_to_list_index.end();
30,757✔
136
}
232,459✔
137

138
void TypeDB::registerStruct(const StructTypeInfo& struct_type, bool overwrite) {
11,463✔
139
  if (isValid(struct_type.type_id) || !isStructType(struct_type.type_id)) {
11,463✔
140
    if (isBuiltinType(struct_type.type_id)) {
80✔
141
      LOG_ERROR("Built-in type ID used for struct " << struct_type.name);
12✔
142
    } else if (isReservedType(struct_type.type_id)) {
80✔
143
      LOG_ERROR("Type ID is reserved for builtin types. Struct: " << struct_type.name);
24✔
144
    } else if (isUnknown(struct_type.type_id)) {
68✔
UNCOV
145
      LOG_ERROR("Type ID is reserved for unknown types. Struct: " << struct_type.name);
×
UNCOV
146
    } else {
×
147
      if (!overwrite) {
44✔
UNCOV
148
        LOG_ERROR("Struct type ID already registered for " << struct_type.name << ". Conflicting struct is "
×
149
                                                           << getStructInfo(struct_type.type_id)->name);
UNCOV
150
        return;
×
151
      }
152
      LOG_DEBUG("Overwrite struct " << struct_type.name)
153
      auto& info = *getStructInfo(struct_type.type_id);
44✔
154
      info       = struct_type;
44✔
155
    }
156
    return;
80✔
157
  }
158

159
  struct_info_vec.push_back(struct_type);
11,383✔
160
  typeid_to_list_index.insert({struct_type.type_id, struct_info_vec.size() - 1});
11,383✔
161
}
11,463✔
162

163
const std::string& TypeDB::getTypeName(int type_id) const {
443,850✔
164
  if (isBuiltinType(type_id)) {
443,850✔
165
    return builtins.get_name(type_id);
403,156✔
166
  }
167
  if (isStructType(type_id)) {
40,694✔
168
    const auto* structInfo = getStructInfo(type_id);
40,622✔
169
    if (structInfo != nullptr) {
40,622✔
170
      return structInfo->name;
40,550✔
171
    }
172
  }
72✔
173

174
  return unknown_struck_name;
144✔
175
}
443,850✔
176

177
size_t TypeDB::getTypeSize(int type_id) const {
459,850✔
178
  if (isReservedType(type_id)) {
459,850✔
179
    if (isBuiltinType(type_id)) {
416,343✔
180
      return builtins.get_size(type_id);
416,307✔
181
    }
182
    return 0;
36✔
183
  }
184

185
  const auto* structInfo = getStructInfo(type_id);
43,507✔
186
  if (structInfo != nullptr) {
43,507✔
187
    return structInfo->extent;
43,459✔
188
  }
189
  return 0;
48✔
190
}
459,850✔
191

192
const StructTypeInfo* TypeDB::getStructInfo(int type_id) const {
85,298✔
193
  const auto index_iter = typeid_to_list_index.find(type_id);
85,298✔
194
  if (index_iter != typeid_to_list_index.end()) {
85,298✔
195
    return &struct_info_vec[index_iter->second];
85,154✔
196
  }
197
  return nullptr;
144✔
198
}
85,298✔
199

200
StructTypeInfo* TypeDB::getStructInfo(int type_id) {
5,472✔
201
  const auto index_iter = typeid_to_list_index.find(type_id);
5,472✔
202
  if (index_iter != typeid_to_list_index.end()) {
5,472✔
203
    return &struct_info_vec[index_iter->second];
5,460✔
204
  }
205
  return nullptr;
12✔
206
}
5,472✔
207

208
const std::vector<StructTypeInfo>& TypeDB::getStructList() const {
5,373✔
209
  return struct_info_vec;
5,373✔
210
}
211

212
}  // namespace typeart
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