1 //===--- ClangCommentCommandInfoEmitter.cpp - Generate command lists -----====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend emits command lists and efficient matchers for command
11 // names that are used in documentation comments.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/TableGen/Record.h"
16 #include "llvm/TableGen/StringMatcher.h"
17 #include "llvm/TableGen/TableGenBackend.h"
23 void EmitClangCommentCommandInfo(RecordKeeper &Records, raw_ostream &OS) {
24 emitSourceFileHeader("A list of commands useable in documentation "
28 "const CommandInfo Commands[] = {\n";
29 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Command");
30 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
31 Record &Tag = *Tags[i];
33 << "\"" << Tag.getValueAsString("Name") << "\", "
34 << "\"" << Tag.getValueAsString("EndCommandName") << "\", "
36 << Tag.getValueAsInt("NumArgs") << ", "
37 << Tag.getValueAsBit("IsInlineCommand") << ", "
38 << Tag.getValueAsBit("IsBlockCommand") << ", "
39 << Tag.getValueAsBit("IsBriefCommand") << ", "
40 << Tag.getValueAsBit("IsReturnsCommand") << ", "
41 << Tag.getValueAsBit("IsParamCommand") << ", "
42 << Tag.getValueAsBit("IsTParamCommand") << ", "
43 << Tag.getValueAsBit("IsDeprecatedCommand") << ", "
44 << Tag.getValueAsBit("IsHeaderfileCommand") << ", "
45 << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", "
46 << Tag.getValueAsBit("IsVerbatimBlockCommand") << ", "
47 << Tag.getValueAsBit("IsVerbatimBlockEndCommand") << ", "
48 << Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
49 << Tag.getValueAsBit("IsDeclarationCommand") << ", "
50 << Tag.getValueAsBit("IsFunctionDeclarationCommand") << ", "
51 << Tag.getValueAsBit("IsRecordLikeDetailCommand") << ", "
52 << Tag.getValueAsBit("IsRecordLikeDeclarationCommand") << ", "
53 << /* IsUnknownCommand = */ "0"
60 "} // unnamed namespace\n\n";
62 std::vector<StringMatcher::StringPair> Matches;
63 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
64 Record &Tag = *Tags[i];
65 std::string Name = Tag.getValueAsString("Name");
67 raw_string_ostream(Return) << "return &Commands[" << i << "];";
68 Matches.push_back(StringMatcher::StringPair(Name, Return));
71 OS << "const CommandInfo *CommandTraits::getBuiltinCommandInfo(\n"
72 << " StringRef Name) {\n";
73 StringMatcher("Name", Matches, OS).Emit();
74 OS << " return NULL;\n"
78 static std::string MangleName(StringRef Str) {
80 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
108 void EmitClangCommentCommandList(RecordKeeper &Records, raw_ostream &OS) {
109 emitSourceFileHeader("A list of commands useable in documentation "
112 OS << "#ifndef COMMENT_COMMAND\n"
113 << "# define COMMENT_COMMAND(NAME)\n"
116 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Command");
117 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
118 Record &Tag = *Tags[i];
119 std::string MangledName = MangleName(Tag.getValueAsString("Name"));
121 OS << "COMMENT_COMMAND(" << MangledName << ")\n";
124 } // end namespace clang