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

daisytuner / sdfglib / 15286028134

27 May 2025 09:23PM UTC coverage: 58.341% (-0.03%) from 58.37%
15286028134

push

github

web-flow
Merge pull request #40 from daisytuner/container-names

check container names

23 of 46 new or added lines in 1 file covered. (50.0%)

7935 of 13601 relevant lines covered (58.34%)

97.23 hits per line

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

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

3
namespace sdfg {
4
namespace builder {
5

6
FunctionBuilder::FunctionBuilder() : element_counter_(1) {};
803✔
7

8
const types::IType& FunctionBuilder::add_container(const std::string& name,
805✔
9
                                                   const types::IType& type, bool is_argument,
10
                                                   bool is_external) const {
11
    if (is_argument && is_external) {
805✔
12
        throw InvalidSDFGException("Container " + name +
×
13
                                   " cannot be both an argument and an external");
14
    }
15
    // Legal name
16
    if (name.find(".") != std::string::npos) {
805✔
NEW
17
        throw InvalidSDFGException("Container name " + name + " contains a dot");
×
18
    } else if (name.find(" ") != std::string::npos) {
805✔
NEW
19
        throw InvalidSDFGException("Container name " + name + " contains a space");
×
20
    } else if (name.find("(") != std::string::npos) {
805✔
NEW
21
        throw InvalidSDFGException("Container name " + name + " contains a parenthesis");
×
22
    } else if (name.find(")") != std::string::npos) {
805✔
NEW
23
        throw InvalidSDFGException("Container name " + name + " contains a parenthesis");
×
24
    } else if (name.find("[") != std::string::npos) {
805✔
NEW
25
        throw InvalidSDFGException("Container name " + name + " contains a bracket");
×
26
    } else if (name.find("]") != std::string::npos) {
805✔
NEW
27
        throw InvalidSDFGException("Container name " + name + " contains a bracket");
×
28
    } else if (name.find("*") != std::string::npos) {
805✔
NEW
29
        throw InvalidSDFGException("Container name " + name + " contains a star");
×
30
    } else if (name.find("&") != std::string::npos) {
805✔
NEW
31
        throw InvalidSDFGException("Container name " + name + " contains a ampersand");
×
32
    } else if (name.find("!") != std::string::npos) {
805✔
NEW
33
        throw InvalidSDFGException("Container name " + name + " contains a bang");
×
34
    } else if (name.find("~") != std::string::npos) {
805✔
NEW
35
        throw InvalidSDFGException("Container name " + name + " contains a tilde");
×
36
    } else if (name.find("`") != std::string::npos) {
805✔
NEW
37
        throw InvalidSDFGException("Container name " + name + " contains a backtick");
×
38
    } else if (name.find("\"") != std::string::npos) {
805✔
NEW
39
        throw InvalidSDFGException("Container name " + name + " contains a quote");
×
40
    } else if (name.find("'") != std::string::npos) {
805✔
NEW
41
        throw InvalidSDFGException("Container name " + name + " contains a single quote");
×
42
    } else if (name.find(";") != std::string::npos) {
805✔
NEW
43
        throw InvalidSDFGException("Container name " + name + " contains a semicolon");
×
44
    } else if (name.find(":") != std::string::npos) {
805✔
NEW
45
        throw InvalidSDFGException("Container name " + name + " contains a colon");
×
46
    } else if (name.find(",") != std::string::npos) {
805✔
NEW
47
        throw InvalidSDFGException("Container name " + name + " contains a comma");
×
48
    } else if (name.find("=") != std::string::npos) {
805✔
NEW
49
        throw InvalidSDFGException("Container name " + name + " contains a equal sign");
×
50
    } else if (name.find("+") != std::string::npos) {
805✔
NEW
51
        throw InvalidSDFGException("Container name " + name + " contains a plus sign");
×
52
    } else if (name.find("-") != std::string::npos) {
805✔
NEW
53
        throw InvalidSDFGException("Container name " + name + " contains a minus sign");
×
54
    } else if (name.find("/") != std::string::npos) {
805✔
NEW
55
        throw InvalidSDFGException("Container name " + name + " contains a slash");
×
56
    } else if (name.find("%") != std::string::npos) {
805✔
NEW
57
        throw InvalidSDFGException("Container name " + name + " contains a percent sign");
×
58
    } else if (name.find("^") != std::string::npos) {
805✔
NEW
59
        throw InvalidSDFGException("Container name " + name + " contains a caret");
×
60
    } else if (name.find("|") != std::string::npos) {
805✔
NEW
61
        throw InvalidSDFGException("Container name " + name + " contains a pipe");
×
62
    }
63

64
    auto res = this->function().containers_.insert({name, type.clone()});
805✔
65
    assert(res.second);
805✔
66

67
    if (is_argument) {
805✔
68
        this->function().arguments_.push_back(name);
205✔
69
    }
205✔
70
    if (is_external) {
805✔
71
        this->function().externals_.push_back(name);
11✔
72
    }
11✔
73
    if (type.is_symbol() && dynamic_cast<const types::Scalar*>(&type)) {
805✔
74
        auto sym = symbolic::symbol(name);
625✔
75
        this->function().assumptions_.insert({sym, symbolic::Assumption::create(sym, type)});
625✔
76
    }
625✔
77

78
    return *(*res.first).second;
805✔
79
};
×
80

81
void FunctionBuilder::remove_container(const std::string& name) const {
6✔
82
    auto& function = this->function();
6✔
83
    if (!function.is_transient(name)) {
6✔
84
        throw InvalidSDFGException("Container " + name + " is not transient");
2✔
85
    }
86
    if (this->function().containers_.find(name) == this->function().containers_.end()) {
4✔
87
        throw InvalidSDFGException("Container " + name + " does not exist");
×
88
    }
89

90
    auto& type = function.containers_[name];
4✔
91
    if (type->is_symbol() && dynamic_cast<const types::Scalar*>(type.get())) {
4✔
92
        function.assumptions_.erase(symbolic::symbol(name));
4✔
93
    }
4✔
94

95
    function.containers_.erase(name);
4✔
96
};
6✔
97

98
void FunctionBuilder::change_type(const std::string& name, const types::IType& type) const {
9✔
99
    auto& function = this->function();
9✔
100
    if (!function.is_transient(name)) {
9✔
101
        throw InvalidSDFGException("Container " + name + " is not transient");
×
102
    }
103
    if (function.containers_.find(name) == function.containers_.end()) {
9✔
104
        throw InvalidSDFGException("Container " + name + " does not exist");
×
105
    }
106

107
    function.containers_[name] = type.clone();
9✔
108
};
9✔
109

110
types::StructureDefinition& FunctionBuilder::add_structure(const std::string& name,
20✔
111
                                                           bool is_packed) const {
112
    if (this->function().structures_.find(name) != this->function().structures_.end()) {
20✔
113
        throw InvalidSDFGException("Structure " + name + " already exists");
×
114
    }
115

116
    auto res = this->function().structures_.insert(
20✔
117
        {name, std::make_unique<types::StructureDefinition>(name, is_packed)});
20✔
118
    assert(res.second);
20✔
119

120
    return *(*res.first).second;
20✔
121
};
×
122

123
void FunctionBuilder::make_array(const std::string& name, const symbolic::Expression& size) const {
2✔
124
    auto& function = this->function();
2✔
125
    if (!function.is_transient(name)) {
2✔
126
        throw InvalidSDFGException("Container " + name + " is not transient");
1✔
127
    }
128
    if (function.containers_.find(name) == function.containers_.end()) {
1✔
129
        throw InvalidSDFGException("Container " + name + " does not exist");
×
130
    }
131

132
    auto& old_type = function.containers_[name];
1✔
133
    if (old_type->is_symbol() && dynamic_cast<const types::Scalar*>(old_type.get())) {
1✔
134
        function.assumptions_.erase(symbolic::symbol(name));
1✔
135
    }
1✔
136

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

140
std::string FunctionBuilder::find_new_name(std::string prefix) const {
4✔
141
    size_t i = 0;
4✔
142
    std::string new_name = prefix + std::to_string(i);
4✔
143
    while (this->function().exists(new_name)) {
4✔
144
        i++;
×
145
        new_name = prefix + std::to_string(i);
×
146
    }
147
    return new_name;
4✔
148
};
4✔
149

150
}  // namespace builder
151
}  // 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