2011-10-29 08:12:39 +08:00
|
|
|
//===--- SerializedDiagnosticPrinter.cpp - Serializer for diagnostics -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2012-10-24 06:26:28 +08:00
|
|
|
#include "clang/Basic/DiagnosticOptions.h"
|
2011-10-29 08:12:39 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2011-10-29 08:12:39 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2011-12-17 13:26:11 +08:00
|
|
|
#include "clang/Frontend/DiagnosticRenderer.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <vector>
|
2011-10-29 08:12:39 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2011-11-05 08:09:57 +08:00
|
|
|
using namespace clang::serialized_diags;
|
2011-10-29 08:12:39 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AbbreviationMap {
|
|
|
|
llvm::DenseMap<unsigned, unsigned> Abbrevs;
|
|
|
|
public:
|
|
|
|
AbbreviationMap() {}
|
|
|
|
|
|
|
|
void set(unsigned recordID, unsigned abbrevID) {
|
|
|
|
assert(Abbrevs.find(recordID) == Abbrevs.end()
|
|
|
|
&& "Abbreviation already set.");
|
|
|
|
Abbrevs[recordID] = abbrevID;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned get(unsigned recordID) {
|
|
|
|
assert(Abbrevs.find(recordID) != Abbrevs.end() &&
|
|
|
|
"Abbreviation not set.");
|
|
|
|
return Abbrevs[recordID];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
typedef SmallVector<uint64_t, 64> RecordData;
|
|
|
|
typedef SmallVectorImpl<uint64_t> RecordDataImpl;
|
2011-12-17 13:26:11 +08:00
|
|
|
|
|
|
|
class SDiagsWriter;
|
|
|
|
|
2012-02-14 10:46:00 +08:00
|
|
|
class SDiagsRenderer : public DiagnosticNoteRenderer {
|
2011-12-17 13:26:11 +08:00
|
|
|
SDiagsWriter &Writer;
|
|
|
|
public:
|
2012-08-21 11:11:53 +08:00
|
|
|
SDiagsRenderer(SDiagsWriter &Writer, const LangOptions &LangOpts,
|
2012-10-24 06:26:28 +08:00
|
|
|
DiagnosticOptions *DiagOpts)
|
2012-08-21 11:11:53 +08:00
|
|
|
: DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer) {}
|
2011-12-17 13:26:11 +08:00
|
|
|
|
|
|
|
virtual ~SDiagsRenderer() {}
|
|
|
|
|
|
|
|
protected:
|
2014-03-13 14:07:04 +08:00
|
|
|
void emitDiagnosticMessage(SourceLocation Loc,
|
|
|
|
PresumedLoc PLoc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
StringRef Message,
|
|
|
|
ArrayRef<CharSourceRange> Ranges,
|
|
|
|
const SourceManager *SM,
|
|
|
|
DiagOrStoredDiag D) override;
|
|
|
|
|
|
|
|
void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
ArrayRef<CharSourceRange> Ranges,
|
|
|
|
const SourceManager &SM) override {}
|
|
|
|
|
|
|
|
void emitNote(SourceLocation Loc, StringRef Message,
|
|
|
|
const SourceManager *SM) override;
|
|
|
|
|
|
|
|
void emitCodeContext(SourceLocation Loc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
SmallVectorImpl<CharSourceRange>& Ranges,
|
|
|
|
ArrayRef<FixItHint> Hints,
|
|
|
|
const SourceManager &SM) override;
|
|
|
|
|
|
|
|
void beginDiagnostic(DiagOrStoredDiag D,
|
|
|
|
DiagnosticsEngine::Level Level) override;
|
|
|
|
void endDiagnostic(DiagOrStoredDiag D,
|
|
|
|
DiagnosticsEngine::Level Level) override;
|
2011-12-17 13:26:11 +08:00
|
|
|
};
|
2011-10-29 08:12:39 +08:00
|
|
|
|
|
|
|
class SDiagsWriter : public DiagnosticConsumer {
|
2011-12-17 13:26:11 +08:00
|
|
|
friend class SDiagsRenderer;
|
2012-12-01 07:32:31 +08:00
|
|
|
|
|
|
|
struct SharedState;
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
explicit SDiagsWriter(IntrusiveRefCntPtr<SharedState> State)
|
2014-05-22 12:46:25 +08:00
|
|
|
: LangOpts(nullptr), OriginalInstance(false), State(State) {}
|
2012-12-01 07:32:31 +08:00
|
|
|
|
|
|
|
public:
|
2014-08-30 04:17:13 +08:00
|
|
|
SDiagsWriter(std::unique_ptr<raw_ostream> os, DiagnosticOptions *diags)
|
|
|
|
: LangOpts(nullptr), OriginalInstance(true),
|
|
|
|
State(new SharedState(std::move(os), diags)) {
|
2011-10-29 08:12:39 +08:00
|
|
|
EmitPreamble();
|
2011-11-15 09:30:40 +08:00
|
|
|
}
|
2012-08-21 11:11:53 +08:00
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
~SDiagsWriter() {}
|
2014-03-13 14:07:04 +08:00
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
|
2014-03-13 14:07:04 +08:00
|
|
|
const Diagnostic &Info) override;
|
|
|
|
|
|
|
|
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override {
|
2011-11-10 16:43:12 +08:00
|
|
|
LangOpts = &LO;
|
|
|
|
}
|
2011-12-07 13:52:12 +08:00
|
|
|
|
2014-03-13 14:07:04 +08:00
|
|
|
void finish() override;
|
2011-12-07 13:52:12 +08:00
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
private:
|
|
|
|
/// \brief Emit the preamble for the serialized diagnostics.
|
|
|
|
void EmitPreamble();
|
|
|
|
|
|
|
|
/// \brief Emit the BLOCKINFO block.
|
|
|
|
void EmitBlockInfoBlock();
|
2011-11-05 08:10:11 +08:00
|
|
|
|
2011-11-09 04:27:29 +08:00
|
|
|
/// \brief Emit the META data block.
|
|
|
|
void EmitMetaBlock();
|
2012-08-21 11:11:53 +08:00
|
|
|
|
|
|
|
/// \brief Start a DIAG block.
|
|
|
|
void EnterDiagBlock();
|
|
|
|
|
|
|
|
/// \brief End a DIAG block.
|
|
|
|
void ExitDiagBlock();
|
|
|
|
|
|
|
|
/// \brief Emit a DIAG record.
|
|
|
|
void EmitDiagnosticMessage(SourceLocation Loc,
|
|
|
|
PresumedLoc PLoc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
StringRef Message,
|
|
|
|
const SourceManager *SM,
|
|
|
|
DiagOrStoredDiag D);
|
|
|
|
|
|
|
|
/// \brief Emit FIXIT and SOURCE_RANGE records for a diagnostic.
|
|
|
|
void EmitCodeContext(SmallVectorImpl<CharSourceRange> &Ranges,
|
|
|
|
ArrayRef<FixItHint> Hints,
|
|
|
|
const SourceManager &SM);
|
|
|
|
|
2011-11-05 08:10:01 +08:00
|
|
|
/// \brief Emit a record for a CharSourceRange.
|
2011-12-17 13:26:11 +08:00
|
|
|
void EmitCharSourceRange(CharSourceRange R, const SourceManager &SM);
|
2011-11-05 08:10:01 +08:00
|
|
|
|
2011-12-17 13:26:11 +08:00
|
|
|
/// \brief Emit the string information for the category.
|
|
|
|
unsigned getEmitCategory(unsigned category = 0);
|
2011-11-05 08:10:07 +08:00
|
|
|
|
|
|
|
/// \brief Emit the string information for diagnostic flags.
|
|
|
|
unsigned getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel,
|
2011-12-17 13:26:11 +08:00
|
|
|
unsigned DiagID = 0);
|
2011-11-05 08:10:04 +08:00
|
|
|
|
2011-11-05 08:10:11 +08:00
|
|
|
/// \brief Emit (lazily) the file string and retrieved the file identifier.
|
2011-12-17 13:26:11 +08:00
|
|
|
unsigned getEmitFile(const char *Filename);
|
|
|
|
|
|
|
|
/// \brief Add SourceLocation information the specified record.
|
2012-05-10 13:03:45 +08:00
|
|
|
void AddLocToRecord(SourceLocation Loc, const SourceManager *SM,
|
2011-12-17 13:26:11 +08:00
|
|
|
PresumedLoc PLoc, RecordDataImpl &Record,
|
|
|
|
unsigned TokSize = 0);
|
|
|
|
|
2011-11-05 08:10:11 +08:00
|
|
|
/// \brief Add SourceLocation information the specified record.
|
2011-11-10 16:43:12 +08:00
|
|
|
void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record,
|
2012-05-10 13:03:45 +08:00
|
|
|
const SourceManager *SM,
|
2011-12-17 13:26:11 +08:00
|
|
|
unsigned TokSize = 0) {
|
2012-05-10 13:03:45 +08:00
|
|
|
AddLocToRecord(Loc, SM, SM ? SM->getPresumedLoc(Loc) : PresumedLoc(),
|
|
|
|
Record, TokSize);
|
2011-12-17 13:26:11 +08:00
|
|
|
}
|
2011-11-05 08:10:11 +08:00
|
|
|
|
2011-11-05 11:34:23 +08:00
|
|
|
/// \brief Add CharSourceRange information the specified record.
|
2011-12-07 13:52:12 +08:00
|
|
|
void AddCharSourceRangeToRecord(CharSourceRange R, RecordDataImpl &Record,
|
2011-12-17 13:26:11 +08:00
|
|
|
const SourceManager &SM);
|
2011-11-05 11:34:23 +08:00
|
|
|
|
2014-10-14 08:57:34 +08:00
|
|
|
/// \brief The version of the diagnostics file.
|
|
|
|
enum { Version = 2 };
|
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief Language options, which can differ from one clone of this client
|
|
|
|
/// to another.
|
2011-11-10 16:43:12 +08:00
|
|
|
const LangOptions *LangOpts;
|
2011-10-29 08:12:39 +08:00
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief Whether this is the original instance (rather than one of its
|
|
|
|
/// clones), responsible for writing the file at the end.
|
|
|
|
bool OriginalInstance;
|
2011-10-29 08:12:39 +08:00
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief State that is shared among the various clones of this diagnostic
|
|
|
|
/// consumer.
|
2013-01-13 03:30:44 +08:00
|
|
|
struct SharedState : RefCountedBase<SharedState> {
|
2014-08-30 04:17:13 +08:00
|
|
|
SharedState(std::unique_ptr<raw_ostream> os, DiagnosticOptions *diags)
|
|
|
|
: DiagOpts(diags), Stream(Buffer), OS(std::move(os)),
|
|
|
|
EmittedAnyDiagBlocks(false) {}
|
2011-10-29 08:12:39 +08:00
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief Diagnostic options.
|
2013-01-13 03:30:44 +08:00
|
|
|
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
|
2011-10-29 08:12:39 +08:00
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief The byte buffer for the serialized content.
|
|
|
|
SmallString<1024> Buffer;
|
|
|
|
|
|
|
|
/// \brief The BitStreamWriter for the serialized diagnostics.
|
|
|
|
llvm::BitstreamWriter Stream;
|
|
|
|
|
|
|
|
/// \brief The name of the diagnostics file.
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<raw_ostream> OS;
|
2012-12-01 07:32:31 +08:00
|
|
|
|
|
|
|
/// \brief The set of constructed record abbreviations.
|
|
|
|
AbbreviationMap Abbrevs;
|
2011-11-05 08:09:50 +08:00
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief A utility buffer for constructing record content.
|
|
|
|
RecordData Record;
|
|
|
|
|
|
|
|
/// \brief A text buffer for rendering diagnostic text.
|
|
|
|
SmallString<256> diagBuf;
|
|
|
|
|
|
|
|
/// \brief The collection of diagnostic categories used.
|
|
|
|
llvm::DenseSet<unsigned> Categories;
|
|
|
|
|
|
|
|
/// \brief The collection of files used.
|
|
|
|
llvm::DenseMap<const char *, unsigned> Files;
|
2011-11-05 08:09:50 +08:00
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
typedef llvm::DenseMap<const void *, std::pair<unsigned, StringRef> >
|
2012-12-01 07:32:31 +08:00
|
|
|
DiagFlagsTy;
|
2012-08-21 11:11:53 +08:00
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
/// \brief Map for uniquing strings.
|
|
|
|
DiagFlagsTy DiagFlags;
|
|
|
|
|
|
|
|
/// \brief Whether we have already started emission of any DIAG blocks. Once
|
|
|
|
/// this becomes \c true, we never close a DIAG block until we know that we're
|
|
|
|
/// starting another one or we're done.
|
|
|
|
bool EmittedAnyDiagBlocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief State shared among the various clones of this diagnostic consumer.
|
2013-01-13 03:30:44 +08:00
|
|
|
IntrusiveRefCntPtr<SharedState> State;
|
2011-10-29 08:12:39 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace serialized_diags {
|
2014-09-16 01:50:10 +08:00
|
|
|
std::unique_ptr<DiagnosticConsumer> create(std::unique_ptr<raw_ostream> OS,
|
|
|
|
DiagnosticOptions *diags) {
|
|
|
|
return llvm::make_unique<SDiagsWriter>(std::move(OS), diags);
|
2011-10-29 08:12:39 +08:00
|
|
|
}
|
|
|
|
} // end namespace serialized_diags
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Serialization methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// \brief Emits a block ID in the BLOCKINFO block.
|
|
|
|
static void EmitBlockID(unsigned ID, const char *Name,
|
|
|
|
llvm::BitstreamWriter &Stream,
|
|
|
|
RecordDataImpl &Record) {
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(ID);
|
|
|
|
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
|
|
|
|
|
|
|
|
// Emit the block name if present.
|
2014-05-22 12:46:25 +08:00
|
|
|
if (!Name || Name[0] == 0)
|
2011-10-29 08:12:39 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
Record.clear();
|
|
|
|
|
|
|
|
while (*Name)
|
|
|
|
Record.push_back(*Name++);
|
|
|
|
|
|
|
|
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Emits a record ID in the BLOCKINFO block.
|
|
|
|
static void EmitRecordID(unsigned ID, const char *Name,
|
|
|
|
llvm::BitstreamWriter &Stream,
|
|
|
|
RecordDataImpl &Record){
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(ID);
|
|
|
|
|
|
|
|
while (*Name)
|
|
|
|
Record.push_back(*Name++);
|
|
|
|
|
|
|
|
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
|
|
|
|
}
|
|
|
|
|
2011-11-05 08:10:11 +08:00
|
|
|
void SDiagsWriter::AddLocToRecord(SourceLocation Loc,
|
2012-05-10 13:03:45 +08:00
|
|
|
const SourceManager *SM,
|
2011-12-17 13:26:11 +08:00
|
|
|
PresumedLoc PLoc,
|
2011-11-10 16:43:12 +08:00
|
|
|
RecordDataImpl &Record,
|
|
|
|
unsigned TokSize) {
|
2011-12-17 13:26:11 +08:00
|
|
|
if (PLoc.isInvalid()) {
|
2011-11-05 08:10:01 +08:00
|
|
|
// Emit a "sentinel" location.
|
2011-11-10 16:43:12 +08:00
|
|
|
Record.push_back((unsigned)0); // File.
|
|
|
|
Record.push_back((unsigned)0); // Line.
|
|
|
|
Record.push_back((unsigned)0); // Column.
|
|
|
|
Record.push_back((unsigned)0); // Offset.
|
2011-11-05 08:10:01 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-17 13:26:11 +08:00
|
|
|
Record.push_back(getEmitFile(PLoc.getFilename()));
|
|
|
|
Record.push_back(PLoc.getLine());
|
|
|
|
Record.push_back(PLoc.getColumn()+TokSize);
|
2012-05-10 13:03:45 +08:00
|
|
|
Record.push_back(SM->getFileOffset(Loc));
|
2011-11-05 08:10:01 +08:00
|
|
|
}
|
|
|
|
|
2011-11-05 11:34:23 +08:00
|
|
|
void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range,
|
2011-12-07 13:52:12 +08:00
|
|
|
RecordDataImpl &Record,
|
2011-12-17 13:26:11 +08:00
|
|
|
const SourceManager &SM) {
|
2012-05-10 13:03:45 +08:00
|
|
|
AddLocToRecord(Range.getBegin(), Record, &SM);
|
2011-11-10 16:43:12 +08:00
|
|
|
unsigned TokSize = 0;
|
|
|
|
if (Range.isTokenRange())
|
|
|
|
TokSize = Lexer::MeasureTokenLength(Range.getEnd(),
|
2011-12-07 13:52:12 +08:00
|
|
|
SM, *LangOpts);
|
2011-11-10 16:43:12 +08:00
|
|
|
|
2012-05-10 13:03:45 +08:00
|
|
|
AddLocToRecord(Range.getEnd(), Record, &SM, TokSize);
|
2011-11-05 11:34:23 +08:00
|
|
|
}
|
|
|
|
|
2011-12-17 13:26:11 +08:00
|
|
|
unsigned SDiagsWriter::getEmitFile(const char *FileName){
|
|
|
|
if (!FileName)
|
2011-11-05 08:10:11 +08:00
|
|
|
return 0;
|
|
|
|
|
2012-12-01 07:32:31 +08:00
|
|
|
unsigned &entry = State->Files[FileName];
|
2011-11-05 08:10:11 +08:00
|
|
|
if (entry)
|
|
|
|
return entry;
|
|
|
|
|
|
|
|
// Lazily generate the record for the file.
|
2012-12-01 07:32:31 +08:00
|
|
|
entry = State->Files.size();
|
2011-11-05 08:10:11 +08:00
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(RECORD_FILENAME);
|
|
|
|
Record.push_back(entry);
|
2011-12-17 13:26:11 +08:00
|
|
|
Record.push_back(0); // For legacy.
|
|
|
|
Record.push_back(0); // For legacy.
|
|
|
|
StringRef Name(FileName);
|
2011-11-05 08:10:11 +08:00
|
|
|
Record.push_back(Name.size());
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME), Record,
|
|
|
|
Name);
|
2011-11-05 08:10:11 +08:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2011-12-07 13:52:12 +08:00
|
|
|
void SDiagsWriter::EmitCharSourceRange(CharSourceRange R,
|
2011-12-17 13:26:11 +08:00
|
|
|
const SourceManager &SM) {
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Record.clear();
|
|
|
|
State->Record.push_back(RECORD_SOURCE_RANGE);
|
|
|
|
AddCharSourceRangeToRecord(R, State->Record, SM);
|
|
|
|
State->Stream.EmitRecordWithAbbrev(State->Abbrevs.get(RECORD_SOURCE_RANGE),
|
|
|
|
State->Record);
|
2011-11-05 08:10:01 +08:00
|
|
|
}
|
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
/// \brief Emits the preamble of the diagnostics file.
|
|
|
|
void SDiagsWriter::EmitPreamble() {
|
|
|
|
// Emit the file header.
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.Emit((unsigned)'D', 8);
|
|
|
|
State->Stream.Emit((unsigned)'I', 8);
|
|
|
|
State->Stream.Emit((unsigned)'A', 8);
|
|
|
|
State->Stream.Emit((unsigned)'G', 8);
|
2011-11-05 08:09:53 +08:00
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
EmitBlockInfoBlock();
|
2011-11-09 04:27:29 +08:00
|
|
|
EmitMetaBlock();
|
2011-10-29 08:12:39 +08:00
|
|
|
}
|
|
|
|
|
2011-11-05 08:10:01 +08:00
|
|
|
static void AddSourceLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
|
|
|
|
using namespace llvm;
|
2011-11-05 08:10:11 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // File ID.
|
2011-11-05 08:10:01 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Line.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Column.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Offset;
|
|
|
|
}
|
2011-11-05 11:34:23 +08:00
|
|
|
|
|
|
|
static void AddRangeLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
|
|
|
|
AddSourceLocationAbbrev(Abbrev);
|
|
|
|
AddSourceLocationAbbrev(Abbrev);
|
|
|
|
}
|
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
void SDiagsWriter::EmitBlockInfoBlock() {
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.EnterBlockInfoBlock(3);
|
2011-11-09 04:27:29 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
2012-12-01 07:32:31 +08:00
|
|
|
llvm::BitstreamWriter &Stream = State->Stream;
|
|
|
|
RecordData &Record = State->Record;
|
|
|
|
AbbreviationMap &Abbrevs = State->Abbrevs;
|
2011-11-09 04:27:29 +08:00
|
|
|
|
|
|
|
// ==---------------------------------------------------------------------==//
|
|
|
|
// The subsequent records and Abbrevs are for the "Meta" block.
|
|
|
|
// ==---------------------------------------------------------------------==//
|
|
|
|
|
|
|
|
EmitBlockID(BLOCK_META, "Meta", Stream, Record);
|
|
|
|
EmitRecordID(RECORD_VERSION, "Version", Stream, Record);
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_VERSION));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
|
|
|
Abbrevs.set(RECORD_VERSION, Stream.EmitBlockInfoAbbrev(BLOCK_META, Abbrev));
|
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
// ==---------------------------------------------------------------------==//
|
|
|
|
// The subsequent records and Abbrevs are for the "Diagnostic" block.
|
|
|
|
// ==---------------------------------------------------------------------==//
|
|
|
|
|
2011-11-05 08:09:50 +08:00
|
|
|
EmitBlockID(BLOCK_DIAG, "Diag", Stream, Record);
|
|
|
|
EmitRecordID(RECORD_DIAG, "DiagInfo", Stream, Record);
|
2011-11-05 08:10:01 +08:00
|
|
|
EmitRecordID(RECORD_SOURCE_RANGE, "SrcRange", Stream, Record);
|
2011-11-05 08:10:04 +08:00
|
|
|
EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record);
|
2011-11-05 08:10:07 +08:00
|
|
|
EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record);
|
2011-11-05 08:10:11 +08:00
|
|
|
EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record);
|
2011-11-05 11:34:23 +08:00
|
|
|
EmitRecordID(RECORD_FIXIT, "FixIt", Stream, Record);
|
2011-11-05 08:10:07 +08:00
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
// Emit abbreviation for RECORD_DIAG.
|
2011-11-09 04:27:29 +08:00
|
|
|
Abbrev = new BitCodeAbbrev();
|
2011-10-29 08:12:39 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG));
|
2011-11-05 08:09:50 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Diag level.
|
2011-11-05 08:10:01 +08:00
|
|
|
AddSourceLocationAbbrev(Abbrev);
|
2011-11-05 08:09:50 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Category.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID.
|
2011-10-29 08:12:39 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Diagnostc text.
|
|
|
|
Abbrevs.set(RECORD_DIAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
|
2011-11-05 08:10:01 +08:00
|
|
|
|
2011-11-05 08:10:04 +08:00
|
|
|
// Emit abbrevation for RECORD_CATEGORY.
|
|
|
|
Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_CATEGORY));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Category ID.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // Text size.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Category text.
|
|
|
|
Abbrevs.set(RECORD_CATEGORY, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
|
|
|
|
|
2011-11-05 08:10:01 +08:00
|
|
|
// Emit abbrevation for RECORD_SOURCE_RANGE.
|
|
|
|
Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_SOURCE_RANGE));
|
2011-11-05 11:34:23 +08:00
|
|
|
AddRangeLocationAbbrev(Abbrev);
|
2011-11-05 08:10:01 +08:00
|
|
|
Abbrevs.set(RECORD_SOURCE_RANGE,
|
|
|
|
Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
|
2011-11-05 08:10:07 +08:00
|
|
|
|
|
|
|
// Emit the abbreviation for RECORD_DIAG_FLAG.
|
|
|
|
Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG_FLAG));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Flag name text.
|
|
|
|
Abbrevs.set(RECORD_DIAG_FLAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
|
|
|
|
Abbrev));
|
2011-11-05 08:10:11 +08:00
|
|
|
|
|
|
|
// Emit the abbreviation for RECORD_FILENAME.
|
2011-10-29 08:12:39 +08:00
|
|
|
Abbrev = new BitCodeAbbrev();
|
2011-11-05 08:09:43 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME));
|
2011-11-05 08:10:11 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped file ID.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Size.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Modifcation time.
|
2011-10-29 08:12:39 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name text.
|
2011-11-05 08:10:11 +08:00
|
|
|
Abbrevs.set(RECORD_FILENAME, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
|
2011-10-29 08:12:39 +08:00
|
|
|
Abbrev));
|
2011-11-05 11:34:23 +08:00
|
|
|
|
|
|
|
// Emit the abbreviation for RECORD_FIXIT.
|
|
|
|
Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(RECORD_FIXIT));
|
|
|
|
AddRangeLocationAbbrev(Abbrev);
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size.
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // FixIt text.
|
|
|
|
Abbrevs.set(RECORD_FIXIT, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
|
|
|
|
Abbrev));
|
2011-10-29 08:12:39 +08:00
|
|
|
|
|
|
|
Stream.ExitBlock();
|
|
|
|
}
|
|
|
|
|
2011-11-09 04:27:29 +08:00
|
|
|
void SDiagsWriter::EmitMetaBlock() {
|
2012-12-01 07:32:31 +08:00
|
|
|
llvm::BitstreamWriter &Stream = State->Stream;
|
|
|
|
RecordData &Record = State->Record;
|
|
|
|
AbbreviationMap &Abbrevs = State->Abbrevs;
|
|
|
|
|
2011-11-09 04:27:29 +08:00
|
|
|
Stream.EnterSubblock(BLOCK_META, 3);
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(RECORD_VERSION);
|
2014-10-14 08:57:34 +08:00
|
|
|
Record.push_back(Version);
|
2011-11-09 04:27:29 +08:00
|
|
|
Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
|
|
|
|
Stream.ExitBlock();
|
|
|
|
}
|
|
|
|
|
2011-12-17 13:26:11 +08:00
|
|
|
unsigned SDiagsWriter::getEmitCategory(unsigned int category) {
|
2014-10-10 23:32:48 +08:00
|
|
|
if (!State->Categories.insert(category).second)
|
2011-11-05 08:10:07 +08:00
|
|
|
return category;
|
2014-10-10 23:32:48 +08:00
|
|
|
|
2011-11-05 08:10:04 +08:00
|
|
|
// We use a local version of 'Record' so that we can be generating
|
|
|
|
// another record when we lazily generate one for the category entry.
|
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(RECORD_CATEGORY);
|
2011-11-05 08:10:07 +08:00
|
|
|
Record.push_back(category);
|
|
|
|
StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
|
2011-11-05 08:10:04 +08:00
|
|
|
Record.push_back(catName.size());
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record,
|
|
|
|
catName);
|
2011-11-05 08:10:07 +08:00
|
|
|
|
|
|
|
return category;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SDiagsWriter::getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel,
|
2011-12-17 13:26:11 +08:00
|
|
|
unsigned DiagID) {
|
2011-11-05 08:10:07 +08:00
|
|
|
if (DiagLevel == DiagnosticsEngine::Note)
|
|
|
|
return 0; // No flag for notes.
|
|
|
|
|
2011-12-17 13:26:11 +08:00
|
|
|
StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(DiagID);
|
2011-11-05 08:10:07 +08:00
|
|
|
if (FlagName.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Here we assume that FlagName points to static data whose pointer
|
|
|
|
// value is fixed. This allows us to unique by diagnostic groups.
|
|
|
|
const void *data = FlagName.data();
|
2012-12-01 07:32:31 +08:00
|
|
|
std::pair<unsigned, StringRef> &entry = State->DiagFlags[data];
|
2011-11-05 08:10:07 +08:00
|
|
|
if (entry.first == 0) {
|
2012-12-01 07:32:31 +08:00
|
|
|
entry.first = State->DiagFlags.size();
|
2011-11-05 08:10:07 +08:00
|
|
|
entry.second = FlagName;
|
|
|
|
|
|
|
|
// Lazily emit the string in a separate record.
|
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(RECORD_DIAG_FLAG);
|
|
|
|
Record.push_back(entry.first);
|
|
|
|
Record.push_back(FlagName.size());
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_DIAG_FLAG),
|
|
|
|
Record, FlagName);
|
2011-11-05 08:10:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return entry.first;
|
2011-11-05 08:10:04 +08:00
|
|
|
}
|
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
|
|
|
|
const Diagnostic &Info) {
|
2012-08-21 11:11:53 +08:00
|
|
|
// Enter the block for a non-note diagnostic immediately, rather than waiting
|
|
|
|
// for beginDiagnostic, in case associated notes are emitted before we get
|
|
|
|
// there.
|
2011-11-05 08:09:47 +08:00
|
|
|
if (DiagLevel != DiagnosticsEngine::Note) {
|
2012-12-01 07:32:31 +08:00
|
|
|
if (State->EmittedAnyDiagBlocks)
|
2012-08-21 11:11:53 +08:00
|
|
|
ExitDiagBlock();
|
|
|
|
|
|
|
|
EnterDiagBlock();
|
2012-12-01 07:32:31 +08:00
|
|
|
State->EmittedAnyDiagBlocks = true;
|
2011-11-05 08:09:47 +08:00
|
|
|
}
|
2011-12-17 13:26:11 +08:00
|
|
|
|
|
|
|
// Compute the diagnostic text.
|
2012-12-01 07:32:31 +08:00
|
|
|
State->diagBuf.clear();
|
|
|
|
Info.FormatDiagnostic(State->diagBuf);
|
2011-12-17 13:26:11 +08:00
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
if (Info.getLocation().isInvalid()) {
|
|
|
|
// Special-case diagnostics with no location. We may not have entered a
|
|
|
|
// source file in this case, so we can't use the normal DiagnosticsRenderer
|
|
|
|
// machinery.
|
2013-02-22 05:40:44 +08:00
|
|
|
|
|
|
|
// Make sure we bracket all notes as "sub-diagnostics". This matches
|
|
|
|
// the behavior in SDiagsRenderer::emitDiagnostic().
|
|
|
|
if (DiagLevel == DiagnosticsEngine::Note)
|
|
|
|
EnterDiagBlock();
|
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
EmitDiagnosticMessage(SourceLocation(), PresumedLoc(), DiagLevel,
|
2014-05-22 12:46:25 +08:00
|
|
|
State->diagBuf, nullptr, &Info);
|
2013-02-22 05:40:44 +08:00
|
|
|
|
|
|
|
if (DiagLevel == DiagnosticsEngine::Note)
|
|
|
|
ExitDiagBlock();
|
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(Info.hasSourceManager() && LangOpts &&
|
|
|
|
"Unexpected diagnostic with valid location outside of a source file");
|
2012-12-01 07:32:31 +08:00
|
|
|
SDiagsRenderer Renderer(*this, *LangOpts, &*State->DiagOpts);
|
2011-12-17 13:26:11 +08:00
|
|
|
Renderer.emitDiagnostic(Info.getLocation(), DiagLevel,
|
2012-12-01 07:32:31 +08:00
|
|
|
State->diagBuf.str(),
|
2011-12-17 13:26:11 +08:00
|
|
|
Info.getRanges(),
|
2014-05-23 03:56:11 +08:00
|
|
|
Info.getFixItHints(),
|
2012-08-21 11:11:53 +08:00
|
|
|
&Info.getSourceManager(),
|
2011-12-17 13:26:11 +08:00
|
|
|
&Info);
|
|
|
|
}
|
|
|
|
|
2014-03-04 02:29:52 +08:00
|
|
|
static serialized_diags::Level getStableLevel(DiagnosticsEngine::Level Level) {
|
|
|
|
switch (Level) {
|
|
|
|
#define CASE(X) case DiagnosticsEngine::X: return serialized_diags::X;
|
|
|
|
CASE(Ignored)
|
|
|
|
CASE(Note)
|
|
|
|
CASE(Remark)
|
|
|
|
CASE(Warning)
|
|
|
|
CASE(Error)
|
|
|
|
CASE(Fatal)
|
|
|
|
#undef CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("invalid diagnostic level");
|
|
|
|
}
|
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc,
|
|
|
|
PresumedLoc PLoc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
StringRef Message,
|
|
|
|
const SourceManager *SM,
|
|
|
|
DiagOrStoredDiag D) {
|
2012-12-01 07:32:31 +08:00
|
|
|
llvm::BitstreamWriter &Stream = State->Stream;
|
|
|
|
RecordData &Record = State->Record;
|
|
|
|
AbbreviationMap &Abbrevs = State->Abbrevs;
|
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
// Emit the RECORD_DIAG record.
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(RECORD_DIAG);
|
2014-03-04 02:29:52 +08:00
|
|
|
Record.push_back(getStableLevel(Level));
|
2012-08-21 11:11:53 +08:00
|
|
|
AddLocToRecord(Loc, SM, PLoc, Record);
|
|
|
|
|
|
|
|
if (const Diagnostic *Info = D.dyn_cast<const Diagnostic*>()) {
|
|
|
|
// Emit the category string lazily and get the category ID.
|
|
|
|
unsigned DiagID = DiagnosticIDs::getCategoryNumberForDiag(Info->getID());
|
|
|
|
Record.push_back(getEmitCategory(DiagID));
|
|
|
|
// Emit the diagnostic flag string lazily and get the mapped ID.
|
|
|
|
Record.push_back(getEmitDiagnosticFlag(Level, Info->getID()));
|
|
|
|
} else {
|
|
|
|
Record.push_back(getEmitCategory());
|
|
|
|
Record.push_back(getEmitDiagnosticFlag(Level));
|
|
|
|
}
|
|
|
|
|
|
|
|
Record.push_back(Message.size());
|
|
|
|
Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, Message);
|
|
|
|
}
|
|
|
|
|
2011-12-17 13:26:11 +08:00
|
|
|
void
|
|
|
|
SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc,
|
|
|
|
PresumedLoc PLoc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
StringRef Message,
|
|
|
|
ArrayRef<clang::CharSourceRange> Ranges,
|
2012-05-10 13:03:45 +08:00
|
|
|
const SourceManager *SM,
|
2012-02-14 10:46:00 +08:00
|
|
|
DiagOrStoredDiag D) {
|
2012-08-21 11:11:53 +08:00
|
|
|
Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, SM, D);
|
|
|
|
}
|
2011-12-17 13:26:11 +08:00
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
void SDiagsWriter::EnterDiagBlock() {
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.EnterSubblock(BLOCK_DIAG, 4);
|
2012-08-21 11:11:53 +08:00
|
|
|
}
|
2011-12-17 13:26:11 +08:00
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
void SDiagsWriter::ExitDiagBlock() {
|
2012-12-01 07:32:31 +08:00
|
|
|
State->Stream.ExitBlock();
|
2011-12-17 13:26:11 +08:00
|
|
|
}
|
|
|
|
|
2012-02-14 10:46:00 +08:00
|
|
|
void SDiagsRenderer::beginDiagnostic(DiagOrStoredDiag D,
|
2011-12-17 13:26:11 +08:00
|
|
|
DiagnosticsEngine::Level Level) {
|
2012-08-21 11:11:53 +08:00
|
|
|
if (Level == DiagnosticsEngine::Note)
|
|
|
|
Writer.EnterDiagBlock();
|
2011-12-17 13:26:11 +08:00
|
|
|
}
|
|
|
|
|
2012-02-14 10:46:00 +08:00
|
|
|
void SDiagsRenderer::endDiagnostic(DiagOrStoredDiag D,
|
2011-12-17 13:26:11 +08:00
|
|
|
DiagnosticsEngine::Level Level) {
|
2012-08-21 11:11:53 +08:00
|
|
|
// Only end note diagnostics here, because we can't be sure when we've seen
|
|
|
|
// the last note associated with a non-note diagnostic.
|
|
|
|
if (Level == DiagnosticsEngine::Note)
|
|
|
|
Writer.ExitDiagBlock();
|
2011-12-17 13:26:11 +08:00
|
|
|
}
|
2011-11-05 11:34:23 +08:00
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
void SDiagsWriter::EmitCodeContext(SmallVectorImpl<CharSourceRange> &Ranges,
|
|
|
|
ArrayRef<FixItHint> Hints,
|
|
|
|
const SourceManager &SM) {
|
2012-12-01 07:32:31 +08:00
|
|
|
llvm::BitstreamWriter &Stream = State->Stream;
|
|
|
|
RecordData &Record = State->Record;
|
|
|
|
AbbreviationMap &Abbrevs = State->Abbrevs;
|
|
|
|
|
2011-11-05 11:34:23 +08:00
|
|
|
// Emit Source Ranges.
|
2012-08-21 11:11:53 +08:00
|
|
|
for (ArrayRef<CharSourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (I->isValid())
|
|
|
|
EmitCharSourceRange(*I, SM);
|
|
|
|
|
2011-11-05 11:34:23 +08:00
|
|
|
// Emit FixIts.
|
2012-08-21 11:11:53 +08:00
|
|
|
for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const FixItHint &Fix = *I;
|
|
|
|
if (Fix.isNull())
|
2011-11-05 11:34:23 +08:00
|
|
|
continue;
|
2012-08-21 11:11:53 +08:00
|
|
|
Record.clear();
|
|
|
|
Record.push_back(RECORD_FIXIT);
|
|
|
|
AddCharSourceRangeToRecord(Fix.RemoveRange, Record, SM);
|
|
|
|
Record.push_back(Fix.CodeToInsert.size());
|
|
|
|
Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_FIXIT), Record,
|
|
|
|
Fix.CodeToInsert);
|
2011-11-05 08:09:47 +08:00
|
|
|
}
|
2011-10-29 08:12:39 +08:00
|
|
|
}
|
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
void SDiagsRenderer::emitCodeContext(SourceLocation Loc,
|
|
|
|
DiagnosticsEngine::Level Level,
|
|
|
|
SmallVectorImpl<CharSourceRange> &Ranges,
|
|
|
|
ArrayRef<FixItHint> Hints,
|
|
|
|
const SourceManager &SM) {
|
|
|
|
Writer.EmitCodeContext(Ranges, Hints, SM);
|
|
|
|
}
|
|
|
|
|
2012-05-10 13:03:45 +08:00
|
|
|
void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message,
|
|
|
|
const SourceManager *SM) {
|
2012-08-21 11:11:53 +08:00
|
|
|
Writer.EnterDiagBlock();
|
|
|
|
PresumedLoc PLoc = SM ? SM->getPresumedLoc(Loc) : PresumedLoc();
|
|
|
|
Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note,
|
|
|
|
Message, SM, DiagOrStoredDiag());
|
|
|
|
Writer.ExitDiagBlock();
|
2011-12-17 13:26:11 +08:00
|
|
|
}
|
|
|
|
|
2011-12-07 13:52:12 +08:00
|
|
|
void SDiagsWriter::finish() {
|
2012-12-01 07:32:31 +08:00
|
|
|
// The original instance is responsible for writing the file.
|
|
|
|
if (!OriginalInstance)
|
|
|
|
return;
|
|
|
|
|
2012-08-21 11:11:53 +08:00
|
|
|
// Finish off any diagnostic we were in the process of emitting.
|
2012-12-01 07:32:31 +08:00
|
|
|
if (State->EmittedAnyDiagBlocks)
|
2012-08-21 11:11:53 +08:00
|
|
|
ExitDiagBlock();
|
2011-11-05 08:10:11 +08:00
|
|
|
|
2011-10-29 08:12:39 +08:00
|
|
|
// Write the generated bitstream to "Out".
|
2012-12-01 07:32:31 +08:00
|
|
|
State->OS->write((char *)&State->Buffer.front(), State->Buffer.size());
|
|
|
|
State->OS->flush();
|
2012-08-21 11:11:53 +08:00
|
|
|
|
2014-07-19 09:06:45 +08:00
|
|
|
State->OS.reset();
|
2011-10-29 08:12:39 +08:00
|
|
|
}
|