10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 {
"::std::ios_base::io_state"},
21 {
"::std::ios_base::open_mode"},
22 {
"::std::ios_base::seek_dir"},
23 {
"::std::ios_base::streamoff"},
24 {
"::std::ios_base::streampos"}};
27 {
"io_state",
"iostate"},
28 {
"open_mode",
"openmode"},
29 {
"seek_dir",
"seekdir"}};
31 void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
34 if (!getLangOpts().CPlusPlus)
37 auto IoStateDecl = typedefDecl(hasAnyName(DeprecatedTypes)).bind(
"TypeDecl");
39 qualType(hasDeclaration(IoStateDecl), unless(elaboratedType()));
41 Finder->addMatcher(typeLoc(loc(IoStateType)).bind(
"TypeLoc"),
this);
44 void DeprecatedIosBaseAliasesCheck::check(
45 const MatchFinder::MatchResult &
Result) {
46 SourceManager &SM = *Result.SourceManager;
48 const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>(
"TypeDecl");
49 StringRef TypeName = Typedef->getName();
50 bool HasReplacement = ReplacementTypes.count(TypeName);
52 const auto *TL = Result.Nodes.getNodeAs<TypeLoc>(
"TypeLoc");
53 SourceLocation IoStateLoc = TL->getBeginLoc();
57 bool Fix = HasReplacement && !TL->getType()->isDependentType();
58 if (IoStateLoc.isMacroID()) {
59 IoStateLoc = SM.getSpellingLoc(IoStateLoc);
63 SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
66 auto FixName = ReplacementTypes.lookup(TypeName);
67 auto Builder = diag(IoStateLoc,
"'std::ios_base::%0' is deprecated; use " 68 "'std::ios_base::%1' instead")
69 << TypeName << FixName;
72 Builder << FixItHint::CreateReplacement(SourceRange(IoStateLoc, EndLoc),
75 diag(IoStateLoc,
"'std::ios_base::%0' is deprecated") << TypeName;
static const llvm::StringMap< StringRef > ReplacementTypes
static const llvm::SmallVector< StringRef, 5 > DeprecatedTypes
CodeCompletionBuilder Builder
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
static cl::opt< bool > Fix("fix", cl::desc(R"(
Apply suggested fixes. Without -fix-errors
clang-tidy will bail out if any compilation
errors were found.
)"), cl::init(false), cl::cat(ClangTidyCategory))