81 lines
1.8 KiB
C++
81 lines
1.8 KiB
C++
#include <elna/source/types.h>
|
|
|
|
namespace elna
|
|
{
|
|
namespace source
|
|
{
|
|
type::type(const std::size_t byte_size)
|
|
: byte_size(byte_size)
|
|
{
|
|
}
|
|
|
|
std::size_t type::size() const noexcept
|
|
{
|
|
return this->byte_size;
|
|
}
|
|
|
|
const pointer_type *type::is_pointer_type() const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
primitive_type::primitive_type(const std::string& type_name, const std::size_t byte_size)
|
|
: type(byte_size), m_type_name(type_name)
|
|
{
|
|
}
|
|
|
|
std::string primitive_type::type_name() const
|
|
{
|
|
return m_type_name;
|
|
}
|
|
|
|
pointer_type::pointer_type(std::shared_ptr<const type> base_type, const std::size_t byte_size)
|
|
: type(byte_size), base_type(base_type)
|
|
{
|
|
}
|
|
|
|
const pointer_type *pointer_type::is_pointer_type() const
|
|
{
|
|
return this;
|
|
}
|
|
|
|
std::string pointer_type::type_name() const
|
|
{
|
|
return '^' + base_type->type_name();
|
|
}
|
|
|
|
procedure_type::procedure_type(std::vector<std::shared_ptr<const type>> arguments, const std::size_t byte_size)
|
|
: arguments(std::move(arguments)), type(byte_size)
|
|
{
|
|
}
|
|
|
|
std::string procedure_type::type_name() const
|
|
{
|
|
std::string result{ "proc(" };
|
|
for (const auto& argument : arguments)
|
|
{
|
|
result += argument->type_name() + ',';
|
|
}
|
|
result.at(result.size() - 1) = ')';
|
|
|
|
return result;
|
|
}
|
|
|
|
bool operator==(const type& lhs, const type& rhs) noexcept
|
|
{
|
|
auto lhs_type = lhs.type_name();
|
|
auto rhs_type = rhs.type_name();
|
|
|
|
return lhs_type == rhs_type;
|
|
}
|
|
|
|
bool operator!=(const type& lhs, const type& rhs) noexcept
|
|
{
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
const primitive_type boolean_type{ "Boolean", 1 };
|
|
const primitive_type int_type{ "Int", 4 };
|
|
}
|
|
}
|