[PATCH] D149677: [clang][TypePrinter] Add option to skip over elaborated types

Eric Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 4 13:54:58 PDT 2023


li.zhe.hua added a comment.

In D149677#4319646 <https://reviews.llvm.org/D149677#4319646>, @aaron.ballman wrote:

> Will this new printing policy be used in tree?

Not initially, no. (I'm understanding "in tree" as "in the LLVM project".)

Some additional context: I'm working on a refactoring tool to, in part, deprecate an alias by replacing it with its definition. That functionality by itself could be provided through something like a clang-tidy, so I say "initially".



================
Comment at: clang/include/clang/AST/PrettyPrinter.h:143-145
+  /// Ignore qualifiers as specified by elaborated type sugar, instead letting
+  /// the underlying type handle printing the qualifiers.
+  unsigned IgnoreElaboratedQualifiers : 1;
----------------
aaron.ballman wrote:
> The name is somewhat confusing to me, because tag names are also elaborations and those are handled by `SuppressTagKeyword` -- so what is the interaction between those when the user specifies true for `IgnoreElaboratedQualifiers` and false for `SuppressTagKeyword`?
Ah, I hadn't considered tag names. Let me see...

I tried this out with the template specialization test case I added. If I have

```
using Alias = struct a::S<struct b::Foo>;
```

then printing the aliased type of `Alias` with true for `IgnoreElaboratedQualifiers` and false for `SuppressTagKeyword` gives `"S<struct shared::b::Foo>"`. (I'm guessing that printing the template specialization with `SuppressTagKeyword` disabled is weird or unexpected?) So it would seem that `SuppressTagKeyword` still functions, as long as the desugared type supports it?

Back to the topic of names, it seems like "qualifiers" is not sufficient, as it also ignores elaborated tag keywords. Perhaps `IgnoreElaboration`?

---
Note: I initially had the name as `IgnoreElaboratedTypes`, but there was also the [[ https://github.com/llvm/llvm-project/blob/1b05e74982242da81d257f660302585cee691f3b/clang/lib/AST/TypePrinter.cpp#L1559-L1568 | tag definition printing logic ]] that I didn't fully understand, so I thought just saying "qualifiers" would be more correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149677



More information about the cfe-commits mailing list