19bool isIf(llvm::StringRef
Line) {
21 if (!
Line.consume_front(
"#"))
24 return Line.starts_with(
"if");
28bool isErrorAboutInclude(llvm::StringRef
Line) {
30 if (!
Line.consume_front(
"#"))
33 if (!
Line.starts_with(
"error"))
35 return Line.contains_insensitive(
40bool isDontIncludeMeHeader(StringRef Content) {
43 Content = Content.take_front(100 * 100);
44 for (
unsigned I = 0; I < 100 && !Content.empty(); ++I) {
45 std::tie(
Line, Content) = Content.split(
'\n');
46 if (isIf(
Line) && isErrorAboutInclude(Content.split(
'\n').first))
52bool isImportLine(llvm::StringRef
Line) {
54 if (!
Line.consume_front(
"#"))
57 return Line.starts_with(
"import");
60llvm::StringRef getFileContents(FileEntryRef FE,
const SourceManager &
SM) {
61 return const_cast<SourceManager &
>(
SM)
62 .getMemoryBufferForFileOrNone(FE)
63 .value_or(llvm::MemoryBufferRef())
75 (
SM.getFileEntryForID(
SM.getMainFileID()) != FE ||
80 return !isDontIncludeMeHeader(getFileContents(FE,
SM));
85 Code = Code.take_front(100 * 100);
87 for (
unsigned I = 0; I < 100 && !Code.empty(); ++I) {
88 std::tie(
Line, Code) = Code.split(
'\n');
89 if (isImportLine(
Line))
97 if (
Text[0] !=
'/' || (
Text[1] !=
'/' &&
Text[1] !=
'*'))
99 bool BlockComment =
Text[1] ==
'*';
103 constexpr llvm::StringLiteral IWYUPragma =
" IWYU pragma: ";
104 if (strncmp(
Text, IWYUPragma.data(), IWYUPragma.size()))
106 Text += IWYUPragma.size();
107 const char *End =
Text;
108 while (*End != 0 && *End !=
'\n')
114 Rest.consume_back(
"*/");
Defines the clang::SourceLocation class and associated facilities.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
This class handles loading and caching of source files into memory.