[cfe-commits] r162969 - in /cfe/trunk: include/clang/AST/CMakeLists.txt include/clang/AST/CommentHTMLTags.td include/clang/AST/CommentSema.h include/clang/AST/Makefile lib/AST/CMakeLists.txt lib/AST/CommentLexer.cpp lib/AST/CommentSema.cpp utils/TableGen/CMakeLists.txt utils/TableGen/ClangCommentHTMLTagsEmitter.cpp utils/TableGen/TableGen.cpp utils/TableGen/TableGenBackends.h

Dmitri Gribenko gribozavr at gmail.com
Thu Aug 30 19:21:44 PDT 2012


Author: gribozavr
Date: Thu Aug 30 21:21:44 2012
New Revision: 162969

URL: http://llvm.org/viewvc/llvm-project?rev=162969&view=rev
Log:
Comment HTML tag name machers: move from StringSwitch to an efficient
TableGen-generated string matcher.

Added:
    cfe/trunk/include/clang/AST/CommentHTMLTags.td
    cfe/trunk/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp
Modified:
    cfe/trunk/include/clang/AST/CMakeLists.txt
    cfe/trunk/include/clang/AST/CommentSema.h
    cfe/trunk/include/clang/AST/Makefile
    cfe/trunk/lib/AST/CMakeLists.txt
    cfe/trunk/lib/AST/CommentLexer.cpp
    cfe/trunk/lib/AST/CommentSema.cpp
    cfe/trunk/utils/TableGen/CMakeLists.txt
    cfe/trunk/utils/TableGen/TableGen.cpp
    cfe/trunk/utils/TableGen/TableGenBackends.h

Modified: cfe/trunk/include/clang/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CMakeLists.txt?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/AST/CMakeLists.txt Thu Aug 30 21:21:44 2012
@@ -20,3 +20,11 @@
   SOURCE ../Basic/CommentNodes.td
   TARGET ClangCommentNodes)
 
+clang_tablegen(CommentHTMLTags.inc -gen-clang-comment-html-tags
+  SOURCE CommentHTMLTags.td
+  TARGET ClangCommentHTMLTags)
+
+clang_tablegen(CommentHTMLTagsProperties.inc -gen-clang-comment-html-tags-properties
+  SOURCE CommentHTMLTags.td
+  TARGET ClangCommentHTMLTagsProperties)
+

Added: cfe/trunk/include/clang/AST/CommentHTMLTags.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentHTMLTags.td?rev=162969&view=auto
==============================================================================
--- cfe/trunk/include/clang/AST/CommentHTMLTags.td (added)
+++ cfe/trunk/include/clang/AST/CommentHTMLTags.td Thu Aug 30 21:21:44 2012
@@ -0,0 +1,54 @@
+class Tag<string spelling> {
+  string Spelling = spelling;
+  bit EndTagOptional = 0;
+  bit EndTagForbidden = 0;
+}
+
+def Em      : Tag<"em">;
+def Strong  : Tag<"strong">;
+def Tt      : Tag<"tt">;
+def I       : Tag<"i">;
+def B       : Tag<"b">;
+def Big     : Tag<"big">;
+def Small   : Tag<"small">;
+def Strike  : Tag<"strike">;
+def S       : Tag<"s">;
+def U       : Tag<"u">;
+def Font    : Tag<"font">;
+def A       : Tag<"a">;
+def Hr      : Tag<"hr"> { let EndTagForbidden = 1; }
+def Div     : Tag<"div">;
+def Span    : Tag<"span">;
+def H1      : Tag<"h1">;
+def H2      : Tag<"h2">;
+def H3      : Tag<"h3">;
+def H4      : Tag<"h4">;
+def H5      : Tag<"h5">;
+def H6      : Tag<"h6">;
+def Code    : Tag<"code">;
+def Blockquote : Tag<"blockquote">;
+def Sub     : Tag<"sub">;
+def Sup     : Tag<"sup">;
+def Img     : Tag<"img"> { let EndTagForbidden = 1; }
+def P       : Tag<"p"> { let EndTagOptional = 1; }
+def Br      : Tag<"br"> { let EndTagForbidden = 1; }
+def Pre     : Tag<"pre">;
+def Ins     : Tag<"ins">;
+def Del     : Tag<"del">;
+def Ul      : Tag<"ul">;
+def Ol      : Tag<"ol">;
+def Li      : Tag<"li"> { let EndTagOptional = 1; }
+def Dl      : Tag<"dl">;
+def Dt      : Tag<"dt"> { let EndTagOptional = 1; }
+def Dd      : Tag<"dd"> { let EndTagOptional = 1; }
+def Table   : Tag<"table">;
+def Caption : Tag<"caption">;
+def Thead   : Tag<"thead"> { let EndTagOptional = 1; }
+def Tfoot   : Tag<"tfoot"> { let EndTagOptional = 1; }
+def Tbody   : Tag<"tbody"> { let EndTagOptional = 1; }
+def Colgroup : Tag<"colgroup"> { let EndTagOptional = 1; }
+def Col     : Tag<"col"> { let EndTagForbidden = 1; }
+def Tr      : Tag<"tr"> { let EndTagOptional = 1; }
+def Th      : Tag<"th"> { let EndTagOptional = 1; }
+def Td      : Tag<"td"> { let EndTagOptional = 1; }
+

Modified: cfe/trunk/include/clang/AST/CommentSema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentSema.h?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentSema.h (original)
+++ cfe/trunk/include/clang/AST/CommentSema.h Thu Aug 30 21:21:44 2012
@@ -215,9 +215,6 @@
 
   InlineCommandComment::RenderKind
   getInlineCommandRenderKind(StringRef Name) const;
-
-  bool isHTMLEndTagOptional(StringRef Name);
-  bool isHTMLEndTagForbidden(StringRef Name);
 };
 
 } // end namespace comments

Modified: cfe/trunk/include/clang/AST/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Makefile?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Makefile (original)
+++ cfe/trunk/include/clang/AST/Makefile Thu Aug 30 21:21:44 2012
@@ -1,6 +1,8 @@
 CLANG_LEVEL := ../../..
 TD_SRC_DIR = $(PROJ_SRC_DIR)/../Basic
-BUILT_SOURCES = Attrs.inc AttrImpl.inc StmtNodes.inc DeclNodes.inc CommentNodes.inc
+BUILT_SOURCES = Attrs.inc AttrImpl.inc StmtNodes.inc DeclNodes.inc \
+                CommentNodes.inc CommentHTMLTags.inc \
+                CommentHTMLTagsProperties.inc
 
 TABLEGEN_INC_FILES_COMMON = 1
 
@@ -33,3 +35,13 @@
 	$(Echo) "Building Clang comment node tables with tblgen"
 	$(Verb) $(ClangTableGen) -gen-clang-comment-nodes -o $(call SYSPATH, $@) $<
 
+$(ObjDir)/CommentHTMLTags.inc.tmp : $(PROJ_SRC_DIR)/CommentHTMLTags.td $(CLANG_TBLGEN) \
+                              $(ObjDir)/.dir
+	$(Echo) "Building Clang comment HTML tag matchers with tblgen"
+	$(Verb) $(ClangTableGen) -gen-clang-comment-html-tags -o $(call SYSPATH, $@) $<
+
+$(ObjDir)/CommentHTMLTagsProperties.inc.tmp : $(PROJ_SRC_DIR)/CommentHTMLTags.td \
+                                              $(CLANG_TBLGEN) $(ObjDir)/.dir
+	$(Echo) "Building Clang comment HTML tag properties with tblgen"
+	$(Verb) $(ClangTableGen) -gen-clang-comment-html-tags-properties -o $(call SYSPATH, $@) $<
+

Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Thu Aug 30 21:21:44 2012
@@ -65,6 +65,8 @@
   ClangAttrList
   ClangAttrImpl
   ClangCommentNodes
+  ClangCommentHTMLTags
+  ClangCommentHTMLTagsProperties
   ClangDeclNodes
   ClangDiagnosticAST
   ClangDiagnosticComment

Modified: cfe/trunk/lib/AST/CommentLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentLexer.cpp?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentLexer.cpp (original)
+++ cfe/trunk/lib/AST/CommentLexer.cpp Thu Aug 30 21:21:44 2012
@@ -29,32 +29,8 @@
          (C >= 'A' && C <= 'F');
 }
 
-bool isHTMLTagName(StringRef Name) {
-  return llvm::StringSwitch<bool>(Name)
-      .Cases("em", "strong", true)
-      .Cases("tt", "i", "b", "big", "small", true)
-      .Cases("strike", "s", "u", "font", true)
-      .Case("a", true)
-      .Case("hr", true)
-      .Cases("div", "span", true)
-      .Cases("h1", "h2", "h3", true)
-      .Cases("h4", "h5", "h6", true)
-      .Case("code", true)
-      .Case("blockquote", true)
-      .Cases("sub", "sup", true)
-      .Case("img", true)
-      .Case("p", true)
-      .Case("br", true)
-      .Case("pre", true)
-      .Cases("ins", "del", true)
-      .Cases("ul", "ol", "li", true)
-      .Cases("dl", "dt", "dd", true)
-      .Cases("table", "caption", true)
-      .Cases("thead", "tfoot", "tbody", true)
-      .Cases("colgroup", "col", true)
-      .Cases("tr", "th", "td", true)
-      .Default(false);
-}
+#include "clang/AST/CommentHTMLTags.inc"
+
 } // unnamed namespace
 
 StringRef Lexer::resolveHTMLNamedCharacterReference(StringRef Name) const {

Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Thu Aug 30 21:21:44 2012
@@ -18,6 +18,10 @@
 namespace clang {
 namespace comments {
 
+namespace {
+#include "clang/AST/CommentHTMLTagsProperties.inc"
+} // unnamed namespace
+
 Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr,
            DiagnosticsEngine &Diags, const CommandTraits &Traits) :
     Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), Traits(Traits),
@@ -745,31 +749,6 @@
       .Default(InlineCommandComment::RenderNormal);
 }
 
-bool Sema::isHTMLEndTagOptional(StringRef Name) {
-  return llvm::StringSwitch<bool>(Name)
-      .Case("p", true)
-      .Case("li", true)
-      .Case("dt", true)
-      .Case("dd", true)
-      .Case("tr", true)
-      .Case("th", true)
-      .Case("td", true)
-      .Case("thead", true)
-      .Case("tfoot", true)
-      .Case("tbody", true)
-      .Case("colgroup", true)
-      .Default(false);
-}
-
-bool Sema::isHTMLEndTagForbidden(StringRef Name) {
-  return llvm::StringSwitch<bool>(Name)
-      .Case("br", true)
-      .Case("hr", true)
-      .Case("img", true)
-      .Case("col", true)
-      .Default(false);
-}
-
 } // end namespace comments
 } // end namespace clang
 

Modified: cfe/trunk/utils/TableGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/CMakeLists.txt?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/CMakeLists.txt (original)
+++ cfe/trunk/utils/TableGen/CMakeLists.txt Thu Aug 30 21:21:44 2012
@@ -5,6 +5,7 @@
 add_tablegen(clang-tblgen CLANG
   ClangASTNodesEmitter.cpp
   ClangAttrEmitter.cpp
+  ClangCommentHTMLTagsEmitter.cpp
   ClangDiagnosticsEmitter.cpp
   ClangSACheckersEmitter.cpp
   NeonEmitter.cpp

Added: cfe/trunk/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp?rev=162969&view=auto
==============================================================================
--- cfe/trunk/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp (added)
+++ cfe/trunk/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp Thu Aug 30 21:21:44 2012
@@ -0,0 +1,69 @@
+//===--- ClangCommentHTMLTagsEmitter.cpp - Generate HTML tag list for Clang -=//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This tablegen backend emits efficient matchers for HTML tags that are used
+// in documentation comments.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
+#include <vector>
+
+using namespace llvm;
+
+namespace clang {
+void EmitClangCommentHTMLTags(RecordKeeper &Records, raw_ostream &OS) {
+  std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag");
+  std::vector<StringMatcher::StringPair> Matches;
+  for (std::vector<Record *>::iterator I = Tags.begin(), E = Tags.end();
+       I != E; ++I) {
+    Record &Tag = **I;
+    std::string Spelling = Tag.getValueAsString("Spelling");
+    Matches.push_back(StringMatcher::StringPair(Spelling, "return true;"));
+  }
+
+  OS << "// This file is generated by TableGen.  Do not edit.\n\n";
+
+  OS << "bool isHTMLTagName(StringRef Name) {\n";
+  StringMatcher("Name", Matches, OS).Emit();
+  OS << "  return false;\n"
+     << "}\n\n";
+}
+
+void EmitClangCommentHTMLTagsProperties(RecordKeeper &Records,
+                                        raw_ostream &OS) {
+  std::vector<Record *> Tags = Records.getAllDerivedDefinitions("Tag");
+  std::vector<StringMatcher::StringPair> MatchesEndTagOptional;
+  std::vector<StringMatcher::StringPair> MatchesEndTagForbidden;
+  for (std::vector<Record *>::iterator I = Tags.begin(), E = Tags.end();
+       I != E; ++I) {
+    Record &Tag = **I;
+    std::string Spelling = Tag.getValueAsString("Spelling");
+    StringMatcher::StringPair Match(Spelling, "return true;");
+    if (Tag.getValueAsBit("EndTagOptional"))
+      MatchesEndTagOptional.push_back(Match);
+    if (Tag.getValueAsBit("EndTagForbidden"))
+      MatchesEndTagForbidden.push_back(Match);
+  }
+
+  OS << "// This file is generated by TableGen.  Do not edit.\n\n";
+
+  OS << "bool isHTMLEndTagOptional(StringRef Name) {\n";
+  StringMatcher("Name", MatchesEndTagOptional, OS).Emit();
+  OS << "  return false;\n"
+     << "}\n\n";
+
+  OS << "bool isHTMLEndTagForbidden(StringRef Name) {\n";
+  StringMatcher("Name", MatchesEndTagForbidden, OS).Emit();
+  OS << "  return false;\n"
+     << "}\n\n";
+}
+} // end namespace clang
+

Modified: cfe/trunk/utils/TableGen/TableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/TableGen.cpp?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/TableGen.cpp (original)
+++ cfe/trunk/utils/TableGen/TableGen.cpp Thu Aug 30 21:21:44 2012
@@ -42,6 +42,8 @@
   GenClangDeclNodes,
   GenClangStmtNodes,
   GenClangSACheckers,
+  GenClangCommentHTMLTags,
+  GenClangCommentHTMLTagsProperties,
   GenOptParserDefs, GenOptParserImpl,
   GenArmNeon,
   GenArmNeonSema,
@@ -95,6 +97,14 @@
                                "Generate Clang AST statement nodes"),
                     clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
                                "Generate Clang Static Analyzer checkers"),
+                    clEnumValN(GenClangCommentHTMLTags,
+                               "gen-clang-comment-html-tags",
+                               "Generate efficient matchers for HTML tag "
+                               "names that are used in documentation comments"),
+                    clEnumValN(GenClangCommentHTMLTagsProperties,
+                               "gen-clang-comment-html-tags-properties",
+                               "Generate efficient matchers for HTML tag "
+                               "properties"),
                     clEnumValN(GenArmNeon, "gen-arm-neon",
                                "Generate arm_neon.h for clang"),
                     clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
@@ -164,6 +174,12 @@
     case GenClangSACheckers:
       EmitClangSACheckers(Records, OS);
       break;
+    case GenClangCommentHTMLTags:
+      EmitClangCommentHTMLTags(Records, OS);
+      break;
+    case GenClangCommentHTMLTagsProperties:
+      EmitClangCommentHTMLTagsProperties(Records, OS);
+      break;
     case GenOptParserDefs:
       EmitOptParser(Records, OS, true);
       break;

Modified: cfe/trunk/utils/TableGen/TableGenBackends.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/TableGenBackends.h?rev=162969&r1=162968&r2=162969&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/TableGenBackends.h (original)
+++ cfe/trunk/utils/TableGen/TableGenBackends.h Thu Aug 30 21:21:44 2012
@@ -47,6 +47,9 @@
 
 void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS);
 
+void EmitClangCommentHTMLTags(RecordKeeper &Records, raw_ostream &OS);
+void EmitClangCommentHTMLTagsProperties(RecordKeeper &Records, raw_ostream &OS);
+
 void EmitNeon(RecordKeeper &Records, raw_ostream &OS);
 void EmitNeonSema(RecordKeeper &Records, raw_ostream &OS);
 void EmitNeonTest(RecordKeeper &Records, raw_ostream &OS);





More information about the cfe-commits mailing list