C++ source tagging
Asked Answered
c++
W

6

23

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.

Whole answered 19/12, 2009 at 8:55 Comment(1)
I have the same problem using ctags: using the command :tags NamespaceName::ClassName::methodName everything ok, but putting cursor above the method name and type CTRL + ] it fail going to wrong method, I discover that using g + ] they show a list of tags than you can select the correct matching. The best to me is a script to analyse current code and correctly call :tagAjit
S
45

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).

Shaveling answered 19/12, 2009 at 10:8 Comment(2)
Great answer, I've been using my same old ctags command line for years even though I do more C++ these days. Guess I never thought to read the man page & see if I needed to add more options for C++. Very helpful.Expansive
--extra option is now obsolete; --extras should be used instead.Britanybritches
N
9

use doxygen its a great tool to browse code and see classes and members relations with each other. the tool produces clickable html output for your source code with references for each usage. you can compile it to a searchable chm file or use a web server to search the code for keywords.

Neil answered 19/12, 2009 at 9:6 Comment(0)
C
1

Try GNU global http://www.gnu.org/software/global/

It can generate navigate:able web pages of your source code as well as having support for vim and a command line interface that is often useful.

Cardboard answered 19/12, 2009 at 10:47 Comment(0)
M
0

I've no experience with this, but I have used Doxygen to browse the source code of complex projects. Just run it with all the settings turned on, and it will generate call graphs, callee graphs, reference and referenced-by relations, template instantiations, etc. Output formats include HTML, LaTeX, CHM, POD

Hope this works!

Meet answered 19/12, 2009 at 9:4 Comment(0)
T
0

For a while I have been mixing different tools for this purposes. Vi is a great editor and you can run it over remote computers without hassles, but the completion information is not semantical.

When confronted with a big problem I tend to use either Eclipse CDT or QTCreator, in both cases the latest versions, versions from a year back are not really so nice. QTCreator is a lightweight tool, but I have been quite impressed on its ability to analyze the code. Eclipse CDT is heavier weight, but I am a little more used to the interface, so at the end I tend to use it.

The project I am working on is compiled within a separated sandbox, where none of those two IDEs can be used, but you can get a copy of the repository just for analysis and use the IDE just as a browsing tool.

Tsar answered 19/12, 2009 at 9:52 Comment(0)
T
0

instead of extras, extra worked for me. Also specified -R to scan all files/folders recursively.

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

Tombstone answered 20/10, 2022 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.