1 //===--- ClangCommentHTMLTagsEmitter.cpp - Generate HTML tag list for Clang -=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend emits efficient matchers for HTML tags that are used
11 // in documentation comments.
13 //===----------------------------------------------------------------------===//
15 #include "TableGenBackends.h"
16 #include "llvm/TableGen/Record.h"
17 #include "llvm/TableGen/StringMatcher.h"
18 #include "llvm/TableGen/TableGenBackend.h"
23 void clang::EmitClangCommentHTMLTags(RecordKeeper &Records, raw_ostream &OS) {
24 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag");
25 std::vector<StringMatcher::StringPair> Matches;
26 for (Record *Tag : Tags) {
27 Matches.emplace_back(Tag->getValueAsString("Spelling"), "return true;");
30 emitSourceFileHeader("HTML tag name matcher", OS);
32 OS << "bool isHTMLTagName(StringRef Name) {\n";
33 StringMatcher("Name", Matches, OS).Emit();
34 OS << " return false;\n"
38 void clang::EmitClangCommentHTMLTagsProperties(RecordKeeper &Records,
40 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag");
41 std::vector<StringMatcher::StringPair> MatchesEndTagOptional;
42 std::vector<StringMatcher::StringPair> MatchesEndTagForbidden;
43 for (Record *Tag : Tags) {
44 std::string Spelling = Tag->getValueAsString("Spelling");
45 StringMatcher::StringPair Match(Spelling, "return true;");
46 if (Tag->getValueAsBit("EndTagOptional"))
47 MatchesEndTagOptional.push_back(Match);
48 if (Tag->getValueAsBit("EndTagForbidden"))
49 MatchesEndTagForbidden.push_back(Match);
52 emitSourceFileHeader("HTML tag properties", OS);
54 OS << "bool isHTMLEndTagOptional(StringRef Name) {\n";
55 StringMatcher("Name", MatchesEndTagOptional, OS).Emit();
56 OS << " return false;\n"
59 OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n";
60 StringMatcher("Name", MatchesEndTagForbidden, OS).Emit();
61 OS << " return false;\n"