10#include "../utils/FileExtensionsUtils.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "llvm/ADT/StringSet.h"
23 HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
26 Finder->addMatcher(decl(functionDecl()).bind(
"func_decl"),
this);
30 const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"func_decl");
33 if (FuncDecl ==
nullptr || !FuncDecl->isInlined())
36 SourceLocation SrcBegin = FuncDecl->getBeginLoc();
39 HeaderFileExtensions))
43 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FuncDecl)) {
44 if (MethodDecl->getParent()->isLambda())
49 auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
50 *Result.SourceManager);
51 llvm::StringRef SrcText =
Loc.getBufferData().drop_front(
Loc.getFileOffset());
52 if (SrcText.starts_with(
"LIBC_INLINE"))
55 diag(SrcBegin,
"%0 must be tagged with the LIBC_INLINE macro; the macro "
56 "should be placed at the beginning of the declaration")
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
InlineFunctionDeclCheck(StringRef Name, ClangTidyContext *Context)
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether spelling location of Loc is in header file.