Beispiel #1
0
void
Parser::elaborate_function_declaration(Function_decl& d)
{
  // Reset the list of implicit parameters.
  state.implicit_parms = {};

  // Elaborate the type of each parameter in turn. Note that this does
  // not declare the parameters, it just checks their types.
  Decl_list& parms = d.parameters();
  for (Decl& d : parms)
    elaborate_parameter_declaration(cast<Object_parm>(d));

  // Elaborate the return type.
  //
  // FIXME: If the return type shares a placehoder name with a parameter,
  // then that's not a placeholder. We need to rewrite the type.
  Type& ret = elaborate_type(d.return_type());

  // Rebuild the function type and update the declaration.
  d.type_ = &cxt.get_function_type(parms, ret);

  // If necessary, make the function a template.
  if (state.implicit_parms.size()) {
    Decl& tmp = cxt.make_template(state.implicit_parms, d);

    // FIXME: Actually make this a declaration! We probably need to
    // replace this entity in the declaration list with its new
    // template. We also need to update the overload set with the same.
    (void)tmp;
  }

}
Beispiel #2
0
// The type of the returned expression shall match the declared
// return type of the enclosing function.
//
// TODO: Implement me.
void
Elaborator::elaborate(Return_stmt* s)
{
  Function_decl* fn = stack.function();
  Type const* t = fn->return_type();

  // Check that the return type matches the returned value.
  Expr* c = require_converted(*this, s->first, t);
  if (!c)
    throw std::runtime_error("return type mismatch");
}