blob: 36fbcd40b2f45c31b066569f00fc3b6cb6c2907c [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 Gribenko0bd98382012-09-22 21:47:50 +000041 << Tag.getValueAsBit("IsDeprecatedCommand") << ", "
Dmitri Gribenkoabcf0dc2012-09-13 20:36:01 +000042 << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", "
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000043 << Tag.getValueAsBit("IsVerbatimBlockCommand") << ", "
44 << Tag.getValueAsBit("IsVerbatimBlockEndCommand") << ", "
45 << Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
46 << Tag.getValueAsBit("IsDeclarationCommand") << ", "
47 << /* IsUnknownCommand = */ "0"
48 << " }";
49 if (i + 1 != e)
50 OS << ",";
51 OS << "\n";
52 }
53 OS << "};\n"
54 "} // unnamed namespace\n\n";
55
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");
60 std::string Return;
61 raw_string_ostream(Return) << "return &Commands[" << i << "];";
62 Matches.push_back(StringMatcher::StringPair(Name, Return));
63 }
64
65 OS << "const CommandInfo *CommandTraits::getBuiltinCommandInfo(\n"
66 << " StringRef Name) {\n";
67 StringMatcher("Name", Matches, OS).Emit();
68 OS << " return NULL;\n"
69 << "}\n\n";
70}
71} // end namespace clang
72