-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcpp_enum.h
More file actions
122 lines (102 loc) · 2.53 KB
/
Copy pathcpp_enum.h
File metadata and controls
122 lines (102 loc) · 2.53 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (C) 2022 Satya Das and CppParser contributors
// SPDX-License-Identifier: MIT
#ifndef F8BEE2E4_A22C_446D_9225_A5B383798075
#define F8BEE2E4_A22C_446D_9225_A5B383798075
#include "cppast/cpp_entity.h"
#include "cppast/cpp_expression.h"
#include <list>
#include <memory>
#include <string>
namespace cppast {
class CppEntity;
class CppExpression;
/**
* @brief Anything that appears inside enum declaration.
*
* Inside an enum definition there can also be enitities other than constant definitions, e.g. comments, and
* proprocessors.
*/
class CppEnumItem
{
public:
CppEnumItem(std::string name, std::unique_ptr<CppExpression> val = nullptr);
CppEnumItem(std::unique_ptr<CppEntity> nonConstEntity);
public:
const std::string& name() const
{
return name_;
}
/**
* @brief Value of the enum constant.
*
* @return nullptr iff the value of the constant is not set.
*/
const CppExpression* val() const
{
return val_.get();
}
/**
* @brief Non const enum item entity.
*
* @return nullptr iff the enum item is a constant definition.
*/
const CppEntity* nonConstEntity() const
{
return nonConstEntity_.get();
}
/**
* @return true iif the enum item is the definition of a constant.
*/
bool isNonConstEntity() const
{
return nonConstEntity_ != nullptr;
}
private:
std::string name_;
std::unique_ptr<CppExpression> val_;
std::unique_ptr<CppEntity> nonConstEntity_;
};
class CppEnum : public CppEntity
{
public:
static constexpr auto EntityType()
{
return CppEntityType::ENUM;
}
public:
CppEnum(std::string name,
std::list<CppEnumItem> itemList,
bool isClass = false,
std::string underlyingType = std::string())
: CppEntity(EntityType())
, name_(std::move(name))
, itemList_(std::move(itemList))
, isClass_(isClass)
, underlyingType_(std::move(underlyingType))
{
}
public:
const std::string& name() const
{
return name_;
}
const std::list<CppEnumItem>& itemList() const
{
return itemList_;
}
bool isClass() const
{
return isClass_;
}
const std::string& underlyingType() const
{
return underlyingType_;
}
private:
std::string name_; // Can be empty for anonymous enum.
std::list<CppEnumItem> itemList_; // Can be nullptr for forward declared enum.
bool isClass_;
std::string underlyingType_;
};
} // namespace cppast
#endif /* F8BEE2E4_A22C_446D_9225_A5B383798075 */