1 //===--- HeaderInclude.h - Header Include -----------------------*- 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 /// \file
10 /// Defines enums used when emitting included header information.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_BASIC_HEADERINCLUDEFORMATKIND_H
15 #define LLVM_CLANG_BASIC_HEADERINCLUDEFORMATKIND_H
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include <utility>
19
20 namespace clang {
21 /// The format in which header information is emitted.
22 enum HeaderIncludeFormatKind { HIFMT_None, HIFMT_Textual, HIFMT_JSON };
23
24 /// Whether header information is filtered or not. If HIFIL_Only_Direct_System
25 /// is used, only information on system headers directly included from
26 /// non-system files is emitted. The HIFIL_Direct_Per_File filtering shows the
27 /// direct imports and includes for each non-system source and header file
28 /// separately.
29 enum HeaderIncludeFilteringKind {
30 HIFIL_None,
31 HIFIL_Only_Direct_System,
32 HIFIL_Direct_Per_File
33 };
34
35 inline HeaderIncludeFormatKind
stringToHeaderIncludeFormatKind(const char * Str)36 stringToHeaderIncludeFormatKind(const char *Str) {
37 return llvm::StringSwitch<HeaderIncludeFormatKind>(Str)
38 .Case("textual", HIFMT_Textual)
39 .Case("json", HIFMT_JSON)
40 .Default(HIFMT_None);
41 }
42
stringToHeaderIncludeFiltering(const char * Str,HeaderIncludeFilteringKind & Kind)43 inline bool stringToHeaderIncludeFiltering(const char *Str,
44 HeaderIncludeFilteringKind &Kind) {
45 std::pair<bool, HeaderIncludeFilteringKind> P =
46 llvm::StringSwitch<std::pair<bool, HeaderIncludeFilteringKind>>(Str)
47 .Case("none", {true, HIFIL_None})
48 .Case("only-direct-system", {true, HIFIL_Only_Direct_System})
49 .Case("direct-per-file", {true, HIFIL_Direct_Per_File})
50 .Default({false, HIFIL_None});
51 Kind = P.second;
52 return P.first;
53 }
54
headerIncludeFormatKindToString(HeaderIncludeFormatKind K)55 inline const char *headerIncludeFormatKindToString(HeaderIncludeFormatKind K) {
56 switch (K) {
57 case HIFMT_None:
58 llvm_unreachable("unexpected format kind");
59 case HIFMT_Textual:
60 return "textual";
61 case HIFMT_JSON:
62 return "json";
63 }
64 llvm_unreachable("Unknown HeaderIncludeFormatKind enum");
65 }
66
67 inline const char *
headerIncludeFilteringKindToString(HeaderIncludeFilteringKind K)68 headerIncludeFilteringKindToString(HeaderIncludeFilteringKind K) {
69 switch (K) {
70 case HIFIL_None:
71 return "none";
72 case HIFIL_Only_Direct_System:
73 return "only-direct-system";
74 case HIFIL_Direct_Per_File:
75 return "direct-per-file";
76 }
77 llvm_unreachable("Unknown HeaderIncludeFilteringKind enum");
78 }
79
80 } // end namespace clang
81
82 #endif // LLVM_CLANG_BASIC_HEADERINCLUDEFORMATKIND_H
83