llvm.org GIT mirror llvm / 4954e9f
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 Douglas Gregor 9 years ago
3 changed file(s) with 74 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2020 #include "llvm/ADT/VectorExtras.h"
2121 #include
2222 #include
23 #include
24 #include
2325 using namespace llvm;
2426
2527 //===----------------------------------------------------------------------===//
120122 } // end anonymous namespace.
121123
122124
123
124125 //===----------------------------------------------------------------------===//
125126 // Warning Tables (.inc file) generation.
126127 //===----------------------------------------------------------------------===//
178179
179180 // Category number.
180181 OS << ", " << CategoryIDs.getID(getDiagnosticCategory(&R, DGParentMap));
182
183 // Brief
184 OS << ", \"";
185 OS.write_escaped(R.getValueAsString("Brief")) << '"';
186
187 // Explanation
188 OS << ", \"";
189 OS.write_escaped(R.getValueAsString("Explanation")) << '"';
181190 OS << ")\n";
182191 }
183192 }
293302 OS << "CATEGORY(\"" << *I << "\")\n";
294303 OS << "#endif // GET_CATEGORY_TABLE\n\n";
295304 }
305
306 //===----------------------------------------------------------------------===//
307 // Diagnostic name index generation
308 //===----------------------------------------------------------------------===//
309
310 namespace {
311 struct RecordIndexElement
312 {
313 RecordIndexElement() {}
314 explicit RecordIndexElement(Record const &R):
315 Name(R.getName()) {}
316
317 std::string Name;
318 };
319
320 struct RecordIndexElementSorter :
321 public std::binary_function {
322
323 bool operator()(RecordIndexElement const &Lhs,
324 RecordIndexElement const &Rhs) const {
325 return Lhs.Name < Rhs.Name;
326 }
327
328 };
329
330 } // end anonymous namespace.
331
332 void ClangDiagsIndexNameEmitter::run(raw_ostream &OS) {
333 const std::vector &Diags =
334 Records.getAllDerivedDefinitions("Diagnostic");
335
336 std::vector Index;
337 Index.reserve(Diags.size());
338 for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
339 const Record &R = *(Diags[i]);
340 Index.push_back(RecordIndexElement(R));
341 }
342
343 std::sort(Index.begin(), Index.end(), RecordIndexElementSorter());
344
345 for (unsigned i = 0, e = Index.size(); i != e; ++i) {
346 const RecordIndexElement &R = Index[i];
347
348 OS << "DIAG_NAME_INDEX(" << R.Name << ")\n";
349 }
350 }
3232 };
3333
3434 class ClangDiagGroupsEmitter : public TableGenBackend {
35 RecordKeeper &Records;
35 RecordKeeper &Records;
3636 public:
3737 explicit ClangDiagGroupsEmitter(RecordKeeper &R) : Records(R) {}
3838
39 void run(raw_ostream &OS);
40 };
41
42 class ClangDiagsIndexNameEmitter : public TableGenBackend {
43 RecordKeeper &Records;
44 public:
45 explicit ClangDiagsIndexNameEmitter(RecordKeeper &R) : Records(R) {}
46
3947 void run(raw_ostream &OS);
4048 };
4149
6464 GenClangAttrSpellingList,
6565 GenClangDiagsDefs,
6666 GenClangDiagGroups,
67 GenClangDiagsIndexName,
6768 GenClangDeclNodes,
6869 GenClangStmtNodes,
6970 GenClangSACheckers,
132133 "Generate clang PCH attribute reader"),
133134 clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
134135 "Generate clang PCH attribute writer"),
135 clEnumValN(GenClangAttrSpellingList, "gen-clang-attr-spelling-list",
136 clEnumValN(GenClangAttrSpellingList,
137 "gen-clang-attr-spelling-list",
136138 "Generate a clang attribute spelling list"),
137139 clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
138140 "Generate Clang diagnostics definitions"),
139141 clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
140142 "Generate Clang diagnostic groups"),
143 clEnumValN(GenClangDiagsIndexName,
144 "gen-clang-diags-index-name",
145 "Generate Clang diagnostic name index"),
141146 clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
142147 "Generate Clang AST declaration nodes"),
143148 clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
294299 case GenClangDiagGroups:
295300 ClangDiagGroupsEmitter(Records).run(Out.os());
296301 break;
302 case GenClangDiagsIndexName:
303 ClangDiagsIndexNameEmitter(Records).run(Out.os());
304 break;
297305 case GenClangDeclNodes:
298306 ClangASTNodesEmitter(Records, "Decl", "Decl").run(Out.os());
299307 ClangDeclContextEmitter(Records).run(Out.os());