xo-expression: + ConvertExpr

This commit is contained in:
Roland Conybeare 2024-08-06 03:20:38 -04:00
commit 0708bc7569
3 changed files with 163 additions and 0 deletions

View file

@ -9,6 +9,7 @@ set(SELF_SRCS
Variable.cpp
IfExpr.cpp
LocalEnv.cpp
ConvertExpr.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})

View file

@ -0,0 +1,53 @@
/* file ConvertExpr.cpp
*
* author: Roland Conybeare
*/
#include "ConvertExpr.hpp"
namespace xo {
namespace ast {
rp<ConvertExpr>
ConvertExpr::make(TypeDescr dest_type,
rp<Expression> arg)
{
return new ConvertExpr(dest_type,
std::move(arg));
}
std::set<std::string>
ConvertExpr::get_free_variables() const {
if (this->arg_)
return this->arg_->get_free_variables();
else
return std::set<std::string>();
}
void
ConvertExpr::display(std::ostream & os) const {
os << "<Convert"
<< xtag("dest_type", this->valuetype()->short_name())
<< xtag("arg", arg_)
<< ">";
}
// ----- ConvertExprAccess -----
rp<ConvertExprAccess>
ConvertExprAccess::make(TypeDescr dest_type,
rp<Expression> arg)
{
return new ConvertExprAccess(dest_type,
std::move(arg));
}
rp<ConvertExprAccess>
ConvertExprAccess::make_empty() {
return new ConvertExprAccess(nullptr /*dest_type*/,
nullptr /*arg*/);
}
} /*namespace ast*/
} /*namespace xo*/
/* end ConvertExpr.cpp */