OSDN Git Service

[clangd] Fix type printing in the presence of qualifiers
authorAdam Czachorowski <adamcz@google.com>
Thu, 7 Jan 2021 20:24:40 +0000 (21:24 +0100)
committerAdam Czachorowski <adamcz@google.com>
Fri, 8 Jan 2021 16:00:39 +0000 (17:00 +0100)
commitd4af86581e80ef0f7a6f4a4fff1c97260a726e71
tree2a218b5302c02137fd4186cd62066bd36368d14a
parent740950cf1cda4e5ccecf3781b7b64c9a9a72b168
[clangd] Fix type printing in the presence of qualifiers

When printing QualType with qualifiers like "const", or pointing to an
elaborated type, we would print garbage like:
  std::const std::vector<int>&
with the initial std:: being calculated correctly, but inserted in the
wrong place and the second std:: not removed (due to elaborated type).

This affected, among others, ExtractFunction and ExpandAuto tweaks.

This change introduces a new callback to PrintingPolicy, which allows us
to influence the printing of namespace qualifiers. In the future, the
same callback can be used to improve handling of "using namespace"
directives as well.

Fixes:
  https://github.com/clangd/clangd/issues/640 (ExtractFunction)
  https://github.com/clangd/clangd/issues/264 (ExpandAuto)
  First point of https://github.com/clangd/clangd/issues/524

Differential Revision: https://reviews.llvm.org/D94259
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
clang/include/clang/AST/PrettyPrinter.h
clang/lib/AST/TypePrinter.cpp