blob: 599d1385a8332fdc73b1a753dc393c76f388409e [file] [log] [blame]
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001//===--- ClangCommentCommandInfoEmitter.cpp - Generate command lists -----====//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tablegen backend emits command lists and efficient matchers command
11// names that are used in documentation comments.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/TableGen/Record.h"
16#include "llvm/TableGen/StringMatcher.h"
17#include <vector>
18
19using namespace llvm;
20
21namespace clang {
22void EmitClangCommentCommandInfo(RecordKeeper &Records, raw_ostream &OS) {
23 OS << "// This file is generated by TableGen. Do not edit.\n\n";
24
25 OS << "namespace {\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];
30 OS << " { "
31 << "\"" << Tag.getValueAsString("Name") << "\", "
32 << "\"" << Tag.getValueAsString("EndCommandName") << "\", "
33 << i << ", "
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") << ", "
Dmitri Gribenkoabcf0dc2012-09-13 20:36:01 +000041 << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", "
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000042 << Tag.getValueAsBit("IsVerbatimBlockCommand") << ", "
43 << Tag.getValueAsBit("IsVerbatimBlockEndCommand") << ", "
44 << Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
45 << Tag.getValueAsBit("IsDeclarationCommand") << ", "
46 << /* IsUnknownCommand = */ "0"
47 << " }";
48 if (i + 1 != e)
49 OS << ",";
50 OS << "\n";
51 }
52 OS << "};\n"
53 "} // unnamed namespace\n\n";
54
55 std::vector<StringMatcher::StringPair> Matches;
56 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
57 Record &Tag = *Tags[i];
58 std::string Name = Tag.getValueAsString("Name");
59 std::string Return;
60 raw_string_ostream(Return) << "return &Commands[" << i << "];";
61 Matches.push_back(StringMatcher::StringPair(Name, Return));
62 }
63
64 OS << "const CommandInfo *CommandTraits::getBuiltinCommandInfo(\n"
65 << " StringRef Name) {\n";
66 StringMatcher("Name", Matches, OS).Emit();
67 OS << " return NULL;\n"
68 << "}\n\n";
69}
70} // end namespace clang
71