1 //===--- ClangCommentHTMLTagsEmitter.cpp - Generate HTML tag list for Clang -=//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This tablegen backend emits efficient matchers for HTML tags that are used
10 // in documentation comments.
12 //===----------------------------------------------------------------------===//
14 #include "TableGenBackends.h"
15 #include "llvm/TableGen/Record.h"
16 #include "llvm/TableGen/StringMatcher.h"
17 #include "llvm/TableGen/TableGenBackend.h"
22 void clang::EmitClangCommentHTMLTags(RecordKeeper &Records, raw_ostream &OS) {
23 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag");
24 std::vector<StringMatcher::StringPair> Matches;
25 for (Record *Tag : Tags) {
26 Matches.emplace_back(Tag->getValueAsString("Spelling"), "return true;");
29 emitSourceFileHeader("HTML tag name matcher", OS);
31 OS << "bool isHTMLTagName(StringRef Name) {\n";
32 StringMatcher("Name", Matches, OS).Emit();
33 OS << " return false;\n"
37 void clang::EmitClangCommentHTMLTagsProperties(RecordKeeper &Records,
39 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag");
40 std::vector<StringMatcher::StringPair> MatchesEndTagOptional;
41 std::vector<StringMatcher::StringPair> MatchesEndTagForbidden;
42 for (Record *Tag : Tags) {
43 std::string Spelling = Tag->getValueAsString("Spelling");
44 StringMatcher::StringPair Match(Spelling, "return true;");
45 if (Tag->getValueAsBit("EndTagOptional"))
46 MatchesEndTagOptional.push_back(Match);
47 if (Tag->getValueAsBit("EndTagForbidden"))
48 MatchesEndTagForbidden.push_back(Match);
51 emitSourceFileHeader("HTML tag properties", OS);
53 OS << "bool isHTMLEndTagOptional(StringRef Name) {\n";
54 StringMatcher("Name", MatchesEndTagOptional, OS).Emit();
55 OS << " return false;\n"
58 OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n";
59 StringMatcher("Name", MatchesEndTagForbidden, OS).Emit();
60 OS << " return false;\n"