Parse cpp_using_directive/declaration
Both of them now also don't have a name() anymore as it was inconsistent with get_full_name().
This commit is contained in:
parent
45e9e5305b
commit
087b9583ff
7 changed files with 176 additions and 22 deletions
|
|
@ -8,6 +8,9 @@ using namespace cppast;
|
|||
|
||||
std::string cppast::full_name(const cpp_entity& e)
|
||||
{
|
||||
if (e.name().empty())
|
||||
return "";
|
||||
|
||||
std::string scopes;
|
||||
|
||||
for (auto cur = e.parent(); cur; cur = cur.value().parent())
|
||||
|
|
|
|||
|
|
@ -43,12 +43,22 @@ cpp_entity_kind cpp_namespace_alias::do_get_entity_kind() const noexcept
|
|||
return kind();
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_using_directive::do_get_entity_kind() const noexcept
|
||||
cpp_entity_kind cpp_using_directive::kind() noexcept
|
||||
{
|
||||
return cpp_entity_kind::using_directive_t;
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_using_declaration::do_get_entity_kind() const noexcept
|
||||
cpp_entity_kind cpp_using_directive::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return kind();
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_using_declaration::kind() noexcept
|
||||
{
|
||||
return cpp_entity_kind::using_declaration_t;
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_using_declaration::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return kind();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "parse_functions.hpp"
|
||||
|
||||
#include <cppast/cpp_namespace.hpp>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
#include "libclang_visitor.hpp"
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_namespace(const detail::parse_cont
|
|||
|
||||
namespace
|
||||
{
|
||||
cpp_entity_id ns_alias_target_id(const CXCursor& cur)
|
||||
cpp_entity_id parse_ns_target_cursor(const CXCursor& cur)
|
||||
{
|
||||
cpp_entity_id result("");
|
||||
detail::visit_children(cur,
|
||||
|
|
@ -61,10 +62,11 @@ namespace
|
|||
result = detail::get_entity_id(referenced);
|
||||
else if (kind == CXCursor_NamespaceAlias)
|
||||
// get target of namespace alias instead
|
||||
result = ns_alias_target_id(referenced);
|
||||
result = parse_ns_target_cursor(referenced);
|
||||
else
|
||||
DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur,
|
||||
"unexpected child of namespace alias");
|
||||
"unexpected target for namespace "
|
||||
"alias/using directive");
|
||||
},
|
||||
true);
|
||||
return result;
|
||||
|
|
@ -89,7 +91,77 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_namespace_alias(const detail::pars
|
|||
while (!detail::skip_if(stream, ";"))
|
||||
target_name += stream.get().c_str();
|
||||
|
||||
auto target = cpp_namespace_ref(ns_alias_target_id(cur), std::move(target_name));
|
||||
auto target = cpp_namespace_ref(parse_ns_target_cursor(cur), std::move(target_name));
|
||||
return cpp_namespace_alias::build(*context.idx, get_entity_id(cur), std::move(name),
|
||||
std::move(target));
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::parse_cpp_using_directive(const detail::parse_context& context,
|
||||
const CXCursor& cur)
|
||||
{
|
||||
DEBUG_ASSERT(cur.kind == CXCursor_UsingDirective, detail::assert_handler{});
|
||||
|
||||
detail::tokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::token_stream stream(tokenizer, cur);
|
||||
|
||||
// using namespace <nested identifier>;
|
||||
detail::skip(stream, "using");
|
||||
detail::skip(stream, "namespace");
|
||||
|
||||
// <nested identifier>;
|
||||
std::string target_name;
|
||||
while (!detail::skip_if(stream, ";"))
|
||||
target_name += stream.get().c_str();
|
||||
|
||||
auto target = cpp_namespace_ref(parse_ns_target_cursor(cur), std::move(target_name));
|
||||
return cpp_using_directive::build(target);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
cpp_entity_id parse_entity_target_cursor(const CXCursor& cur)
|
||||
{
|
||||
cpp_entity_id result("");
|
||||
detail::visit_children(cur,
|
||||
[&](const CXCursor& child) {
|
||||
switch (clang_getCursorKind(child))
|
||||
{
|
||||
case CXCursor_TypeRef:
|
||||
case CXCursor_TemplateRef:
|
||||
case CXCursor_MemberRef:
|
||||
case CXCursor_OverloadedDeclRef:
|
||||
case CXCursor_VariableRef:
|
||||
break;
|
||||
|
||||
default:
|
||||
DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur,
|
||||
"unexpected target for using declaration");
|
||||
}
|
||||
|
||||
auto referenced = clang_getCursorReferenced(child);
|
||||
result = detail::get_entity_id(referenced);
|
||||
},
|
||||
true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::parse_cpp_using_declaration(
|
||||
const detail::parse_context& context, const CXCursor& cur)
|
||||
{
|
||||
DEBUG_ASSERT(cur.kind == CXCursor_UsingDeclaration, detail::assert_handler{});
|
||||
|
||||
detail::tokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::token_stream stream(tokenizer, cur);
|
||||
|
||||
// using <nested identifier>;
|
||||
detail::skip(stream, "using");
|
||||
|
||||
// <nested identifier>;
|
||||
std::string target_name;
|
||||
while (!detail::skip_if(stream, ";"))
|
||||
target_name += stream.get().c_str();
|
||||
|
||||
auto target = cpp_entity_ref(parse_entity_target_cursor(cur), std::move(target_name));
|
||||
return cpp_using_declaration::build(std::move(target));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
|
|||
return parse_cpp_namespace(context, cur);
|
||||
case CXCursor_NamespaceAlias:
|
||||
return parse_cpp_namespace_alias(context, cur);
|
||||
case CXCursor_UsingDirective:
|
||||
return parse_cpp_using_directive(context, cur);
|
||||
case CXCursor_UsingDeclaration:
|
||||
return parse_cpp_using_declaration(context, cur);
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -28,9 +28,12 @@ namespace cppast
|
|||
|
||||
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,
|
||||
const CXCursor& cur);
|
||||
std::unique_ptr<cpp_entity> parse_cpp_using_directive(const parse_context& context,
|
||||
const CXCursor& cur);
|
||||
std::unique_ptr<cpp_entity> parse_cpp_using_declaration(const parse_context& context,
|
||||
const CXCursor& cur);
|
||||
|
||||
std::unique_ptr<cpp_entity> parse_entity(const parse_context& context, const CXCursor& cur);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue