1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[AST] Add generator for source location introspection

Generate a json file containing descriptions of AST classes and their
public accessors which return SourceLocation or SourceRange.

Use the JSON file to generate a C++ API and implementation for accessing
the source locations and method names for accessing them for a given AST
node.

This new API can be used to implement 'srcloc' output in clang-query:

  http://ce.steveire.com/z/m_kTIo

The JSON file can also be used to generate bindings for other languages,
such as Python and Javascript:

  https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching

In this first version of this feature, only the accessors for Stmt
classes are generated, not Decls, TypeLocs etc.  Those can be added
after this change is reviewed, as this change is mostly about
infrastructure of these code generators.

Also in this version, the platforms/cmake configurations are excluded as
much as possible so that support can be added iteratively.  Currently a
break on any platform causes a revert of the entire feature.  This way,
the `OR WIN32` can be removed in a future commit and if it breaks the
buildbots, only that commit gets reverted, making the entire process
easier to manage.

Differential Revision: https://reviews.llvm.org/D93164
This commit is contained in:
Stephen Kelly 2021-03-14 16:18:54 +00:00
parent 9a84a85fd4
commit 84c98ffec3
4 changed files with 55 additions and 0 deletions

View File

@ -1,7 +1,19 @@
# FIXME: The cmake build runs DumpTool:clang-ast-dump to generate a json
# file and feeds it into this step in non-debug builds or if an option is set.
action("node_introspection_inc") {
script = "DumpTool/generate_cxx_src_locs.py"
outputs = [ "$target_gen_dir/clang/Tooling/NodeIntrospection.inc" ]
args = [
"--empty-implementation=1",
"--output-file=" + rebase_path(outputs[0], root_build_dir),
]
}
static_library("Tooling") {
output_name = "clangTooling"
configs += [ "//llvm/utils/gn/build:clang_code" ]
deps = [
":node_introspection_inc",
"//clang/include/clang/Driver:Options",
"//clang/lib/AST",
"//clang/lib/ASTMatchers",
@ -13,6 +25,7 @@ static_library("Tooling") {
"//clang/lib/Rewrite",
"//clang/lib/Tooling/Core",
]
include_dirs = [ target_gen_dir ]
sources = [
"AllTUsExecution.cpp",
"ArgumentsAdjusters.cpp",
@ -25,6 +38,7 @@ static_library("Tooling") {
"GuessTargetAndModeCompilationDatabase.cpp",
"InterpolatingCompilationDatabase.cpp",
"JSONCompilationDatabase.cpp",
"NodeIntrospection.cpp",
"Refactoring.cpp",
"RefactoringCallbacks.cpp",
"StandaloneExecution.cpp",

View File

@ -0,0 +1,20 @@
executable("clang-ast-dump") {
configs += [ "//llvm/utils/gn/build:clang_code" ]
deps = [
"//clang/lib/AST",
"//clang/lib/ASTMatchers",
"//clang/lib/Basic",
"//clang/lib/Driver",
"//clang/lib/Format",
"//clang/lib/Frontend",
"//clang/lib/Lex",
"//clang/lib/Rewrite",
"//clang/lib/Serialization",
"//clang/lib/Tooling/Core",
]
sources = [
"ASTSrcLocProcessor.cpp",
"ClangSrcLocDump.cpp",
]
}

View File

@ -12,6 +12,7 @@ group("unittests") {
"Format:FormatTests",
"Frontend:FrontendTests",
"Index:IndexTests",
"Introspection:IntrospectionTests",
"Lex:LexTests",
"Rename:ClangRenameTests",
"Rewrite:RewriteTests",

View File

@ -0,0 +1,20 @@
import("//llvm/utils/unittest/unittest.gni")
unittest("IntrospectionTests") {
configs += [ "//llvm/utils/gn/build:clang_code" ]
deps = [
"//clang/lib/AST",
"//clang/lib/ASTMatchers",
"//clang/lib/Basic",
"//clang/lib/Frontend",
"//clang/lib/Serialization",
"//clang/lib/Tooling",
"//llvm/lib/Support",
"//llvm/lib/Testing/Support",
]
defines = [ "SKIP_INTROSPECTION_GENERATION" ]
sources = [ "IntrospectionTest.cpp" ]
}