Commit c98ccffa authored by s_kleplj's avatar s_kleplj
Browse files

improved macro definitions and word inits

parent 2c205ff4
......@@ -39,41 +39,32 @@ bool macroprocessor_impl::process(
}
if (is_def) {
if (parsed.size() != 1) {
std::vector<word*>* vector;
auto it = words_.find(parsed[0]);
if (it == words_.end()) {
it = words_.emplace(
std::piecewise_construct,
std::forward_as_tuple(parsed[0]),
std::forward_as_tuple(std::string {parsed[0]}, std::vector<word*>{})).first;
const_cast<std::string_view&>(it->first) = it->second.name_;
}
auto&& [it, inserted] = words_.try_emplace(
parsed[0],
parsed[0]);
if (inserted) {
const_cast<std::string_view&>(it->first) = it->second.name_;
} else {
it->second.value_.clear();
}
vector = &(it->second.value_);
vector->clear();
if (parsed.size() != 1) {
std::vector<word*>* vector = &(it->second.value_);
vector->reserve(parsed.size() - 1);
for (auto i = parsed.begin() + 1; i != parsed.end(); ++i) {
it = words_.find(*i);
if (it == words_.end()) {
it = words_.emplace(*i, std::string{*i}).first;
auto&& [it, inserted] = words_.try_emplace(
*i,
*i,
true);
if (inserted) {
const_cast<std::string_view&>(it->first) = it->second.name_;
}
vector->emplace_back(&it->second);
}
} else {
auto it = words_.find(parsed[0]);
if (it == words_.end()) {
it = words_.emplace(
std::piecewise_construct,
std::forward_as_tuple(parsed[0]),
std::forward_as_tuple(std::string {parsed[0]}, std::vector<word*>{})).first;
const_cast<std::string_view&>(it->first) = it->second.name_;
} else {
it->second.value_ = {};
}
}
return false;
......
......@@ -39,17 +39,19 @@ class macroprocessor_impl {
private:
struct word {
word(std::string&& name) noexcept :
name_{std::move(name)},
value_{std::vector{this}}
word (std::string_view name) :
name_{std::string{name}},
value_{},
length{}
{}
word(std::string&& name, std::vector<word*>&& vector) noexcept :
name_{std::move(name)},
value_{std::move(vector)}
word (std::string_view name, bool) :
name_{std::string{name}},
value_{this},
length{}
{}
void append_to(std::string& output) {
void append_to(std::string& output) const {
if (length == 0) {
return;
}
......@@ -90,7 +92,7 @@ class macroprocessor_impl {
std::string name_;
std::vector<word*> value_;
std::size_t length = 0;
std::size_t length;
};
std::map<std::string_view, word> words_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment