1 //===--- HeaderAnalysis.h -----------------------------------------*-C++-*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H 10 #define LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H 11 12 #include "llvm/ADT/StringRef.h" 13 #include <optional> 14 15 namespace clang { 16 class FileEntry; 17 class SourceManager; 18 class HeaderSearch; 19 20 namespace tooling { 21 22 /// Returns true if the given physical file is a self-contained header. 23 /// 24 /// A header is considered self-contained if 25 // - it has a proper header guard or has been #imported or contains #import(s) 26 // - *and* it doesn't have a dont-include-me pattern. 27 /// 28 /// This function can be expensive as it may scan the source code to find out 29 /// dont-include-me pattern heuristically. 30 bool isSelfContainedHeader(const FileEntry *FE, const SourceManager &SM, 31 const HeaderSearch &HeaderInfo); 32 33 /// This scans the given source code to see if it contains #import(s). 34 bool codeContainsImports(llvm::StringRef Code); 35 36 /// If Text begins an Include-What-You-Use directive, returns it. 37 /// Given "// IWYU pragma: keep", returns "keep". 38 /// Input is a null-terminated char* as provided by SM.getCharacterData(). 39 /// (This should not be StringRef as we do *not* want to scan for its length). 40 /// For multi-line comments, we return only the first line. 41 std::optional<llvm::StringRef> parseIWYUPragma(const char *Text); 42 43 } // namespace tooling 44 } // namespace clang 45 46 #endif // LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H 47