[clang] aee6c86 - [AST] De-duplicate empty node introspection
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 22 04:30:15 PDT 2021
Author: Stephen Kelly
Date: 2021-04-22T12:30:04+01:00
New Revision: aee6c86c4dc78da6ca75e0e6e6cfd50f95f2d956
URL: https://github.com/llvm/llvm-project/commit/aee6c86c4dc78da6ca75e0e6e6cfd50f95f2d956
DIFF: https://github.com/llvm/llvm-project/commit/aee6c86c4dc78da6ca75e0e6e6cfd50f95f2d956.diff
LOG: [AST] De-duplicate empty node introspection
This way we can add support for other nodes without duplication.
Differential Revision: https://reviews.llvm.org/D98774
Added:
clang/lib/Tooling/EmptyNodeIntrospection.inc.in
Modified:
clang/lib/Tooling/CMakeLists.txt
clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
Removed:
################################################################################
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index 2baea134271e..8d77b233233d 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -30,46 +30,10 @@ if (NOT Python3_EXECUTABLE
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 {
-
-bool NodeIntrospection::hasIntrospectionSupport() { return false; }
-
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::CXXCtorInitializer const *) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::NestedNameSpecifierLoc const&) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::TemplateArgumentLoc const&) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::CXXBaseSpecifier const*) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::TypeLoc 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()
@@ -115,11 +79,14 @@ else()
OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
+ ${CMAKE_CURRENT_SOURCE_DIR}/EmptyNodeIntrospection.inc.in
COMMAND
${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_
diff erent
${CMAKE_CURRENT_BINARY_DIR}/NodeIntrospection.inc
diff --git a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
index c06835d8c710..94795cfeb816 100755
--- a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
+++ b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
@@ -4,7 +4,8 @@
import os
import sys
import json
-
+import filecmp
+import shutil
import argparse
class Generator(object):
@@ -326,13 +327,16 @@ def main():
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)):
@@ -346,47 +350,9 @@ def main():
use_empty_implementation = True
if use_empty_implementation:
- with open(os.path.join(os.getcwd(),
- options.output_file), 'w') as f:
- f.write("""
-namespace clang {
-namespace tooling {
-
-bool NodeIntrospection::hasIntrospectionSupport() { return false; }
-
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::CXXCtorInitializer const *) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::NestedNameSpecifierLoc const&) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::TemplateArgumentLoc const&) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::CXXBaseSpecifier const*) {
- return {};
-}
-NodeLocationAccessors NodeIntrospection::GetLocations(
- clang::TypeLoc const&) {
- return {};
-}
-NodeLocationAccessors
-NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
- return {};
-}
-} // namespace tooling
-} // namespace clang
- """)
+ if not os.path.exists(options.output_file) or \
+ not filecmp.cmp(options.empty_implementation, options.output_file):
+ shutil.copyfile(options.empty_implementation, options.output_file)
sys.exit(0)
templateClasses = []
diff --git a/clang/lib/Tooling/EmptyNodeIntrospection.inc.in b/clang/lib/Tooling/EmptyNodeIntrospection.inc.in
new file mode 100644
index 000000000000..04a7647c6d19
--- /dev/null
+++ b/clang/lib/Tooling/EmptyNodeIntrospection.inc.in
@@ -0,0 +1,44 @@
+//===- 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 {
+bool NodeIntrospection::hasIntrospectionSupport() { return false; }
+
+NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
+ return {};
+}
+NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) {
+ return {};
+}
+NodeLocationAccessors NodeIntrospection::GetLocations(
+ clang::CXXCtorInitializer const *) {
+ return {};
+}
+NodeLocationAccessors NodeIntrospection::GetLocations(
+ clang::NestedNameSpecifierLoc const&) {
+ return {};
+}
+NodeLocationAccessors NodeIntrospection::GetLocations(
+ clang::TemplateArgumentLoc const&) {
+ return {};
+}
+NodeLocationAccessors NodeIntrospection::GetLocations(
+ clang::CXXBaseSpecifier const*) {
+ return {};
+}
+NodeLocationAccessors NodeIntrospection::GetLocations(
+ clang::TypeLoc const&) {
+ return {};
+}
+NodeLocationAccessors
+NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
+ return {};
+}
+} // namespace tooling
+} // namespace clang
More information about the cfe-commits
mailing list