steveire created this revision.
steveire added reviewers: thakis, njames93.
Herald added a subscriber: mgorny.
steveire requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This way we can add support for other nodes without duplication.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98774

Files:
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
  clang/lib/Tooling/EmptyNodeIntrospection.inc.in
  llvm/utils/gn/secondary/clang/lib/Tooling/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Tooling/BUILD.gn
===================================================================
--- llvm/utils/gn/secondary/clang/lib/Tooling/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Tooling/BUILD.gn
@@ -4,7 +4,8 @@
   script = "DumpTool/generate_cxx_src_locs.py"
   outputs = [ "$target_gen_dir/clang/Tooling/NodeIntrospection.inc" ]
   args = [
-    "--empty-implementation=1",
+    "--use-empty-implementation=1",
+    "--empty-implementation=" + rebase_path(".") + "/EmptyNodeIntrospection.inc",
     "--output-file=" + rebase_path(outputs[0], root_build_dir),
   ]
 }
Index: clang/lib/Tooling/EmptyNodeIntrospection.inc.in
===================================================================
--- /dev/null
+++ clang/lib/Tooling/EmptyNodeIntrospection.inc.in
@@ -0,0 +1,20 @@
+//===- EmptyNodeIntrospection.inc.in --------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+namespace clang {
+namespace tooling {
+
+NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
+  return {};
+}
+NodeLocationAccessors
+NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
+  return {};
+}
+} // namespace tooling
+} // namespace clang
Index: clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
===================================================================
--- clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
+++ clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
@@ -148,13 +148,16 @@
                       help='Read API description from FILE', metavar='FILE')
     parser.add_argument('--output-file', help='Generate output in FILEPATH',
                       metavar='FILEPATH')
-    parser.add_argument('--empty-implementation',
+    parser.add_argument('--use-empty-implementation',
                       help='Generate empty implementation',
                       action="store", type=int)
+    parser.add_argument('--empty-implementation',
+                      help='Copy empty implementation from FILEPATH',
+                      action="store", metavar='FILEPATH')
 
     options = parser.parse_args()
 
-    use_empty_implementation = options.empty_implementation
+    use_empty_implementation = options.use_empty_implementation
 
     if (not use_empty_implementation
             and not os.path.exists(options.json_input_path)):
@@ -170,20 +173,7 @@
     if use_empty_implementation:
         with open(os.path.join(os.getcwd(),
                   options.output_file), 'w') as f:
-            f.write("""
-namespace clang {
-namespace tooling {
-
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
-  return {};
-}
-NodeLocationAccessors
-NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
-  return {};
-}
-} // namespace tooling
-} // namespace clang
-    """)
+            f.write(options.empty_implementation)
         sys.exit(0)
 
     g = Generator()
Index: clang/lib/Tooling/CMakeLists.txt
===================================================================
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -32,21 +32,10 @@
     OR NOT LLVM_NATIVE_ARCH IN_LIST LLVM_TARGETS_TO_BUILD
     OR NOT X86 IN_LIST LLVM_TARGETS_TO_BUILD
     )
-  file(GENERATE OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
-    CONTENT "
-namespace clang {
-namespace tooling {
-
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
-  return {};
-}
-NodeLocationAccessors
-NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
-  return {};
-}
-} // namespace tooling
-} // namespace clang
-"
+    configure_file(
+      EmptyNodeIntrospection.inc.in
+      ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
+      COPYONLY
     )
     set(CLANG_TOOLING_BUILD_AST_INTROSPECTION "OFF" CACHE BOOL "")
 else()
@@ -102,7 +91,9 @@
       ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
         --json-input-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
         --output-file NodeIntrospection.inc
-        --empty-implementation ${skip_expensive_processing}
+        --use-empty-implementation ${skip_expensive_processing}
+        --empty-implementation
+          "${CMAKE_CURRENT_SOURCE_DIR}/EmptyNodeIntrospection.inc.in"
       COMMAND
       ${CMAKE_COMMAND} -E copy_if_different
         ${CMAKE_CURRENT_BINARY_DIR}/NodeIntrospection.inc
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to