11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/ASTMatchers/ASTMatchers.h"
15 using namespace clang::ast_matchers;
22 UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
25 RawStringHeaderFileExtensions(
26 Options.getLocalOrGlobal(
"HeaderFileExtensions",
"h,hh,hpp,hxx")) {
30 llvm::errs() <<
"Invalid header file extension: "
31 << RawStringHeaderFileExtensions <<
"\n";
37 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
41 ast_matchers::MatchFinder *
Finder) {
45 Finder->addMatcher(namespaceDecl(isAnonymous()).bind(
"anonymousNamespace"),
51 const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>(
"anonymousNamespace");
52 SourceLocation
Loc = N->getLocStart();
57 HeaderFileExtensions))
58 diag(Loc,
"do not use unnamed namespaces in header files");
SourceLocation Loc
'#' location in the include directive
LangOptions getLangOpts() const
Returns the language options from the context.
bool parseHeaderFileExtensions(StringRef AllHeaderFileExtensions, HeaderFileExtensionsSet &HeaderFileExtensions, char delimiter)
Parses header file extensions from a semicolon-separated list.
std::unique_ptr< ast_matchers::MatchFinder > Finder
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.
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.
std::map< std::string, std::string > OptionMap
ClangTidyContext & Context
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.