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 20 using namespace llvm; 21 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(std::string(Tag->getValueAsString("Spelling")), 27 "return true;"); 28 } 29 30 emitSourceFileHeader("HTML tag name matcher", OS); 31 32 OS << "bool isHTMLTagName(StringRef Name) {\n"; 33 StringMatcher("Name", Matches, OS).Emit(); 34 OS << " return false;\n" 35 << "}\n\n"; 36 } 37 38 void clang::EmitClangCommentHTMLTagsProperties(RecordKeeper &Records, 39 raw_ostream &OS) { 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 = std::string(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); 50 } 51 52 emitSourceFileHeader("HTML tag properties", OS); 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 65