1 //===--- IncludeSpeller.h - Spelling strategies for headers.-------- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
8 // An extension point to let applications introduce custom spelling
9 // strategies for physical headers.
10 //===----------------------------------------------------------------------===//
12 #ifndef CLANG_INCLUDE_CLEANER_INCLUDESPELLER_H
13 #define CLANG_INCLUDE_CLEANER_INCLUDESPELLER_H
15 #include "clang-include-cleaner/Types.h"
16 #include "clang/Lex/HeaderSearch.h"
17 #include "llvm/Support/Registry.h"
20 namespace clang::include_cleaner
{
22 /// IncludeSpeller provides an extension point to allow clients implement
23 /// custom include spelling strategies for physical headers.
24 class IncludeSpeller
{
26 /// Provides the necessary information for custom spelling computations.
29 const HeaderSearch
&HS
;
30 const FileEntry
*Main
;
32 virtual ~IncludeSpeller() = default;
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;
40 using IncludeSpellingStrategy
= llvm::Registry
<IncludeSpeller
>;
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.
46 std::string
spellHeader(const IncludeSpeller::Input
&Input
);
47 } // namespace clang::include_cleaner