Add cpp_alias_template
This commit is contained in:
parent
67a1b01efc
commit
f75776df33
6 changed files with 139 additions and 0 deletions
40
include/cppast/cpp_alias_template.hpp
Normal file
40
include/cppast/cpp_alias_template.hpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// 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_ALIAS_TEMPLATE_HPP_INCLUDED
|
||||
#define CPPAST_CPP_ALIAS_TEMPLATE_HPP_INCLUDED
|
||||
|
||||
#include <cppast/cpp_template.hpp>
|
||||
#include <cppast/cpp_type_alias.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// A [cppast::cpp_entity]() modelling a C++ alias template.
|
||||
class cpp_alias_template final : public cpp_template
|
||||
{
|
||||
public:
|
||||
/// Builder for [cppast::cpp_alias_template]().
|
||||
class builder : public basic_builder<cpp_alias_template, cpp_type_alias>
|
||||
{
|
||||
public:
|
||||
using basic_builder::basic_builder;
|
||||
};
|
||||
|
||||
/// \returns A reference to the type alias that is being templated.
|
||||
const cpp_type_alias& type_alias() const noexcept
|
||||
{
|
||||
return static_cast<const cpp_type_alias&>(*begin());
|
||||
}
|
||||
|
||||
private:
|
||||
cpp_alias_template(std::string name, std::unique_ptr<cpp_type_alias> alias)
|
||||
: cpp_template(std::move(name), std::unique_ptr<cpp_entity>(alias.release()))
|
||||
{
|
||||
}
|
||||
|
||||
cpp_entity_kind do_get_entity_kind() const noexcept override;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_ALIAS_TEMPLATE_HPP_INCLUDED
|
||||
|
|
@ -44,6 +44,8 @@ namespace cppast
|
|||
template_type_parameter_t,
|
||||
non_type_template_parameter_t,
|
||||
|
||||
alias_template_t,
|
||||
|
||||
count,
|
||||
};
|
||||
|
||||
|
|
|
|||
76
include/cppast/cpp_template.hpp
Normal file
76
include/cppast/cpp_template.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_TEMPLATE_HPP_INCLUDED
|
||||
#define CPPAST_CPP_TEMPLATE_HPP_INCLUDED
|
||||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_entity_container.hpp>
|
||||
#include <cppast/cpp_template_parameter.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// Base class for all entities modelling a C++ template of some kind.
|
||||
///
|
||||
/// It is a container of a single [cppast::cpp_entity]() that is the entity being templated.
|
||||
class cpp_template : public cpp_entity, public cpp_entity_container<cpp_template, cpp_entity>
|
||||
{
|
||||
public:
|
||||
/// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]() entities.
|
||||
/// \notes These may be empty for a full specialization.
|
||||
detail::iteratable_intrusive_list<cpp_template_parameter> parameter_types() const noexcept
|
||||
{
|
||||
return type_safe::ref(parameters_);
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Builder class for templates.
|
||||
///
|
||||
/// Inherit from it to provide additional setter.
|
||||
template <typename T, typename EntityT>
|
||||
class basic_builder
|
||||
{
|
||||
public:
|
||||
/// \effects Sets the name and the entity that is begin templated.
|
||||
basic_builder(std::string name, std::unique_ptr<EntityT> templ)
|
||||
: template_entity(new T(name, std::move(templ)))
|
||||
{
|
||||
}
|
||||
|
||||
/// \effects Adds a parameter.
|
||||
void add_parameter(std::unique_ptr<cpp_template_parameter> parameter)
|
||||
{
|
||||
static_cast<cpp_template&>(*template_entity)
|
||||
.parameters_.push_back(*template_entity, std::move(parameter));
|
||||
}
|
||||
|
||||
/// \effects Registers the template.
|
||||
/// \returns The finished template.
|
||||
std::unique_ptr<T> finish(const cpp_entity_index& idx, cpp_entity_id id)
|
||||
{
|
||||
idx.register_entity(std::move(id), type_safe::cref(*template_entity));
|
||||
return std::move(template_entity);
|
||||
}
|
||||
|
||||
protected:
|
||||
basic_builder() = default;
|
||||
~basic_builder() noexcept = default;
|
||||
|
||||
std::unique_ptr<T> template_entity;
|
||||
};
|
||||
|
||||
/// \effects Sets the name of the template and the entity to be templated.
|
||||
/// \notes It does not include the parameters.
|
||||
cpp_template(std::string name, std::unique_ptr<cpp_entity> entity)
|
||||
: cpp_entity(std::move(name))
|
||||
{
|
||||
add_child(std::move(entity));
|
||||
}
|
||||
|
||||
private:
|
||||
detail::intrusive_list<cpp_template_parameter> parameters_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_TEMPLATE_HPP_INCLUDED
|
||||
14
src/cpp_alias_template.cpp
Normal file
14
src/cpp_alias_template.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// 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_alias_template.hpp>
|
||||
|
||||
#include <cppast/cpp_entity_kind.hpp>
|
||||
|
||||
using namespace cppast;
|
||||
|
||||
cpp_entity_kind cpp_alias_template::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return cpp_entity_kind::alias_template_t;
|
||||
}
|
||||
|
|
@ -65,6 +65,9 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept
|
|||
case cpp_entity_kind::non_type_template_parameter_t:
|
||||
return "non type template parameter";
|
||||
|
||||
case cpp_entity_kind::alias_template_t:
|
||||
return "alias template";
|
||||
|
||||
case cpp_entity_kind::count:
|
||||
break;
|
||||
}
|
||||
|
|
@ -101,6 +104,7 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept
|
|||
case cpp_entity_kind::destructor_t:
|
||||
case cpp_entity_kind::template_type_parameter_t:
|
||||
case cpp_entity_kind::non_type_template_parameter_t:
|
||||
case cpp_entity_kind::alias_template_t:
|
||||
case cpp_entity_kind::count:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <cppast/visitor.hpp>
|
||||
|
||||
#include <cppast/cpp_alias_template.hpp>
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_entity_kind.hpp>
|
||||
#include <cppast/cpp_class.hpp>
|
||||
|
|
@ -57,6 +58,8 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
|
|||
return handle_container<cpp_conversion_op>(e, cb, functor);
|
||||
case cpp_entity_kind::constructor_t:
|
||||
return handle_container<cpp_constructor>(e, cb, functor);
|
||||
case cpp_entity_kind::alias_template_t:
|
||||
return handle_container<cpp_alias_template>(e, cb, functor);
|
||||
|
||||
case cpp_entity_kind::namespace_alias_t:
|
||||
case cpp_entity_kind::using_directive_t:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue