[PATCH] D135518: [clangAST] support TypeLoc in TextNodeDumper

Tobias Ribizel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 8 12:37:44 PDT 2022


upsj created this revision.
upsj added a reviewer: aaron.ballman.
Herald added a project: All.
upsj requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

TextNodeDumper currently doesn't support printing the `TypeLoc` hierarchy, which makes navigating `clang-query` output involving `TypeLoc` hard to understand.
This diff replicates the `Type` hierarchy as well as possible, relying on `Type` visitors for printing type-specific info.
The only exception where this doesn't work is most sugared types and any kinds of parameters (function or template), for which the `TypeLoc` is not easily accessible.

Example `clang-query` output:

  clang-query> set output dump
  clang-query> match typeLoc(loc(type().bind("type")))
  ...
  Binding for "root":
  QualifiedTypeLoc </home/tribizel/llvm-project/build/test.cpp:23:10, col:60> 'matrix::Dense<typename remove_complex_t<T>::type> *const' const
  `-PointerTypeLoc <col:10, col:60> 'matrix::Dense<typename remove_complex_t<T>::type> *'
    `-ElaboratedTypeLoc <col:10, col:58> 'matrix::Dense<typename remove_complex_t<T>::type>'
      `-TemplateSpecializationTypeLoc <col:18, col:58> 'Dense<typename remove_complex_t<T>::type>' Dense
  
  Binding for "type":
  PointerType 0x261f2b0 'matrix::Dense<typename remove_complex_t<T>::type> *' dependent
  `-ElaboratedType 0x261f250 'matrix::Dense<typename remove_complex_t<T>::type>' sugar dependent
    `-TemplateSpecializationType 0x261f210 'Dense<typename remove_complex_t<T>::type>' dependent Dense
      `-TemplateArgument type 'typename remove_complex_t<T>::type'
        `-DependentNameType 0x261f190 'typename remove_complex_t<T>::type' dependent


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135518

Files:
  clang/include/clang/AST/ASTDumperUtils.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/TypeLoc.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135518.466304.patch
Type: text/x-patch
Size: 14198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221008/147f7e9a/attachment.bin>


More information about the cfe-commits mailing list