10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/ASTMatchers/ASTMatchers.h" 21 UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
24 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
27 HeaderFileExtensions,
',')) {
28 llvm::errs() <<
"Invalid header file extension: " 29 << RawStringHeaderFileExtensions <<
"\n";
35 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
39 ast_matchers::MatchFinder *Finder) {
43 Finder->addMatcher(namespaceDecl(isAnonymous()).bind(
"anonymousNamespace"),
48 const MatchFinder::MatchResult &
Result) {
49 const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>(
"anonymousNamespace");
50 SourceLocation
Loc = N->getBeginLoc();
55 HeaderFileExtensions))
56 diag(Loc,
"do not use unnamed namespaces in header files");
SourceLocation Loc
'#' location in the include directive
bool parseHeaderFileExtensions(StringRef AllHeaderFileExtensions, HeaderFileExtensionsSet &HeaderFileExtensions, char delimiter)
Parses header file extensions from a semicolon-separated list.
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const HeaderFileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
StringRef defaultHeaderFileExtensions()
Returns recommended default value for the list of header file extensions.
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.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.