Debian Codegraph @

libcextract/Error.cpp

raw
1 //===- Error.cpp - Implements a simple error pointing mechanism *- C++ -*-===//
2 //
3 // This project is licensed 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 /// \file
10 /// Implements a simple error pointing mechanism.
11 //
12 //===----------------------------------------------------------------------===//
13
14 /* Author: Giuliano Belinassi */
15
16 #include "Error.hh"
17 #include "PrettyPrint.hh"
18 #include "NonLLVMMisc.hh"
19
20 DiagnosticOptionsWithColor::DiagnosticOptionsWithColor(void)
21 : DOpts(new DiagnosticOptions())
22 {
23 DOpts->ShowColors = check_color_available();
24 }
25
26 DiagsClass DiagsClass::sDiag;
27
28 DiagsClass::DiagsClass(void)
29 : LangOpts(),
30 DOpts(DiagnosticOptionsWithColor()),
31 DiagsEngine(llvm::errs(), LangOpts, DOpts.getDiagsOptsToEngine())
32 {}
33
34 /* Print error giving a piece of source code that caused the error. */
35 void DiagsClass::EmitMessage(const StringRef message, DiagnosticsEngine::Level level,
36 const SourceRange &range, const SourceManager &sm)
37 {
38 CharSourceRange charsrc_range = CharSourceRange::getCharRange(range);
39 FullSourceLoc loc = FullSourceLoc(range.getBegin(), sm);
40
41 const std::string ce_message = Append_CE(message);
42 DiagsEngine.emitDiagnostic(loc, level, ce_message, charsrc_range, FixItHint(), nullptr);
43 }
44 /* Print error without giving a piece of source code that caused the error. */
45 void DiagsClass::EmitMessage(const StringRef message, DiagnosticsEngine::Level level)
46 {
47 bool colored = Is_Colored();
48 const std::string ce_message = Append_CE(message);
49 TextDiagnostic::printDiagnosticLevel(llvm::errs(), level, colored);
50 TextDiagnostic::printDiagnosticMessage(llvm::errs(), false, ce_message, 0, 0, colored);
51 }