Add cpp_variable_base
This commit is contained in:
parent
eedc029e66
commit
4b69e823c8
4 changed files with 48 additions and 2 deletions
|
|
@ -1,24 +0,0 @@
|
|||
// 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;
|
||||
}
|
||||
46
include/cppast/cpp_variable_base.hpp
Normal file
46
include/cppast/cpp_variable_base.hpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// 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_VARIABLE_BASE_HPP_INCLUDED
|
||||
#define CPPAST_CPP_VARIABLE_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_expression.hpp>
|
||||
#include <cppast/cpp_type.hpp>
|
||||
|
||||
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<const cpp_expression> default_value() const noexcept
|
||||
{
|
||||
return *default_;
|
||||
}
|
||||
|
||||
protected:
|
||||
cpp_variable_base(std::string name, std::unique_ptr<cpp_type> type,
|
||||
std::unique_ptr<cpp_expression> def)
|
||||
: cpp_entity(std::move(name)), type_(std::move(type)), default_(std::move(def))
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<cpp_type> type_;
|
||||
std::unique_ptr<cpp_expression> default_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_VARIABLE_BASE_HPP_INCLUDED
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue