Clang Project

clang_source_code/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp
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 &Recordsraw_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;");
27  }
28
29  emitSourceFileHeader("HTML tag name matcher"OS);
30
31  OS << "bool isHTMLTagName(StringRef Name) {\n";
32  StringMatcher("Name", Matches, OS).Emit();
33  OS << "  return false;\n"
34     << "}\n\n";
35}
36
37void clang::EmitClangCommentHTMLTagsProperties(RecordKeeper &Records,
38                                               raw_ostream &OS) {
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);
49  }
50
51  emitSourceFileHeader("HTML tag properties"OS);
52
53  OS << "bool isHTMLEndTagOptional(StringRef Name) {\n";
54  StringMatcher("Name", MatchesEndTagOptional, OS).Emit();
55  OS << "  return false;\n"
56     << "}\n\n";
57
58  OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n";
59  StringMatcher("Name", MatchesEndTagForbidden, OS).Emit();
60  OS << "  return false;\n"
61     << "}\n\n";
62}
63
64