clang 22.0.0git
TrapReasonBuilder.cpp
Go to the documentation of this file.
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
15namespace clang {
16namespace CodeGen {
17
19 unsigned DiagID, TrapReason &TR)
20 : DiagnosticBuilder(DiagObj, SourceLocation(), DiagID), TR(TR) {
21 assert(DiagObj->getDiagnosticIDs()->isTrapDiag(DiagID));
22}
23
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
34void TrapReasonBuilder::getMessage(SmallVectorImpl<char> &Storage) {
35 // Render the Diagnostic
36 Diagnostic Info(getDiagnosticsEngine(), *this);
37 Info.FormatDiagnostic(Storage);
38}
39
40StringRef 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
This file contains the declaration of TrapReasonBuilder and related classes.
TrapReasonBuilder(DiagnosticsEngine *DiagObj, unsigned DiagID, TrapReason &TR)
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1233
void Clear() const
Clear out the current diagnostic.
Definition: Diagnostic.h:1271
DiagnosticsEngine * getDiagnosticsEngine() const
Definition: Diagnostic.h:1267
unsigned getDiagID() const
Definition: Diagnostic.h:1268
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
Definition: Diagnostic.h:1548
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:591
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.