Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ source tagging

Tags:

Any suggestions on a quality way to tag and search c++ code. I use cscope/ctags for most stuff, but I have found it insufficient to find my way around some of the overly complex c++ code at work. I have started to switch from vim to Slickedit (which is still not perfect, but better) for browsing code, but would like to go back to exclusively vim.

What I would like is something that can understand scope of class members so, for instance, if I search for references to a member of a class where the same member name exists in other classes (and possibly out of c++ code) it will only give me the relevant references.

I'd prefer something that already works nice with vim, but any open source package such that I might create a plugin myself would be fine.

Any suggestions appreciated, thanks.

like image 453
Jeff Thomas Avatar asked Dec 19 '09 08:12

Jeff Thomas


1 Answers

Are you sure you called ctags with the right options? For C++, I use:

ctags --c++-kinds=+p --fields=+iaS --extras=+q --language-force=C++

This is what the documentation has to say about the --c++-kinds=+p option:

When parsing a C++ member function definition (e.g. "className::function"), ctags cannot determine whether the scope specifier is a class name or a namespace specifier and always lists it as a class name in the scope portion of the extension fields. Also, if a C++ function is defined outside of the class declaration (the usual case), the access specification (i.e. public, protected, or private) and implementation information (e.g. virtual, pure virtual) contained in the function declaration are not known when the tag is generated for the function definition. It will, however be available for prototypes
(e.g --c++-kinds=+p).

The --fields=+iaS option:

 a   Access (or export) of class members  i   Inheritance information  S   Signature of routine (e.g. prototype or parameter list) 

The --extras=+q option:

Because, by default, ctags only generates tags for the separate identifiers found in the source files. If you specify the --extra=+q option, then ctags will also generate a second, class-qualified tag for each class member (data and function/method) in the form class::member for C++, and in the form class.method for Eiffel and Java.

The --language-force=C++ option:

By default, ctags automatically selects the language of a source file, ignoring those files whose language cannot be determined (see SOURCE FILES, above). This option forces the specified language (case-insensitive; either built-in or user-defined) to be used for every supplied file instead of automatically selecting the language based upon its extension. In addition, the special value auto indicates that the language should be automatically selected (which effectively disables this option).

like image 81
Ton van den Heuvel Avatar answered Oct 11 '22 14:10

Ton van den Heuvel