1//===--- ClangCommentHTMLTagsEmitter.cpp - Generate HTML tag list for Clang -=//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This tablegen backend emits efficient matchers for HTML tags that are used
10// in documentation comments.
11//
12//===----------------------------------------------------------------------===//
13
14#include "TableGenBackends.h"
15#include "llvm/TableGen/Record.h"
16#include "llvm/TableGen/StringMatcher.h"
17#include "llvm/TableGen/TableGenBackend.h"
18#include <vector>
19
20using namespace llvm;
21
22void clang::EmitClangCommentHTMLTags(RecordKeeper &Records, raw_ostream &OS) {
23 std::vector<Record *> Tags = Records.getAllDerivedDefinitions(ClassName: "Tag");
24 std::vector<StringMatcher::StringPair> Matches;
25 for (Record *Tag : Tags) {
26 Matches.emplace_back(args: std::string(Tag->getValueAsString(FieldName: "Spelling")),
27 args: "return true;");
28 }
29
30 emitSourceFileHeader(Desc: "HTML tag name matcher", OS, Record: Records);
31
32 OS << "bool isHTMLTagName(StringRef Name) {\n";
33 StringMatcher("Name", Matches, OS).Emit();
34 OS << " return false;\n"
35 << "}\n\n";
36}
37
38void clang::EmitClangCommentHTMLTagsProperties(RecordKeeper &Records,
39 raw_ostream &OS) {
40 std::vector<Record *> Tags = Records.getAllDerivedDefinitions(ClassName: "Tag");
41 std::vector<StringMatcher::StringPair> MatchesEndTagOptional;
42 std::vector<StringMatcher::StringPair> MatchesEndTagForbidden;
43 for (Record *Tag : Tags) {
44 std::string Spelling = std::string(Tag->getValueAsString(FieldName: "Spelling"));
45 StringMatcher::StringPair Match(Spelling, "return true;");
46 if (Tag->getValueAsBit(FieldName: "EndTagOptional"))
47 MatchesEndTagOptional.push_back(x: Match);
48 if (Tag->getValueAsBit(FieldName: "EndTagForbidden"))
49 MatchesEndTagForbidden.push_back(x: Match);
50 }
51
52 emitSourceFileHeader(Desc: "HTML tag properties", OS, Record: Records);
53
54 OS << "bool isHTMLEndTagOptional(StringRef Name) {\n";
55 StringMatcher("Name", MatchesEndTagOptional, OS).Emit();
56 OS << " return false;\n"
57 << "}\n\n";
58
59 OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n";
60 StringMatcher("Name", MatchesEndTagForbidden, OS).Emit();
61 OS << " return false;\n"
62 << "}\n\n";
63}
64

source code of clang/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp