Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. void Inliner::operator()(const ast::CallExp& e)
  2.   {
  3.     // Get the declaration of the function
  4.     const auto* dec = dynamic_cast<const FunctionDec*>(e.def_get());
  5.     assert(dec);
  6.  
  7.     // If it is recursive or a primitive, don't inline it
  8.     if (rec_funs_.has(dec) || !dec->body_get())
  9.     {
  10.       super_type::operator()(e);
  11.       return;
  12.     }
  13.  
  14.     parse::Tweast s;
  15.  
  16.     // If there are no arguments, avoid having an extra let in EXP end
  17.     // with no declarations
  18.     if (e.args_get()->size())
  19.     {
  20.       s << "let ";
  21.  
  22.       for (size_t i = 0; i < e.args_get()->size(); ++i)
  23.       {
  24.         const VarDec* var = dec->formals_get()->decs_get()[i];
  25.         s << "var " << var->name_get() << " := " << *(*e.args_get())[i] << " ";
  26.       }
  27.  
  28.       s << "in " << " ";
  29.     }
  30.  
  31.     // Always add the body
  32.     s << *dec->body_get();
  33.  
  34.     // Add an extra end if the let/in/end was created
  35.     if (e.args_get()->size())
  36.       s << " end";
  37.  
  38.     // Parse the expression and add it to the current node
  39.     ast::Exp* r = parse::parse(s);
  40.     result_ = r;
  41.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement