r298170 - [index] For C++ constructors/destructors, add references to the parent type where its name appears in definitions and declarations

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 17 16:42:00 PDT 2017


Author: akirtzidis
Date: Fri Mar 17 18:41:59 2017
New Revision: 298170

URL: http://llvm.org/viewvc/llvm-project?rev=298170&view=rev
Log:
[index] For C++ constructors/destructors, add references to the parent type where its name appears in definitions and declarations

Patch by Nathan Hawes!
https://reviews.llvm.org/D30730

Modified:
    cfe/trunk/lib/Index/IndexDecl.cpp
    cfe/trunk/lib/Index/IndexingContext.h
    cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=298170&r1=298169&r2=298170&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Fri Mar 17 18:41:59 2017
@@ -158,6 +158,9 @@ public:
     handleDeclarator(D);
 
     if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
+      IndexCtx.handleReference(Ctor->getParent(), Ctor->getLocation(),
+                               Ctor->getParent(), Ctor->getDeclContext());
+
       // Constructor initializers.
       for (const auto *Init : Ctor->inits()) {
         if (Init->isWritten()) {
@@ -168,6 +171,12 @@ public:
           IndexCtx.indexBody(Init->getInit(), D, D);
         }
       }
+    } else if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(D)) {
+      if (auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
+        IndexCtx.handleReference(Dtor->getParent(),
+                                 TypeNameInfo->getTypeLoc().getLocStart(),
+                                 Dtor->getParent(), Dtor->getDeclContext());
+      }
     }
 
     if (D->isThisDeclarationADefinition()) {

Modified: cfe/trunk/lib/Index/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.h?rev=298170&r1=298169&r2=298170&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.h (original)
+++ cfe/trunk/lib/Index/IndexingContext.h Fri Mar 17 18:41:59 2017
@@ -71,7 +71,7 @@ public:
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
                        const NamedDecl *Parent,
                        const DeclContext *DC,
-                       SymbolRoleSet Roles,
+                       SymbolRoleSet Roles = SymbolRoleSet(),
                        ArrayRef<SymbolRelation> Relations = None,
                        const Expr *RefE = nullptr,
                        const Decl *RefD = nullptr);

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=298170&r1=298169&r2=298170&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Fri Mar 17 18:41:59 2017
@@ -2,13 +2,20 @@
 
 // CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | <no-cgname> | Def | rel: 0
 class Cls {
-  // CHECK: [[@LINE+2]]:3 | constructor/C++ | Cls | c:@S at Cls@F at Cls#I# | __ZN3ClsC1Ei | Decl,RelChild | rel: 1
+  // CHECK: [[@LINE+3]]:3 | constructor/C++ | Cls | c:@S at Cls@F at Cls#I# | __ZN3ClsC1Ei | Decl,RelChild | rel: 1
   // CHECK-NEXT: RelChild | Cls | c:@S at Cls
+  // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
   Cls(int x);
-  // CHECK: [[@LINE+1]]:3 | constructor/cxx-copy-ctor/C++ | Cls | c:@S at Cls@F at Cls#&1$@S at Cls# | __ZN3ClsC1ERKS_ | Decl,RelChild | rel: 1
+  // CHECK: [[@LINE+2]]:3 | constructor/cxx-copy-ctor/C++ | Cls | c:@S at Cls@F at Cls#&1$@S at Cls# | __ZN3ClsC1ERKS_ | Decl,RelChild | rel: 1
+  // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
   Cls(const Cls &);
-  // CHECK: [[@LINE+1]]:3 | constructor/cxx-move-ctor/C++ | Cls | c:@S at Cls@F at Cls#&&$@S at Cls# | __ZN3ClsC1EOS_ | Decl,RelChild | rel: 1
+  // CHECK: [[@LINE+2]]:3 | constructor/cxx-move-ctor/C++ | Cls | c:@S at Cls@F at Cls#&&$@S at Cls# | __ZN3ClsC1EOS_ | Decl,RelChild | rel: 1
+  // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
   Cls(Cls &&);
+
+  // CHECK: [[@LINE+2]]:3 | destructor/C++ | ~Cls | c:@S at Cls@F@~Cls# | __ZN3ClsD1Ev | Decl,RelChild | rel: 1
+  // CHECK: [[@LINE+1]]:4 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
+  ~Cls();
 };
 
 // CHECK: [[@LINE+3]]:7 | class/C++ | SubCls1 | [[SubCls1_USR:.*]] | <no-cgname> | Def | rel: 0
@@ -24,6 +31,16 @@ typedef Cls ClsAlias;
 // CHECK-NEXT: RelBase,RelCont | SubCls2 | [[SubCls2_USR]]
 class SubCls2 : public ClsAlias {};
 
+Cls::Cls(int x) {}
+// CHECK: [[@LINE-1]]:6 | constructor/C++ | Cls | c:@S at Cls@F at Cls#I# | __ZN3ClsC1Ei | Def,RelChild | rel: 1
+// CHECK: [[@LINE-2]]:1 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK: [[@LINE-3]]:6 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
+
+Cls::~/*a comment*/Cls() {}
+// CHECK: [[@LINE-1]]:6 | destructor/C++ | ~Cls | c:@S at Cls@F@~Cls# | __ZN3ClsD1Ev | Def,RelChild | rel: 1
+// CHECK: [[@LINE-2]]:1 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK: [[@LINE-3]]:20 | class/C++ | Cls | c:@S at Cls | <no-cgname> | Ref,RelCont | rel: 1
+
 template <typename TemplArg>
 class TemplCls {
 // CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | TemplCls | c:@ST>1#T at TemplCls | <no-cgname> | Def | rel: 0




More information about the cfe-commits mailing list