[PATCH] D53186: [clangd] Support hover on "aut^o *".
Haojian Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 12 03:13:20 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344330: [clangd] Support hover on "aut^o *". (authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D53186?vs=169357&id=169363#toc
Repository:
rL LLVM
https://reviews.llvm.org/D53186
Files:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
Index: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
@@ -756,6 +756,15 @@
"int",
},
{
+ R"cpp(// Simple initialization with auto*
+ void foo() {
+ int a = 1;
+ ^auto* i = &a;
+ }
+ )cpp",
+ "int",
+ },
+ {
R"cpp(// Auto with initializer list.
namespace std
{
@@ -863,6 +872,16 @@
"struct Bar",
},
{
+ R"cpp(// auto* in function return
+ struct Bar {};
+ ^auto* test() {
+ Bar* bar;
+ return bar;
+ }
+ )cpp",
+ "struct Bar",
+ },
+ {
R"cpp(// const auto& in function return
struct Bar {};
const ^auto& test() {
Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -579,20 +579,28 @@
llvm::Optional<QualType> getDeducedType() { return DeducedType; }
+ // Remove the surrounding Reference or Pointer type of the given type T.
+ QualType UnwrapReferenceOrPointer(QualType T) {
+ // "auto &" is represented as a ReferenceType containing an AutoType
+ if (const ReferenceType *RT = dyn_cast<ReferenceType>(T.getTypePtr()))
+ return RT->getPointeeType();
+ // "auto *" is represented as a PointerType containing an AutoType
+ if (const PointerType *PT = dyn_cast<PointerType>(T.getTypePtr()))
+ return PT->getPointeeType();
+ return T;
+ }
+
// Handle auto initializers:
//- auto i = 1;
//- decltype(auto) i = 1;
//- auto& i = 1;
+ //- auto* i = &a;
bool VisitDeclaratorDecl(DeclaratorDecl *D) {
if (!D->getTypeSourceInfo() ||
D->getTypeSourceInfo()->getTypeLoc().getBeginLoc() != SearchedLocation)
return true;
- auto DeclT = D->getType();
- // "auto &" is represented as a ReferenceType containing an AutoType
- if (const ReferenceType *RT = dyn_cast<ReferenceType>(DeclT.getTypePtr()))
- DeclT = RT->getPointeeType();
-
+ auto DeclT = UnwrapReferenceOrPointer(D->getType());
const AutoType *AT = dyn_cast<AutoType>(DeclT.getTypePtr());
if (AT && !AT->getDeducedType().isNull()) {
// For auto, use the underlying type because the const& would be
@@ -626,11 +634,7 @@
if (CurLoc != SearchedLocation)
return true;
- auto T = D->getReturnType();
- // "auto &" is represented as a ReferenceType containing an AutoType.
- if (const ReferenceType *RT = dyn_cast<ReferenceType>(T.getTypePtr()))
- T = RT->getPointeeType();
-
+ auto T = UnwrapReferenceOrPointer(D->getReturnType());
const AutoType *AT = dyn_cast<AutoType>(T.getTypePtr());
if (AT && !AT->getDeducedType().isNull()) {
DeducedType = T.getUnqualifiedType();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53186.169363.patch
Type: text/x-patch
Size: 3125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181012/ed5a996e/attachment.bin>
More information about the llvm-commits
mailing list