10#include "clang/Basic/CharInfo.h"
11#include "llvm/Support/Path.h"
18 SourceLocation ExpansionLoc = SM.getExpansionLoc(
Loc);
19 return isFileExtension(SM.getFilename(ExpansionLoc), HeaderFileExtensions);
24 PresumedLoc PresumedLocation = SM.getPresumedLoc(
Loc);
25 return isFileExtension(PresumedLocation.getFilename(), HeaderFileExtensions);
30 SourceLocation SpellingLoc = SM.getSpellingLoc(
Loc);
31 return isFileExtension(SM.getFilename(SpellingLoc), HeaderFileExtensions);
36 StringRef Delimiters) {
38 for (
char Delimiter : Delimiters) {
39 if (AllFileExtensions.contains(Delimiter)) {
40 AllFileExtensions.split(
Suffixes, Delimiter);
45 FileExtensions.clear();
47 StringRef Extension =
Suffix.trim();
48 if (!llvm::all_of(Extension, isAlphanumeric))
50 FileExtensions.insert(Extension);
55std::optional<StringRef>
57 StringRef Extension = llvm::sys::path::extension(
FileName);
58 if (Extension.empty())
61 if (!FileExtensions.count(Extension.substr(1)))
static constexpr llvm::StringLiteral Suffixes
std::optional< StringRef > getFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions)
Decides whether a file has a header file extension.
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.
bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether expansion location of Loc is in header file.
bool isFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions)
Decides whether a file has one of the specified file extensions.
bool parseFileExtensions(StringRef AllFileExtensions, FileExtensionsSet &FileExtensions, StringRef Delimiters)
Parses header file extensions from a semicolon-separated list.
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether spelling location of Loc is in header file.
llvm::SmallSet< llvm::StringRef, 5 > FileExtensionsSet