Пример #1
0
// Produce an implicit specialization of the template declaration
// `d`, given a list of template arguments.
//
// Note that this only builds the declaration. It does not fully
// instantiate the definition.
Decl&
specialize_template(Context& cxt, Template_decl& tmp, Term_list& args)
{
  // Convert parameters and build the substution.
  Decl_list& parms = tmp.parameters();
  Term_list conv = initialize_template_parameters(cxt, parms, args);
  Substitution sub(parms, conv);

  Decl& decl = tmp.parameterized_declaration();
  return specialize_declaration(cxt, tmp, decl, sub);
}
Пример #2
0
// TODO: This is basically what happens for every single declaration.
// Find a way of generalizing it.
Decl&
specialize_decl(Context& cxt, Variable_decl& d, Term_list& orig)
{
  Builder build(cxt);

  // Convert parameter.
  Template_decl& tmp = cast<Template_decl>(*d.context());
  Decl_list& parms = tmp.parameters();
  Term_list args = initialize_template_parameters(cxt, parms, orig);

  // Create the specialization name.
  Name& n = build.get_template_id(tmp, args);

  // Substitute into the type.
  //
  // TODO: Don't substitute or re-declare if we've already
  // created a specialization for these arguments.
  Substitution sub(parms, args);
  Type& t = substitute(cxt, d.type(), sub);

  // TODO: Issue declaration or later?
  return build.make_variable(n, t);
}