diff --git a/include/cppast/cpp_variable_base.hpp b/include/cppast/cpp_variable_base.hpp new file mode 100644 index 0000000..98b54c4 --- /dev/null +++ b/include/cppast/cpp_variable_base.hpp @@ -0,0 +1,46 @@ +// 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_BASE_HPP_INCLUDED +#define CPPAST_CPP_VARIABLE_BASE_HPP_INCLUDED + +#include +#include +#include + +namespace cppast +{ + /// Base class for all [cppast::cpp_entity]() modelling some kind of variable. + /// + /// Examples are [cppast::cpp_variable]() or [cppast::cpp_function_parameter](), + /// or anything that is name/type/default-value triple. + class cpp_variable_base : public cpp_entity + { + public: + /// \returns A reference to the [cppast::cpp_type]() of the variable. + const cpp_type& type() const noexcept + { + return *type_; + } + + /// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the default value. + type_safe::optional_ref default_value() const noexcept + { + return *default_; + } + + protected: + cpp_variable_base(std::string name, std::unique_ptr type, + std::unique_ptr def) + : cpp_entity(std::move(name)), type_(std::move(type)), default_(std::move(def)) + { + } + + private: + std::unique_ptr type_; + std::unique_ptr default_; + }; +} // namespace cppast + +#endif // CPPAST_CPP_VARIABLE_BASE_HPP_INCLUDED diff --git a/include/cppast/visitor.hpp b/include/cppast/visitor.hpp index 1744392..243a0f5 100644 --- a/include/cppast/visitor.hpp +++ b/include/cppast/visitor.hpp @@ -12,7 +12,7 @@ namespace cppast /// Information about the state of a visit operation. enum class visitor_info { - leave_entity, //< Callback called for a leave entity without children. + leaf_entity, //< Callback called for a leaf entity without children. container_entity_enter, //< Callback called for a container entity before the children. container_entity_exit, //< Callback called for a container entity after the children. diff --git a/include/cppast/cpp_type_alias.cpp b/src/cpp_type_alias.cpp similarity index 100% rename from include/cppast/cpp_type_alias.cpp rename to src/cpp_type_alias.cpp diff --git a/src/visitor.cpp b/src/visitor.cpp index 2a17259..e42e11c 100644 --- a/src/visitor.cpp +++ b/src/visitor.cpp @@ -47,7 +47,7 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun case cpp_entity_kind::using_declaration_t: case cpp_entity_kind::type_alias_t: case cpp_entity_kind::enum_value_t: - return cb(functor, e, visitor_info::leave_entity); + return cb(functor, e, visitor_info::leaf_entity); case cpp_entity_kind::count: break;