Is clang able to replace Exuberant Ctags?

4.1k views Asked by At

To investigate new files I'm used to run ctags with the appropriate options, the problem is that apparently this program doesn't support C++11 and I was just using it fine until I discovered that the development of this program ended years ago .

Now I need an equivalent tool for C++11 and beyond, and I remember that clang alone is able to output the AST of any given file so I was wondering if the fronted had similar functionalities that were comparable to what I used to do with ctags .

For example this are the entities that you can easily list with ctags in C++ mode

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]

Does clang is able to perform a similar task ?

2

There are 2 answers

1
Nikolai On

Have a look at rtags tool. It uses clang to recompile your entire project. After that you can use it to navigate through the sources. The only problem is that AST is built after preprocessor has run, so the code that was disabled by macros is not available for navigation.

The projects maintains a set of elisp bindings that allows you to control RTags from emacs. For integration in vim see the third-party projects by lyuts or Shane Harper.

0
Hotschke On

The llvm/clang project does not include a tool to generate tag files from the ast. However, there are several projects on github using clang to do this, which can be found via: https://github.com/search?utf8=%E2%9C%93&q=clang+tags

Following two projects got some attention (stars, issues, pull requests)

Unfortunately, there are no recent commits, however, the authors still respond to raised issues.

Disclaimer I know link-only answers are discouraged. I will extend this question when I find the time to test the projects and see how they compare to Exuberant-ctags or Universal-ctags.