[AST] Add generator for source location introspection
authorStephen Kelly <steveire@gmail.com>
Sun, 14 Mar 2021 16:18:54 +0000 (16:18 +0000)
committerStephen Kelly <steveire@gmail.com>
Mon, 15 Mar 2021 10:52:44 +0000 (10:52 +0000)
commit19740652c4c4329e2b9e77f96e5e31c360b4e8bb
treeab99f2933fc34fa4e001022bb6266fe409ce03f7
parentaa440ba24dc25e4c95f6dcf8ff647024f3b12661
[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
16 files changed:
clang/include/clang/Tooling/NodeIntrospection.h [new file with mode: 0644]
clang/lib/Tooling/CMakeLists.txt
clang/lib/Tooling/DumpTool/APIData.h [new file with mode: 0644]
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp [new file with mode: 0644]
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h [new file with mode: 0644]
clang/lib/Tooling/DumpTool/CMakeLists.txt [new file with mode: 0644]
clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp [new file with mode: 0644]
clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py [new file with mode: 0755]
clang/lib/Tooling/NodeIntrospection.cpp [new file with mode: 0644]
clang/unittests/CMakeLists.txt
clang/unittests/Introspection/CMakeLists.txt [new file with mode: 0644]
clang/unittests/Introspection/IntrospectionTest.cpp [new file with mode: 0644]
llvm/utils/gn/secondary/clang/lib/Tooling/BUILD.gn
llvm/utils/gn/secondary/clang/lib/Tooling/DumpTool/BUILD.gn [new file with mode: 0644]
llvm/utils/gn/secondary/clang/unittests/BUILD.gn
llvm/utils/gn/secondary/clang/unittests/Introspection/BUILD.gn [new file with mode: 0644]