void DeprecatedIosBaseAliasesCheck::check( const MatchFinder::MatchResult &Result) { SourceManager &SM = *Result.SourceManager; const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl"); StringRef TypeName = Typedef->getName(); bool HasReplacement = ReplacementTypes.count(TypeName); const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("TypeLoc"); SourceLocation IoStateLoc = TL->getBeginLoc(); // Do not generate fixits for matches depending on template arguments and // macro expansions. bool Fix = HasReplacement && !TL->getType()->isDependentType(); if (IoStateLoc.isMacroID()) { IoStateLoc = SM.getSpellingLoc(IoStateLoc); Fix = false; } SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1); if (HasReplacement) { auto FixName = ReplacementTypes.lookup(TypeName); auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use " "'std::ios_base::%1' instead") << TypeName << FixName; if (Fix) Builder << FixItHint::CreateReplacement(SourceRange(IoStateLoc, EndLoc), FixName); } else diag(IoStateLoc, "'std::ios_base::%0' is deprecated") << TypeName; }
static FoundationClass findKnownClass(const ObjCInterfaceDecl *ID) { static llvm::StringMap<FoundationClass> Classes; if (Classes.empty()) { Classes["NSArray"] = FC_NSArray; Classes["NSDictionary"] = FC_NSDictionary; Classes["NSEnumerator"] = FC_NSEnumerator; Classes["NSOrderedSet"] = FC_NSOrderedSet; Classes["NSSet"] = FC_NSSet; Classes["NSString"] = FC_NSString; } // FIXME: Should we cache this at all? FoundationClass result = Classes.lookup(ID->getIdentifier()->getName()); if (result == FC_None) if (const ObjCInterfaceDecl *Super = ID->getSuperClass()) return findKnownClass(Super); return result; }