@@ -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,
@@ -217,17 +239,6 @@ clang::ast_matchers::DeclarationMatcher statusOrOperatorBaseClass() {
217239 hasName (" absl::internal_statusor::OperatorBase" ));
218240}
219241
220- clang::ast_matchers::TypeMatcher possiblyAliasedStatusOrType () {
221- using namespace ::clang::ast_matchers; // NOLINT: Too many names
222- return hasUnqualifiedDesugaredType (
223- recordType (hasDeclaration (statusOrClass ())));
224- }
225-
226- clang::ast_matchers::TypeMatcher possiblyAliasedStatusType () {
227- using namespace ::clang::ast_matchers; // NOLINT: Too many names
228- return hasUnqualifiedDesugaredType (recordType (hasDeclaration (statusClass ())));
229- }
230-
231242clang::ast_matchers::TypeMatcher statusOrType () {
232243 using namespace ::clang::ast_matchers; // NOLINT: Too many names
233244 return hasCanonicalType (qualType (hasDeclaration (statusOrClass ())));
@@ -239,11 +250,11 @@ bool isRecordTypeWithName(QualType Type, llvm::StringRef TypeName) {
239250}
240251
241252bool isStatusOrType (QualType Type) {
242- return isRecordTypeWithName (Type, " absl:: StatusOr" );
253+ return isTypeNamed (Type, { " absl" }, " StatusOr" );
243254}
244255
245256bool isStatusType (QualType Type) {
246- return isRecordTypeWithName (Type, " absl:: Status" );
257+ return isTypeNamed (Type, { " absl" }, " Status" );
247258}
248259
249260llvm::StringMap<QualType> getSyntheticFields (QualType Ty, QualType StatusType,
0 commit comments