HeaderAnalysis.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- HeaderAnalysis.h -----------------------------------------*-C++-*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H
  14. #define LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include <optional>
  17. namespace clang {
  18. class FileEntry;
  19. class SourceManager;
  20. class HeaderSearch;
  21. namespace tooling {
  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. HeaderSearch &HeaderInfo);
  32. /// This scans the given source code to see if it contains #import(s).
  33. bool codeContainsImports(llvm::StringRef Code);
  34. /// If Text begins an Include-What-You-Use directive, returns it.
  35. /// Given "// IWYU pragma: keep", returns "keep".
  36. /// Input is a null-terminated char* as provided by SM.getCharacterData().
  37. /// (This should not be StringRef as we do *not* want to scan for its length).
  38. /// For multi-line comments, we return only the first line.
  39. std::optional<llvm::StringRef> parseIWYUPragma(const char *Text);
  40. } // namespace tooling
  41. } // namespace clang
  42. #endif // LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H
  43. #ifdef __GNUC__
  44. #pragma GCC diagnostic pop
  45. #endif