2016-02-01 19 views
2

我使用ctags來索引我的源代碼。 爲了簡單起見,我組裝了一些示例代碼,如下所示。ctags不是索引類的成員函數

namespace test_space 
{ 
template<typename TYPE> 
class A 
{ 
public: 
    void test_func(TYPE a); 
    void test_func_2(TYPE a); 
    void test_func_3(TYPE a); 
} 
class B 
{ 
public: 
    void test_func_b(); 
} 

void easy_func() 
{ 
} 

} 

我把它命名爲a.h文件,並使用ctags a.h生成標籤文件,但只CTAGS索引的命名空間,類和函數,但不是我的類成員函數(如test_func),爲什麼呢?如何啓用此功能? 這是生成的標籤文件內容:

!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/ 
!_TAG_PROGRAM_NAME Exuberant Ctags // 
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 
!_TAG_PROGRAM_VERSION 5.6 // 
A a.h /^class A$/;" c namespace:test_space 
B a.h /^class B$/;" c namespace:test_space 
easy_func a.h /^void easy_func()$/;" f namespace:test_space 
test_space a.h /^namespace test_space$/;" n 

回答

2

看來旺盛,ctags的默認只添加標籤時,看到一個定義,而不是一個聲明。您A類更改爲

template<typename TYPE> 
class A 
{ 
public: 
    void test_func(TYPE a) 
    { 
    } 
    void test_func_2(TYPE a); 
    void test_func_3(TYPE a); 
}; 

使得test_functags文件顯示:

!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/ 
!_TAG_PROGRAM_NAME Exuberant Ctags // 
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 
!_TAG_PROGRAM_VERSION 5.9~svn20110310 // 
A a.h /^class A$/;" c namespace:test_space 
B a.h /^class B$/;" c namespace:test_space 
easy_func a.h /^void easy_func()$/;" f namespace:test_space 
test_func a.h /^ void test_func(TYPE a)$/;" f class:test_space::A 
test_space a.h /^namespace test_space$/;" n 

,但其他功能沒有顯示出來。我自己並不使用ctags,但通常您希望能夠找到定義而不是聲明,這是有道理的。

如果你告訴ctags的索引protoypes,你可以讓你在找什麼:

ctags --c-kinds=+p a.h 

對於你的榜樣,這導致

!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/ 
!_TAG_PROGRAM_NAME Exuberant Ctags // 
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 
!_TAG_PROGRAM_VERSION 5.9~svn20110310 // 
A a.h /^class A$/;" c namespace:test_space 
B a.h /^class B$/;" c namespace:test_space 
easy_func a.h /^void easy_func()$/;" f namespace:test_space 
test_func a.h /^ void test_func(TYPE a);$/;" p class:test_space::A 
test_func_2 a.h /^ void test_func_2(TYPE a);$/;" p class:test_space::A 
test_func_3 a.h /^ void test_func_3(TYPE a);$/;" p class:test_space::A 
test_func_b a.h /^ void test_func_b();$/;" p class:test_space::B 
test_space a.h /^namespace test_space$/;" n 

你可以在這事情的詳細信息標籤是這樣的:

$ ctags --list-kinds=c 
c classes 
d macro definitions 
e enumerators (values inside an enumeration) 
f function definitions 
g enumeration names 
l local variables [off] 
m class, struct, and union members 
n namespaces 
p function prototypes [off] 
s structure names 
t typedefs 
u union names 
v variable definitions 
x external and forward variable declarations [off] 

你可以看到,默認情況下,函數原型沒有被標記。