forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_member_variable.hpp
More file actions
90 lines (73 loc) · 3.27 KB
/
Copy pathcpp_member_variable.hpp
File metadata and controls
90 lines (73 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
// 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_entity.hpp>
#include <cppast/cpp_variable_base.hpp>
namespace cppast
{
/// Base class for all kinds of member variables.
class cpp_member_variable_base : public cpp_entity, 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_entity(std::move(name)), cpp_variable_base(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:
static cpp_entity_kind kind() noexcept;
/// \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(const cpp_entity_index& idx, cpp_entity_id id,
std::string name,
std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def,
bool 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:
static cpp_entity_kind kind() noexcept;
/// \returns A newly created and registered bitfield.
/// \notes It cannot have a member initializer, i.e. default value.
static std::unique_ptr<cpp_bitfield> build(const cpp_entity_index& idx, cpp_entity_id id,
std::string name, std::unique_ptr<cpp_type> type,
unsigned no_bits, bool is_mutable);
/// \returns A newly created unnamed bitfield.
/// \notes It will not be registered, as it is unnamed.
static std::unique_ptr<cpp_bitfield> build(std::unique_ptr<cpp_type> type, unsigned no_bits,
bool is_mutable);
/// \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, unsigned no_bits,
bool is_mutable)
: cpp_member_variable_base(std::move(name), std::move(type), nullptr, 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