[llvm] 1899112 - [gn build] manually port 18f9e25ce1fa43 (AttrDocTable)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 12 18:31:12 PDT 2021


Author: Nico Weber
Date: 2021-08-12T21:30:59-04:00
New Revision: 189911203779e793cb7767ad233d9994a88c7ea3

URL: https://github.com/llvm/llvm-project/commit/189911203779e793cb7767ad233d9994a88c7ea3
DIFF: https://github.com/llvm/llvm-project/commit/189911203779e793cb7767ad233d9994a88c7ea3.diff

LOG: [gn build] manually port 18f9e25ce1fa43 (AttrDocTable)

Also clang ClangAttrEmitter for -gen-clang-attr-doc-table to be
like all other tablegen: Produce a .inc file with the generated bits
and put the static parts into a regular .cpp file that includes the
.inc file.

Added: 
    clang/lib/AST/AttrDocTable.cpp

Modified: 
    clang/lib/AST/CMakeLists.txt
    clang/utils/TableGen/ClangAttrEmitter.cpp
    llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
    llvm/utils/gn/secondary/clang/unittests/AST/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/AttrDocTable.cpp b/clang/lib/AST/AttrDocTable.cpp
new file mode 100644
index 0000000000000..3bfedac8b8f13
--- /dev/null
+++ b/clang/lib/AST/AttrDocTable.cpp
@@ -0,0 +1,27 @@
+//===--- AttrDocTable.cpp - implements Attr::getDocumentation() -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file contains out-of-line methods for Attr classes.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/Attr.h"
+#include "llvm/ADT/StringRef.h"
+
+#include "AttrDocTable.inc"
+
+static const llvm::StringRef AttrDoc[] = {
+#define ATTR(NAME) AttrDoc_##NAME,
+#include "clang/Basic/AttrList.inc"
+};
+
+llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
+  if(K < llvm::array_lengthof(AttrDoc))
+    return AttrDoc[K];
+  return "";
+}

diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 2cb74a40b9800..9365a2272b3e7 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -13,7 +13,7 @@ clang_tablegen(Opcodes.inc
   SOURCE Interp/Opcodes.td
   TARGET Opcodes)
 
-clang_tablegen(AttrDocTable.cpp -gen-clang-attr-doc-table
+clang_tablegen(AttrDocTable.inc -gen-clang-attr-doc-table
   -I ${CMAKE_CURRENT_SOURCE_DIR}/../../include/
   SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../include/clang/Basic/Attr.td
   TARGET ClangAttrDocTable)
@@ -124,6 +124,7 @@ add_clang_library(clangAST
   clangLex
 
   DEPENDS
+  ClangAttrDocTable
   Opcodes
   omp_gen
   )

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 345b13692b5ca..e5ac0847e1080 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4207,10 +4207,6 @@ void EmitClangAttrSubjectMatchRulesParserStringSwitches(RecordKeeper &Records,
 void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
   emitSourceFileHeader("Clang attribute documentation", OS);
 
-  OS << R"cpp(
-  #include "clang/AST/Attr.h"
-  #include "llvm/ADT/StringRef.h"
-  )cpp";
   std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
   for (const auto *A : Attrs) {
     if (!A->getValueAsBit("ASTNode"))
@@ -4226,18 +4222,6 @@ void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
       break;
     }
   }
-  OS << R"cpp(
-  static const llvm::StringRef AttrDoc[] = {
-  #define ATTR(NAME) AttrDoc_##NAME,
-  #include "clang/Basic/AttrList.inc"
-  };
-
-  llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
-    if(K < llvm::array_lengthof(AttrDoc))
-      return AttrDoc[K];
-    return "";
-  }
-  )cpp";
 }
 
 enum class SpellingKind {

diff  --git a/llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
index 4d645799dbf65..aee4db327096f 100644
--- a/llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
@@ -6,10 +6,17 @@ clang_tablegen("Opcodes") {
   td_file = "Interp/Opcodes.td"
 }
 
+clang_tablegen("AttrDocTable") {
+  visibility = [ ":AST" ]
+  args = [ "-gen-clang-attr-doc-table" ]
+  td_file = "//clang/include/clang/Basic/Attr.td"
+}
+
 static_library("AST") {
   output_name = "clangAST"
   configs += [ "//llvm/utils/gn/build:clang_code" ]
   deps = [
+    ":AttrDocTable",
     ":Opcodes",
     "//clang/include/clang/AST:AttrImpl",
     "//clang/include/clang/AST:AttrNodeTraverse",
@@ -51,6 +58,7 @@ static_library("AST") {
     "ASTImporterLookupTable.cpp",
     "ASTStructuralEquivalence.cpp",
     "ASTTypeTraits.cpp",
+    "AttrDocTable.cpp",
     "AttrImpl.cpp",
     "CXXInheritance.cpp",
     "Comment.cpp",

diff  --git a/llvm/utils/gn/secondary/clang/unittests/AST/BUILD.gn b/llvm/utils/gn/secondary/clang/unittests/AST/BUILD.gn
index 127542d829f04..c275553d01c96 100644
--- a/llvm/utils/gn/secondary/clang/unittests/AST/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/unittests/AST/BUILD.gn
@@ -24,6 +24,7 @@ unittest("ASTTests") {
     "ASTTraverserTest.cpp",
     "ASTTypeTraitsTest.cpp",
     "ASTVectorTest.cpp",
+    "AttrTest.cpp",
     "CommentLexer.cpp",
     "CommentParser.cpp",
     "CommentTextTest.cpp",


        


More information about the llvm-commits mailing list