// Check if the template-id n refers to a type. Type& Parser::on_type_name(Name& n) { Template_id& id = cast<Template_id>(n); Template_decl& tmp = id.declaration(); Term_list& args = id.arguments(); Decl& decl = specialize_template(cxt, tmp, args); if (Type* type = get_type_for_decl(cxt, decl)) return *type; throw Lookup_error("not a type name"); }
int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: %s conf-file\n", argv[0]); return 1; } struct conf_info conf_info = parse_conf_file(argv[1]); specialize_template(conf_info); return 0; }
void test_specialize(Context& cxt) { std::cout << "--- specialization ---\n"; Builder build(cxt); // Substitutable type and an argument. Decl& parm = build.make_type_parameter("T"); Type& arg = build.get_int_type(); Term_list args {&arg}; // Substitution patterns Type& t = build.get_typename_type(parm); Type& p_t = build.get_pointer_type(t); Decl& v1 = build.make_variable("v1", p_t); Template_decl& tv1 = build.make_template({&parm}, v1); std::cout << tv1 << "\n vvvv\n"; Decl& ts1 = specialize_template(cxt, tv1, args); std::cout << ts1 << '\n'; }