Parse cpp_language_linkage
This commit is contained in:
parent
8fdfd3a707
commit
8d864bdbe1
7 changed files with 80 additions and 2 deletions
|
|
@ -15,6 +15,8 @@ namespace cppast
|
|||
public cpp_entity_container<cpp_language_linkage, cpp_entity>
|
||||
{
|
||||
public:
|
||||
static cpp_entity_kind kind() noexcept;
|
||||
|
||||
/// Builds a [cppast::cpp_language_linkage]().
|
||||
class builder
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@
|
|||
|
||||
using namespace cppast;
|
||||
|
||||
cpp_entity_kind cpp_language_linkage::kind() noexcept
|
||||
{
|
||||
return cpp_entity_kind::language_linkage_t;
|
||||
}
|
||||
|
||||
bool cpp_language_linkage::is_block() const noexcept
|
||||
{
|
||||
DEBUG_ASSERT(begin() != end(), detail::assert_handler{}, "empty container");
|
||||
|
|
@ -16,5 +21,5 @@ bool cpp_language_linkage::is_block() const noexcept
|
|||
|
||||
cpp_entity_kind cpp_language_linkage::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return cpp_entity_kind::language_linkage_t;
|
||||
return kind();
|
||||
}
|
||||
|
|
|
|||
46
src/libclang/language_linkage_parser.cpp
Normal file
46
src/libclang/language_linkage_parser.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
|
||||
// This file is subject to the license terms in the LICENSE file
|
||||
// found in the top-level directory of this distribution.
|
||||
|
||||
#include "parse_functions.hpp"
|
||||
|
||||
#include <cppast/cpp_language_linkage.hpp>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
#include "libclang_visitor.hpp"
|
||||
|
||||
using namespace cppast;
|
||||
|
||||
namespace
|
||||
{
|
||||
cpp_language_linkage::builder make_ll_builder(const detail::parse_context& context,
|
||||
const CXCursor& cur)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::try_parse_cpp_language_linkage(const parse_context& context,
|
||||
const CXCursor& cur)
|
||||
{
|
||||
DEBUG_ASSERT(cur.kind == CXCursor_UnexposedDecl,
|
||||
detail::assert_handler{}); // not exposed currently
|
||||
|
||||
detail::tokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::token_stream stream(tokenizer, cur);
|
||||
|
||||
// extern <name> ...
|
||||
if (!detail::skip_if(stream, "extern"))
|
||||
return nullptr;
|
||||
// unexposed variable starting with extern - must be a language linkage
|
||||
// (function, variables are not unexposed)
|
||||
auto& name = stream.get().value();
|
||||
|
||||
auto builder = cpp_language_linkage::builder(name.c_str());
|
||||
detail::visit_children(cur, [&](const CXCursor& child) {
|
||||
auto entity = parse_entity(context, child);
|
||||
if (entity)
|
||||
builder.add_child(std::move(entity));
|
||||
});
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
#include "parse_functions.hpp"
|
||||
|
||||
#include <cppast/cpp_namespace.hpp>
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
#include "libclang_visitor.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
|
|||
auto kind = clang_getCursorKind(cur);
|
||||
switch (kind)
|
||||
{
|
||||
case CXCursor_UnexposedDecl:
|
||||
// go through all the try_parse_XXX functions
|
||||
if (auto entity = try_parse_cpp_language_linkage(context, cur))
|
||||
return std::move(entity);
|
||||
break;
|
||||
|
||||
case CXCursor_Namespace:
|
||||
return parse_cpp_namespace(context, cur);
|
||||
case CXCursor_NamespaceAlias:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,14 @@ namespace cppast
|
|||
type_safe::object_ref<const cpp_entity_index> idx;
|
||||
};
|
||||
|
||||
// parse_entity() dispatches on the cursor type
|
||||
// it calls one of the other parse functions defined elsewhere
|
||||
// try_parse_XXX are not exposed entities
|
||||
// they are called on an unexposed cursor and see whether they match
|
||||
|
||||
std::unique_ptr<cpp_entity> try_parse_cpp_language_linkage(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,
|
||||
|
|
|
|||
12
test/cpp_language_linkage.cpp
Normal file
12
test/cpp_language_linkage.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
|
||||
// This file is subject to the license terms in the LICENSE file
|
||||
// found in the top-level directory of this distribution.
|
||||
|
||||
#include "test_parser.hpp"
|
||||
|
||||
using namespace cppast;
|
||||
|
||||
TEST_CASE("cpp_language_linkage")
|
||||
{
|
||||
// TODO: need actual entities to parse
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue