-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcpp_var.h
More file actions
133 lines (112 loc) · 2.74 KB
/
Copy pathcpp_var.h
File metadata and controls
133 lines (112 loc) · 2.74 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
123
124
125
126
127
128
129
130
131
132
133
// Copyright (C) 2022 Satya Das and CppParser contributors
// SPDX-License-Identifier: MIT
#ifndef C3CE34A1_F1C2_4151_A68B_02D7B83E467E
#define C3CE34A1_F1C2_4151_A68B_02D7B83E467E
#include "cppast/cpp_entity.h"
#include "cppast/cpp_templatable_entity.h"
#include "cppast/cpp_var_decl.h"
namespace cppast {
/**
* Represents C++ variable definition.
* A variable can be global, local or member of a class, namespace, or union.
* It can also be a function parameter.
*/
class CppVar : public CppEntity, public CppTemplatableEntity
{
public:
static constexpr auto EntityType()
{
return CppEntityType::VAR;
}
public:
CppVar(CppVarType* varType, CppVarDecl varDecl)
: CppEntity(EntityType())
, varType_(varType)
, varDecl_(std::move(varDecl))
{
}
CppVar(std::unique_ptr<CppVarType> varType, CppVarDecl varDecl)
: CppEntity(EntityType())
, varType_(std::move(varType))
, varDecl_(std::move(varDecl))
{
}
CppVar(CppFunctionPointer* fptr, CppTypeModifier modifier)
: CppEntity(EntityType())
, varType_(new CppVarType(fptr, modifier))
, varDecl_(std::string())
{
}
void initialize(CppVarInitInfo initInfo)
{
varDecl_.initialize(std::move(initInfo));
}
const CppVarType& varType() const
{
return *varType_;
}
const std::string& name() const
{
return varDecl_.name();
}
std::uint32_t typeAttr() const
{
return varType_->typeAttr();
}
void addAttr(std::uint32_t attr)
{
varType_->addAttr(attr);
}
const CppVarDecl& varDecl() const
{
return varDecl_;
}
bool isInitialized() const
{
return varDecl_.isInitialized();
}
std::optional<CppVarInitializeType> initializeType() const
{
return varDecl_.initializeType();
}
/**
* @brief Gets the value assigned to variable.
*
* @return value assigned to variable.
* @note The returned value can be nullptr.
*/
const CppExpression* assignValue() const
{
return varDecl_.assignValue();
}
const CppExpression* bitField() const
{
return varDecl_.bitField();
}
void bitField(std::unique_ptr<CppExpression> bitFieldArg)
{
varDecl_.bitField(std::move(bitFieldArg));
}
const CppArraySizes& arraySizes() const
{
return varDecl_.arraySizes();
}
void addArraySize(CppExpression* arraySize)
{
varDecl_.addArraySize(arraySize);
}
const std::string& apidecor() const
{
return apidecor_;
}
void apidecor(std::string apidecorArg)
{
apidecor_ = std::move(apidecorArg);
}
private:
std::unique_ptr<CppVarType> varType_;
CppVarDecl varDecl_;
std::string apidecor_; // It holds things like WINAPI, __declspec(dllexport), etc.
};
} // namespace cppast
#endif /* C3CE34A1_F1C2_4151_A68B_02D7B83E467E */