Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Inliner::operator()(const ast::CallExp& e)
- {
- // Get the declaration of the function
- const auto* dec = dynamic_cast<const FunctionDec*>(e.def_get());
- assert(dec);
- // If it is recursive or a primitive, don't inline it
- if (rec_funs_.has(dec) || !dec->body_get())
- {
- super_type::operator()(e);
- return;
- }
- parse::Tweast s;
- // If there are no arguments, avoid having an extra let in EXP end
- // with no declarations
- if (e.args_get()->size())
- {
- s << "let ";
- for (size_t i = 0; i < e.args_get()->size(); ++i)
- {
- const VarDec* var = dec->formals_get()->decs_get()[i];
- s << "var " << var->name_get() << " := " << *(*e.args_get())[i] << " ";
- }
- s << "in " << " ";
- }
- // Always add the body
- s << *dec->body_get();
- // Add an extra end if the let/in/end was created
- if (e.args_get()->size())
- s << " end";
- // Parse the expression and add it to the current node
- ast::Exp* r = parse::parse(s);
- result_ = r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement