diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-04-15 22:04:07 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-04-15 22:04:07 +0000 |
| commit | f29216072eb676d1a835cf298f6d90f1f8c5e8f1 (patch) | |
| tree | 56096dbcfb0a7f0bd251d2e3034af1146fe6d142 /llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp | |
| parent | e24891251c9bff66912051c1cc70c6d16205230c (diff) | |
| download | bcm5719-llvm-f29216072eb676d1a835cf298f6d90f1f8c5e8f1.tar.gz bcm5719-llvm-f29216072eb676d1a835cf298f6d90f1f8c5e8f1.zip | |
Initial work to improve documentation for Clang's diagnostics, from Matthieu Monrocq
llvm-svn: 129613
Diffstat (limited to 'llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp')
| -rw-r--r-- | llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp b/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp index 60e67c46746..d5cd4d71ca8 100644 --- a/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -21,6 +21,8 @@ #include "llvm/ADT/VectorExtras.h" #include <set> #include <map> +#include <algorithm> +#include <functional> using namespace llvm; //===----------------------------------------------------------------------===// @@ -121,7 +123,6 @@ namespace { } // end anonymous namespace. - //===----------------------------------------------------------------------===// // Warning Tables (.inc file) generation. //===----------------------------------------------------------------------===// @@ -179,6 +180,14 @@ void ClangDiagsDefsEmitter::run(raw_ostream &OS) { // Category number. OS << ", " << CategoryIDs.getID(getDiagnosticCategory(&R, DGParentMap)); + + // Brief + OS << ", \""; + OS.write_escaped(R.getValueAsString("Brief")) << '"'; + + // Explanation + OS << ", \""; + OS.write_escaped(R.getValueAsString("Explanation")) << '"'; OS << ")\n"; } } @@ -294,3 +303,49 @@ void ClangDiagGroupsEmitter::run(raw_ostream &OS) { OS << "CATEGORY(\"" << *I << "\")\n"; OS << "#endif // GET_CATEGORY_TABLE\n\n"; } + +//===----------------------------------------------------------------------===// +// Diagnostic name index generation +//===----------------------------------------------------------------------===// + +namespace { +struct RecordIndexElement +{ + RecordIndexElement() {} + explicit RecordIndexElement(Record const &R): + Name(R.getName()) {} + + std::string Name; +}; + +struct RecordIndexElementSorter : + public std::binary_function<RecordIndexElement, RecordIndexElement, bool> { + + bool operator()(RecordIndexElement const &Lhs, + RecordIndexElement const &Rhs) const { + return Lhs.Name < Rhs.Name; + } + +}; + +} // end anonymous namespace. + +void ClangDiagsIndexNameEmitter::run(raw_ostream &OS) { + const std::vector<Record*> &Diags = + Records.getAllDerivedDefinitions("Diagnostic"); + + std::vector<RecordIndexElement> Index; + Index.reserve(Diags.size()); + for (unsigned i = 0, e = Diags.size(); i != e; ++i) { + const Record &R = *(Diags[i]); + Index.push_back(RecordIndexElement(R)); + } + + std::sort(Index.begin(), Index.end(), RecordIndexElementSorter()); + + for (unsigned i = 0, e = Index.size(); i != e; ++i) { + const RecordIndexElement &R = Index[i]; + + OS << "DIAG_NAME_INDEX(" << R.Name << ")\n"; + } +} |

