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

daisytuner / sdfglib / 17404796220

02 Sep 2025 01:18PM UTC coverage: 59.036% (-0.04%) from 59.078%
17404796220

Pull #218

github

web-flow
Merge fd4010d6a into 3395851ae
Pull Request #218: adds new utility functions to builder API

8 of 11 new or added lines in 2 files covered. (72.73%)

8 existing lines in 1 file now uncovered.

9215 of 15609 relevant lines covered (59.04%)

116.23 hits per line

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

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

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

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

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

70
    auto res = this->function().containers_.insert({name, type.clone()});
885✔
71
    assert(res.second);
885✔
72

73
    if (is_argument) {
885✔
74
        this->function().arguments_.push_back(name);
247✔
75
    }
247✔
76
    if (is_external) {
885✔
77
        this->function().externals_.push_back(name);
13✔
78
        this->function().externals_linkage_types_[name] = LinkageType_External;
13✔
79
    }
13✔
80
    if (type.is_symbol() && dynamic_cast<const types::Scalar*>(&type)) {
885✔
81
        auto sym = symbolic::symbol(name);
639✔
82
        this->function().assumptions_.insert({sym, symbolic::Assumption::create(sym, type)});
639✔
83
    }
639✔
84

85
    return *(*res.first).second;
885✔
86
};
×
87

88
const types::IType& FunctionBuilder::
89
    add_external(const std::string& name, const types::IType& type, LinkageType linkage_type) const {
9✔
90
    check_name(name);
9✔
91

92
    auto res = this->function().containers_.insert({name, type.clone()});
9✔
93
    assert(res.second);
9✔
94

95
    this->function().externals_.push_back(name);
9✔
96
    this->function().externals_linkage_types_[name] = linkage_type;
9✔
97

98
    return *(*res.first).second;
9✔
99
};
×
100

101
void FunctionBuilder::remove_container(const std::string& name) const {
6✔
102
    auto& function = this->function();
6✔
103
    if (!function.is_transient(name)) {
6✔
104
        throw InvalidSDFGException("Container " + name + " is not transient");
2✔
105
    }
106
    if (this->function().containers_.find(name) == this->function().containers_.end()) {
4✔
107
        throw InvalidSDFGException("Container " + name + " does not exist");
×
108
    }
109

110
    auto& type = function.containers_[name];
4✔
111
    if (type->is_symbol() && dynamic_cast<const types::Scalar*>(type.get())) {
4✔
112
        function.assumptions_.erase(symbolic::symbol(name));
4✔
113
    }
4✔
114

115
    function.containers_.erase(name);
4✔
116
};
6✔
117

118
void FunctionBuilder::change_type(const std::string& name, const types::IType& type) const {
9✔
119
    auto& function = this->function();
9✔
120
    if (!function.is_transient(name)) {
9✔
121
        throw InvalidSDFGException("Container " + name + " is not transient");
×
122
    }
123
    if (function.containers_.find(name) == function.containers_.end()) {
9✔
124
        throw InvalidSDFGException("Container " + name + " does not exist");
×
125
    }
126

127
    function.containers_[name] = type.clone();
9✔
128
};
9✔
129

130
types::StructureDefinition& FunctionBuilder::add_structure(const std::string& name, bool is_packed) const {
18✔
131
    if (this->function().structures_.find(name) != this->function().structures_.end()) {
18✔
132
        throw InvalidSDFGException("Structure " + name + " already exists");
×
133
    }
134

135
    auto res = this->function().structures_.insert({name, std::make_unique<types::StructureDefinition>(name, is_packed)}
18✔
136
    );
137
    assert(res.second);
18✔
138

139
    return *(*res.first).second;
18✔
140
};
×
141

142
void FunctionBuilder::make_array(const std::string& name, const symbolic::Expression& size) const {
2✔
143
    auto& function = this->function();
2✔
144
    if (!function.is_transient(name)) {
2✔
145
        throw InvalidSDFGException("Container " + name + " is not transient");
1✔
146
    }
147
    if (function.containers_.find(name) == function.containers_.end()) {
1✔
148
        throw InvalidSDFGException("Container " + name + " does not exist");
×
149
    }
150

151
    auto& old_type = function.containers_[name];
1✔
152
    if (old_type->is_symbol() && dynamic_cast<const types::Scalar*>(old_type.get())) {
1✔
153
        function.assumptions_.erase(symbolic::symbol(name));
1✔
154
    }
1✔
155

156
    function.containers_[name] = std::make_unique<types::Array>(*old_type, size);
1✔
157
};
2✔
158

159
std::string FunctionBuilder::find_new_name(std::string prefix) const {
42✔
160
    size_t i = 0;
42✔
161
    std::string new_name = prefix + std::to_string(i);
42✔
162
    while (this->function().exists(new_name)) {
69✔
163
        i++;
27✔
164
        new_name = prefix + std::to_string(i);
27✔
165
    }
166
    return new_name;
42✔
167
};
42✔
168

NEW
169
void FunctionBuilder::update_tasklet(data_flow::Tasklet& tasklet, const data_flow::TaskletCode code) {
×
NEW
170
    tasklet.code_ = code;
×
NEW
171
}
×
172

173
} // namespace builder
174
} // 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

© 2025 Coveralls, Inc