clang 20.0.0git
SerializedDiagnosticPrinter.cpp
Go to the documentation of this file.
1//===--- SerializedDiagnosticPrinter.cpp - Serializer for diagnostics -----===//
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
18#include "clang/Lex/Lexer.h"
19#include "llvm/ADT/DenseSet.h"
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/SmallString.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Bitstream/BitCodes.h"
24#include "llvm/Bitstream/BitstreamReader.h"
25#include "llvm/Support/FileSystem.h"
26#include "llvm/Support/raw_ostream.h"
27#include <utility>
28
29using namespace clang;
30using namespace clang::serialized_diags;
31
32namespace {
33
34class AbbreviationMap {
35 llvm::DenseMap<unsigned, unsigned> Abbrevs;
36public:
37 AbbreviationMap() {}
38
39 void set(unsigned recordID, unsigned abbrevID) {
40 assert(!Abbrevs.contains(recordID) && "Abbreviation already set.");
41 Abbrevs[recordID] = abbrevID;
42 }
43
44 unsigned get(unsigned recordID) {
45 assert(Abbrevs.contains(recordID) && "Abbreviation not set.");
46 return Abbrevs[recordID];
47 }
48};
49
50typedef SmallVector<uint64_t, 64> RecordData;
51typedef SmallVectorImpl<uint64_t> RecordDataImpl;
52typedef ArrayRef<uint64_t> RecordDataRef;
53
54class SDiagsWriter;
55
56class SDiagsRenderer : public DiagnosticNoteRenderer {
57 SDiagsWriter &Writer;
58public:
59 SDiagsRenderer(SDiagsWriter &Writer, const LangOptions &LangOpts,
60 DiagnosticOptions *DiagOpts)
61 : DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer) {}
62
63 ~SDiagsRenderer() override {}
64
65protected:
67 DiagnosticsEngine::Level Level, StringRef Message,
69 DiagOrStoredDiag D) override;
70
73 ArrayRef<CharSourceRange> Ranges) override {}
74
75 void emitNote(FullSourceLoc Loc, StringRef Message) override;
76
79 ArrayRef<FixItHint> Hints) override;
80
85};
86
87typedef llvm::DenseMap<unsigned, unsigned> AbbrevLookup;
88
89class SDiagsMerger : SerializedDiagnosticReader {
90 SDiagsWriter &Writer;
91 AbbrevLookup FileLookup;
92 AbbrevLookup CategoryLookup;
93 AbbrevLookup DiagFlagLookup;
94
95public:
96 SDiagsMerger(SDiagsWriter &Writer) : Writer(Writer) {}
97
98 std::error_code mergeRecordsFromFile(const char *File) {
99 return readDiagnostics(File);
100 }
101
102protected:
103 std::error_code visitStartOfDiagnostic() override;
104 std::error_code visitEndOfDiagnostic() override;
105 std::error_code visitCategoryRecord(unsigned ID, StringRef Name) override;
106 std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name) override;
107 std::error_code