Skip to content

Output "context" (namespace / class / function) for a location in a C++ source file

License

Notifications You must be signed in to change notification settings

shaneharper/cpp_context

Repository files navigation

C++ Context

C++ Context was written to aid software developers quickly comprehend C++ code.

C++ Context takes as input a position in a C++ source file and outputs the corresponding "context", viz. the scope (namespace, class, and/or function). C++ Context effectively "filters" context information from the source code text reducing the amount of text for the software developer to read.

C++ Context could be used:

  • to annotate the output of a search tool such as 'grep'. (Knowing the class/function where something appears can be more useful than knowing just the file and possibly line number.)
  • to annotate a text editor's "tag stack", adding context to the "jumped from" locations.
  • when viewing long, unfamiliar function or class definitions - context could be shown in a status bar or at the top of the window.

C++ Context uses libclang.

Getting Started

On Ubuntu 13.10:

sudo apt-get install clang-3.4 clang-3.4-dev
cd cpp_context && make

Compilation database

c++_context uses a compile_commands.json file to find which compiler options are needed for each source file. c++_context will use compile_commands.json from the current directory if it exists, otherwise it will search parent directories.

See:

At the time of writing, cmake and bear don't output entries in compile_commands.json for header files. :-(

Using C++ Context with Vim editor

c++_context.vim maps <localleader>c to display the context for the current cursor position. (<localleader> defaults to \.)

:source /path/to/c++_context.vim

can be added to your .vimrc.

About

Output "context" (namespace / class / function) for a location in a C++ source file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published