10 #include "../utils/OptionsUtils.h" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 18 namespace readability {
21 "::std::basic_string;::std::basic_string_view;::std::vector;::std::array";
23 SimplifySubscriptExprCheck::SimplifySubscriptExprCheck(
26 Options.get(
"Types", kDefaultTypes))) {
33 const auto TypesMatcher = hasUnqualifiedDesugaredType(
34 recordType(hasDeclaration(cxxRecordDecl(hasAnyName(
35 llvm::SmallVector<StringRef, 8>(Types.begin(), Types.end()))))));
38 arraySubscriptExpr(hasBase(ignoringParenImpCasts(
40 has(memberExpr().bind(
"member")),
42 unless(anyOf(substTemplateTypeParmType(),
43 hasDescendant(substTemplateTypeParmType()))),
44 anyOf(TypesMatcher, pointerType(pointee(TypesMatcher)))))),
45 callee(namedDecl(hasName(
"data"))))
51 const auto *Call = Result.Nodes.getNodeAs<CXXMemberCallExpr>(
"call");
52 if (Result.Context->getSourceManager().isMacroBodyExpansion(
56 const auto *Member = Result.Nodes.getNodeAs<MemberExpr>(
"member");
58 diag(Member->getMemberLoc(),
59 "accessing an element of the container does not require a call to " 60 "'data()'; did you mean to use 'operator[]'?");
61 if (Member->isArrow())
62 DiagBuilder << FixItHint::CreateInsertion(Member->getBeginLoc(),
"(*")
63 << FixItHint::CreateInsertion(Member->getOperatorLoc(),
")");
64 DiagBuilder << FixItHint::CreateRemoval(
65 {Member->getOperatorLoc(), Call->getEndLoc()});
std::string serializeStringList(ArrayRef< std::string > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
static const char kDefaultTypes[]
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
std::vector< std::string > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.