Add and parse cpp_friend
Only works in clang>=4.
This commit is contained in:
parent
9c46c96820
commit
c3d1d97892
18 changed files with 629 additions and 92 deletions
|
|
@ -44,6 +44,8 @@ namespace cppast
|
|||
constructor_t,
|
||||
destructor_t,
|
||||
|
||||
friend_t,
|
||||
|
||||
template_type_parameter_t,
|
||||
non_type_template_parameter_t,
|
||||
template_template_parameter_t,
|
||||
|
|
|
|||
76
include/cppast/cpp_friend.hpp
Normal file
76
include/cppast/cpp_friend.hpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// 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_FRIEND_HPP_INCLUDED
|
||||
#define CPPAST_CPP_FRIEND_HPP_INCLUDED
|
||||
|
||||
#include <type_safe/optional.hpp>
|
||||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_entity_container.hpp>
|
||||
#include <cppast/cpp_type.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// A [cppast::cpp_entity]() representing a friend declaration.
|
||||
///
|
||||
/// It can either declare or define a `friend` function (template), declare a `friend` class,
|
||||
/// or refer to an existing type.
|
||||
class cpp_friend : public cpp_entity, private cpp_entity_container<cpp_friend, cpp_entity>
|
||||
{
|
||||
public:
|
||||
static cpp_entity_kind kind() noexcept;
|
||||
|
||||
/// \returns A newly created friend declaring the given entity as `friend`.
|
||||
/// \notes The friend declaration itself will not be registered,
|
||||
/// but the referring entity is.
|
||||
static std::unique_ptr<cpp_friend> build(std::unique_ptr<cpp_entity> e)
|
||||
{
|
||||
return std::unique_ptr<cpp_friend>(new cpp_friend(std::move(e)));
|
||||
}
|
||||
|
||||
/// \returns A newly created friend declaring the given type as `friend`.
|
||||
/// \notes It will not be registered.
|
||||
static std::unique_ptr<cpp_friend> build(std::unique_ptr<cpp_type> type)
|
||||
{
|
||||
return std::unique_ptr<cpp_friend>(new cpp_friend(std::move(type)));
|
||||
}
|
||||
|
||||
/// \returns An optional reference to the entity it declares as friend, or `nullptr`.
|
||||
type_safe::optional_ref<const cpp_entity> entity() const noexcept
|
||||
{
|
||||
if (begin() == end())
|
||||
return nullptr;
|
||||
return type_safe::ref(*begin());
|
||||
}
|
||||
|
||||
/// \returns An optional reference to the type it declares as friend, or `nullptr`.
|
||||
type_safe::optional_ref<const cpp_type> type() const noexcept
|
||||
{
|
||||
return type_safe::opt_ref(type_.get());
|
||||
}
|
||||
|
||||
private:
|
||||
cpp_friend(std::unique_ptr<cpp_entity> e) : cpp_entity("")
|
||||
{
|
||||
add_child(std::move(e));
|
||||
}
|
||||
|
||||
cpp_friend(std::unique_ptr<cpp_type> type) : cpp_entity(""), type_(std::move(type))
|
||||
{
|
||||
}
|
||||
|
||||
cpp_entity_kind do_get_entity_kind() const noexcept override;
|
||||
|
||||
std::unique_ptr<cpp_type> type_;
|
||||
|
||||
friend cpp_entity_container<cpp_friend, cpp_entity>;
|
||||
};
|
||||
|
||||
/// \returns Whether or not the given entity is "friended",
|
||||
/// that is, its declaration exists as part of a [cppast::cpp_friend]() declaration.
|
||||
bool is_friended(const cpp_entity& e) noexcept;
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_FRIEND_HPP_INCLUDED
|
||||
|
|
@ -147,8 +147,10 @@ namespace cppast
|
|||
|
||||
/// \returns The finished function without registering it.
|
||||
/// \notes This is intended for templated functions only.
|
||||
std::unique_ptr<T> finish(cpp_function_body_kind body_kind)
|
||||
std::unique_ptr<T> finish(cpp_entity_id id, cpp_function_body_kind body_kind)
|
||||
{
|
||||
if (!cppast::is_definition(body_kind))
|
||||
function->set_definition(id);
|
||||
function->body_ = body_kind;
|
||||
return std::move(function);
|
||||
}
|
||||
|
|
@ -174,8 +176,7 @@ namespace cppast
|
|||
/// A [cppast::cpp_entity]() modelling a C++ function.
|
||||
/// \notes This is not a member function,
|
||||
/// use [cppast::cpp_member_function]() for that.
|
||||
/// It can be a `static` function of a class,
|
||||
/// or a `friend`, however.
|
||||
/// It can be a `static` function of a class, however.
|
||||
class cpp_function final : public cpp_function_base
|
||||
{
|
||||
public:
|
||||
|
|
@ -203,12 +204,6 @@ namespace cppast
|
|||
{
|
||||
function->constexpr_ = true;
|
||||
}
|
||||
|
||||
/// \effects Marks the function as `friend`.
|
||||
void is_friend()
|
||||
{
|
||||
function->friend_ = true;
|
||||
}
|
||||
};
|
||||
|
||||
/// \returns A reference to the return [cppast::cpp_type]().
|
||||
|
|
@ -231,12 +226,6 @@ namespace cppast
|
|||
return constexpr_;
|
||||
}
|
||||
|
||||
/// \returns Whether the function is a `friend` function of the parent [cppast::cpp_class]().
|
||||
bool is_friend() const noexcept
|
||||
{
|
||||
return friend_;
|
||||
}
|
||||
|
||||
private:
|
||||
cpp_entity_kind do_get_entity_kind() const noexcept override;
|
||||
|
||||
|
|
@ -244,14 +233,12 @@ namespace cppast
|
|||
: cpp_function_base(std::move(name)),
|
||||
return_type_(std::move(ret)),
|
||||
storage_(cpp_storage_class_auto),
|
||||
friend_(false),
|
||||
constexpr_(false)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_type> return_type_;
|
||||
cpp_storage_class_specifiers storage_;
|
||||
bool friend_;
|
||||
bool constexpr_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace cppast
|
|||
if (entity)
|
||||
result += " (" + entity.value() + "):";
|
||||
}
|
||||
else if (entity)
|
||||
else if (entity && !entity.value().empty())
|
||||
result += entity.value() + ":";
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue