From 78157d43fc49e8b45ef7c47523b25e1659835b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Sun, 5 Feb 2017 22:03:57 +0100 Subject: [PATCH] Add cpp_variable_template --- include/cppast/cpp_entity_kind.hpp | 1 + include/cppast/cpp_variable_template.hpp | 42 ++++++++++++++++++++++++ src/cpp_entity_kind.cpp | 4 +++ src/cpp_variable_template.cpp | 14 ++++++++ src/visitor.cpp | 3 ++ 5 files changed, 64 insertions(+) create mode 100644 include/cppast/cpp_variable_template.hpp create mode 100644 src/cpp_variable_template.cpp diff --git a/include/cppast/cpp_entity_kind.hpp b/include/cppast/cpp_entity_kind.hpp index 1a66bb4..2eef2e8 100644 --- a/include/cppast/cpp_entity_kind.hpp +++ b/include/cppast/cpp_entity_kind.hpp @@ -46,6 +46,7 @@ namespace cppast template_template_parameter_t, alias_template_t, + variable_template_t, function_template_t, function_template_specialization_t, class_template_t, diff --git a/include/cppast/cpp_variable_template.hpp b/include/cppast/cpp_variable_template.hpp new file mode 100644 index 0000000..af00c7e --- /dev/null +++ b/include/cppast/cpp_variable_template.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#ifndef CPPAST_CPP_VARIABLE_TEMPLATE_HPP_INCLUDED +#define CPPAST_CPP_VARIABLE_TEMPLATE_HPP_INCLUDED + +#include +#include + +namespace cppast +{ + /// A [cppast::cpp_entity]() modelling a C++ alias template. + class cpp_variable_template final : public cpp_template + { + public: + /// Builder for [cppast::cpp_variable_template](). + class builder : public basic_builder + { + public: + using basic_builder::basic_builder; + }; + + /// \returns A reference to the type variable that is being templated. + const cpp_variable& variable() const noexcept + { + return static_cast(*begin()); + } + + private: + cpp_variable_template(std::unique_ptr variable) + : cpp_template(std::unique_ptr(variable.release())) + { + } + + cpp_entity_kind do_get_entity_kind() const noexcept override; + + friend basic_builder; + }; +} // namespace cppast + +#endif // CPPAST_CPP_VARIABLE_TEMPLATE_HPP_INCLUDED diff --git a/src/cpp_entity_kind.cpp b/src/cpp_entity_kind.cpp index a0d033d..91aeab4 100644 --- a/src/cpp_entity_kind.cpp +++ b/src/cpp_entity_kind.cpp @@ -69,6 +69,8 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept case cpp_entity_kind::alias_template_t: return "alias template"; + case cpp_entity_kind::variable_template_t: + return "variable template"; case cpp_entity_kind::function_template_t: return "function template"; case cpp_entity_kind::function_template_specialization_t: @@ -116,6 +118,7 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept case cpp_entity_kind::non_type_template_parameter_t: case cpp_entity_kind::template_template_parameter_t: case cpp_entity_kind::alias_template_t: + case cpp_entity_kind::variable_template_t: case cpp_entity_kind::function_template_t: case cpp_entity_kind::function_template_specialization_t: case cpp_entity_kind::class_template_t: @@ -132,6 +135,7 @@ bool cppast::is_template(cpp_entity_kind kind) noexcept switch (kind) { case cpp_entity_kind::alias_template_t: + case cpp_entity_kind::variable_template_t: case cpp_entity_kind::function_template_t: case cpp_entity_kind::function_template_specialization_t: case cpp_entity_kind::class_template_t: diff --git a/src/cpp_variable_template.cpp b/src/cpp_variable_template.cpp new file mode 100644 index 0000000..7268cdc --- /dev/null +++ b/src/cpp_variable_template.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#include + +#include + +using namespace cppast; + +cpp_entity_kind cpp_variable_template::do_get_entity_kind() const noexcept +{ + return cpp_entity_kind::variable_template_t; +} diff --git a/src/visitor.cpp b/src/visitor.cpp index 7ec3193..73f9ddd 100644 --- a/src/visitor.cpp +++ b/src/visitor.cpp @@ -17,6 +17,7 @@ #include #include #include +#include using namespace cppast; @@ -65,6 +66,8 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun return handle_container(e, cb, functor); case cpp_entity_kind::alias_template_t: return handle_container(e, cb, functor); + case cpp_entity_kind::variable_template_t: + return handle_container(e, cb, functor); case cpp_entity_kind::function_template_t: return handle_container(e, cb, functor); case cpp_entity_kind::function_template_specialization_t: