Add 'xo-expression/' from commit '5ac3c03a0c'
git-subtree-dir: xo-expression git-subtree-mainline:d0f5ccc1cegit-subtree-split:5ac3c03a0c
This commit is contained in:
commit
aecabbb144
46 changed files with 3241 additions and 0 deletions
93
xo-expression/src/expression/AssignExpr.cpp
Normal file
93
xo-expression/src/expression/AssignExpr.cpp
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* file AssignExpr.cpp
|
||||
*
|
||||
* author: Roland Conybeare
|
||||
*/
|
||||
|
||||
#include "AssignExpr.hpp"
|
||||
#include "xo/indentlog/print/tag.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace ast {
|
||||
rp<AssignExpr>
|
||||
AssignExpr::make(const rp<Variable> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
{
|
||||
return new AssignExpr(lhs, rhs);
|
||||
}
|
||||
|
||||
AssignExpr::AssignExpr(const rp<Variable> & lhs,
|
||||
const rp<Expression> & rhs)
|
||||
: Expression(exprtype::assign, rhs->valuetype()),
|
||||
lhs_{lhs}, rhs_{rhs}
|
||||
{
|
||||
this->free_var_set_ = this->calc_free_variables();
|
||||
}
|
||||
|
||||
std::set<std::string>
|
||||
AssignExpr::calc_free_variables() const
|
||||
{
|
||||
std::set<std::string> retval = lhs_->get_free_variables();
|
||||
|
||||
std::set<std::string> tmp = rhs_->get_free_variables();
|
||||
|
||||
for (const auto & name : tmp)
|
||||
retval.insert(name);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::set<std::string>
|
||||
AssignExpr::get_free_variables() const {
|
||||
return free_var_set_;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
AssignExpr::visit_preorder(VisitFn visitor_fn) {
|
||||
std::size_t n = 1;
|
||||
|
||||
visitor_fn(this);
|
||||
|
||||
n += lhs_->visit_preorder(visitor_fn);
|
||||
n += rhs_->visit_preorder(visitor_fn);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
AssignExpr::visit_layer(VisitFn visitor_fn) {
|
||||
std::size_t n = 1;
|
||||
|
||||
visitor_fn(this);
|
||||
|
||||
n += lhs_->visit_layer(visitor_fn);
|
||||
n += rhs_->visit_layer(visitor_fn);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
rp<Expression>
|
||||
AssignExpr::xform_layer(TransformFn xform_fn) {
|
||||
this->lhs_ = Variable::from(lhs_->xform_layer(xform_fn)).promote();
|
||||
this->rhs_ = rhs_->xform_layer(xform_fn);
|
||||
|
||||
return xform_fn(this);
|
||||
}
|
||||
|
||||
void
|
||||
AssignExpr::attach_envs(ref::brw<Environment> p) {
|
||||
lhs_->attach_envs(p);
|
||||
rhs_->attach_envs(p);
|
||||
}
|
||||
|
||||
void
|
||||
AssignExpr::display(std::ostream & os) const {
|
||||
os << "<Assign"
|
||||
<< xtag("lhs", lhs_)
|
||||
<< xtag("rhs", rhs_)
|
||||
<< ">";
|
||||
}
|
||||
} /*namespace ast*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end AssignExpr.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue