[PATCH] D53347: [clangd] Simplify auto hover

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 24 03:11:39 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL345128: [clangd] Simplify auto hover (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53347?vs=170273&id=170835#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53347

Files:
  clang-tools-extra/trunk/clangd/XRefs.cpp
  clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp


Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -585,17 +585,6 @@
 
   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;
@@ -606,17 +595,9 @@
         D->getTypeSourceInfo()->getTypeLoc().getBeginLoc() != SearchedLocation)
       return true;
 
-    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
-      // represented twice: written in the code and in the hover.
-      // Example: "const auto I = 1", we only want "int" when hovering on auto,
-      // not "const int".
-      //
-      // For decltype(auto), take the type as is because it cannot be written
-      // with qualifiers or references but its decuded type can be const-ref.
-      DeducedType = AT->isDecltypeAuto() ? DeclT : DeclT.getUnqualifiedType();
+    if (auto *AT = D->getType()->getContainedAutoType()) {
+      if (!AT->getDeducedType().isNull())
+        DeducedType = AT->getDeducedType();
     }
     return true;
   }
@@ -640,12 +621,13 @@
     if (CurLoc != SearchedLocation)
       return true;
 
-    auto T = UnwrapReferenceOrPointer(D->getReturnType());
-    const AutoType *AT = dyn_cast<AutoType>(T.getTypePtr());
+    const AutoType *AT = D->getReturnType()->getContainedAutoType();
     if (AT && !AT->getDeducedType().isNull()) {
-      DeducedType = T.getUnqualifiedType();
-    } else { // auto in a trailing return type just points to a DecltypeType.
-      const DecltypeType *DT = dyn_cast<DecltypeType>(T.getTypePtr());
+      DeducedType = AT->getDeducedType();
+    } else {
+      // auto in a trailing return type just points to a DecltypeType and
+      // getContainedAutoType does not unwrap it.
+      const DecltypeType *DT = dyn_cast<DecltypeType>(D->getReturnType());
       if (!DT->getUnderlyingType().isNull())
         DeducedType = DT->getUnderlyingType();
     }
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
@@ -999,6 +999,13 @@
           )cpp",
           "",
       },
+      {
+          R"cpp(// More compilcated structured types.
+            int bar();
+            ^auto (*foo)() = bar;
+          )cpp",
+          "int",
+      },
   };
 
   for (const OneTest &Test : Tests) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53347.170835.patch
Type: text/x-patch
Size: 3268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181024/eb4b4e6b/attachment.bin>


More information about the llvm-commits mailing list