@@ -103,15 +103,18 @@ std::optional<bool> isRefCountable(const CXXRecordDecl* R)
103
103
return hasRef && hasDeref;
104
104
}
105
105
106
+ bool isRefType (const std::string &Name) {
107
+ return Name == " Ref" || Name == " RefAllowingPartiallyDestroyed" ||
108
+ Name == " RefPtr" || Name == " RefPtrAllowingPartiallyDestroyed" ;
109
+ }
110
+
106
111
bool isCtorOfRefCounted (const clang::FunctionDecl *F) {
107
112
assert (F);
108
- const auto &FunctionName = safeGetName (F);
109
-
110
- return FunctionName == " Ref" || FunctionName == " makeRef"
111
-
112
- || FunctionName == " RefPtr" || FunctionName == " makeRefPtr"
113
+ const std::string &FunctionName = safeGetName (F);
113
114
114
- || FunctionName == " UniqueRef" || FunctionName == " makeUniqueRef" ||
115
+ return isRefType (FunctionName) || FunctionName == " makeRef" ||
116
+ FunctionName == " makeRefPtr" || FunctionName == " UniqueRef" ||
117
+ FunctionName == " makeUniqueRef" ||
115
118
FunctionName == " makeUniqueRefWithoutFastMallocCheck"
116
119
117
120
|| FunctionName == " String" || FunctionName == " AtomString" ||
@@ -131,7 +134,7 @@ bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
131
134
if (auto *specialT = type->getAs <TemplateSpecializationType>()) {
132
135
if (auto *decl = specialT->getTemplateName ().getAsTemplateDecl ()) {
133
136
auto name = decl->getNameAsString ();
134
- return name == " Ref " || name == " RefPtr " ;
137
+ return isRefType ( name) ;
135
138
}
136
139
return false ;
137
140
}
@@ -172,20 +175,18 @@ std::optional<bool> isGetterOfRefCounted(const CXXMethodDecl* M)
172
175
if (isa<CXXMethodDecl>(M)) {
173
176
const CXXRecordDecl *calleeMethodsClass = M->getParent ();
174
177
auto className = safeGetName (calleeMethodsClass);
175
- auto methodName = safeGetName (M);
178
+ auto method = safeGetName (M);
176
179
177
- if (((className == " Ref" || className == " RefPtr" ) &&
178
- methodName == " get" ) ||
179
- (className == " Ref" && methodName == " ptr" ) ||
180
+ if ((isRefType (className) && (method == " get" || method == " ptr" )) ||
180
181
((className == " String" || className == " AtomString" ||
181
182
className == " AtomStringImpl" || className == " UniqueString" ||
182
183
className == " UniqueStringImpl" || className == " Identifier" ) &&
183
- methodName == " impl" ))
184
+ method == " impl" ))
184
185
return true ;
185
186
186
187
// Ref<T> -> T conversion
187
188
// FIXME: Currently allowing any Ref<T> -> whatever cast.
188
- if (className == " Ref " || className == " RefPtr " ) {
189
+ if (isRefType ( className) ) {
189
190
if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
190
191
if (auto *targetConversionType =
191
192
maybeRefToRawOperator->getConversionType ().getTypePtrOrNull ()) {
@@ -202,7 +203,7 @@ bool isRefCounted(const CXXRecordDecl *R) {
202
203
if (auto *TmplR = R->getTemplateInstantiationPattern ()) {
203
204
// FIXME: String/AtomString/UniqueString
204
205
const auto &ClassName = safeGetName (TmplR);
205
- return ClassName == " RefPtr " || ClassName == " Ref " ;
206
+ return isRefType ( ClassName) ;
206
207
}
207
208
return false ;
208
209
}
0 commit comments