Add cpp_language_linkage

This commit is contained in:
Jonathan Müller 2017-01-22 13:17:00 +01:00
commit 160fa1fe64
5 changed files with 83 additions and 0 deletions

View file

@ -14,6 +14,8 @@ namespace cppast
{
file_t,
language_linkage_t,
namespace_t,
namespace_alias_t,
using_directive_t,

View file

@ -0,0 +1,54 @@
// 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.
#ifndef CPPAST_CPP_LANGUAGE_LINKAGE_HPP_INCLUDED
#define CPPAST_CPP_LANGUAGE_LINKAGE_HPP_INCLUDED
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_container.hpp>
namespace cppast
{
/// A [cppast::cpp_entity]() modelling a language linkage.
class cpp_language_linkage final : public cpp_entity,
public cpp_entity_container<cpp_language_linkage, cpp_entity>
{
public:
/// Builds a [cppast::cpp_language_linkage]().
class builder
{
public:
/// \effects Sets the name, that is the kind of language linkage.
explicit builder(std::string name) : linkage_(new cpp_language_linkage(std::move(name)))
{
}
/// \effects Adds an entity to the language linkage.
void add_child(std::unique_ptr<cpp_entity> child)
{
linkage_->add_child(std::move(child));
}
/// \returns The finalized language linkage.
/// \notes It is not registered on purpose as nothing can refer to it.
std::unique_ptr<cpp_language_linkage> finish()
{
return std::move(linkage_);
}
private:
std::unique_ptr<cpp_language_linkage> linkage_;
};
/// \returns `true` if the linkage is a block, `false` otherwise.
bool is_block() const noexcept;
private:
using cpp_entity::cpp_entity;
cpp_entity_kind do_get_entity_kind() const noexcept override;
};
} // namespace cppast
#endif // CPPAST_CPP_LANGUAGE_LINKAGE_HPP_INCLUDED

View file

@ -13,6 +13,9 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept
case cpp_entity_kind::file_t:
return "file";
case cpp_entity_kind::language_linkage_t:
return "language linkage";
case cpp_entity_kind::namespace_t:
return "namespace";
case cpp_entity_kind::namespace_alias_t:
@ -49,6 +52,7 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept
return true;
case cpp_entity_kind::file_t:
case cpp_entity_kind::language_linkage_t:
case cpp_entity_kind::namespace_t:
case cpp_entity_kind::namespace_alias_t:
case cpp_entity_kind::using_directive_t:

View file

@ -0,0 +1,20 @@
// 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 <cppast/cpp_language_linkage.hpp>
#include <cppast/cpp_entity_kind.hpp>
using namespace cppast;
bool cpp_language_linkage::is_block() const noexcept
{
DEBUG_ASSERT(begin() != end(), detail::assert_handler{}, "empty container");
return std::next(begin()) != end(); // more than one entity, so block
}
cpp_entity_kind cpp_language_linkage::do_get_entity_kind() const noexcept
{
return cpp_entity_kind::language_linkage_t;
}

View file

@ -8,6 +8,7 @@
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_enum.hpp>
#include <cppast/cpp_file.hpp>
#include <cppast/cpp_language_linkage.hpp>
#include <cppast/cpp_namespace.hpp>
using namespace cppast;
@ -37,6 +38,8 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
{
case cpp_entity_kind::file_t:
return handle_container<cpp_file>(e, cb, functor);
case cpp_entity_kind::language_linkage_t:
return handle_container<cpp_language_linkage>(e, cb, functor);
case cpp_entity_kind::namespace_t:
return handle_container<cpp_namespace>(e, cb, functor);
case cpp_entity_kind::enum_t: