summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-11-05 03:34:23 +0000
committerTed Kremenek <kremenek@apple.com>2011-11-05 03:34:23 +0000
commitd89a827b5cfeefe2a01d6772d11c50bc2cca75a8 (patch)
tree623c8aec8417bc92046914dec48d3a974c044731
parent8cc2e865bcc13160e08188032379845f892c5720 (diff)
downloadbcm5719-llvm-d89a827b5cfeefe2a01d6772d11c50bc2cca75a8.tar.gz
bcm5719-llvm-d89a827b5cfeefe2a01d6772d11c50bc2cca75a8.zip
serialized diagnostics: include FixIt information in serialized diagnostics.
llvm-svn: 143776
-rw-r--r--clang/include/clang/Frontend/SerializedDiagnosticPrinter.h3
-rw-r--r--clang/lib/Frontend/SerializedDiagnosticPrinter.cpp47
2 files changed, 43 insertions, 7 deletions
diff --git a/clang/include/clang/Frontend/SerializedDiagnosticPrinter.h b/clang/include/clang/Frontend/SerializedDiagnosticPrinter.h
index b418efcddda..f7b61a9f3ea 100644
--- a/clang/include/clang/Frontend/SerializedDiagnosticPrinter.h
+++ b/clang/include/clang/Frontend/SerializedDiagnosticPrinter.h
@@ -32,7 +32,8 @@ enum RecordIDs {
RECORD_SOURCE_RANGE,
RECORD_DIAG_FLAG,
RECORD_CATEGORY,
- RECORD_FILENAME
+ RECORD_FILENAME,
+ RECORD_FIXIT
};
/// \brief Returns a DiagnosticConsumer that serializes diagnostics to
diff --git a/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp b/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
index 263a4100567..669f289c4ff 100644
--- a/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
@@ -101,6 +101,9 @@ private:
/// \brief Add SourceLocation information the specified record.
void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record);
+ /// \brief Add CharSourceRange information the specified record.
+ void AddCharSourceRangeToRecord(CharSourceRange R, RecordDataImpl &Record);
+
/// \brief The version of the diagnostics file.
enum { Version = 1 };
@@ -211,6 +214,12 @@ void SDiagsWriter::AddLocToRecord(SourceLocation Loc,
Record.push_back(FileOffset);
}
+void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range,
+ RecordDataImpl &Record) {
+ AddLocToRecord(Range.getBegin(), Record);
+ AddLocToRecord(Range.getEnd(), Record);
+}
+
unsigned SDiagsWriter::getEmitFile(SourceLocation Loc) {
SourceManager &SM = Diags.getSourceManager();
assert(Loc.isValid());
@@ -240,8 +249,7 @@ unsigned SDiagsWriter::getEmitFile(SourceLocation Loc) {
void SDiagsWriter::EmitCharSourceRange(CharSourceRange R) {
Record.clear();
Record.push_back(RECORD_SOURCE_RANGE);
- AddLocToRecord(R.getBegin(), Record);
- AddLocToRecord(R.getEnd(), Record);
+ AddCharSourceRangeToRecord(R, Record);
Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_SOURCE_RANGE), Record);
}
@@ -261,6 +269,12 @@ static void AddSourceLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Column.
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Offset;
}
+
+static void AddRangeLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) {
+ AddSourceLocationAbbrev(Abbrev);
+ AddSourceLocationAbbrev(Abbrev);
+}
+
void SDiagsWriter::EmitBlockInfoBlock() {
Stream.EnterBlockInfoBlock(3);
@@ -274,6 +288,7 @@ void SDiagsWriter::EmitBlockInfoBlock() {
EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record);
EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record);
EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record);
+ EmitRecordID(RECORD_FIXIT, "FixIt", Stream, Record);
// Emit Abbrevs.
using namespace llvm;
@@ -300,8 +315,7 @@ void SDiagsWriter::EmitBlockInfoBlock() {
// Emit abbrevation for RECORD_SOURCE_RANGE.
Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(RECORD_SOURCE_RANGE));
- AddSourceLocationAbbrev(Abbrev);
- AddSourceLocationAbbrev(Abbrev);
+ AddRangeLocationAbbrev(Abbrev);
Abbrevs.set(RECORD_SOURCE_RANGE,
Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
@@ -324,6 +338,15 @@ void SDiagsWriter::EmitBlockInfoBlock() {
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name text.
Abbrevs.set(RECORD_FILENAME, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG,
Abbrev));
+
+ // 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));
Stream.ExitBlock();
}
@@ -405,14 +428,26 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
Info.FormatDiagnostic(diagBuf); // Compute the diagnostic text.
Record.push_back(diagBuf.str().size());
Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, diagBuf.str());
-
+
+ // Emit Source Ranges.
ArrayRef<CharSourceRange> Ranges = Info.getRanges();
for (ArrayRef<CharSourceRange>::iterator it=Ranges.begin(), ei=Ranges.end();
it != ei; ++it) {
EmitCharSourceRange(*it);
}
- // FIXME: emit fixits
+ // Emit FixIts.
+ for (unsigned i = 0, n = Info.getNumFixItHints(); i != n; ++i) {
+ const FixItHint &fix = Info.getFixItHint(i);
+ if (fix.isNull())
+ continue;
+ Record.clear();
+ Record.push_back(RECORD_FIXIT);
+ AddCharSourceRangeToRecord(fix.RemoveRange, Record);
+ Record.push_back(fix.CodeToInsert.size());
+ Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_FIXIT), Record,
+ fix.CodeToInsert);
+ }
if (DiagLevel == DiagnosticsEngine::Note) {
// Notes currently cannot have child diagnostics. Complete the
OpenPOWER on IntegriCloud