]> granicus.if.org Git - clang/commitdiff
serialized diagnostics: include FixIt information in serialized diagnostics.
authorTed Kremenek <kremenek@apple.com>
Sat, 5 Nov 2011 03:34:23 +0000 (03:34 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 5 Nov 2011 03:34:23 +0000 (03:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143776 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/SerializedDiagnosticPrinter.h
lib/Frontend/SerializedDiagnosticPrinter.cpp

index b418efcddda6ed15c28a5dabb3f77025bdc8a994..f7b61a9f3ea0cee5cbc18223383d519cde19be24 100644 (file)
@@ -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
index 263a4100567d3ba2024872049a2bfbe45f9f648f..669f289c4ff4e4387d050bc50a2024c751dcfbff 100644 (file)
@@ -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