r178911 - [libclang] Fix cursor visitation to not ignore template arguments in out-of-line member functions.

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Apr 5 14:04:10 PDT 2013


Author: akirtzidis
Date: Fri Apr  5 16:04:10 2013
New Revision: 178911

URL: http://llvm.org/viewvc/llvm-project?rev=178911&view=rev
Log:
[libclang] Fix cursor visitation to not ignore template arguments in out-of-line member functions.

rdar://13535645

Modified:
    cfe/trunk/test/Index/annotate-tokens.cpp
    cfe/trunk/test/Index/get-cursor.cpp
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/test/Index/annotate-tokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.cpp?rev=178911&r1=178910&r2=178911&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens.cpp (original)
+++ cfe/trunk/test/Index/annotate-tokens.cpp Fri Apr  5 16:04:10 2013
@@ -20,7 +20,15 @@ void test3(S2 s2) {
   X foo;
 }
 
-// RUN: c-index-test -test-annotate-tokens=%s:1:1:21:1 %s | FileCheck %s
+template <bool (*tfn)(X*)>
+struct TS {
+  void foo();
+};
+
+template <bool (*tfn)(X*)>
+void TS<tfn>::foo() {}
+
+// RUN: c-index-test -test-annotate-tokens=%s:1:1:30:1 %s | FileCheck %s
 // CHECK: Keyword: "struct" [1:1 - 1:7] StructDecl=bonk:1:8 (Definition)
 // CHECK: Identifier: "bonk" [1:8 - 1:12] StructDecl=bonk:1:8 (Definition)
 // CHECK: Punctuation: "{" [1:13 - 1:14] StructDecl=bonk:1:8 (Definition)
@@ -120,3 +128,48 @@ void test3(S2 s2) {
 // CHECK: Identifier: "foo" [20:5 - 20:8] VarDecl=foo:20:5 (Definition)
 // CHECK: Punctuation: ";" [20:8 - 20:9] DeclStmt=
 // CHECK: Punctuation: "}" [21:1 - 21:2] CompoundStmt=
+// CHECK: Keyword: "template" [23:1 - 23:9] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Punctuation: "<" [23:10 - 23:11] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Keyword: "bool" [23:11 - 23:15] NonTypeTemplateParameter=tfn:23:18 (Definition)
+// CHECK: Punctuation: "(" [23:16 - 23:17] NonTypeTemplateParameter=tfn:23:18 (Definition)
+// CHECK: Punctuation: "*" [23:17 - 23:18] NonTypeTemplateParameter=tfn:23:18 (Definition)
+// CHECK: Identifier: "tfn" [23:18 - 23:21] NonTypeTemplateParameter=tfn:23:18 (Definition)
+// CHECK: Punctuation: ")" [23:21 - 23:22] NonTypeTemplateParameter=tfn:23:18 (Definition)
+// CHECK: Punctuation: "(" [23:22 - 23:23] NonTypeTemplateParameter=tfn:23:18 (Definition)
+// CHECK: Identifier: "X" [23:23 - 23:24] TypeRef=struct X:7:8
+// CHECK: Punctuation: "*" [23:24 - 23:25] ParmDecl=:23:25 (Definition)
+// CHECK: Punctuation: ")" [23:25 - 23:26] ParmDecl=:23:25 (Definition)
+// CHECK: Punctuation: ">" [23:26 - 23:27] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Keyword: "struct" [24:1 - 24:7] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Identifier: "TS" [24:8 - 24:10] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Punctuation: "{" [24:11 - 24:12] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Keyword: "void" [25:3 - 25:7] CXXMethod=foo:25:8
+// CHECK: Identifier: "foo" [25:8 - 25:11] CXXMethod=foo:25:8
+// CHECK: Punctuation: "(" [25:11 - 25:12] CXXMethod=foo:25:8
+// CHECK: Punctuation: ")" [25:12 - 25:13] CXXMethod=foo:25:8
+// CHECK: Punctuation: ";" [25:13 - 25:14] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Punctuation: "}" [26:1 - 26:2] ClassTemplate=TS:24:8 (Definition)
+// CHECK: Punctuation: ";" [26:2 - 26:3]
+// CHECK: Keyword: "template" [28:1 - 28:9] CXXMethod=foo:29:15 (Definition)
+// CHECK: Punctuation: "<" [28:10 - 28:11] CXXMethod=foo:29:15 (Definition)
+// CHECK: Keyword: "bool" [28:11 - 28:15] NonTypeTemplateParameter=tfn:28:18 (Definition)
+// CHECK: Punctuation: "(" [28:16 - 28:17] NonTypeTemplateParameter=tfn:28:18 (Definition)
+// CHECK: Punctuation: "*" [28:17 - 28:18] NonTypeTemplateParameter=tfn:28:18 (Definition)
+// CHECK: Identifier: "tfn" [28:18 - 28:21] NonTypeTemplateParameter=tfn:28:18 (Definition)
+// CHECK: Punctuation: ")" [28:21 - 28:22] NonTypeTemplateParameter=tfn:28:18 (Definition)
+// CHECK: Punctuation: "(" [28:22 - 28:23] NonTypeTemplateParameter=tfn:28:18 (Definition)
+// CHECK: Identifier: "X" [28:23 - 28:24] TypeRef=struct X:7:8
+// CHECK: Punctuation: "*" [28:24 - 28:25] ParmDecl=:28:25 (Definition)
+// CHECK: Punctuation: ")" [28:25 - 28:26] ParmDecl=:28:25 (Definition)
+// CHECK: Punctuation: ">" [28:26 - 28:27] CXXMethod=foo:29:15 (Definition)
+// CHECK: Keyword: "void" [29:1 - 29:5] CXXMethod=foo:29:15 (Definition)
+// CHECK: Identifier: "TS" [29:6 - 29:8] TemplateRef=TS:24:8
+// CHECK: Punctuation: "<" [29:8 - 29:9] CXXMethod=foo:29:15 (Definition)
+// CHECK: Identifier: "tfn" [29:9 - 29:12] DeclRefExpr=tfn:28:18
+// CHECK: Punctuation: ">" [29:12 - 29:13] CXXMethod=foo:29:15 (Definition)
+// CHECK: Punctuation: "::" [29:13 - 29:15] CXXMethod=foo:29:15 (Definition)
+// CHECK: Identifier: "foo" [29:15 - 29:18] CXXMethod=foo:29:15 (Definition)
+// CHECK: Punctuation: "(" [29:18 - 29:19] CXXMethod=foo:29:15 (Definition)
+// CHECK: Punctuation: ")" [29:19 - 29:20] CXXMethod=foo:29:15 (Definition)
+// CHECK: Punctuation: "{" [29:21 - 29:22] CompoundStmt=
+// CHECK: Punctuation: "}" [29:22 - 29:23] CompoundStmt=

Modified: cfe/trunk/test/Index/get-cursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/get-cursor.cpp?rev=178911&r1=178910&r2=178911&view=diff
==============================================================================
--- cfe/trunk/test/Index/get-cursor.cpp (original)
+++ cfe/trunk/test/Index/get-cursor.cpp Fri Apr  5 16:04:10 2013
@@ -47,6 +47,14 @@ void test() {
   };
 }
 
+template <bool (*tfn)(X*)>
+struct TS {
+  void foo();
+};
+
+template <bool (*tfn)(X*)>
+void TS<tfn>::foo() {}
+
 // RUN: c-index-test -cursor-at=%s:6:4 %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s
 // CHECK-COMPLETION-1: CXXConstructor=X:6:3
 // CHECK-COMPLETION-1-NEXT: Completion string: {TypedText X}{LeftParen (}{Placeholder int}{Comma , }{Placeholder int}{RightParen )}
@@ -103,3 +111,7 @@ void test() {
 
 // RUN: c-index-test -cursor-at=%s:45:9 %s | FileCheck -check-prefix=CHECK-LOCALCLASS %s
 // CHECK-LOCALCLASS: 45:9 DeclRefExpr=x:44:11 Extent=[45:9 - 45:10] Spelling=x ([45:9 - 45:10])
+
+// RUN: c-index-test -cursor-at=%s:50:23 -cursor-at=%s:55:23 %s | FileCheck -check-prefix=CHECK-TEMPLPARAM %s
+// CHECK-TEMPLPARAM: 50:23 TypeRef=struct X:3:8 Extent=[50:23 - 50:24] Spelling=struct X ([50:23 - 50:24])
+// CHECK-TEMPLPARAM: 55:23 TypeRef=struct X:3:8 Extent=[55:23 - 55:24] Spelling=struct X ([55:23 - 55:24])

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=178911&r1=178910&r2=178911&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Apr  5 16:04:10 2013
@@ -723,6 +723,13 @@ bool CursorVisitor::VisitEnumConstantDec
 }
 
 bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
+  unsigned NumParamList = DD->getNumTemplateParameterLists();
+  for (unsigned i = 0; i < NumParamList; i++) {
+    TemplateParameterList* Params = DD->getTemplateParameterList(i);
+    if (VisitTemplateParameters(Params))
+      return true;
+  }
+
   if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo())
     if (Visit(TSInfo->getTypeLoc()))
       return true;
@@ -751,6 +758,13 @@ static int CompareCXXCtorInitializers(co
 }
 
 bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
+  unsigned NumParamList = ND->getNumTemplateParameterLists();
+  for (unsigned i = 0; i < NumParamList; i++) {
+    TemplateParameterList* Params = ND->getTemplateParameterList(i);
+    if (VisitTemplateParameters(Params))
+      return true;
+  }
+
   if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) {
     // Visit the function declaration's syntactic components in the order
     // written. This requires a bit of work.





More information about the cfe-commits mailing list