blob: 11b2f51f71b68060e9f6e9a40e09b1c7c9b0a15e [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") << ", "
41 << Tag.getValueAsBit("IsVerbatimBlockCommand") << ", "
42 << Tag.getValueAsBit("IsVerbatimBlockEndCommand") << ", "
43 << Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
44 << Tag.getValueAsBit("IsDeclarationCommand") << ", "
45 << /* IsUnknownCommand = */ "0"
46 << " }";
47 if (i + 1 != e)
48 OS << ",";
49 OS << "\n";
50 }
51 OS << "};\n"
52 "} // unnamed namespace\n\n";
53
54 std::vector<StringMatcher::StringPair> Matches;
55 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
56 Record &Tag = *Tags[i];
57 std::string Name = Tag.getValueAsString("Name");
58 std::string Return;
59 raw_string_ostream(Return) << "return &Commands[" << i << "];";
60 Matches.push_back(StringMatcher::StringPair(Name, Return));
61 }
62
63 OS << "const CommandInfo *CommandTraits::getBuiltinCommandInfo(\n"
64 << " StringRef Name) {\n";
65 StringMatcher("Name", Matches, OS).Emit();
66 OS << " return NULL;\n"
67 << "}\n\n";
68}
69} // end namespace clang
70