11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/ASTMatchers/ASTMatchers.h" 14 #include "clang/Lex/Lexer.h" 21 namespace readability {
23 GlobalNamesInHeadersCheck::GlobalNamesInHeadersCheck(StringRef
Name,
26 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
29 HeaderFileExtensions,
',')) {
30 llvm::errs() <<
"Invalid header file extension: " 31 << RawStringHeaderFileExtensions <<
"\n";
37 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
41 ast_matchers::MatchFinder *Finder) {
42 Finder->addMatcher(decl(anyOf(usingDecl(), usingDirectiveDecl()),
43 hasDeclContext(translationUnitDecl()))
49 const auto *D = Result.Nodes.getNodeAs<Decl>(
"using_decl");
51 if (D->getLocStart().isMacroID())
55 if (Result.SourceManager->isInMainFile(
56 Result.SourceManager->getExpansionLoc(D->getLocStart()))) {
59 D->getLocStart(), *Result.SourceManager, HeaderFileExtensions))
63 if (
const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(D)) {
64 if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
73 diag(D->getLocStart(),
74 "using declarations in the global namespace in headers are prohibited");
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.
bool parseHeaderFileExtensions(StringRef AllHeaderFileExtensions, HeaderFileExtensionsSet &HeaderFileExtensions, char delimiter)
Parses header file extensions from a semicolon-separated list.
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const HeaderFileExtensionsSet &HeaderFileExtensions)
Checks whether spelling 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.