Debian Codegraph @

clang/lib/CodeGen/TrapReasonBuilder.cpp

raw
1 //===----------------------------------------------------------------------===//
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 /// \file
10 /// This file implements TrapReasonBuilder and related classes.
11 ///
12 //===----------------------------------------------------------------------===//
13 #include "TrapReasonBuilder.h"
14
15 namespace clang {
16 namespace CodeGen {
17
18 TrapReasonBuilder::TrapReasonBuilder(DiagnosticsEngine *DiagObj,
19 unsigned DiagID, TrapReason &TR)
20 : DiagnosticBuilder(DiagObj, SourceLocation(), DiagID), TR(TR) {
21 assert(DiagObj->getDiagnosticIDs()->isTrapDiag(DiagID));
22 }
23
24 TrapReasonBuilder::~TrapReasonBuilder() {
25 // Store the trap message and category into the TrapReason object.
26 getMessage(TR.Message);
27 TR.Category = getCategory();
28
29 // Make sure that when `DiagnosticBuilder::~DiagnosticBuilder()`
30 // calls `Emit()` that it does nothing.
31 Clear();
32 }
33
34 void TrapReasonBuilder::getMessage(SmallVectorImpl<char> &Storage) {
35 // Render the Diagnostic
36 Diagnostic Info(getDiagnosticsEngine(), *this);
37 Info.FormatDiagnostic(Storage);
38 }
39
40 StringRef TrapReasonBuilder::getCategory() {
41 auto CategoryID =
42 getDiagnosticsEngine()->getDiagnosticIDs()->getCategoryNumberForDiag(
43 getDiagID());
44 if (CategoryID == 0)
45 return "";
46 return getDiagnosticsEngine()->getDiagnosticIDs()->getCategoryNameFromID(
47 CategoryID);
48 }
49 } // namespace CodeGen
50 } // namespace clang