| 1 | //===- DiagnosticBuilderWrappers.cpp ----------------------------*- 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 | #include "DiagnosticBuilderWrappers.h" |
| 10 | #include "llvm/ADT/STLExtras.h" |
| 11 | #include "llvm/Support/raw_ostream.h" |
| 12 | #include "llvm/TextAPI/Platform.h" |
| 13 | |
| 14 | using clang::DiagnosticBuilder; |
| 15 | |
| 16 | namespace llvm { |
| 17 | namespace MachO { |
| 18 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 19 | const Architecture &Arch) { |
| 20 | DB.AddString(V: getArchitectureName(Arch)); |
| 21 | return DB; |
| 22 | } |
| 23 | |
| 24 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 25 | const ArchitectureSet &ArchSet) { |
| 26 | DB.AddString(V: std::string(ArchSet)); |
| 27 | return DB; |
| 28 | } |
| 29 | |
| 30 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 31 | const PlatformType &Platform) { |
| 32 | DB.AddString(V: getPlatformName(Platform)); |
| 33 | return DB; |
| 34 | } |
| 35 | |
| 36 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 37 | const PlatformVersionSet &Platforms) { |
| 38 | std::string PlatformAsString; |
| 39 | raw_string_ostream Stream(PlatformAsString); |
| 40 | |
| 41 | Stream << "[ " ; |
| 42 | llvm::interleaveComma( |
| 43 | c: Platforms, os&: Stream, |
| 44 | each_fn: [&Stream](const std::pair<PlatformType, VersionTuple> &PV) { |
| 45 | Stream << getPlatformName(Platform: PV.first); |
| 46 | if (!PV.second.empty()) |
| 47 | Stream << PV.second.getAsString(); |
| 48 | }); |
| 49 | Stream << " ]" ; |
| 50 | DB.AddString(V: PlatformAsString); |
| 51 | return DB; |
| 52 | } |
| 53 | |
| 54 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 55 | const FileType &Type) { |
| 56 | switch (Type) { |
| 57 | case FileType::MachO_Bundle: |
| 58 | DB.AddString(V: "mach-o bundle" ); |
| 59 | return DB; |
| 60 | case FileType::MachO_DynamicLibrary: |
| 61 | DB.AddString(V: "mach-o dynamic library" ); |
| 62 | return DB; |
| 63 | case FileType::MachO_DynamicLibrary_Stub: |
| 64 | DB.AddString(V: "mach-o dynamic library stub" ); |
| 65 | return DB; |
| 66 | case FileType::TBD_V1: |
| 67 | DB.AddString(V: "tbd-v1" ); |
| 68 | return DB; |
| 69 | case FileType::TBD_V2: |
| 70 | DB.AddString(V: "tbd-v2" ); |
| 71 | return DB; |
| 72 | case FileType::TBD_V3: |
| 73 | DB.AddString(V: "tbd-v3" ); |
| 74 | return DB; |
| 75 | case FileType::TBD_V4: |
| 76 | DB.AddString(V: "tbd-v4" ); |
| 77 | return DB; |
| 78 | case FileType::TBD_V5: |
| 79 | DB.AddString(V: "tbd-v5" ); |
| 80 | return DB; |
| 81 | case FileType::Invalid: |
| 82 | case FileType::All: |
| 83 | break; |
| 84 | } |
| 85 | llvm_unreachable("Unexpected file type for diagnostics." ); |
| 86 | } |
| 87 | |
| 88 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 89 | const PackedVersion &Version) { |
| 90 | std::string VersionString; |
| 91 | raw_string_ostream OS(VersionString); |
| 92 | OS << Version; |
| 93 | DB.AddString(V: VersionString); |
| 94 | return DB; |
| 95 | } |
| 96 | |
| 97 | const clang::DiagnosticBuilder & |
| 98 | operator<<(const clang::DiagnosticBuilder &DB, |
| 99 | const clang::installapi::LibAttrs::Entry &LibAttr) { |
| 100 | std::string Entry; |
| 101 | raw_string_ostream OS(Entry); |
| 102 | |
| 103 | OS << LibAttr.first << " [ " << LibAttr.second << " ]" ; |
| 104 | DB.AddString(V: Entry); |
| 105 | return DB; |
| 106 | } |
| 107 | |
| 108 | } // namespace MachO |
| 109 | } // namespace llvm |
| 110 | |