@@ -39,8 +39,30 @@ using ::clang::ast_matchers::StatementMatcher;
3939
4040} // namespace
4141
42- static bool isStatusOrOperatorBaseType (QualType type) {
43- return isRecordTypeWithName (type, " absl::internal_statusor::OperatorBase" );
42+ static bool namespaceEquals (const NamespaceDecl *NS,
43+ clang::ArrayRef<clang::StringRef> NamespaceNames) {
44+ while (!NamespaceNames.empty () && NS) {
45+ if (NS->getName () != NamespaceNames.consume_back ())
46+ return false ;
47+ NS = dyn_cast_or_null<NamespaceDecl>(NS->getParent ());
48+ }
49+ return NamespaceNames.empty () && !NS;
50+ }
51+
52+ // TODO: move this to a proper place to share with the rest of clang
53+ static bool isTypeNamed (QualType Type, clang::ArrayRef<clang::StringRef> NS,
54+ StringRef Name) {
55+ if (Type.isNull ())
56+ return false ;
57+ if (auto *RD = Type->getAsRecordDecl ())
58+ if (RD->getName () == Name)
59+ if (const auto *N = dyn_cast_or_null<NamespaceDecl>(RD->getDeclContext ()))
60+ return namespaceEquals (N, NS);
61+ return false ;
62+ }
63+
64+ static bool isStatusOrOperatorBaseType (QualType Type) {
65+ return isTypeNamed (Type, {" absl" , " internal_statusor" }, " OperatorBase" );
4466}
4567
4668static bool isSafeUnwrap (RecordStorageLocation *StatusOrLoc,
@@ -252,17 +274,6 @@ clang::ast_matchers::DeclarationMatcher statusOrOperatorBaseClass() {
252274 hasName (" absl::internal_statusor::OperatorBase" ));
253275}
254276
255- clang::ast_matchers::TypeMatcher possiblyAliasedStatusOrType () {
256- using namespace ::clang::ast_matchers; // NOLINT: Too many names
257- return hasUnqualifiedDesugaredType (
258- recordType (hasDeclaration (statusOrClass ())));
259- }
260-
261- clang::ast_matchers::TypeMatcher possiblyAliasedStatusType () {
262- using namespace ::clang::ast_matchers; // NOLINT: Too many names
263- return hasUnqualifiedDesugaredType (recordType (hasDeclaration (statusClass ())));
264- }
265-
266277clang::ast_matchers::TypeMatcher statusOrType () {
267278 using namespace ::clang::ast_matchers; // NOLINT: Too many names
268279 return hasCanonicalType (qualType (hasDeclaration (statusOrClass ())));
@@ -274,11 +285,11 @@ bool isRecordTypeWithName(QualType Type, llvm::StringRef TypeName) {
274285}
275286
276287bool isStatusOrType (QualType Type) {
277- return isRecordTypeWithName (Type, " absl:: StatusOr" );
288+ return isTypeNamed (Type, { " absl" }, " StatusOr" );
278289}
279290
280291bool isStatusType (QualType Type) {
281- return isRecordTypeWithName (Type, " absl:: Status" );
292+ return isTypeNamed (Type, { " absl" }, " Status" );
282293}
283294
284295llvm::StringMap<QualType> getSyntheticFields (QualType Ty, QualType StatusType,
0 commit comments