Add cpp_member_variable and cpp_bitfield

This commit is contained in:
Jonathan Müller 2017-01-24 20:47:50 +01:00
commit d2b5a79ba2
5 changed files with 108 additions and 0 deletions

View file

@ -31,6 +31,8 @@ namespace cppast
base_class_t,
variable_t,
member_variable_t,
bitfield_t,
function_parameter_t,
function_t,

View file

@ -0,0 +1,79 @@
// 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_MEMBER_VARIABLE_HPP_INCLUDED
#define CPPAST_CPP_MEMBER_VARIABLE_HPP_INCLUDED
#include <cppast/cpp_variable_base.hpp>
namespace cppast
{
/// Base class for all kinds of member variables.
class cpp_member_variable_base : public cpp_variable_base
{
public:
/// \returns Whether or not the member variable is declared `mutable`.
bool is_mutable() const noexcept
{
return mutable_;
}
protected:
cpp_member_variable_base(std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, bool is_mutable)
: cpp_variable_base(std::move(name), std::move(type), std::move(def)), mutable_(is_mutable)
{
}
private:
bool mutable_;
};
/// A [cppast::cpp_entity]() modelling a C++ member variable.
class cpp_member_variable final : public cpp_member_variable_base
{
public:
/// \returns A newly created and registered member variable.
/// \notes `def` may be `nullptr` in which case there is no member initializer provided.
static std::unique_ptr<cpp_member_variable> build(std::string name,
std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def,
bool is_mutable)
{
return std::unique_ptr<cpp_member_variable>(
new cpp_member_variable(std::move(name), std::move(type), std::move(def),
is_mutable));
}
private:
using cpp_member_variable_base::cpp_member_variable_base;
cpp_entity_kind do_get_entity_kind() const noexcept override;
};
/// A [cppast::cpp_entity]() modelling a C++ bitfield.
class cpp_bitfield final : public cpp_member_variable_base
{
public:
/// \returns The number of bits of the bitfield.
unsigned no_bits() const noexcept
{
return bits_;
}
private:
cpp_bitfield(std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, unsigned no_bits, bool is_mutable)
: cpp_member_variable_base(std::move(name), std::move(type), std::move(def), is_mutable),
bits_(no_bits)
{
}
cpp_entity_kind do_get_entity_kind() const noexcept override;
unsigned bits_;
};
} // namespace cppast
#endif // CPPAST_CPP_MEMBER_VARIABLE_HPP_INCLUDED