blob: 496bd18e78e27356b2429c9e4501080c84322dc5 [file] [log] [blame]
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001//===- llvm/Support/DiagnosticInfo.cpp - Diagnostic Definitions -*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Quentin Colombetb4c44d22013-12-17 17:47:22 +00006//
7//===----------------------------------------------------------------------===//
8//
Robin Morisset039781e2014-08-29 21:53:01 +00009// This file defines a diagnostic printer relying on raw_ostream.
Quentin Colombetb4c44d22013-12-17 17:47:22 +000010//
11//===----------------------------------------------------------------------===//
12
Quentin Colombetb4c44d22013-12-17 17:47:22 +000013#include "llvm/IR/DiagnosticPrinter.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000014#include "llvm/ADT/Twine.h"
Manman Ren2ebfb422014-01-16 01:51:12 +000015#include "llvm/IR/Module.h"
Quentin Colombetb4c44d22013-12-17 17:47:22 +000016#include "llvm/IR/Value.h"
Alex Lorenz735c47e2015-06-15 20:30:22 +000017#include "llvm/Support/SourceMgr.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000018#include "llvm/Support/raw_ostream.h"
Quentin Colombetb4c44d22013-12-17 17:47:22 +000019
20using namespace llvm;
21
22DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(char C) {
23 Stream << C;
24 return *this;
25}
26
27DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned char C) {
28 Stream << C;
29 return *this;
30}
31
32DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(signed char C) {
33 Stream << C;
34 return *this;
35}
36
37DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(StringRef Str) {
38 Stream << Str;
39 return *this;
40}
41
42DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const char *Str) {
43 Stream << Str;
44 return *this;
45}
46
47DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(
48 const std::string &Str) {
49 Stream << Str;
50 return *this;
51}
52
53DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned long N) {
54 Stream << N;
55 return *this;
56}
57DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(long N) {
58 Stream << N;
59 return *this;
60}
61
62DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(
63 unsigned long long N) {
64 Stream << N;
65 return *this;
66}
67
68DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(long long N) {
69 Stream << N;
70 return *this;
71}
72
73DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const void *P) {
74 Stream << P;
75 return *this;
76}
77
78DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned int N) {
79 Stream << N;
80 return *this;
81}
82
83DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(int N) {
84 Stream << N;
85 return *this;
86}
87
88DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(double N) {
89 Stream << N;
90 return *this;
91}
92
93DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Twine &Str) {
Quentin Colombet98e79a02013-12-17 22:35:07 +000094 Str.print(Stream);
Quentin Colombetb4c44d22013-12-17 17:47:22 +000095 return *this;
96}
97
98// IR related types.
99DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Value &V) {
100 Stream << V.getName();
101 return *this;
102}
Manman Ren2ebfb422014-01-16 01:51:12 +0000103
104DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Module &M) {
105 Stream << M.getModuleIdentifier();
106 return *this;
107}
Alex Lorenz735c47e2015-06-15 20:30:22 +0000108
109// Other types.
110DiagnosticPrinter &DiagnosticPrinterRawOStream::
111operator<<(const SMDiagnostic &Diag) {
112 // We don't have to print the SMDiagnostic kind, as the diagnostic severity
113 // is printed by the diagnostic handler.
114 Diag.print("", Stream, /*ShowColors=*/true, /*ShowKindLabel=*/false);
115 return *this;
116}