-
Notifications
You must be signed in to change notification settings - Fork 71
/
Meta.h
123 lines (108 loc) · 3.46 KB
/
Meta.h
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
#pragma once
#include <vector>
#include <string_view>
#include <string>
namespace Ubpa::USRefl {
struct Attr {
std::string ns;
std::string name;
std::string value;
// ns::name
// name
std::string GenerateName(bool withoutQuatation) const;
std::string GenerateValue(bool toFunction) const;
std::string GenerateValue(const std::string& type) const;
};
enum class AccessSpecifier {
PUBLIC,
PROTECTED,
PRIVATE,
DEFAULT
};
using DeclSpecifier = std::string;
struct Parameter {
//std::vector<Attr> attrs;
bool isPacked{ false };
std::string type; // typename, class, ...
std::string name;
std::string initializer; // expression or {expression}
// type[...]
std::string GenerateTypeName() const;
// type[...] name
std::string GenerateParameterName() const;
// name[...]
std::string GenerateArgumentName() const;
};
struct Field {
enum class Mode {
Variable,
Function,
Value // enum, static constepxr
};
Mode mode{ Mode::Variable };
AccessSpecifier accessSpecifier{ AccessSpecifier::PRIVATE };
std::vector<Attr> attrs;
std::vector<DeclSpecifier> declSpecifiers;
std::vector<std::string> pointerOperators; // *, &, &&
std::string name;
std::string initializer; // expression or {expression}
std::vector<Parameter> parameters;
std::vector<std::string> qualifiers; // const, volatile, &, &&
bool isTemplate{ false };
void Clear();
bool IsStaticConstexprVariable() const;
// declSpecifiers + pointerOperators
std::string GenerateFieldType() const;
// typeSpecifier + pointerOperators
std::string GenerateSimpleFieldType() const;
// Mode::Function && contains 'static' && !friend
bool IsMemberFunction() const;
bool IsFriendFunction() const;
bool IsDeletedFunction() const;
// arg_type0, arg_type1, ..., arg_typeN
std::string GenerateParamTypeList() const;
// arg_type0, arg_type1, ..., arg_type(num-1)
std::string GenerateParamTypeList(std::size_t num) const;
std::string GenerateFunctionType(std::string_view obj) const;
std::string GenerateInitFunction() const;
std::size_t GetDefaultParameterNum() const;
// arg_type0 arg_name0, arg_type1 arg_name1, ..., arg_type(num-1) arg_name(num-1)
std::string GenerateNamedParameterList(std::size_t num) const;
// std::forward<arg_type0>(arg_name0), std::forward<arg_type0>(arg_name1), ..., std::forward<arg_type0>(arg_name(num-1))
std::string GenerateForwardArgumentList(std::size_t num) const;
std::string GenerateQualifiers() const;
};
struct Base {
// Base<name[, true]>[...]
std::string GenerateText() const;
AccessSpecifier accessSpecifier{ AccessSpecifier::DEFAULT };
std::string name;
bool isVirtual{ false };
bool isPacked{ false };
};
struct TypeMeta {
enum class Mode {
Class,
Struct,
Enum
};
Mode mode{ Mode::Class };
std::vector<std::string> namespaces;
std::vector<Parameter> templateParameters;
std::vector<Attr> attrs;
std::string name;
std::vector<Base> bases;
std::vector<Field> fields;
bool IsTemplateType() const noexcept { return !templateParameters.empty(); }
// namespaces + name
std::string GenerateNsName() const;
// namespaces + name + template
std::string GenerateFullName() const;
// templateParameter_0, templateParameter_1, ..., templateParameter_N
std::string GenerateTemplateList() const;
std::vector<std::size_t> GetPublicBaseIndices() const;
bool IsOverloaded(std::string_view name) const;
// public, non-friend, non-delete
bool HaveAnyOutputField() const;
};
}