Beispiel #1
0
void
Parser::elaborate_function_definition(Function_decl& decl, Expression_def& def)
{
  // Declare parameters as local variables prior to elaborating
  // the definition.
  //
  // TODO: Should we be using a specifici kind of scope here?
  Enter_scope scope(cxt);
  for (Decl& d : decl.parameters())
    declare(cxt, d);

  // Elaborate the definition, possibly parsing it.
  Expr& expr = elaborate_expression(def.expression());

  // Transform the returned expression into a normal function
  // definition with a single return statement with that expression.
  Stmt& ret = cxt.make_return_statement(expr);
  Stmt& body = cxt.make_compound_statement({&ret});
  decl.def_ = &cxt.make_function_definition(body);
}
Beispiel #2
0
void
Parser::elaborate_variable_initializer(Variable_decl& decl, Expression_def& def)
{
  def.expr_ = &elaborate_expression(def.expression());
}
Beispiel #3
0
void
Elaborate_expressions::on_function_definition(Expression_def& d)
{
  d.expr_ = &get_expr(d.expression());
}
Beispiel #4
0
void
Elaborate_expressions::on_variable_initializer(Expression_def& d)
{
  d.expr_ = &get_expr(d.expression());
}