1 //===--- TextDiagnostic.cpp - Text Diagnostic Pretty-Printing -------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
11 //===----------------------------------------------------------------------===//
13 #include "flang/Frontend/TextDiagnostic.h"
14 #include "clang/Basic/DiagnosticOptions.h"
15 #include "llvm/Support/raw_ostream.h"
17 using namespace Fortran::frontend
;
19 // TODO: Similar enums are defined in clang/lib/Frontend/TextDiagnostic.cpp.
20 // It would be best to share them
21 static const enum llvm::raw_ostream::Colors noteColor
=
22 llvm::raw_ostream::BLACK
;
23 static const enum llvm::raw_ostream::Colors remarkColor
=
24 llvm::raw_ostream::BLUE
;
25 static const enum llvm::raw_ostream::Colors warningColor
=
26 llvm::raw_ostream::MAGENTA
;
27 static const enum llvm::raw_ostream::Colors errorColor
= llvm::raw_ostream::RED
;
28 static const enum llvm::raw_ostream::Colors fatalColor
= llvm::raw_ostream::RED
;
29 // Used for changing only the bold attribute.
30 static const enum llvm::raw_ostream::Colors savedColor
=
31 llvm::raw_ostream::SAVEDCOLOR
;
33 TextDiagnostic::TextDiagnostic() {}
35 TextDiagnostic::~TextDiagnostic() {}
38 TextDiagnostic::printDiagnosticLevel(llvm::raw_ostream
&os
,
39 clang::DiagnosticsEngine::Level level
,
42 // Print diagnostic category in bold and color
44 case clang::DiagnosticsEngine::Ignored
:
45 llvm_unreachable("Invalid diagnostic type");
46 case clang::DiagnosticsEngine::Note
:
47 os
.changeColor(noteColor
, true);
49 case clang::DiagnosticsEngine::Remark
:
50 os
.changeColor(remarkColor
, true);
52 case clang::DiagnosticsEngine::Warning
:
53 os
.changeColor(warningColor
, true);
55 case clang::DiagnosticsEngine::Error
:
56 os
.changeColor(errorColor
, true);
58 case clang::DiagnosticsEngine::Fatal
:
59 os
.changeColor(fatalColor
, true);
65 case clang::DiagnosticsEngine::Ignored
:
66 llvm_unreachable("Invalid diagnostic type");
67 case clang::DiagnosticsEngine::Note
:
70 case clang::DiagnosticsEngine::Remark
:
73 case clang::DiagnosticsEngine::Warning
:
76 case clang::DiagnosticsEngine::Error
:
79 case clang::DiagnosticsEngine::Fatal
:
91 void TextDiagnostic::printDiagnosticMessage(llvm::raw_ostream
&os
,
93 llvm::StringRef message
,
95 if (showColors
&& !isSupplemental
) {
96 // Print primary diagnostic messages in bold and without color.
97 os
.changeColor(savedColor
, true);