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

vla5924-practice / compiler-project / 13747492526

09 Mar 2025 10:28AM UTC coverage: 83.592% (-0.03%) from 83.626%
13747492526

push

github

web-flow
Add `numElements` property to PointerType (#199)

3 of 6 new or added lines in 2 files covered. (50.0%)

3286 of 3931 relevant lines covered (83.59%)

285.25 hits per line

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

74.55
/compiler/lib/optree/types.cpp
1
#include "types.hpp"
2

3
#include <algorithm>
4
#include <ostream>
5
#include <sstream>
6
#include <string>
7
#include <unordered_map>
8

9
#include "compiler/utils/helpers.hpp"
10

11
#define TYPE_COMPARE_EARLY_RETURN(CLASS_NAME, OTHER_NAME)                                                              \
12
    if (this == &(OTHER_NAME))                                                                                         \
13
        return true;                                                                                                   \
14
    if (!(OTHER_NAME).is<CLASS_NAME>())                                                                                \
15
        return false;
16

17
using namespace optree;
18

19
bool sameTypes(const Type::Ptr &lhs, const Type::Ptr &rhs) {
23✔
20
    return *lhs == *rhs;
23✔
21
}
22

23
void dumpTypes(std::ostream &stream, const Type::PtrVector &types) {
122✔
24
    utils::interleaveComma(stream, types, [&](const Type::Ptr &type) { type->dump(stream); });
231✔
25
}
122✔
26

27
unsigned Type::bitWidth() const {
1✔
28
    return 0U;
1✔
29
}
30

31
void Type::dump(std::ostream &stream) const {
×
32
    stream << "<<NULL TYPE>>";
×
33
}
×
34

35
std::string Type::dump() const {
×
36
    std::stringstream str;
×
37
    dump(str);
×
38
    return str.str();
×
39
}
×
40

41
bool NoneType::operator==(const Type &other) const {
14✔
42
    return this == &other || other.is<NoneType>();
14✔
43
}
44

45
void NoneType::dump(std::ostream &stream) const {
168✔
46
    stream << "none";
168✔
47
}
168✔
48

49
bool IntegerType::operator==(const Type &other) const {
153✔
50
    TYPE_COMPARE_EARLY_RETURN(IntegerType, other)
153✔
51
    return width == other.as<IntegerType>().width;
1✔
52
}
53

54
unsigned IntegerType::bitWidth() const {
11✔
55
    return width;
11✔
56
}
57

58
void IntegerType::dump(std::ostream &stream) const {
612✔
59
    stream << "int(" << width << ")";
612✔
60
}
612✔
61

62
bool FloatType::operator==(const Type &other) const {
64✔
63
    TYPE_COMPARE_EARLY_RETURN(FloatType, other)
64✔
64
    return width == other.as<FloatType>().width;
1✔
65
}
66

67
unsigned FloatType::bitWidth() const {
10✔
68
    return width;
10✔
69
}
70

71
void FloatType::dump(std::ostream &stream) const {
337✔
72
    stream << "float(" << width << ")";
337✔
73
}
337✔
74

75
bool StrType::operator==(const Type &other) const {
2✔
76
    TYPE_COMPARE_EARLY_RETURN(StrType, other)
2✔
77
    return charWidth == other.as<StrType>().charWidth;
×
78
}
79

80
void StrType::dump(std::ostream &stream) const {
16✔
81
    stream << "str(" << charWidth << ")";
16✔
82
}
16✔
83

84
bool FunctionType::operator==(const Type &other) const {
13✔
85
    TYPE_COMPARE_EARLY_RETURN(FunctionType, other)
13✔
86
    const auto &otherFunc = other.as<FunctionType>();
13✔
87
    if (arguments.size() != otherFunc.arguments.size() || *result != *otherFunc.result)
13✔
88
        return false;
1✔
89
    return std::equal(arguments.begin(), arguments.end(), otherFunc.arguments.begin(), sameTypes);
12✔
90
}
91

92
void FunctionType::dump(std::ostream &stream) const {
122✔
93
    stream << "func((";
122✔
94
    dumpTypes(stream, arguments);
122✔
95
    stream << ") -> ";
122✔
96
    result->dump(stream);
122✔
97
    stream << ')';
122✔
98
}
122✔
99

100
bool PointerType::operator==(const Type &other) const {
×
101
    TYPE_COMPARE_EARLY_RETURN(PointerType, other)
×
NEW
102
    const auto &otherPointer = other.as<PointerType>();
×
NEW
103
    return numElements == otherPointer.numElements && *pointee == *otherPointer.pointee;
×
104
}
105

106
void PointerType::dump(std::ostream &stream) const {
66✔
107
    stream << "ptr(";
66✔
108
    pointee->dump(stream);
66✔
109
    if (numElements != 1U)
66✔
NEW
110
        stream << ", " << numElements;
×
111
    stream << ')';
66✔
112
}
66✔
113

114
bool TupleType::operator==(const Type &other) const {
×
115
    TYPE_COMPARE_EARLY_RETURN(TupleType, other)
×
116
    const auto &otherTuple = other.as<TupleType>();
×
117
    if (members.size() != otherTuple.members.size())
×
118
        return false;
×
119
    return std::equal(members.begin(), members.end(), otherTuple.members.begin(), sameTypes);
×
120
}
121

122
void TupleType::dump(std::ostream &stream) const {
×
123
    stream << "tuple(";
×
124
    dumpTypes(stream, members);
×
125
    stream << ")";
×
126
}
×
127

128
NoneType::Ptr TypeStorage::noneType() {
153✔
129
    static NoneType::Ptr ptr = Type::make<NoneType>();
153✔
130
    return ptr;
153✔
131
}
132

133
IntegerType::Ptr TypeStorage::integerType(unsigned width) {
156✔
134
    static std::unordered_map<unsigned, IntegerType::Ptr> storage;
156✔
135
    IntegerType::Ptr ptr;
156✔
136
    if (!storage.contains(width)) {
156✔
137
        ptr = Type::make<IntegerType>(width);
4✔
138
        storage[width] = ptr;
4✔
139
    } else {
140
        ptr = storage[width];
152✔
141
    }
142
    return ptr;
156✔
143
}
×
144

145
BoolType::Ptr TypeStorage::boolType() {
160✔
146
    static BoolType::Ptr ptr = Type::make<BoolType>();
160✔
147
    return ptr;
160✔
148
}
149

150
FloatType::Ptr TypeStorage::floatType(unsigned width) {
147✔
151
    static std::unordered_map<unsigned, FloatType::Ptr> storage;
147✔
152
    FloatType::Ptr ptr;
147✔
153
    if (!storage.contains(width)) {
147✔
154
        ptr = Type::make<FloatType>(width);
4✔
155
        storage[width] = ptr;
4✔
156
    } else {
157
        ptr = storage[width];
143✔
158
    }
159
    return ptr;
147✔
160
}
×
161

162
StrType::Ptr TypeStorage::strType(unsigned width) {
111✔
163
    static std::unordered_map<unsigned, StrType::Ptr> storage;
111✔
164
    StrType::Ptr ptr;
111✔
165
    if (!storage.contains(width)) {
111✔
166
        ptr = Type::make<StrType>(width);
3✔
167
        storage[width] = ptr;
3✔
168
    } else {
169
        ptr = storage[width];
108✔
170
    }
171
    return ptr;
111✔
172
}
×
173

174
#undef TYPE_COMPARE_EARLY_RETURN
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