Parse cpp_class_template_specialization
This commit is contained in:
parent
22fd582756
commit
1bbc962b8c
7 changed files with 120 additions and 6 deletions
|
|
@ -18,7 +18,12 @@ cpp_entity_kind cpp_class_template::do_get_entity_kind() const noexcept
|
|||
return kind();
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_class_template_specialization::do_get_entity_kind() const noexcept
|
||||
cpp_entity_kind cpp_class_template_specialization::kind() noexcept
|
||||
{
|
||||
return cpp_entity_kind::class_template_specialization_t;
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_class_template_specialization::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return kind();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,12 +104,15 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context&
|
|||
else if (kind == CXCursor_CXXFinalAttr)
|
||||
builder.is_final();
|
||||
else if (kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter
|
||||
|| kind == CXCursor_TemplateTemplateParameter)
|
||||
|| kind == CXCursor_TemplateTemplateParameter || clang_isExpression(kind)
|
||||
|| clang_isReference(kind))
|
||||
// other children due to templates and stuff
|
||||
return;
|
||||
else if (auto entity = parse_entity(context, child))
|
||||
builder.add_child(std::move(entity));
|
||||
});
|
||||
auto is_templated = clang_getTemplateCursorKind(cur) != CXCursor_NoDeclFound;
|
||||
auto is_templated = (clang_getTemplateCursorKind(cur) != CXCursor_NoDeclFound
|
||||
|| !clang_Cursor_isNull(clang_getSpecializedCursorTemplate(cur)));
|
||||
if (clang_isCursorDefinition(cur))
|
||||
return is_templated ? builder.finish() : builder.finish(*context.idx, get_entity_id(cur));
|
||||
else
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
|
|||
case CXCursor_ClassDecl:
|
||||
case CXCursor_StructDecl:
|
||||
case CXCursor_UnionDecl:
|
||||
if (auto spec = try_parse_full_cpp_class_template_specialization(context, cur))
|
||||
return spec;
|
||||
return parse_cpp_class(context, cur);
|
||||
|
||||
case CXCursor_VarDecl:
|
||||
|
|
@ -134,6 +136,8 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
|
|||
return parse_cpp_function_template(context, cur);
|
||||
case CXCursor_ClassTemplate:
|
||||
return parse_cpp_class_template(context, cur);
|
||||
case CXCursor_ClassTemplatePartialSpecialization:
|
||||
return parse_cpp_class_template_specialization(context, cur);
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -95,6 +95,10 @@ namespace cppast
|
|||
std::unique_ptr<cpp_entity> try_parse_cpp_function_template_specialization(
|
||||
const parse_context& context, const CXCursor& cur);
|
||||
|
||||
// on class cursors
|
||||
std::unique_ptr<cpp_entity> try_parse_full_cpp_class_template_specialization(
|
||||
const parse_context& context, const CXCursor& cur);
|
||||
|
||||
std::unique_ptr<cpp_entity> parse_cpp_namespace(const parse_context& context,
|
||||
const CXCursor& cur);
|
||||
std::unique_ptr<cpp_entity> parse_cpp_namespace_alias(const parse_context& context,
|
||||
|
|
@ -135,6 +139,8 @@ namespace cppast
|
|||
const CXCursor& cur);
|
||||
std::unique_ptr<cpp_entity> parse_cpp_class_template(const parse_context& context,
|
||||
const CXCursor& cur);
|
||||
std::unique_ptr<cpp_entity> parse_cpp_class_template_specialization(
|
||||
const parse_context& context, const CXCursor& cur);
|
||||
|
||||
// as_template: true, iff currently parsing a template
|
||||
std::unique_ptr<cpp_entity> parse_entity(
|
||||
|
|
|
|||
|
|
@ -355,3 +355,45 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_class_template(const detail::parse
|
|||
return builder.finish(*context.idx, detail::get_entity_id(cur),
|
||||
builder.get().class_().is_definition());
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::try_parse_full_cpp_class_template_specialization(
|
||||
const detail::parse_context& context, const CXCursor& cur)
|
||||
{
|
||||
DEBUG_ASSERT(clang_getCursorKind(cur) == CXCursor_ClassDecl
|
||||
|| clang_getCursorKind(cur) == CXCursor_StructDecl
|
||||
|| clang_getCursorKind(cur) == CXCursor_UnionDecl,
|
||||
detail::assert_handler{});
|
||||
|
||||
auto templ = clang_getSpecializedCursorTemplate(cur);
|
||||
if (clang_Cursor_isNull(templ))
|
||||
return nullptr;
|
||||
return detail::parse_cpp_class_template_specialization(context, cur);
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::parse_cpp_class_template_specialization(
|
||||
const detail::parse_context& context, const CXCursor& cur)
|
||||
{
|
||||
DEBUG_ASSERT(clang_getCursorKind(cur) == CXCursor_ClassTemplatePartialSpecialization
|
||||
|| clang_getCursorKind(cur) == CXCursor_ClassDecl
|
||||
|| clang_getCursorKind(cur) == CXCursor_StructDecl
|
||||
|| clang_getCursorKind(cur) == CXCursor_UnionDecl,
|
||||
detail::assert_handler{});
|
||||
|
||||
auto primary = clang_getSpecializedCursorTemplate(cur);
|
||||
auto c = detail::parse_cpp_class(context, cur);
|
||||
if (!c)
|
||||
return nullptr;
|
||||
|
||||
// steal comment
|
||||
auto comment = type_safe::copy(c->comment());
|
||||
c->set_comment(type_safe::nullopt);
|
||||
|
||||
cpp_class_template_specialization::builder
|
||||
builder(std::unique_ptr<cpp_class>(static_cast<cpp_class*>(c.release())),
|
||||
cpp_template_ref(detail::get_entity_id(primary), ""));
|
||||
builder.get().set_comment(std::move(comment));
|
||||
parse_parameters(builder, context, cur);
|
||||
parse_arguments(builder, context, cur);
|
||||
return builder.finish(*context.idx, detail::get_entity_id(cur),
|
||||
builder.get().class_().is_definition());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue