| ||Code comprehension is an integral part of a developer’s everyday programming tasks. Today’s modern, graphical IDEs have many features that facilitate this process. Unfortunately, using these IDEs is often impractical when working with large C/C++ code bases (in the order of millions to tens of millions of lines of code) as they are difficult to integrate with the custom and often complex build systems commonly employed in such projects, and their start-up time and memory usage can be excessive due the sheer volume of code involved. For these reasons, it has been our experience that developers often fall back to lightweight editors, such as Emacs or Vim, and use regex-based text scanning tools like Grep or CScope to aid in code comprehension tasks. But while these text scanning tools are fast, they are also largely unaware of symbol types, scopes and linking information, handle the C pre-processor poorly, and deal only with direct dependencies.
We are developing a code comprehension tool called Frappé that aims to address the limitations of these tools while maintaining a comparable level of scalability and ease-of-integration. Our approach is based around building and incrementally maintaining a dependency graph of the program. The nodes in the graph represent source entities such as functions, global variables, types, macros, files, etc. and the edges represent the relations between them, e.g. calls, reads, writes, uses, contains, etc. Code comprehension questions then become graph-matching problems. This works both for questions involving direct dependencies, like finding all functions that write to a particular global variable (match all function nodes with an outgoing writes edge to the global variable of interest) and transitive dependencies, like estimating the impact of a code change (match all functions in the transitive closure of calls edges from the function or functions to be modified). Integration with custom builds is made easy by providing wrapper scripts that serve as drop-in replacements for the most common compilers (e.g. gcc, icc, cc, clang). These scripts still execute the native compiler they wrap, but also run a modified version of the clang compiler to write out precise information on the various source entities and dependencies in the given compilation unit. Frappé reads this information in as it becomes available and incrementally constructs (or updates) the dependency graph of the system as it does so.
Frappé provides several UIs for exploring the dependency data it generates, including editor plugins for Emacs and Vim and a web UI that allows users to navigate the dependencies in their code and write their own custom queries from their web browser. The web UI overlays query results on a 2D spatial visualisation of the code called a Code Map that gives an immediate general impression of the location, locality and quantity of results. The prototype version of Frappé has seen a positive initial response from internal development organisations. A formal evaluation is planned.|