roza/lib/FunTy.cpp

62 lines
921 B
C++
Raw Permalink Normal View History

2023-09-01 20:38:12 +00:00
#include "FunTy.hpp"
namespace roza
{
/*explicit*/ FunTy::FunTy()
: Type(TY_FUN)
{
}
/*virtual*/ FunTy::~FunTy()
{
}
void FunTy::add_input(std::shared_ptr<Type> ty)
{
m_inputs.push_back(ty);
}
void FunTy::set_output(std::shared_ptr<Type> ty)
{
m_output = ty;
}
std::string FunTy::string() const /*override*/
{
std::stringstream ss;
ss << "FUN";
ss << "<";
if (m_inputs.empty() && m_output->base() == TY_NIL)
{
ss << ">";
return ss.str();
}
std::string sep;
for (auto ty: m_inputs)
{
ss << sep << ty->string();
sep = " -> ";
}
ss << " -> " << m_output->string();
ss << ">";
return ss.str();
}
bool FunTy::equals(BaseType base_type) const /*override*/
{
return base_type == TY_FUN;
}
bool FunTy::equals(Type const&) const /*override*/
{
return false;
}
}