зеркало из https://github.com/microsoft/clang-1.git
Refactor DiagnosticRenderer and SDiagsRenderer to have some functionality
pulled into DiagnosticNoteRenderer, and common DiagnosticRenderer that assumes that all custom diagnostic messages are notes. Also extend DiagnosticRenderer to work with StoredDiagnostics in preparation for subsequent changes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150455 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
6700d67925
Коммит
8be51eab5a
|
@ -19,12 +19,17 @@
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "clang/Basic/LLVM.h"
|
#include "clang/Basic/LLVM.h"
|
||||||
#include "clang/Basic/SourceLocation.h"
|
#include "clang/Basic/SourceLocation.h"
|
||||||
|
#include "llvm/ADT/PointerUnion.h"
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
|
||||||
class DiagnosticOptions;
|
class DiagnosticOptions;
|
||||||
class LangOptions;
|
class LangOptions;
|
||||||
class SourceManager;
|
class SourceManager;
|
||||||
|
|
||||||
|
typedef llvm::PointerUnion<const Diagnostic *,
|
||||||
|
const StoredDiagnostic *> DiagOrStoredDiag;
|
||||||
|
|
||||||
/// \brief Class to encapsulate the logic for formatting a diagnostic message.
|
/// \brief Class to encapsulate the logic for formatting a diagnostic message.
|
||||||
/// Actual "printing" logic is implemented by subclasses.
|
/// Actual "printing" logic is implemented by subclasses.
|
||||||
///
|
///
|
||||||
|
@ -71,7 +76,7 @@ protected:
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
StringRef Message,
|
StringRef Message,
|
||||||
ArrayRef<CharSourceRange> Ranges,
|
ArrayRef<CharSourceRange> Ranges,
|
||||||
const Diagnostic *Info) = 0;
|
DiagOrStoredDiag Info) = 0;
|
||||||
|
|
||||||
virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
|
@ -86,9 +91,9 @@ protected:
|
||||||
|
|
||||||
virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc) = 0;
|
virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc) = 0;
|
||||||
|
|
||||||
virtual void beginDiagnostic(const Diagnostic *Info,
|
virtual void beginDiagnostic(DiagOrStoredDiag D,
|
||||||
DiagnosticsEngine::Level Level) {}
|
DiagnosticsEngine::Level Level) {}
|
||||||
virtual void endDiagnostic(const Diagnostic *Info,
|
virtual void endDiagnostic(DiagOrStoredDiag D,
|
||||||
DiagnosticsEngine::Level Level) {}
|
DiagnosticsEngine::Level Level) {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +122,28 @@ public:
|
||||||
void emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level,
|
void emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level,
|
||||||
StringRef Message, ArrayRef<CharSourceRange> Ranges,
|
StringRef Message, ArrayRef<CharSourceRange> Ranges,
|
||||||
ArrayRef<FixItHint> FixItHints,
|
ArrayRef<FixItHint> FixItHints,
|
||||||
const Diagnostic *Info = 0);
|
DiagOrStoredDiag D = (Diagnostic *)0);
|
||||||
|
|
||||||
|
void emitStoredDiagnostic(StoredDiagnostic &Diag);
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Subclass of DiagnosticRender that turns all subdiagostics into explicit
|
||||||
|
/// notes. It is up to subclasses to further define the behavior.
|
||||||
|
class DiagnosticNoteRenderer : public DiagnosticRenderer {
|
||||||
|
public:
|
||||||
|
DiagnosticNoteRenderer(const SourceManager &SM,
|
||||||
|
const LangOptions &LangOpts,
|
||||||
|
const DiagnosticOptions &DiagOpts)
|
||||||
|
: DiagnosticRenderer(SM, LangOpts, DiagOpts) {}
|
||||||
|
|
||||||
|
virtual ~DiagnosticNoteRenderer();
|
||||||
|
|
||||||
|
virtual void emitBasicNote(StringRef Message);
|
||||||
|
|
||||||
|
virtual void emitIncludeLocation(SourceLocation Loc,
|
||||||
|
PresumedLoc PLoc);
|
||||||
|
|
||||||
|
virtual void emitNote(SourceLocation Loc, StringRef Message) = 0;
|
||||||
};
|
};
|
||||||
} // end clang namespace
|
} // end clang namespace
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -81,7 +81,7 @@ protected:
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
StringRef Message,
|
StringRef Message,
|
||||||
ArrayRef<CharSourceRange> Ranges,
|
ArrayRef<CharSourceRange> Ranges,
|
||||||
const Diagnostic *Info);
|
DiagOrStoredDiag D);
|
||||||
|
|
||||||
virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
|
|
|
@ -133,9 +133,9 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc,
|
||||||
StringRef Message,
|
StringRef Message,
|
||||||
ArrayRef<CharSourceRange> Ranges,
|
ArrayRef<CharSourceRange> Ranges,
|
||||||
ArrayRef<FixItHint> FixItHints,
|
ArrayRef<FixItHint> FixItHints,
|
||||||
const Diagnostic *Info) {
|
DiagOrStoredDiag D) {
|
||||||
|
|
||||||
beginDiagnostic(Info, Level);
|
beginDiagnostic(D, Level);
|
||||||
|
|
||||||
PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Loc);
|
PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Loc);
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc,
|
||||||
emitIncludeStack(PLoc.getIncludeLoc(), Level);
|
emitIncludeStack(PLoc.getIncludeLoc(), Level);
|
||||||
|
|
||||||
// Next, emit the actual diagnostic message.
|
// Next, emit the actual diagnostic message.
|
||||||
emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, Info);
|
emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, D);
|
||||||
|
|
||||||
// Only recurse if we have a valid location.
|
// Only recurse if we have a valid location.
|
||||||
if (Loc.isValid()) {
|
if (Loc.isValid()) {
|
||||||
|
@ -166,7 +166,14 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc,
|
||||||
LastLoc = Loc;
|
LastLoc = Loc;
|
||||||
LastLevel = Level;
|
LastLevel = Level;
|
||||||
|
|
||||||
endDiagnostic(Info, Level);
|
endDiagnostic(D, Level);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DiagnosticRenderer::emitStoredDiagnostic(StoredDiagnostic &Diag) {
|
||||||
|
emitDiagnostic(Diag.getLocation(), Diag.getLevel(), Diag.getMessage(),
|
||||||
|
Diag.getRanges(), Diag.getFixIts(),
|
||||||
|
&Diag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Prints an include stack when appropriate for a particular
|
/// \brief Prints an include stack when appropriate for a particular
|
||||||
|
@ -304,3 +311,19 @@ void DiagnosticRenderer::emitMacroExpansionsAndCarets(
|
||||||
Ranges, ArrayRef<FixItHint>());
|
Ranges, ArrayRef<FixItHint>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiagnosticNoteRenderer::~DiagnosticNoteRenderer() {}
|
||||||
|
|
||||||
|
void DiagnosticNoteRenderer::emitIncludeLocation(SourceLocation Loc,
|
||||||
|
PresumedLoc PLoc) {
|
||||||
|
// Generate a note indicating the include location.
|
||||||
|
SmallString<200> MessageStorage;
|
||||||
|
llvm::raw_svector_ostream Message(MessageStorage);
|
||||||
|
Message << "in file included from " << PLoc.getFilename() << ':'
|
||||||
|
<< PLoc.getLine() << ":";
|
||||||
|
emitNote(Loc, Message.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiagnosticNoteRenderer::emitBasicNote(StringRef Message) {
|
||||||
|
emitNote(SourceLocation(), Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ typedef llvm::SmallVectorImpl<uint64_t> RecordDataImpl;
|
||||||
|
|
||||||
class SDiagsWriter;
|
class SDiagsWriter;
|
||||||
|
|
||||||
class SDiagsRenderer : public DiagnosticRenderer {
|
class SDiagsRenderer : public DiagnosticNoteRenderer {
|
||||||
SDiagsWriter &Writer;
|
SDiagsWriter &Writer;
|
||||||
RecordData &Record;
|
RecordData &Record;
|
||||||
public:
|
public:
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
const SourceManager &SM,
|
const SourceManager &SM,
|
||||||
const LangOptions &LangOpts,
|
const LangOptions &LangOpts,
|
||||||
const DiagnosticOptions &DiagOpts)
|
const DiagnosticOptions &DiagOpts)
|
||||||
: DiagnosticRenderer(SM, LangOpts, DiagOpts),
|
: DiagnosticNoteRenderer(SM, LangOpts, DiagOpts),
|
||||||
Writer(Writer), Record(Record){}
|
Writer(Writer), Record(Record){}
|
||||||
|
|
||||||
virtual ~SDiagsRenderer() {}
|
virtual ~SDiagsRenderer() {}
|
||||||
|
@ -67,27 +67,22 @@ protected:
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
StringRef Message,
|
StringRef Message,
|
||||||
ArrayRef<CharSourceRange> Ranges,
|
ArrayRef<CharSourceRange> Ranges,
|
||||||
const Diagnostic *Info);
|
DiagOrStoredDiag D);
|
||||||
|
|
||||||
virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
ArrayRef<CharSourceRange> Ranges) {}
|
ArrayRef<CharSourceRange> Ranges) {}
|
||||||
|
|
||||||
virtual void emitBasicNote(StringRef Message);
|
|
||||||
|
|
||||||
void emitNote(SourceLocation Loc, StringRef Message);
|
void emitNote(SourceLocation Loc, StringRef Message);
|
||||||
|
|
||||||
virtual void emitIncludeLocation(SourceLocation Loc,
|
|
||||||
PresumedLoc PLoc);
|
|
||||||
|
|
||||||
virtual void emitCodeContext(SourceLocation Loc,
|
virtual void emitCodeContext(SourceLocation Loc,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
SmallVectorImpl<CharSourceRange>& Ranges,
|
SmallVectorImpl<CharSourceRange>& Ranges,
|
||||||
ArrayRef<FixItHint> Hints);
|
ArrayRef<FixItHint> Hints);
|
||||||
|
|
||||||
virtual void beginDiagnostic(const Diagnostic *Info,
|
virtual void beginDiagnostic(DiagOrStoredDiag D,
|
||||||
DiagnosticsEngine::Level Level);
|
DiagnosticsEngine::Level Level);
|
||||||
virtual void endDiagnostic(const Diagnostic *Info,
|
virtual void endDiagnostic(DiagOrStoredDiag D,
|
||||||
DiagnosticsEngine::Level Level);
|
DiagnosticsEngine::Level Level);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -505,14 +500,14 @@ SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
StringRef Message,
|
StringRef Message,
|
||||||
ArrayRef<clang::CharSourceRange> Ranges,
|
ArrayRef<clang::CharSourceRange> Ranges,
|
||||||
const Diagnostic *Info) {
|
DiagOrStoredDiag D) {
|
||||||
// Emit the RECORD_DIAG record.
|
// Emit the RECORD_DIAG record.
|
||||||
Writer.Record.clear();
|
Writer.Record.clear();
|
||||||
Writer.Record.push_back(RECORD_DIAG);
|
Writer.Record.push_back(RECORD_DIAG);
|
||||||
Writer.Record.push_back(Level);
|
Writer.Record.push_back(Level);
|
||||||
Writer.AddLocToRecord(Loc, SM, PLoc, Record);
|
Writer.AddLocToRecord(Loc, SM, PLoc, Record);
|
||||||
|
|
||||||
if (Info) {
|
if (const Diagnostic *Info = D.dyn_cast<const Diagnostic*>()) {
|
||||||
// Emit the category string lazily and get the category ID.
|
// Emit the category string lazily and get the category ID.
|
||||||
unsigned DiagID = DiagnosticIDs::getCategoryNumberForDiag(Info->getID());
|
unsigned DiagID = DiagnosticIDs::getCategoryNumberForDiag(Info->getID());
|
||||||
Writer.Record.push_back(Writer.getEmitCategory(DiagID));
|
Writer.Record.push_back(Writer.getEmitCategory(DiagID));
|
||||||
|
@ -529,14 +524,14 @@ SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc,
|
||||||
Writer.Record, Message);
|
Writer.Record, Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDiagsRenderer::beginDiagnostic(const Diagnostic *Info,
|
void SDiagsRenderer::beginDiagnostic(DiagOrStoredDiag D,
|
||||||
DiagnosticsEngine::Level Level) {
|
DiagnosticsEngine::Level Level) {
|
||||||
Writer.Stream.EnterSubblock(BLOCK_DIAG, 4);
|
Writer.Stream.EnterSubblock(BLOCK_DIAG, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDiagsRenderer::endDiagnostic(const Diagnostic *Info,
|
void SDiagsRenderer::endDiagnostic(DiagOrStoredDiag D,
|
||||||
DiagnosticsEngine::Level Level) {
|
DiagnosticsEngine::Level Level) {
|
||||||
if (Info && Level != DiagnosticsEngine::Note)
|
if (D && Level != DiagnosticsEngine::Note)
|
||||||
return;
|
return;
|
||||||
Writer.Stream.ExitBlock();
|
Writer.Stream.ExitBlock();
|
||||||
}
|
}
|
||||||
|
@ -581,20 +576,6 @@ void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message) {
|
||||||
Writer.Stream.ExitBlock();
|
Writer.Stream.ExitBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDiagsRenderer::emitIncludeLocation(SourceLocation Loc,
|
|
||||||
PresumedLoc PLoc) {
|
|
||||||
// Generate a note indicating the include location.
|
|
||||||
SmallString<200> MessageStorage;
|
|
||||||
llvm::raw_svector_ostream Message(MessageStorage);
|
|
||||||
Message << "in file included from " << PLoc.getFilename() << ':'
|
|
||||||
<< PLoc.getLine() << ":";
|
|
||||||
emitNote(Loc, Message.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDiagsRenderer::emitBasicNote(StringRef Message) {
|
|
||||||
emitNote(SourceLocation(), Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDiagsWriter::finish() {
|
void SDiagsWriter::finish() {
|
||||||
if (inNonNoteDiagnostic) {
|
if (inNonNoteDiagnostic) {
|
||||||
// Finish off any diagnostics we were in the process of emitting.
|
// Finish off any diagnostics we were in the process of emitting.
|
||||||
|
|
|
@ -339,7 +339,7 @@ TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
StringRef Message,
|
StringRef Message,
|
||||||
ArrayRef<clang::CharSourceRange> Ranges,
|
ArrayRef<clang::CharSourceRange> Ranges,
|
||||||
const Diagnostic *Info) {
|
DiagOrStoredDiag D) {
|
||||||
uint64_t StartOfLocationInfo = OS.tell();
|
uint64_t StartOfLocationInfo = OS.tell();
|
||||||
|
|
||||||
// Emit the location of this particular diagnostic.
|
// Emit the location of this particular diagnostic.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче