1 //===--- ClangCommentHTMLTagsEmitter.cpp - Generate HTML tag list for Clang -=// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This tablegen backend emits efficient matchers for HTML tags that are used 11 // in documentation comments. 12 // 13 //===----------------------------------------------------------------------===// 14 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 namespace clang { 23 void EmitClangCommentHTMLTags(RecordKeeper &Records, raw_ostream &OS) { 24 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag"); 25 std::vector<StringMatcher::StringPair> Matches; 26 for (std::vector<Record *>::iterator I = Tags.begin(), E = Tags.end(); 27 I != E; ++I) { 28 Record &Tag = **I; 29 std::string Spelling = Tag.getValueAsString("Spelling"); 30 Matches.push_back(StringMatcher::StringPair(Spelling, "return true;")); 31 } 32 33 emitSourceFileHeader("HTML tag name matcher", OS); 34 35 OS << "bool isHTMLTagName(StringRef Name) {\n"; 36 StringMatcher("Name", Matches, OS).Emit(); 37 OS << " return false;\n" 38 << "}\n\n"; 39 } 40 41 void EmitClangCommentHTMLTagsProperties(RecordKeeper &Records, 42 raw_ostream &OS) { 43 std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag"); 44 std::vector<StringMatcher::StringPair> MatchesEndTagOptional; 45 std::vector<StringMatcher::StringPair> MatchesEndTagForbidden; 46 for (std::vector<Record *>::iterator I = Tags.begin(), E = Tags.end(); 47 I != E; ++I) { 48 Record &Tag = **I; 49 std::string Spelling = Tag.getValueAsString("Spelling"); 50 StringMatcher::StringPair Match(Spelling, "return true;"); 51 if (Tag.getValueAsBit("EndTagOptional")) 52 MatchesEndTagOptional.push_back(Match); 53 if (Tag.getValueAsBit("EndTagForbidden")) 54 MatchesEndTagForbidden.push_back(Match); 55 } 56 57 emitSourceFileHeader("HTML tag properties", OS); 58 59 OS << "bool isHTMLEndTagOptional(StringRef Name) {\n"; 60 StringMatcher("Name", MatchesEndTagOptional, OS).Emit(); 61 OS << " return false;\n" 62 << "}\n\n"; 63 64 OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n"; 65 StringMatcher("Name", MatchesEndTagForbidden, OS).Emit(); 66 OS << " return false;\n" 67 << "}\n\n"; 68 } 69 } // end namespace clang 70 71