| 1 | //===-- ClangCommentHTMLTagsEmitter.cpp - Generate HTML tag list ----------===// |
| 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::(const RecordKeeper &Records, |
| 23 | raw_ostream &OS) { |
| 24 | ArrayRef<const Record *> Tags = Records.getAllDerivedDefinitions(ClassName: "Tag" ); |
| 25 | std::vector<StringMatcher::StringPair> Matches; |
| 26 | for (const Record *Tag : Tags) { |
| 27 | Matches.emplace_back(args: Tag->getValueAsString(FieldName: "Spelling" ).str(), |
| 28 | args: "return true;" ); |
| 29 | } |
| 30 | |
| 31 | emitSourceFileHeader(Desc: "HTML tag name matcher" , OS, Record: Records); |
| 32 | |
| 33 | OS << "bool isHTMLTagName(StringRef Name) {\n" ; |
| 34 | StringMatcher("Name" , Matches, OS).Emit(); |
| 35 | OS << " return false;\n" |
| 36 | << "}\n\n" ; |
| 37 | } |
| 38 | |
| 39 | void clang::(const RecordKeeper &Records, |
| 40 | raw_ostream &OS) { |
| 41 | ArrayRef<const Record *> Tags = Records.getAllDerivedDefinitions(ClassName: "Tag" ); |
| 42 | std::vector<StringMatcher::StringPair> MatchesEndTagOptional; |
| 43 | std::vector<StringMatcher::StringPair> MatchesEndTagForbidden; |
| 44 | for (const Record *Tag : Tags) { |
| 45 | std::string Spelling = Tag->getValueAsString(FieldName: "Spelling" ).str(); |
| 46 | StringMatcher::StringPair Match(Spelling, "return true;" ); |
| 47 | if (Tag->getValueAsBit(FieldName: "EndTagOptional" )) |
| 48 | MatchesEndTagOptional.push_back(x: Match); |
| 49 | if (Tag->getValueAsBit(FieldName: "EndTagForbidden" )) |
| 50 | MatchesEndTagForbidden.push_back(x: Match); |
| 51 | } |
| 52 | |
| 53 | emitSourceFileHeader(Desc: "HTML tag properties" , OS, Record: Records); |
| 54 | |
| 55 | OS << "bool isHTMLEndTagOptional(StringRef Name) {\n" ; |
| 56 | StringMatcher("Name" , MatchesEndTagOptional, OS).Emit(); |
| 57 | OS << " return false;\n" |
| 58 | << "}\n\n" ; |
| 59 | |
| 60 | OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n" ; |
| 61 | StringMatcher("Name" , MatchesEndTagForbidden, OS).Emit(); |
| 62 | OS << " return false;\n" |
| 63 | << "}\n\n" ; |
| 64 | } |
| 65 | |