blob: e6253942e0bfdc1ed923fdeaa0aaf15717647a5b [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//
Dmitri Gribenko8f1fa252013-01-30 21:54:20 +000010// This tablegen backend emits command lists and efficient matchers for command
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000011// names that are used in documentation comments.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/TableGen/Record.h"
16#include "llvm/TableGen/StringMatcher.h"
Dmitri Gribenko8f1fa252013-01-30 21:54:20 +000017#include "llvm/TableGen/TableGenBackend.h"
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000018#include <vector>
19
20using namespace llvm;
21
22namespace clang {
23void EmitClangCommentCommandInfo(RecordKeeper &Records, raw_ostream &OS) {
Dmitri Gribenko8f1fa252013-01-30 21:54:20 +000024 emitSourceFileHeader("A list of commands useable in documentation "
25 "comments", OS);
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000026
27 OS << "namespace {\n"
28 "const CommandInfo Commands[] = {\n";
29 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Command");
30 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
31 Record &Tag = *Tags[i];
32 OS << " { "
33 << "\"" << Tag.getValueAsString("Name") << "\", "
34 << "\"" << Tag.getValueAsString("EndCommandName") << "\", "
35 << i << ", "
36 << Tag.getValueAsInt("NumArgs") << ", "
37 << Tag.getValueAsBit("IsInlineCommand") << ", "
38 << Tag.getValueAsBit("IsBlockCommand") << ", "
39 << Tag.getValueAsBit("IsBriefCommand") << ", "
40 << Tag.getValueAsBit("IsReturnsCommand") << ", "
41 << Tag.getValueAsBit("IsParamCommand") << ", "
42 << Tag.getValueAsBit("IsTParamCommand") << ", "
Dmitri Gribenko0bd98382012-09-22 21:47:50 +000043 << Tag.getValueAsBit("IsDeprecatedCommand") << ", "
Fariborz Jahanianf843a582013-01-31 23:12:39 +000044 << Tag.getValueAsBit("IsHeaderfileCommand") << ", "
Dmitri Gribenkoabcf0dc2012-09-13 20:36:01 +000045 << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", "
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000046 << Tag.getValueAsBit("IsVerbatimBlockCommand") << ", "
47 << Tag.getValueAsBit("IsVerbatimBlockEndCommand") << ", "
48 << Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
49 << Tag.getValueAsBit("IsDeclarationCommand") << ", "
50 << /* IsUnknownCommand = */ "0"
51 << " }";
52 if (i + 1 != e)
53 OS << ",";
54 OS << "\n";
55 }
56 OS << "};\n"
57 "} // unnamed namespace\n\n";
58
59 std::vector<StringMatcher::StringPair> Matches;
60 for (size_t i = 0, e = Tags.size(); i != e; ++i) {
61 Record &Tag = *Tags[i];
62 std::string Name = Tag.getValueAsString("Name");
63 std::string Return;
64 raw_string_ostream(Return) << "return &Commands[" << i << "];";
65 Matches.push_back(StringMatcher::StringPair(Name, Return));
66 }
67
68 OS << "const CommandInfo *CommandTraits::getBuiltinCommandInfo(\n"
69 << " StringRef Name) {\n";
70 StringMatcher("Name", Matches, OS).Emit();
71 OS << " return NULL;\n"
72 << "}\n\n";
73}
74} // end namespace clang
75