-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDimetaData.h
140 lines (121 loc) · 3.08 KB
/
DimetaData.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// llvm-dimeta library
// Copyright (c) 2022-2025 llvm-dimeta authors
// Distributed under the BSD 3-Clause license.
// (See accompanying file LICENSE)
// SPDX-License-Identifier: BSD-3-Clause
//
#ifndef DIMETA_DIMETADATA_H
#define DIMETA_DIMETADATA_H
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <variant>
#include <vector>
namespace dimeta {
using Extent = std::uint64_t;
using Offset = std::uint64_t;
using ArraySize = std::uint64_t;
enum class Qualifier {
kNone = 0x0,
kConst = 0x1,
kPtr = 0x2,
kRef = 0x4,
kPtrToMember = 0x8,
kArray = 0x10,
kVector = 0x20
};
struct Member;
struct BaseClass;
using Members = std::vector<std::shared_ptr<Member>>;
using Bases = std::vector<std::shared_ptr<BaseClass>>;
using Offsets = std::vector<Offset>;
using Sizes = std::vector<Extent>;
using Qualifiers = std::vector<Qualifier>;
using ArraySizeList = std::vector<ArraySize>;
struct CompoundType {
// struct, union, class etc.
enum Tag {
kUnknown = 0x0,
kStruct = 0x1,
kClass = 0x2,
kUnion = 0x4,
kEnum = 0x8,
kEnumClass = 0x10,
};
std::string name;
std::string identifier;
Tag type;
Extent extent;
Offsets offsets;
Sizes sizes;
// Mapping: Base -> Compound
Bases bases;
// Mapping: Member -> name, QualType<[Compound, FundamentalType, (Padding)]>
Members members;
};
struct FundamentalType {
// int, double etc.
enum Encoding {
kUnknown = 0,
kFloat = 1 << 0,
kChar = 1 << 1,
kInt = 1 << 2,
kSigned = 1 << 3,
kUnsigned = 1 << 4,
kBool = 1 << 5,
kPadding = 1 << 6,
kVoid = 1 << 7,
kVtablePtr = 1 << 8,
kNullptr = 1 << 9,
kUTFChar = 1 << 10,
kComplex = 1 << 11,
kSignedChar = kChar | kSigned,
kUnsignedChar = kChar | kUnsigned,
kSignedInt = kInt | kSigned,
kUnsignedInt = kInt | kUnsigned,
};
std::string name;
Extent extent;
Encoding encoding{Encoding::kUnknown};
};
template <typename T>
struct QualType {
T type{};
ArraySizeList array_size;
Qualifiers qual;
std::string typedef_name;
Extent vector_size{0};
bool is_vector{false};
bool is_forward_decl{false};
bool is_recurring{false};
};
using QualifiedFundamental = QualType<FundamentalType>;
using QualifiedCompound = QualType<CompoundType>;
using QualifiedType = std::variant<QualifiedCompound, QualifiedFundamental>;
using QualifiedTypeList = std::vector<QualifiedType>;
struct CompileUnitTypes {
std::string name;
QualifiedTypeList types;
};
using CompileUnitTypeList = std::vector<CompileUnitTypes>;
struct BaseClass {
QualifiedCompound base{};
};
struct Member {
std::string name;
QualifiedType member;
};
namespace location {
struct SourceLocation {
std::string file;
std::string function;
unsigned line{};
};
} // namespace location
struct LocatedType {
QualifiedType type;
location::SourceLocation location;
};
} // namespace dimeta
#endif // DIMETA_DIMETADATA_H