62 lines
921 B
C++
62 lines
921 B
C++
|
#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;
|
||
|
}
|
||
|
|
||
|
}
|