aboutsummaryrefslogtreecommitdiff
path: root/boot/symbol.cc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-19 23:23:22 +0200
committerEugen Wissner <belka@caraus.de>2026-07-20 00:48:12 +0200
commitd09cd98bd3df9920f0ecab97615048c0594e8f7f (patch)
tree6923b34ae6b603e19ede189098206cfe25feef35 /boot/symbol.cc
parentcdbc1695a93910df5729779de31912a3b4b4172b (diff)
downloadelna-d09cd98bd3df9920f0ecab97615048c0594e8f7f.tar.gz
Add clang-tidy support
Diffstat (limited to 'boot/symbol.cc')
-rw-r--r--boot/symbol.cc109
1 files changed, 63 insertions, 46 deletions
diff --git a/boot/symbol.cc b/boot/symbol.cc
index 7b45612..d7a1cae 100644
--- a/boot/symbol.cc
+++ b/boot/symbol.cc
@@ -17,6 +17,8 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/symbol.h"
+#include <utility>
+
namespace elna::boot
{
type::type(std::shared_ptr<alias_type> alias)
@@ -64,14 +66,16 @@ namespace elna::boot
{
if constexpr (std::is_same_v<T, alias_type>)
{
- if (auto *wp = std::get_if<std::weak_ptr<alias_type>>(&payload))
- return wp->lock();
+ if (const auto *weak_pointer = std::get_if<std::weak_ptr<alias_type>>(&payload)) {
+ return weak_pointer->lock();
+}
return nullptr;
}
else
{
- if (auto *sp = std::get_if<std::shared_ptr<T>>(&payload))
- return *sp;
+ if (auto *shared_pointer = std::get_if<std::shared_ptr<T>>(&payload)) {
+ return *shared_pointer;
+}
return nullptr;
}
}
@@ -93,8 +97,8 @@ namespace elna::boot
bool type::operator==(const type& other) const
{
- type resolved_this = resolve_aliases(*this);
- type resolved_that = resolve_aliases(other);
+ type const resolved_this = resolve_aliases(*this);
+ type const resolved_that = resolve_aliases(other);
if (auto left_record = resolved_this.get<record_type>())
{
@@ -146,64 +150,79 @@ namespace elna::boot
std::string type::to_string() const
{
- return std::visit([](const auto& p) -> std::string {
- using T = std::decay_t<decltype(p)>;
+ return std::visit([](const auto& payload) -> std::string {
+ using T = std::decay_t<decltype(payload)>;
if constexpr (std::is_same_v<T, std::monostate>)
+ {
return "<empty>";
+ }
else if constexpr (std::is_same_v<T, std::weak_ptr<alias_type>>)
- return p.lock()->name;
+ {
+ return payload.lock()->name;
+ }
else if constexpr (std::is_same_v<T, std::shared_ptr<primitive_type>>)
- return p->identifier;
+ {
+ return payload->identifier;
+ }
else if constexpr (std::is_same_v<T, std::shared_ptr<pointer_type>>)
- return "^" + p->base.to_string();
+ {
+ return "^" + payload->base.to_string();
+ }
else if constexpr (std::is_same_v<T, std::shared_ptr<constant_type>>)
- return "const " + p->unqualified.to_string();
+ {
+ return "const " + payload->unqualified.to_string();
+ }
else if constexpr (std::is_same_v<T, std::shared_ptr<array_type>>)
- return "[" + std::to_string(p->size) + "]" + p->base.to_string();
+ {
+ return "[" + std::to_string(payload->size) + "]" + payload->base.to_string();
+ }
else if constexpr (std::is_same_v<T, std::shared_ptr<record_type>>)
{
- if (p->base.empty())
- return "record ... end";
- else
- return "record(" + p->base.to_string() + ") ... end";
+ return payload->base.empty()
+ ? "record ... end"
+ : "record(" + payload->base.to_string() + ") ... end";
}
else if constexpr (std::is_same_v<T, std::shared_ptr<procedure_type>>)
{
std::string result = "proc(";
- for (std::size_t i = 0; i < p->parameters.size(); ++i)
+ for (std::size_t i = 0; i < payload->parameters.size(); ++i)
{
- if (i > 0) result += ", ";
- result += p->parameters[i].to_string();
+ if (i > 0) { result += ", ";
+}
+ result += payload->parameters[i].to_string();
}
result += ")";
- if (p->return_type.no_return)
+ if (payload->return_type.no_return) {
result += ": !";
- else if (!p->return_type.proper_type.empty())
- result += ": " + p->return_type.proper_type.to_string();
+ } else if (!payload->return_type.proper_type.empty()) {
+ result += ": " + payload->return_type.proper_type.to_string();
+}
return result;
}
else if constexpr (std::is_same_v<T, std::shared_ptr<enumeration_type>>)
+ {
return "(enumeration)";
+ }
}, payload);
}
alias_type::alias_type(const std::string& name)
- : name(name), referent()
+ : name(name)
{
}
pointer_type::pointer_type(type base)
- : base(base)
+ : base(std::move(base))
{
}
constant_type::constant_type(type unqualified)
- : unqualified(unqualified)
+ : unqualified(std::move(unqualified))
{
}
array_type::array_type(type base, std::uint64_t size)
- : base(base), size(size)
+ : base(std::move(base)), size(size)
{
}
@@ -213,12 +232,12 @@ namespace elna::boot
}
record_type::record_type(type base)
- : base(base)
+ : base(std::move(base))
{
}
procedure_type::procedure_type(return_t return_type)
- : return_type(return_type)
+ : return_type(std::move(return_type))
{
}
@@ -227,9 +246,7 @@ namespace elna::boot
{
}
- info::~info()
- {
- }
+ info::~info() = default;
std::shared_ptr<type_info> info::is_type()
{
@@ -246,7 +263,7 @@ namespace elna::boot
return nullptr;
}
- type_info::type_info(const type symbol)
+ type_info::type_info(const type& symbol)
: symbol(symbol)
{
}
@@ -256,9 +273,9 @@ namespace elna::boot
return std::static_pointer_cast<type_info>(shared_from_this());
}
- procedure_info::procedure_info(const procedure_type symbol, const std::vector<std::string> names,
+ procedure_info::procedure_info(const procedure_type& symbol, const std::vector<std::string>& names,
std::shared_ptr<symbol_table> scope)
- : symbol(symbol), names(names), scope(scope)
+ : symbol(symbol), names(names), scope(std::move(scope))
{
}
@@ -272,7 +289,7 @@ namespace elna::boot
return this->scope == nullptr;
}
- variable_info::variable_info(const type symbol, bool is_extern)
+ variable_info::variable_info(const type& symbol, bool is_extern)
: symbol(symbol), is_extern(is_extern)
{
}
@@ -293,19 +310,19 @@ namespace elna::boot
result->enter("Float", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Float"))));
result->enter("String", std::make_shared<type_info>(type(std::make_shared<primitive_type>("String"))));
- type boolean = type(std::make_shared<primitive_type>("Bool"));
+ type const boolean = type(std::make_shared<primitive_type>("Bool"));
result->enter("Bool", std::make_shared<type_info>(boolean));
procedure_type assert_symbol{ procedure_type::return_t() };
assert_symbol.parameters.push_back(boolean);
- std::shared_ptr<procedure_info> assert_info = std::make_shared<procedure_info>(assert_symbol,
+ std::shared_ptr<procedure_info> const assert_info = std::make_shared<procedure_info>(assert_symbol,
std::vector<std::string>{ "condition" });
result->enter("assert", assert_info);
return result;
}
- symbol_bag::symbol_bag(forward_table&& unresolved, std::shared_ptr<symbol_table> global_table)
+ symbol_bag::symbol_bag(forward_table&& unresolved, const std::shared_ptr<symbol_table>& global_table)
: unresolved(unresolved)
{
this->symbols = std::make_shared<symbol_table>(global_table);
@@ -313,7 +330,7 @@ namespace elna::boot
std::shared_ptr<info> symbol_bag::lookup(const std::string& name)
{
- for (auto import_bag : this->imports)
+ for (const auto& import_bag : this->imports)
{
if (auto result = import_bag->lookup(name))
{
@@ -323,7 +340,7 @@ namespace elna::boot
return this->symbols->lookup(name);
}
- bool symbol_bag::enter(const std::string& name, std::shared_ptr<info> entry)
+ bool symbol_bag::enter(const std::string& name, const std::shared_ptr<info>& entry)
{
return this->symbols->enter(name, entry);
}
@@ -336,7 +353,7 @@ namespace elna::boot
void symbol_bag::enter(std::shared_ptr<symbol_table> child)
{
- this->symbols = child;
+ this->symbols = std::move(child);
}
std::shared_ptr<symbol_table> symbol_bag::leave()
@@ -383,7 +400,7 @@ namespace elna::boot
return m_exported;
}
- type resolve_underlying_type(std::shared_ptr<alias_type> alias)
+ type resolve_underlying_type(const std::shared_ptr<alias_type>& alias)
{
return resolve_underlying_type(alias->referent);
}
@@ -422,7 +439,7 @@ namespace elna::boot
bool is_numeric_type(const type& checked)
{
- type resolved = resolve_underlying_type(checked);
+ type const resolved = resolve_underlying_type(checked);
return is_primitive_type(resolved, "Int")
|| is_primitive_type(resolved, "Word")
@@ -431,7 +448,7 @@ namespace elna::boot
bool is_integral_type(const type& checked)
{
- type resolved = resolve_underlying_type(checked);
+ type const resolved = resolve_underlying_type(checked);
return is_primitive_type(resolved, "Int")
|| is_primitive_type(resolved, "Word");
@@ -439,7 +456,7 @@ namespace elna::boot
bool is_discrete_type(const type& checked)
{
- type resolved = resolve_underlying_type(checked);
+ type const resolved = resolve_underlying_type(checked);
return is_primitive_type(resolved, "Int")
|| is_primitive_type(resolved, "Word")