1//===--- IncludeSpeller.h - Spelling strategies for headers.-------- 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// An extension point to let applications introduce custom spelling
9// strategies for physical headers.
10//===----------------------------------------------------------------------===//
11
12#ifndef CLANG_INCLUDE_CLEANER_INCLUDESPELLER_H
13#define CLANG_INCLUDE_CLEANER_INCLUDESPELLER_H
14
15#include "clang-include-cleaner/Types.h"
16#include "clang/Lex/HeaderSearch.h"
17#include "llvm/Support/Registry.h"
18#include <string>
19
20namespace clang::include_cleaner {
21
22/// IncludeSpeller provides an extension point to allow clients implement
23/// custom include spelling strategies for physical headers.
24class IncludeSpeller {
25public:
26 /// Provides the necessary information for custom spelling computations.
27 struct Input {
28 const Header &H;
29 const HeaderSearch &HS;
30 const FileEntry *Main;
31 };
32 virtual ~IncludeSpeller() = default;
33
34 /// Takes in an `Input` struct with necessary infos about a header and
35 /// returns a verbatim include spelling (with angles/quotes) or an empty
36 /// string to indicate no customizations are needed.
37 virtual std::string operator()(const Input &Input) const = 0;
38};
39
40using IncludeSpellingStrategy = llvm::Registry<IncludeSpeller>;
41
42/// Generates a spelling for the header in the `Input` that can be directly
43/// included in the main file. When the `Input` specifies a physical header,
44/// prefers the spelling provided by custom llvm strategies, if any.
45/// Otherwise, uses header search info to generate shortest spelling.
46std::string spellHeader(const IncludeSpeller::Input &Input);
47} // namespace clang::include_cleaner
48
49#endif
50

source code of clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h