File indexing completed on 2026-05-10 08:36:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "clang/AST/ASTContext.h"
0010 #include "clang/ASTMatchers/ASTMatchFinder.h"
0011 #include <algorithm>
0012
0013 namespace clang::ast_matchers {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 AST_POLYMORPHIC_MATCHER(
0031 isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc,
0032 NestedNameSpecifierLoc)) {
0033 auto &SourceManager = Finder->getASTContext().getSourceManager();
0034 SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
0035 if (Loc.isInvalid())
0036 return false;
0037 OptionalFileEntryRef FileEntry =
0038 SourceManager.getFileEntryRefForID(SourceManager.getFileID(Loc));
0039 if (!FileEntry)
0040 return false;
0041
0042
0043 StringRef Path = FileEntry->getName();
0044 static constexpr llvm::StringLiteral AbslPrefix("absl/");
0045 size_t PrefixPosition = Path.find(AbslPrefix);
0046 if (PrefixPosition == StringRef::npos)
0047 return false;
0048 Path = Path.drop_front(PrefixPosition + AbslPrefix.size());
0049 static const char *AbseilLibraries[] = {
0050 "algorithm", "base", "container", "debugging", "flags",
0051 "hash", "iterator", "memory", "meta", "numeric",
0052 "profiling", "random", "status", "strings", "synchronization",
0053 "time", "types", "utility"};
0054 return llvm::any_of(AbseilLibraries, [&](const char *Library) {
0055 return Path.starts_with(Library);
0056 });
0057 }
0058
0059 }