Initial work to improve documentation for Clang's diagnostics, from Matthieu Monrocq

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129613 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2011-04-15 22:04:07 +00:00
parent 4552c9a3b3
commit 4954e9f2d9
3 changed files with 74 additions and 3 deletions

View File

@ -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";
}
}

View File

@ -33,13 +33,21 @@ public:
};
class ClangDiagGroupsEmitter : public TableGenBackend {
RecordKeeper &Records;
RecordKeeper &Records;
public:
explicit ClangDiagGroupsEmitter(RecordKeeper &R) : Records(R) {}
void run(raw_ostream &OS);
};
class ClangDiagsIndexNameEmitter : public TableGenBackend {
RecordKeeper &Records;
public:
explicit ClangDiagsIndexNameEmitter(RecordKeeper &R) : Records(R) {}
void run(raw_ostream &OS);
};
} // End llvm namespace

View File

@ -65,6 +65,7 @@ enum ActionType {
GenClangAttrSpellingList,
GenClangDiagsDefs,
GenClangDiagGroups,
GenClangDiagsIndexName,
GenClangDeclNodes,
GenClangStmtNodes,
GenClangSACheckers,
@ -133,12 +134,16 @@ namespace {
"Generate clang PCH attribute reader"),
clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
"Generate clang PCH attribute writer"),
clEnumValN(GenClangAttrSpellingList, "gen-clang-attr-spelling-list",
clEnumValN(GenClangAttrSpellingList,
"gen-clang-attr-spelling-list",
"Generate a clang attribute spelling list"),
clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
"Generate Clang diagnostics definitions"),
clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
"Generate Clang diagnostic groups"),
clEnumValN(GenClangDiagsIndexName,
"gen-clang-diags-index-name",
"Generate Clang diagnostic name index"),
clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
"Generate Clang AST declaration nodes"),
clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
@ -295,6 +300,9 @@ int main(int argc, char **argv) {
case GenClangDiagGroups:
ClangDiagGroupsEmitter(Records).run(Out.os());
break;
case GenClangDiagsIndexName:
ClangDiagsIndexNameEmitter(Records).run(Out.os());
break;
case GenClangDeclNodes:
ClangASTNodesEmitter(Records, "Decl", "Decl").run(Out.os());
ClangDeclContextEmitter(Records).run(Out.os());