[PATCH] D85439: [SyntaxTree] Expand support for `NestedNameSpecifier`

Eduardo Caldas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 10 08:13:21 PDT 2020


eduucaldas added a comment.

There are some refinements to do, to generate a complete syntax tree. Namely tag decltype-name-specifier and simple-template-specifier children with roles, to allow for accessors.



================
Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:838-842
+      // TODO: Build `SimpleTemplateNameSpecifier` children and implement
+      // accessors to them.
+      // Be aware, we cannot do that simply by calling `TraverseTypeLoc`,
+      // some `TypeLoc`s have inside them the previous name specifier and
+      // we want to treat them independently.
----------------
Let's generate the syntax tree for the nested-name-specifier:
```
T::template U<int>::X::
```

`T` and `X` are just identifier-name-specifiers. They are easy.

`template U<int>` however is a simple-template-name-specifier. 
```
simple-template-name-specifier :
  template_opt simple-template-id
```
We could generate it by traversing the corresponding semantic node. But this node is a `DependentTemplateSpecializationTypeLoc` and it covers `T::template U<int>`. The traversal would then cover `T::` and thus generate a crash.

As such, we should treat simple-template-name-specifier in a less generic way.


================
Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:849-850
+      const auto TL = NNSLoc.getTypeLoc().castAs<DecltypeTypeLoc>();
+      if (!RecursiveASTVisitor::TraverseDecltypeTypeLoc(TL))
+        return nullptr;
+      auto *NS = new (allocator()) syntax::DecltypeNameSpecifier;
----------------
eduucaldas wrote:
> Since we are overriding the TraverseNestedNameSpecifierLoc that previously fired TraverseTypeLoc we fire it when building a NameSpecifier.
As opposed to simple-template-name-specifier, we can here use a normal traversal to build the decltype-name-specifier because this specifier doesn't cross boundaries of name specifiers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85439/new/

https://reviews.llvm.org/D85439



More information about the cfe-commits mailing list