preprocessor-0.1.0.0: Remove cpp annotations to get the source ready for static analysis.

Description

After cpp preprocessing, the file is left by the compilation pipeline in the output format of the cpp program, described in this section of the C Preprocessor manual.

By default, the cpp program inserts blank lines to preserve line numbering, but only if the number of blank lines to be created is not too high (<6 or so). Otherwise a linemarker is created, to reduce the size of the generated file, of the form:

# linenum filename flags


As cpp doesn't have an option to output only blank lines and keeping the line numbering, the following functions parse a file with linemarkers separating it in CppOutputComponents (the source chunks between the linemarkers), and pad them with the appropriate amount of blank lines.

Synopsis

Substitutes the lineMarker in the content of a file with the appropriate blank line padding.

# Data Types

A LineMarker follows the structure described here. We only retain the linenumber and the file the line is referring to. Note that the filename is surrounded by quotation marks in the cpp output, but not in this representation.

Constructors

 LineMarker FieldsbeginsAtLine :: Int filePath :: FilePath

Instances

 Source # MethodsshowList :: [LineMarker] -> ShowS #
>>> isLineMarker "# 42 \"/path/to/file\""
True

>>> parseLineMarker "# 42 \"/path/to/file\""
LineMarker {beginsAtLine = 42, filePath = "/path/to/file"}


A CppOutputComponent is constituted by a LineMarker and the block of code till the next LineMarker.

Constructors

 CppOutputComponent FieldslineMarker :: LineMarker sourceBlock :: [String]

Instances

 Source # MethodsshowList :: [CppOutputComponent] -> ShowS #

Given the lines of a file, parses the CppOutputComponents. Note that a file that doesn't need cpp preprocessing doesn't have any LineMarker. In that case a dummy component is created, with an empty path.