forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_variable.hpp
More file actions
68 lines (57 loc) · 2.7 KB
/
Copy pathcpp_variable.hpp
File metadata and controls
68 lines (57 loc) · 2.7 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
// Copyright (C) 2017-2023 Jonathan Müller and cppast contributors
// SPDX-License-Identifier: MIT
#ifndef CPPAST_CPP_VARIABLE_HPP_INCLUDED
#define CPPAST_CPP_VARIABLE_HPP_INCLUDED
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_forward_declarable.hpp>
#include <cppast/cpp_storage_class_specifiers.hpp>
#include <cppast/cpp_variable_base.hpp>
namespace cppast
{
/// A [cppast::cpp_entity]() modelling a C++ variable.
/// \notes This is not a member variable,
/// use [cppast::cpp_member_variable]() for that.
/// But it can be `static` member variable.
class cpp_variable final : public cpp_entity,
public cpp_variable_base,
public cpp_forward_declarable
{
public:
static cpp_entity_kind kind() noexcept;
/// \returns A newly created and registered variable.
/// \notes The default value may be `nullptr` indicating no default value.
static std::unique_ptr<cpp_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,
cpp_storage_class_specifiers spec, bool is_constexpr,
type_safe::optional<cpp_entity_ref> semantic_parent
= {});
/// \returns A newly created variable that is a declaration.
/// A declaration will not be registered and it does not have the default value.
static std::unique_ptr<cpp_variable> build_declaration(
cpp_entity_id definition_id, std::string name, std::unique_ptr<cpp_type> type,
cpp_storage_class_specifiers spec, bool is_constexpr,
type_safe::optional<cpp_entity_ref> semantic_parent = {});
/// \returns The [cppast::cpp_storage_specifiers]() on that variable.
cpp_storage_class_specifiers storage_class() const noexcept
{
return storage_;
}
/// \returns Whether the variable is marked `constexpr`.
bool is_constexpr() const noexcept
{
return is_constexpr_;
}
private:
cpp_variable(std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, cpp_storage_class_specifiers spec,
bool is_constexpr)
: cpp_entity(std::move(name)), cpp_variable_base(std::move(type), std::move(def)),
storage_(spec), is_constexpr_(is_constexpr)
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_storage_class_specifiers storage_;
bool is_constexpr_;
};
} // namespace cppast
#endif // CPPAST_CPP_VARIABLE_HPP_INCLUDED