10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/ASTMatchers/ASTMatchers.h" 13 #include "clang/Lex/Lexer.h" 20 namespace readability {
22 GlobalNamesInHeadersCheck::GlobalNamesInHeadersCheck(StringRef
Name,
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) {
41 Finder->addMatcher(decl(anyOf(usingDecl(), usingDirectiveDecl()),
42 hasDeclContext(translationUnitDecl()))
48 const auto *
D = Result.Nodes.getNodeAs<Decl>(
"using_decl");
50 if (
D->getBeginLoc().isMacroID())
54 if (Result.SourceManager->isInMainFile(
55 Result.SourceManager->getExpansionLoc(
D->getBeginLoc()))) {
58 D->getBeginLoc(), *Result.SourceManager, HeaderFileExtensions))
62 if (
const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(
D)) {
63 if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
72 diag(
D->getBeginLoc(),
73 "using declarations in the global namespace in headers are prohibited");
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.
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.