9#include "clang/AST/ASTContext.h"
10#include "clang/ASTMatchers/ASTMatchFinder.h"
31 isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(
Decl, Stmt, TypeLoc,
32 NestedNameSpecifierLoc)) {
33 auto &SourceManager = Finder->getASTContext().getSourceManager();
34 SourceLocation
Loc = SourceManager.getSpellingLoc(
Node.getBeginLoc());
37 OptionalFileEntryRef FileEntry =
38 SourceManager.getFileEntryRefForID(SourceManager.getFileID(
Loc));
43 StringRef
Path = FileEntry->getName();
44 static constexpr llvm::StringLiteral AbslPrefix(
"absl/");
45 size_t PrefixPosition =
Path.find(AbslPrefix);
46 if (PrefixPosition == StringRef::npos)
48 Path =
Path.drop_front(PrefixPosition + AbslPrefix.size());
49 static const char *AbseilLibraries[] = {
50 "algorithm",
"base",
"container",
"debugging",
"flags",
51 "hash",
"iterator",
"memory",
"meta",
"numeric",
52 "profiling",
"random",
"status",
"strings",
"synchronization",
53 "time",
"types",
"utility"};
54 return llvm::any_of(AbseilLibraries, [&](
const char *Library) {
55 return Path.starts_with(Library);
const FunctionDecl * Decl
std::vector< HeaderHandle > Path
::clang::DynTypedNode Node
AST_POLYMORPHIC_MATCHER(isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc, NestedNameSpecifierLoc))
Matches AST nodes that were found within Abseil files.