aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/SerializedDiagnosticPrinter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-11-05 00:10:07 +0000
committerTed Kremenek <kremenek@apple.com>2011-11-05 00:10:07 +0000
commit3baf63d37d0b6267885b584db1106232fc036cb9 (patch)
tree13aa00ef1717d21a936bec4275f2b1a03d3186b2 /lib/Frontend/SerializedDiagnosticPrinter.cpp
parent0dbadc4a8e54df02aab05d5fe45f2048a2e84c6d (diff)
serialized diagnostics: pull emission of diagnostic flag string into diagnostics block.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143764 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/SerializedDiagnosticPrinter.cpp')
-rw-r--r--lib/Frontend/SerializedDiagnosticPrinter.cpp127
1 files changed, 62 insertions, 65 deletions
diff --git a/lib/Frontend/SerializedDiagnosticPrinter.cpp b/lib/Frontend/SerializedDiagnosticPrinter.cpp
index 12448650a3..4604e699ae 100644
--- a/lib/Frontend/SerializedDiagnosticPrinter.cpp
+++ b/lib/Frontend/SerializedDiagnosticPrinter.cpp
@@ -94,8 +94,12 @@ private:
/// \brief Emit a record for a CharSourceRange.
void EmitCharSourceRange(CharSourceRange R);
- /// \brief Emit the string information for a category.
- void EmitCategory(unsigned CatID);
+ /// \brief Emit the string information for the category for a diagnostic.
+ unsigned getEmitCategory(unsigned DiagID);
+
+ /// \brief Emit the string information for diagnostic flags.
+ unsigned getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel,
+ const Diagnostic &Info);
/// \brief The version of the diagnostics file.
enum { Version = 1 };
@@ -242,7 +246,8 @@ void SDiagsWriter::EmitBlockInfoBlock() {
EmitRecordID(RECORD_DIAG, "DiagInfo", Stream, Record);
EmitRecordID(RECORD_SOURCE_RANGE, "SrcRange", Stream, Record);
EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record);
-
+ EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record);
+
// Emit Abbrevs.
using namespace llvm;
@@ -272,6 +277,15 @@ void SDiagsWriter::EmitBlockInfoBlock() {
AddSourceLocationAbbrev(Abbrev);
Abbrevs.set(RECORD_SOURCE_RANGE,
Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
+
+ // 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));
// ==---------------------------------------------------------------------==//
// The subsequent records and Abbrevs are for the "Strings" block.
@@ -279,7 +293,6 @@ void SDiagsWriter::EmitBlockInfoBlock() {
EmitBlockID(BLOCK_STRINGS, "Strings", Stream, Record);
EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record);
- EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record);
Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME));
@@ -289,33 +302,57 @@ void SDiagsWriter::EmitBlockInfoBlock() {
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name text.
Abbrevs.set(RECORD_FILENAME, Stream.EmitBlockInfoAbbrev(BLOCK_STRINGS,
Abbrev));
-
- // 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_STRINGS,
- Abbrev));
Stream.ExitBlock();
}
-void SDiagsWriter::EmitCategory(unsigned int CatID) {
- if (Categories.count(CatID))
- return;
+unsigned SDiagsWriter::getEmitCategory(unsigned int DiagID) {
+ unsigned category = DiagnosticIDs::getCategoryNumberForDiag(DiagID);
+
+ if (Categories.count(category))
+ return category;
- Categories.insert(CatID);
+ Categories.insert(category);
// 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);
- Record.push_back(CatID);
- StringRef catName = DiagnosticIDs::getCategoryNameFromID(CatID);
+ Record.push_back(category);
+ StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
Record.push_back(catName.size());
Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_CATEGORY), Record, catName);
+
+ return category;
+}
+
+unsigned SDiagsWriter::getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel,
+ const Diagnostic &Info) {
+ if (DiagLevel == DiagnosticsEngine::Note)
+ return 0; // No flag for notes.
+
+ StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(Info.getID());
+ 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();
+ std::pair<unsigned, StringRef> &entry = DiagFlags[data];
+ if (entry.first == 0) {
+ entry.first = DiagFlags.size();
+ 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());
+ Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG_FLAG),
+ Record, FlagName);
+ }
+
+ return entry.first;
}
void SDiagsWriter::EmitRawStringContents(llvm::StringRef str) {
@@ -341,32 +378,12 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
Record.clear();
Record.push_back(RECORD_DIAG);
Record.push_back(DiagLevel);
- AddLocToRecord(Diags.getSourceManager(), Info.getLocation(), Record);
- unsigned category = DiagnosticIDs::getCategoryNumberForDiag(Info.getID());
- Record.push_back(category);
-
- // Emit the category string lazily if we haven't already.
- EmitCategory(category);
-
- Categories.insert(category);
- if (DiagLevel == DiagnosticsEngine::Note)
- Record.push_back(0); // No flag for notes.
- else {
- StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(Info.getID());
- if (FlagName.empty())
- Record.push_back(0);
- else {
- // Here we assume that FlagName points to static data whose pointer
- // value is fixed.
- const void *data = FlagName.data();
- std::pair<unsigned, StringRef> &entry = DiagFlags[data];
- if (entry.first == 0) {
- entry.first = DiagFlags.size();
- entry.second = FlagName;
- }
- Record.push_back(entry.first);
- }
- }
+ AddLocToRecord(Diags.getSourceManager(), Info.getLocation(), Record);
+ // Emit the category string lazily and get the category ID.
+ Record.push_back(getEmitCategory(Info.getID()));
+ // Emit the diagnostic flag string lazily and get the mapped ID.
+ Record.push_back(getEmitDiagnosticFlag(DiagLevel, Info));
+
diagBuf.clear();
Info.FormatDiagnostic(diagBuf); // Compute the diagnostic text.
@@ -425,26 +442,6 @@ void SDiagsWriter::EmitCategoriesAndFileNames() {
Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_FILENAME), Record, Name);
}
}
-
- // Emit the flag strings.
- {
- std::vector<StringRef> scribble;
- scribble.resize(DiagFlags.size());
-
- for (DiagFlagsTy::iterator it = DiagFlags.begin(), ei = DiagFlags.end();
- it != ei; ++it) {
- scribble[it->second.first - 1] = it->second.second;
- }
- for (unsigned i = 0, n = scribble.size(); i != n; ++i) {
- Record.clear();
- Record.push_back(RECORD_DIAG_FLAG);
- Record.push_back(i+1);
- StringRef FlagName = scribble[i];
- Record.push_back(FlagName.size());
- Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG_FLAG),
- Record, FlagName);
- }
- }
}
void SDiagsWriter::EndSourceFile() {