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

daisytuner / sdfglib / 20764569418

06 Jan 2026 10:50PM UTC coverage: 62.168% (+21.4%) from 40.764%
20764569418

push

github

web-flow
Merge pull request #433 from daisytuner/clang-coverage

updates clang coverage flags

14988 of 24109 relevant lines covered (62.17%)

88.57 hits per line

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

48.62
/src/builder/function_builder.cpp
1
#include "sdfg/builder/function_builder.h"
2

3
namespace sdfg {
4
namespace builder {
5

6
void check_name(const std::string& name) {
2,123✔
7
    if (name.find(".") != std::string::npos) {
2,123✔
8
        throw InvalidSDFGException("Container name " + name + " contains a dot");
×
9
    } else if (name.find(" ") != std::string::npos) {
2,123✔
10
        throw InvalidSDFGException("Container name " + name + " contains a space");
×
11
    } else if (name.find("(") != std::string::npos) {
2,123✔
12
        throw InvalidSDFGException("Container name " + name + " contains a parenthesis");
×
13
    } else if (name.find(")") != std::string::npos) {
2,123✔
14
        throw InvalidSDFGException("Container name " + name + " contains a parenthesis");
×
15
    } else if (name.find("[") != std::string::npos) {
2,123✔
16
        throw InvalidSDFGException("Container name " + name + " contains a bracket");
×
17
    } else if (name.find("]") != std::string::npos) {
2,123✔
18
        throw InvalidSDFGException("Container name " + name + " contains a bracket");
×
19
    } else if (name.find("*") != std::string::npos) {
2,123✔
20
        throw InvalidSDFGException("Container name " + name + " contains a star");
×
21
    } else if (name.find("&") != std::string::npos) {
2,123✔
22
        throw InvalidSDFGException("Container name " + name + " contains a ampersand");
×
23
    } else if (name.find("!") != std::string::npos) {
2,123✔
24
        throw InvalidSDFGException("Container name " + name + " contains a bang");
×
25
    } else if (name.find("~") != std::string::npos) {
2,123✔
26
        throw InvalidSDFGException("Container name " + name + " contains a tilde");
×
27
    } else if (name.find("`") != std::string::npos) {
2,123✔
28
        throw InvalidSDFGException("Container name " + name + " contains a backtick");
×
29
    } else if (name.find("\"") != std::string::npos) {
2,123✔
30
        throw InvalidSDFGException("Container name " + name + " contains a quote");
×
31
    } else if (name.find("'") != std::string::npos) {
2,123✔
32
        throw InvalidSDFGException("Container name " + name + " contains a single quote");
×
33
    } else if (name.find(";") != std::string::npos) {
2,123✔
34
        throw InvalidSDFGException("Container name " + name + " contains a semicolon");
×
35
    } else if (name.find(":") != std::string::npos) {
2,123✔
36
        throw InvalidSDFGException("Container name " + name + " contains a colon");
×
37
    } else if (name.find(",") != std::string::npos) {
2,123✔
38
        throw InvalidSDFGException("Container name " + name + " contains a comma");
×
39
    } else if (name.find("=") != std::string::npos) {
2,123✔
40
        throw InvalidSDFGException("Container name " + name + " contains a equal sign");
×
41
    } else if (name.find("+") != std::string::npos) {
2,123✔
42
        throw InvalidSDFGException("Container name " + name + " contains a plus sign");
×
43
    } else if (name.find("-") != std::string::npos) {
2,123✔
44
        throw InvalidSDFGException("Container name " + name + " contains a minus sign");
×
45
    } else if (name.find("/") != std::string::npos) {
2,123✔
46
        throw InvalidSDFGException("Container name " + name + " contains a slash");
×
47
    } else if (name.find("%") != std::string::npos) {
2,123✔
48
        throw InvalidSDFGException("Container name " + name + " contains a percent sign");
×
49
    } else if (name.find("^") != std::string::npos) {
2,123✔
50
        throw InvalidSDFGException("Container name " + name + " contains a caret");
×
51
    } else if (name.find("|") != std::string::npos) {
2,123✔
52
        throw InvalidSDFGException("Container name " + name + " contains a pipe");
×
53
    }
×
54
};
2,123✔
55

56
size_t FunctionBuilder::new_element_id() const { return ++this->function().element_counter_; };
9,779✔
57

58
void FunctionBuilder::set_element_counter(size_t element_counter) {
14✔
59
    this->function().element_counter_ = element_counter;
14✔
60
};
14✔
61

62
void FunctionBuilder::set_return_type(const types::IType& type) const { this->function().return_type_ = type.clone(); };
×
63

64
const types::IType& FunctionBuilder::
65
    add_container(const std::string& name, const types::IType& type, bool is_argument, bool is_external) const {
2,114✔
66
    if (is_argument && is_external) {
2,114✔
67
        throw InvalidSDFGException("Container " + name + " cannot be both an argument and an external");
×
68
    }
×
69
    // Legal name
70
    check_name(name);
2,114✔
71

72
    auto res = this->function().containers_.insert({name, type.clone()});
2,114✔
73
    if (!res.second) {
2,114✔
74
        throw InvalidSDFGException("Container " + name + " already exists");
×
75
    }
×
76

77
    if (is_argument) {
2,114✔
78
        this->function().arguments_.push_back(name);
416✔
79
    }
416✔
80
    if (is_external) {
2,114✔
81
        this->function().externals_.push_back(name);
10✔
82
        this->function().externals_linkage_types_[name] = LinkageType_External;
10✔
83
    }
10✔
84
    if (type.is_symbol()) {
2,114✔
85
        auto sym = symbolic::symbol(name);
1,657✔
86
        this->function().assumptions_.insert({sym, symbolic::Assumption::create(sym, type)});
1,657✔
87
    }
1,657✔
88

89
    return *(*res.first).second;
2,114✔
90
};
2,114✔
91

92
const types::IType& FunctionBuilder::
93
    add_external(const std::string& name, const types::IType& type, LinkageType linkage_type) const {
9✔
94
    check_name(name);
9✔
95

96
    auto res = this->function().containers_.insert({name, type.clone()});
9✔
97
    if (!res.second) {
9✔
98
        throw InvalidSDFGException("Container " + name + " already exists");
×
99
    }
×
100

101
    this->function().externals_.push_back(name);
9✔
102
    this->function().externals_linkage_types_[name] = linkage_type;
9✔
103

104
    return *(*res.first).second;
9✔
105
};
9✔
106

107
void FunctionBuilder::remove_container(const std::string& name) const {
6✔
108
    auto& function = this->function();
6✔
109
    if (!function.is_transient(name)) {
6✔
110
        throw InvalidSDFGException("Container " + name + " is not transient");
2✔
111
    }
2✔
112
    if (this->function().containers_.find(name) == this->function().containers_.end()) {
4✔
113
        throw InvalidSDFGException("Container " + name + " does not exist");
×
114
    }
×
115

116
    auto& type = function.containers_[name];
4✔
117
    if (type->is_symbol() && dynamic_cast<const types::Scalar*>(type.get())) {
4✔
118
        function.assumptions_.erase(symbolic::symbol(name));
4✔
119
    }
4✔
120

121
    function.containers_.erase(name);
4✔
122
};
4✔
123

124
void FunctionBuilder::rename_container(const std::string& old_name, const std::string& new_name) const {
×
125
    auto& function = this->function();
×
126
    if (!function.exists(old_name)) {
×
127
        throw InvalidSDFGException("Container " + old_name + " does not exist");
×
128
    }
×
129

130
    // Move type
131
    function.containers_[new_name] = std::move(function.containers_[old_name]);
×
132
    function.containers_.erase(old_name);
×
133

134
    // Handling of argument
135
    if (function.is_argument(old_name)) {
×
136
        auto it = std::find(function.arguments_.begin(), function.arguments_.end(), old_name);
×
137
        assert(it != function.arguments_.end());
×
138
        *it = new_name;
×
139
    }
×
140
    // Handling of external
141
    if (function.is_external(old_name)) {
×
142
        auto it = std::find(function.externals_.begin(), function.externals_.end(), old_name);
×
143
        assert(it != function.externals_.end());
×
144
        *it = new_name;
×
145
        function.externals_linkage_types_[new_name] = function.externals_linkage_types_[old_name];
×
146
        function.externals_linkage_types_.erase(old_name);
×
147
    }
×
148
    // Handling of assumption
149
    if (function.assumptions().find(symbolic::symbol(old_name)) != function.assumptions().end()) {
×
150
        auto assumption = function.assumption(symbolic::symbol(old_name));
×
151

152
        symbolic::Assumption new_assumption(symbolic::symbol(new_name));
×
153
        new_assumption.lower_bound_deprecated(assumption.lower_bound_deprecated());
×
154
        new_assumption.upper_bound_deprecated(assumption.upper_bound_deprecated());
×
155
        new_assumption.tight_lower_bound(assumption.tight_lower_bound());
×
156
        new_assumption.tight_upper_bound(assumption.tight_upper_bound());
×
157
        for (auto& lb : assumption.lower_bounds()) {
×
158
            new_assumption.add_lower_bound(lb);
×
159
        }
×
160
        for (auto& ub : assumption.upper_bounds()) {
×
161
            new_assumption.add_upper_bound(ub);
×
162
        }
×
163

164
        new_assumption.constant(assumption.constant());
×
165
        new_assumption.map(assumption.map());
×
166

167
        function.assumptions_.erase(symbolic::symbol(old_name));
×
168
        function.assumptions_.insert({new_assumption.symbol(), new_assumption});
×
169
    }
×
170
};
×
171

172
void FunctionBuilder::change_type(const std::string& name, const types::IType& type) const {
14✔
173
    auto& function = this->function();
14✔
174
    if (function.containers_.find(name) == function.containers_.end()) {
14✔
175
        throw InvalidSDFGException("Container " + name + " does not exist");
×
176
    }
×
177

178
    function.containers_[name] = type.clone();
14✔
179
};
14✔
180

181
types::StructureDefinition& FunctionBuilder::add_structure(const std::string& name, bool is_packed) const {
20✔
182
    if (this->function().structures_.find(name) != this->function().structures_.end()) {
20✔
183
        throw InvalidSDFGException("Structure " + name + " already exists");
×
184
    }
×
185

186
    auto res = this->function().structures_.insert({name, std::make_unique<types::StructureDefinition>(name, is_packed)}
20✔
187
    );
20✔
188
    if (!res.second) {
20✔
189
        throw InvalidSDFGException("Structure " + name + " already exists");
×
190
    }
×
191

192
    return *(*res.first).second;
20✔
193
};
20✔
194

195
std::string FunctionBuilder::find_new_name(std::string prefix) const {
272✔
196
    size_t i = 0;
272✔
197
    std::string new_name = prefix + std::to_string(i);
272✔
198
    while (this->function().exists(new_name)) {
484✔
199
        i++;
212✔
200
        new_name = prefix + std::to_string(i);
212✔
201
    }
212✔
202
    return new_name;
272✔
203
};
272✔
204

205
void FunctionBuilder::update_tasklet(data_flow::Tasklet& tasklet, const data_flow::TaskletCode code) {
×
206
    tasklet.code_ = code;
×
207
}
×
208

209
std::unique_ptr<types::Structure> FunctionBuilder::
210
    create_vector_type(const types::Scalar& element_type, size_t vector_size) {
×
211
    std::string struct_name = "__daisy_vec_" + std::to_string(element_type.primitive_type()) + "_" +
×
212
                              std::to_string(vector_size);
×
213
    auto defined_structures = this->function().structures();
×
214
    if (std::find(defined_structures.begin(), defined_structures.end(), struct_name) != defined_structures.end()) {
×
215
        return std::make_unique<types::Structure>(struct_name);
×
216
    }
×
217

218
    auto& struct_def = this->add_structure(struct_name, true);
×
219
    for (size_t i = 0; i < vector_size; i++) {
×
220
        struct_def.add_member(element_type);
×
221
    }
×
222

223
    return std::make_unique<types::Structure>(struct_name);
×
224
}
×
225

226
} // namespace builder
227
} // namespace sdfg
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