Add cpp_type_alias
This commit is contained in:
parent
c14e4dca40
commit
eedc029e66
10 changed files with 96 additions and 14 deletions
|
|
@ -12,6 +12,8 @@
|
|||
namespace cppast
|
||||
{
|
||||
enum class cpp_entity_kind;
|
||||
class cpp_entity_index;
|
||||
struct cpp_entity_id;
|
||||
|
||||
/// The base class for all entities in the C++ AST.
|
||||
class cpp_entity : detail::intrusive_list_node<cpp_entity>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ namespace cppast
|
|||
using_directive_t,
|
||||
using_declaration_t,
|
||||
|
||||
type_alias_t,
|
||||
|
||||
enum_t,
|
||||
enum_value_t,
|
||||
|
||||
|
|
|
|||
|
|
@ -25,13 +25,7 @@ namespace cppast
|
|||
/// \notes `value` may be `nullptr`, in which case the enum has an implicit value.
|
||||
static std::unique_ptr<cpp_enum_value> build(
|
||||
const cpp_entity_index& idx, cpp_entity_id id, std::string name,
|
||||
std::unique_ptr<cpp_expression> value = nullptr)
|
||||
{
|
||||
auto result = std::unique_ptr<cpp_enum_value>(
|
||||
new cpp_enum_value(std::move(name), std::move(value)));
|
||||
idx.register_entity(std::move(id), type_safe::ref(*result));
|
||||
return result;
|
||||
}
|
||||
std::unique_ptr<cpp_expression> value = nullptr);
|
||||
|
||||
/// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the enum value.
|
||||
/// \notes It only has an associated expression if the value is explictly given.
|
||||
|
|
|
|||
|
|
@ -90,13 +90,7 @@ namespace cppast
|
|||
/// \returns A newly created and registered namespace alias.
|
||||
static std::unique_ptr<cpp_namespace_alias> build(const cpp_entity_index& idx,
|
||||
cpp_entity_id id, std::string name,
|
||||
cpp_namespace_ref target)
|
||||
{
|
||||
auto ptr = std::unique_ptr<cpp_namespace_alias>(
|
||||
new cpp_namespace_alias(std::move(name), std::move(target)));
|
||||
idx.register_entity(std::move(id), type_safe::ref(*ptr));
|
||||
return ptr;
|
||||
}
|
||||
cpp_namespace_ref target);
|
||||
|
||||
/// \returns The [cppast::cpp_namespace_ref]() to the aliased namespace.
|
||||
const cpp_namespace_ref& target() const noexcept
|
||||
|
|
|
|||
24
include/cppast/cpp_type_alias.cpp
Normal file
24
include/cppast/cpp_type_alias.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// 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_type_alias.hpp>
|
||||
|
||||
#include <cppast/cpp_entity_kind.hpp>
|
||||
|
||||
using namespace cppast;
|
||||
|
||||
std::unique_ptr<cpp_type_alias> cpp_type_alias::build(const cpp_entity_index& idx, cpp_entity_id id,
|
||||
std::string name,
|
||||
std::unique_ptr<cpp_type> type)
|
||||
{
|
||||
auto result =
|
||||
std::unique_ptr<cpp_type_alias>(new cpp_type_alias(std::move(name), std::move(type)));
|
||||
idx.register_entity(std::move(id), type_safe::cref(*result));
|
||||
return result;
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_type_alias::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return cpp_entity_kind::type_alias_t;
|
||||
}
|
||||
41
include/cppast/cpp_type_alias.hpp
Normal file
41
include/cppast/cpp_type_alias.hpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// 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_TYPE_ALIAS_HPP_INCLUDED
|
||||
#define CPPAST_CPP_TYPE_ALIAS_HPP_INCLUDED
|
||||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_type.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// A [cppast::cpp_entity]() modelling a type alias/typedef.
|
||||
/// \notes There is no distinction between `using` and `typedef` type aliases made in the AST.
|
||||
class cpp_type_alias final : public cpp_entity
|
||||
{
|
||||
public:
|
||||
/// \returns A newly created and registered type alias.
|
||||
static std::unique_ptr<cpp_type_alias> build(const cpp_entity_index& idx, cpp_entity_id id,
|
||||
std::string name,
|
||||
std::unique_ptr<cpp_type> type);
|
||||
|
||||
/// \returns A reference to the aliased [cppast::cpp_type]().
|
||||
const cpp_type& underlying_type() const noexcept
|
||||
{
|
||||
return *type_;
|
||||
}
|
||||
|
||||
private:
|
||||
cpp_type_alias(std::string name, std::unique_ptr<cpp_type> type)
|
||||
: cpp_entity(std::move(name)), type_(std::move(type))
|
||||
{
|
||||
}
|
||||
|
||||
cpp_entity_kind do_get_entity_kind() const noexcept override;
|
||||
|
||||
std::unique_ptr<cpp_type> type_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_TYPE_ALIAS_HPP_INCLUDED
|
||||
Loading…
Add table
Add a link
Reference in a new issue