File: DiagnosticBuilderWrappers.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (110 lines) | stat: -rw-r--r-- 3,258 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//===- DiagnosticBuilderWrappers.cpp ----------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DiagnosticBuilderWrappers.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TextAPI/Platform.h"

using clang::DiagnosticBuilder;

namespace llvm {
namespace MachO {
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    const Architecture &Arch) {
  DB.AddString(getArchitectureName(Arch));
  return DB;
}

const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    const ArchitectureSet &ArchSet) {
  DB.AddString(std::string(ArchSet));
  return DB;
}

const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    const PlatformType &Platform) {
  DB.AddString(getPlatformName(Platform));
  return DB;
}

const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    const PlatformVersionSet &Platforms) {
  std::string PlatformAsString;
  raw_string_ostream Stream(PlatformAsString);

  Stream << "[ ";
  llvm::interleaveComma(
      Platforms, Stream,
      [&Stream](const std::pair<PlatformType, VersionTuple> &PV) {
        Stream << getPlatformName(PV.first);
        if (!PV.second.empty())
          Stream << PV.second.getAsString();
      });
  Stream << " ]";
  DB.AddString(PlatformAsString);
  return DB;
}

const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    const FileType &Type) {
  switch (Type) {
  case FileType::MachO_Bundle:
    DB.AddString("mach-o bundle");
    return DB;
  case FileType::MachO_DynamicLibrary:
    DB.AddString("mach-o dynamic library");
    return DB;
  case FileType::MachO_DynamicLibrary_Stub:
    DB.AddString("mach-o dynamic library stub");
    return DB;
  case FileType::TBD_V1:
    DB.AddString("tbd-v1");
    return DB;
  case FileType::TBD_V2:
    DB.AddString("tbd-v2");
    return DB;
  case FileType::TBD_V3:
    DB.AddString("tbd-v3");
    return DB;
  case FileType::TBD_V4:
    DB.AddString("tbd-v4");
    return DB;
  case FileType::TBD_V5:
    DB.AddString("tbd-v5");
    return DB;
  case FileType::Invalid:
  case FileType::All:
    break;
  }
  llvm_unreachable("Unexpected file type for diagnostics.");
}

const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    const PackedVersion &Version) {
  std::string VersionString;
  raw_string_ostream OS(VersionString);
  OS << Version;
  DB.AddString(VersionString);
  return DB;
}

const clang::DiagnosticBuilder &
operator<<(const clang::DiagnosticBuilder &DB,
           const StringMapEntry<ArchitectureSet> &LibAttr) {
  std::string IFAsString;
  raw_string_ostream OS(IFAsString);

  OS << LibAttr.getKey() << " [ " << LibAttr.getValue() << " ]";
  DB.AddString(IFAsString);
  return DB;
}

} // namespace MachO
} // namespace llvm