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

source code of clang/lib/InstallAPI/DiagnosticBuilderWrappers.cpp