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

Copyright(c) Carlo Nucera, 2016
LicenseBSD3
Maintainermeditans@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Language.C.Preprocessor.Remover.Internal.AddPadding

Contents

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

Entry point for padding

addPadding :: FilePath -> String -> String Source #

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

Data Types

data LineMarker Source #

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 

isLineMarker :: String -> Bool Source #

>>> isLineMarker "# 42 \"/path/to/file\""
True

parseLineMarker :: String -> LineMarker Source #

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

Stages of padding

parseCppOutputComponents :: [String] -> [CppOutputComponent] Source #

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.

discardUnusefulComponents :: FilePath -> [CppOutputComponent] -> [CppOutputComponent] Source #

Discard the parts of cpp output which correspond to cpp include files. If there's a unique component then we return that one, otherwise we return all the components relative to our file other than the first (which has no real meaning).

reconstructSource :: [CppOutputComponent] -> [String] Source #

Adds padding to the source blocks to mantain the correct line numbers of the source code.