Proceedings of ISP RAS


Lazy source code analysis for C/C++ languages.

Savitskiy V.O., Sidorov D.V.

Abstract

The article describes a way to implement syntax analysis for C/C++ languages which allows to reduce significantly the required resources. The method is based on the fact that each source file includes lots of header files from which only a portion of definitions is used. The analysis of definitions in headers can be postponed to the moment of actual access to them, thus avoiding the analysis of definitions that are never used. Such definitions as templates, classes, functions could be skipped during code parsing until access of such definitions will be found in source code. For these purposes parser of C/C++ code modified to support postponed parsing of skipped parts along with revision system like caching of semantic information for parsed code. As the result of implementation of such parser performance growth of source code parsing up to 36% observed on several open source projects. The distinctive feature of this method is that only a small amount of changes is required to add the "lazy" behaviour to an existing parser. This method of source code parser performance improvement is implemented in the Klocwork Insight static analyzer.

Keywords

lazy analysis, syntax analysis, C/C++

Edition

Proceedings of the Institute for System Programming, vol. 23, 2012, pp. 133-142.

ISSN 2220-6426 (Online), ISSN 2079-8156 (Print).

DOI: 10.15514/ISPRAS-2012-23-8

Full text of the paper in pdf (in Russian) Back to the contents of the volume