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 command
11 // names that are used in documentation comments.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/TableGen/Record.h"
16 #include "llvm/TableGen/StringMatcher.h"
22 void EmitClangCommentCommandInfo(RecordKeeper &Records, raw_ostream &OS) {
23 OS << "// This file is generated by TableGen. Do not edit.\n\n";
26 "const CommandInfo Commands[] = {\n";
27 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Command");
28 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
29 Record &Tag = *Tags[i];
31 << "\"" << Tag.getValueAsString("Name") << "\", "
32 << "\"" << Tag.getValueAsString("EndCommandName") << "\", "
34 << Tag.getValueAsInt("NumArgs") << ", "
35 << Tag.getValueAsBit("IsInlineCommand") << ", "
36 << Tag.getValueAsBit("IsBlockCommand") << ", "
37 << Tag.getValueAsBit("IsBriefCommand") << ", "
38 << Tag.getValueAsBit("IsReturnsCommand") << ", "
39 << Tag.getValueAsBit("IsParamCommand") << ", "
40 << Tag.getValueAsBit("IsTParamCommand") << ", "
41 << Tag.getValueAsBit("IsDeprecatedCommand") << ", "
42 << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", "
43 << Tag.getValueAsBit("IsVerbatimBlockCommand") << ", "
44 << Tag.getValueAsBit("IsVerbatimBlockEndCommand") << ", "
45 << Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
46 << Tag.getValueAsBit("IsDeclarationCommand") << ", "
47 << /* IsUnknownCommand = */ "0"
54 "} // unnamed namespace\n\n";
56 std::vector<StringMatcher::StringPair> Matches;
57 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
58 Record &Tag = *Tags[i];
59 std::string Name = Tag.getValueAsString("Name");
61 raw_string_ostream(Return) << "return &Commands[" << i << "];";
62 Matches.push_back(StringMatcher::StringPair(Name, Return));
65 OS << "const CommandInfo *CommandTraits::getBuiltinCommandInfo(\n"
66 << " StringRef Name) {\n";
67 StringMatcher("Name", Matches, OS).Emit();
68 OS << " return NULL;\n"
71 } // end namespace clang