Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 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 | // |
Dmitri Gribenko | 8f1fa25 | 2013-01-30 21:54:20 +0000 | [diff] [blame] | 10 | // This tablegen backend emits command lists and efficient matchers for command |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 11 | // names that are used in documentation comments. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/TableGen/Record.h" |
| 16 | #include "llvm/TableGen/StringMatcher.h" |
Dmitri Gribenko | 8f1fa25 | 2013-01-30 21:54:20 +0000 | [diff] [blame] | 17 | #include "llvm/TableGen/TableGenBackend.h" |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | namespace clang { |
| 23 | void EmitClangCommentCommandInfo(RecordKeeper &Records, raw_ostream &OS) { |
Dmitri Gribenko | 8f1fa25 | 2013-01-30 21:54:20 +0000 | [diff] [blame] | 24 | emitSourceFileHeader("A list of commands useable in documentation " |
| 25 | "comments", OS); |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 26 | |
| 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 Gribenko | 0bd9838 | 2012-09-22 21:47:50 +0000 | [diff] [blame] | 43 | << Tag.getValueAsBit("IsDeprecatedCommand") << ", " |
Fariborz Jahanian | f843a58 | 2013-01-31 23:12:39 +0000 | [diff] [blame^] | 44 | << Tag.getValueAsBit("IsHeaderfileCommand") << ", " |
Dmitri Gribenko | abcf0dc | 2012-09-13 20:36:01 +0000 | [diff] [blame] | 45 | << Tag.getValueAsBit("IsEmptyParagraphAllowed") << ", " |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 46 | << 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 | |