aboutsummaryrefslogtreecommitdiff
path: root/boot/symbol.cc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-11 22:33:03 +0200
committerEugen Wissner <belka@caraus.de>2026-07-11 22:33:03 +0200
commit14d4977e2ab2409bb7344395ca01d19e49f130f1 (patch)
tree5e08f1356a970b53f16ee554642eb555550d1491 /boot/symbol.cc
parentb7dd49c1d5832ac7d82edba27316884ab53e614c (diff)
downloadelna-14d4977e2ab2409bb7344395ca01d19e49f130f1.tar.gz
Implement record extension
Diffstat (limited to 'boot/symbol.cc')
-rw-r--r--boot/symbol.cc68
1 files changed, 61 insertions, 7 deletions
diff --git a/boot/symbol.cc b/boot/symbol.cc
index 512cf04..b75cdc1 100644
--- a/boot/symbol.cc
+++ b/boot/symbol.cc
@@ -157,11 +157,6 @@ namespace elna::boot
return *this;
}
- bool type::operator==(const std::nullptr_t&)
- {
- return empty();
- }
-
type::~type()
{
switch (tag)
@@ -243,6 +238,57 @@ namespace elna::boot
return tag == type_tag::enumeration ? this->enumeration : nullptr;
}
+ bool type::operator==(const std::nullptr_t&) const
+ {
+ return empty();
+ }
+
+ bool type::operator==(const type& other) const
+ {
+ type resolved_this = inner_aliased_type(*this);
+ type resolved_that = inner_aliased_type(other);
+
+ if (auto left_record = resolved_this.get<record_type>())
+ {
+ return left_record == resolved_that.get<record_type>();
+ }
+ if (auto left_primitive = resolved_this.get<primitive_type>())
+ {
+ auto right_primitive = resolved_that.get<primitive_type>();
+
+ return right_primitive != nullptr && left_primitive->identifier == right_primitive->identifier;
+ }
+ if (auto left_union = resolved_this.get<union_type>())
+ {
+ return left_union == resolved_that.get<union_type>();
+ }
+ if (auto left_enumeration = resolved_this.get<enumeration_type>())
+ {
+ return left_enumeration == resolved_that.get<enumeration_type>();
+ }
+ if (auto left_pointer = resolved_this.get<pointer_type>())
+ {
+ auto right_pointer = resolved_that.get<pointer_type>();
+
+ return right_pointer != nullptr && left_pointer->base == right_pointer->base;
+ }
+ if (auto left_array = resolved_this.get<array_type>())
+ {
+ auto right_array = resolved_that.get<array_type>();
+
+ return right_array != nullptr && left_array->size == right_array->size
+ && left_array->base == right_array->base;
+ }
+ if (auto left_procedure = resolved_this.get<procedure_type>())
+ {
+ auto right_procedure = resolved_that.get<procedure_type>();
+
+ return right_procedure != nullptr && left_procedure->return_type == right_procedure->return_type
+ && left_procedure->parameters == right_procedure->parameters;
+ }
+ return resolved_this.empty() && resolved_that.empty();
+ }
+
bool type::empty() const
{
return tag == type_tag::empty;
@@ -360,11 +406,19 @@ namespace elna::boot
result->enter("Int", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Int"))));
result->enter("Word", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Word"))));
result->enter("Char", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Char"))));
- result->enter("Bool", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Bool"))));
result->enter("Pointer", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Pointer"))));
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"));
+ 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::vector<std::string>{ "condition" });
+ result->enter("assert", assert_info);
+
return result;
}
@@ -435,7 +489,7 @@ namespace elna::boot
return inner_aliased_type(alias->reference);
}
- type inner_aliased_type(type alias)
+ type inner_aliased_type(const type& alias)
{
if (auto aliased = alias.get<alias_type>())
{