11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/ASTMatchers/ASTMatchers.h" 22 UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
25 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
28 HeaderFileExtensions,
',')) {
29 llvm::errs() <<
"Invalid header file extension: " 30 << RawStringHeaderFileExtensions <<
"\n";
36 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
40 ast_matchers::MatchFinder *Finder) {
44 Finder->addMatcher(namespaceDecl(isAnonymous()).bind(
"anonymousNamespace"),
49 const MatchFinder::MatchResult &Result) {
50 const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>(
"anonymousNamespace");
51 SourceLocation
Loc = N->getLocStart();
56 HeaderFileExtensions))
57 diag(Loc,
"do not use unnamed namespaces in header files");
SourceLocation Loc
'#' location in the include directive
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.
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.
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.
StringRef defaultHeaderFileExtensions()
Returns recommended default value for the list of header file extensions.
std::map< std::string, std::string > OptionMap
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
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.