/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Basic/HeaderInclude.h
Line | Count | Source (jump to first uncovered line) |
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 headers is emitted. |
27 | | enum HeaderIncludeFilteringKind { HIFIL_None, HIFIL_Only_Direct_System }; |
28 | | |
29 | | inline HeaderIncludeFormatKind |
30 | 3 | stringToHeaderIncludeFormatKind(const char *Str) { |
31 | 3 | return llvm::StringSwitch<HeaderIncludeFormatKind>(Str) |
32 | 3 | .Case("textual", HIFMT_Textual) |
33 | 3 | .Case("json", HIFMT_JSON) |
34 | 3 | .Default(HIFMT_None); |
35 | 3 | } |
36 | | |
37 | | inline bool stringToHeaderIncludeFiltering(const char *Str, |
38 | 3 | HeaderIncludeFilteringKind &Kind) { |
39 | 3 | std::pair<bool, HeaderIncludeFilteringKind> P = |
40 | 3 | llvm::StringSwitch<std::pair<bool, HeaderIncludeFilteringKind>>(Str) |
41 | 3 | .Case("none", {true, HIFIL_None}) |
42 | 3 | .Case("only-direct-system", {true, HIFIL_Only_Direct_System}) |
43 | 3 | .Default({false, HIFIL_None}); |
44 | 3 | Kind = P.second; |
45 | 3 | return P.first; |
46 | 3 | } |
47 | | |
48 | 10 | inline const char *headerIncludeFormatKindToString(HeaderIncludeFormatKind K) { |
49 | 10 | switch (K) { |
50 | 0 | case HIFMT_None: |
51 | 0 | llvm_unreachable("unexpected format kind"); |
52 | 9 | case HIFMT_Textual: |
53 | 9 | return "textual"; |
54 | 1 | case HIFMT_JSON: |
55 | 1 | return "json"; |
56 | 10 | } |
57 | 0 | llvm_unreachable("Unknown HeaderIncludeFormatKind enum"); |
58 | 0 | } |
59 | | |
60 | | inline const char * |
61 | 10 | headerIncludeFilteringKindToString(HeaderIncludeFilteringKind K) { |
62 | 10 | switch (K) { |
63 | 9 | case HIFIL_None: |
64 | 9 | return "none"; |
65 | 1 | case HIFIL_Only_Direct_System: |
66 | 1 | return "only-direct-system"; |
67 | 10 | } |
68 | 0 | llvm_unreachable("Unknown HeaderIncludeFilteringKind enum"); |
69 | 0 | } |
70 | | |
71 | | } // end namespace clang |
72 | | |
73 | | #endif // LLVM_CLANG_BASIC_HEADERINCLUDEFORMATKIND_H |