clang 20.0.0git
HeaderAnalysis.h
Go to the documentation of this file.
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
13#include "llvm/ADT/StringRef.h"
14#include <optional>
15
16namespace clang {
17class SourceManager;
18class HeaderSearch;
19
20namespace 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.
30bool isSelfContainedHeader(FileEntryRef FE, const SourceManager &SM,
31 const HeaderSearch &HeaderInfo);
32
33/// This scans the given source code to see if it contains #import(s).
34bool 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.
41std::optional<llvm::StringRef> parseIWYUPragma(const char *Text);
42
43} // namespace tooling
44} // namespace clang
45
46#endif // LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H
#define SM(sm)
Definition: Cuda.cpp:84
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
StringRef Text
Definition: Format.cpp:3033
@ HeaderSearch
Remove unused header search paths including header maps.
bool codeContainsImports(llvm::StringRef Code)
This scans the given source code to see if it contains #import(s).
bool isSelfContainedHeader(FileEntryRef FE, const SourceManager &SM, const HeaderSearch &HeaderInfo)
Returns true if the given physical file is a self-contained header.
std::optional< llvm::StringRef > parseIWYUPragma(const char *Text)
If Text begins an Include-What-You-Use directive, returns it.
The JSON file list parser is used to communicate input to InstallAPI.