]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/utils/TableGen/ClangCommentCommandInfoEmitter.cpp
MFC r244628:
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / utils / TableGen / ClangCommentCommandInfoEmitter.cpp
1 //===--- 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
19 using namespace llvm;
20
21 namespace clang {
22 void 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("IsDeprecatedCommand") << ", "
42        << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", "
43        << 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