Repository navigation
Expand file tree
/
Copy pathMetadataEntry.cpp
More file actions
137 lines (102 loc) · 3.63 KB
/
Copy pathMetadataEntry.cpp
File metadata and controls
137 lines (102 loc) · 3.63 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
134
135
136
137
#include "MetadataNode.h"
#include "MetadataEntry.h"
#include "MetadataMethodInfo.h"
#include "MetadataReader.h"
using namespace tns;
MetadataEntry::MetadataEntry(MetadataTreeNode *m_treeNode, NodeType nodeType) :
treeNode(m_treeNode), type(nodeType), isExtensionFunction(false), isStatic(false),
isTypeMember(false), memberId(nullptr), clazz(nullptr), mi(nullptr),fi(nullptr), sfi(nullptr),
retType(MethodReturnType::Unknown),
paramCount(-1), isFinal(false), isResolved(false), retTypeParsed(false),
isFinalSet(false), isResolvedSet(false) {}
std::string &MetadataEntry::getName() {
if (!name.empty()) return name;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::Field) {
name = reader->ReadName(fi->nameOffset);
} else if (type == NodeType::StaticField) {
name = reader->ReadName(sfi->nameOffset);
} else if (type == NodeType::Method) {
name = mi.GetName();
}
return name;
}
std::string &MetadataEntry::getSig() {
if (!sig.empty()) return sig;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::Field) {
sig = reader->ReadTypeName(fi->nodeId);
} else if (type == NodeType::StaticField) {
sig = reader->ReadTypeName(sfi->nodeId);
} else if (type == NodeType::Method) {
auto sigLength = mi.GetSignatureLength();
if (sigLength > 0)
sig = mi.GetSignature();
}
return sig;
}
std::string &MetadataEntry::getReturnType() {
if (!returnType.empty()) return returnType;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::Method) {
if (mi.GetSignatureLength() > 0) {
returnType = MetadataReader::ParseReturnType(this->getSig());
}
} else {
return returnType;
}
return returnType;
}
MethodReturnType MetadataEntry::getRetType() {
if (retTypeParsed) return retType;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::Method && !this->getReturnType().empty()) {
retType = MetadataReader::GetReturnType(this->returnType);
}
retTypeParsed = true;
return retType;
}
std::string &MetadataEntry::getDeclaringType() {
if (!declaringType.empty()) return declaringType;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::StaticField) {
declaringType = (sfi->flags & FieldInfo::HAS_DECLARING_TYPE)
? reader->ReadTypeName(sfi->declaringType)
: reader->ReadTypeName(treeNode);
} else if (type == NodeType::Method && isStatic) {
declaringType = mi.GetDeclaringType();
}
return declaringType;
}
int MetadataEntry::getParamCount() {
if (paramCount != -1) return paramCount;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::Method) {
auto sigLength = mi.GetSignatureLength();
if (sigLength > 0) {
paramCount = sigLength - 1;
} else {
paramCount = 0;
}
}
return paramCount;
}
bool MetadataEntry::getIsFinal() {
if (isFinalSet) return isFinal;
if (type == NodeType::Field) {
isFinal = (fi->flags & FieldInfo::FINAL) != 0;
} else if (type == NodeType::StaticField) {
isFinal = (sfi->flags & FieldInfo::FINAL) != 0;
}
isFinalSet = true;
return isFinal;
}
bool MetadataEntry::getIsResolved() {
if (isResolvedSet) return isResolved;
auto reader = MetadataNode::getMetadataReader();
if (type == NodeType::Method) {
isResolved = mi.CheckIsResolved() == 1;
}
isResolvedSet = true;
return isResolved;
}