97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
#include <elna/source/types.hpp>
|
|
|
|
namespace elna::source
|
|
{
|
|
type::type(const std::size_t byte_size)
|
|
: byte_size(byte_size)
|
|
{
|
|
}
|
|
|
|
std::size_t type::size() const noexcept
|
|
{
|
|
return this->byte_size;
|
|
}
|
|
|
|
primitive_type::primitive_type(const std::string& type_name, const std::size_t byte_size)
|
|
: type(byte_size), type_name(type_name)
|
|
{
|
|
}
|
|
|
|
bool primitive_type::operator==(const primitive_type& that) const noexcept
|
|
{
|
|
return this->type_name == that.type_name;
|
|
}
|
|
|
|
bool primitive_type::operator!=(const primitive_type& that) const noexcept
|
|
{
|
|
return this->type_name != that.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)
|
|
{
|
|
}
|
|
|
|
bool pointer_type::operator==(const pointer_type& that) const noexcept
|
|
{
|
|
return this->base_type == that.base_type;
|
|
}
|
|
|
|
bool pointer_type::operator!=(const pointer_type& that) const noexcept
|
|
{
|
|
return this->base_type != that.base_type;
|
|
}
|
|
|
|
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)
|
|
{
|
|
}
|
|
|
|
bool procedure_type::operator==(const procedure_type &that) const noexcept
|
|
{
|
|
return this->arguments == that.arguments;
|
|
}
|
|
|
|
bool procedure_type::operator!=(const procedure_type &that) const noexcept
|
|
{
|
|
return this->arguments != that.arguments;
|
|
}
|
|
|
|
bool operator==(const type& lhs, const type& rhs) noexcept
|
|
{
|
|
{
|
|
auto lhs_type = dynamic_cast<const primitive_type *>(&lhs);
|
|
auto rhs_type = dynamic_cast<const primitive_type *>(&rhs);
|
|
|
|
if (lhs_type != nullptr && rhs_type != nullptr)
|
|
{
|
|
return *lhs_type == *rhs_type;
|
|
}
|
|
}
|
|
{
|
|
auto lhs_type = dynamic_cast<const pointer_type *>(&lhs);
|
|
auto rhs_type = dynamic_cast<const pointer_type *>(&rhs);
|
|
|
|
if (lhs_type != nullptr && rhs_type != nullptr)
|
|
{
|
|
return *lhs_type == *rhs_type;
|
|
}
|
|
}
|
|
{
|
|
auto lhs_type = dynamic_cast<const procedure_type *>(&lhs);
|
|
auto rhs_type = dynamic_cast<const procedure_type *>(&rhs);
|
|
|
|
if (lhs_type != nullptr && rhs_type != nullptr)
|
|
{
|
|
return *lhs_type == *rhs_type;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool operator!=(const type& lhs, const type& rhs) noexcept
|
|
{
|
|
return !(lhs == rhs);
|
|
}
|
|
}
|