HomePhabricator

[AST] Add generator for source location introspection

Authored by stephenkelly on Dec 12 2020, 5:17 AM.

Description

[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

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.

Differential Revision: https://reviews.llvm.org/D93164

Event Timeline

thakis added inline comments.
/clang/lib/Tooling/DumpTool/CMakeLists.txt
2

All other executables are in //clang/tools. Should this be there too?

Those seem to be user tools. This tool is only for build time, not for users, not for installation etc.

Those seem to be user tools. This tool is only for build time, not for users, not for installation etc.

Not all of them. See eg c-index-test, c-arcmt-test, diagtool, apinotes-test.

/clang/lib/Tooling/DumpTool/CMakeLists.txt
13

Do you need all these deps? At first sight, I don't see includes of /Format for example.

thakis added inline comments.Mar 10 2021, 3:57 PM
/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
8

Please use argparse.

10

Please have a main() function and call this at the bottom if __name__ == '__main__':, so that variables here are function-scoped instead of global-scoped

15

Please wrap to 80 columns.

16

Is the metavar='FILEPATH' right here?

/clang/unittests/Introspection/CMakeLists.txt
3

I don't see includes of Fronten/OpenMP or Targets/ either.

steveire added inline comments.Mar 14 2021, 8:49 AM
/clang/unittests/Introspection/CMakeLists.txt
3

The ASTMatchers seems to depend on FrontendOpenMP. I don't understand the llvm buildsystem though, so maybe something is wrong here.