diff options
Diffstat (limited to 'boot/symbol.cc')
| -rw-r--r-- | boot/symbol.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/boot/symbol.cc b/boot/symbol.cc index d7ceacb..a3a36c1 100644 --- a/boot/symbol.cc +++ b/boot/symbol.cc @@ -270,6 +270,54 @@ namespace elna::boot return tag == type_tag::empty; } + std::string type::to_string() const + { + switch (tag) + { + case type_tag::empty: + return "<empty>"; + case type_tag::alias: + return alias.lock()->name; + case type_tag::primitive: + return primitive->identifier; + case type_tag::pointer: + return "^" + pointer->base.to_string(); + case type_tag::array: + return "[" + std::to_string(array->size) + "]" + array->base.to_string(); + case type_tag::record: + if (record->base.empty()) + { + return "record ... end"; + } + else + { + return "record(" + record->base.to_string() + ") ... end"; + } + case type_tag::procedure: + { + std::string result = "proc("; + for (std::size_t i = 0; i < procedure->parameters.size(); ++i) + { + if (i > 0) result += ", "; + result += procedure->parameters[i].to_string(); + } + result += ")"; + if (procedure->return_type.no_return) + { + result += ": !"; + } + else if (!procedure->return_type.proper_type.empty()) + { + result += ": " + procedure->return_type.proper_type.to_string(); + } + return result; + } + case type_tag::enumeration: + return "(enumeration)"; + } + __builtin_unreachable(); + } + alias_type::alias_type(const std::string& name) : name(name), reference() { |
