-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Remove cpp annotations to get the source ready for static analysis. -- -- Remove cpp annotations using the configuration with which you build -- the package, to get the source ready for static analysis with a -- parsing library like haskell-src-exts. @package preprocessor @version 0.1.0.0 -- | 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. module Language.C.Preprocessor.Remover.Internal.AddPadding -- | Substitutes the lineMarker in the content of a file with the -- appropriate blank line padding. addPadding :: FilePath -> String -> String -- | 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. data LineMarker LineMarker :: Int -> FilePath -> LineMarker [beginsAtLine] :: LineMarker -> Int [filePath] :: LineMarker -> FilePath -- |
--   >>> isLineMarker "# 42 \"/path/to/file\""
--   True
--   
isLineMarker :: String -> Bool -- |
--   >>> parseLineMarker "# 42 \"/path/to/file\""
--   LineMarker {beginsAtLine = 42, filePath = "/path/to/file"}
--   
parseLineMarker :: String -> LineMarker -- | A CppOutputComponent is constituted by a LineMarker and -- the block of code till the next LineMarker. data CppOutputComponent CppOutputComponent :: LineMarker -> [String] -> CppOutputComponent [lineMarker] :: CppOutputComponent -> LineMarker [sourceBlock] :: CppOutputComponent -> [String] -- | 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. parseCppOutputComponents :: [String] -> [CppOutputComponent] -- | 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). discardUnusefulComponents :: FilePath -> [CppOutputComponent] -> [CppOutputComponent] -- | Adds padding to the source blocks to mantain the correct line numbers -- of the source code. reconstructSource :: [CppOutputComponent] -> [String] instance GHC.Show.Show Language.C.Preprocessor.Remover.Internal.AddPadding.CppOutputComponent instance GHC.Show.Show Language.C.Preprocessor.Remover.Internal.AddPadding.LineMarker module Language.C.Preprocessor.Remover.Internal.Types -- | CppOptions represent the options which are passed, through the -- ghc api, to the cpp preprocessing program. For reference, here -- is the part of the gcc manual corresponding to the preprocessing -- options. data CppOptions CppOptions :: [String] -> [FilePath] -> [FilePath] -> CppOptions -- | CPP #define macros. Corresponds to a -D option for the cpp -- program. [cppDefine] :: CppOptions -> [String] -- | CPP Includes directory. Corresponds to a -I option for the -- cpp program. [cppInclude] :: CppOptions -> [FilePath] -- | CPP pre-include file. Corresponds to a -include option for -- the cpp program. [cppFile] :: CppOptions -> [FilePath] -- |
--   >>> emptyCppOptions
--   CppOptions {cppDefine = [], cppInclude = [], cppFile = []}
--   
emptyCppOptions :: CppOptions -- | ProjectDir is the directory which contains the .cabal file for the -- project. type ProjectDir = FilePath -- | The path of the main .cabal file of the project. type CabalFilePath = FilePath instance GHC.Show.Show Language.C.Preprocessor.Remover.Internal.Types.CppOptions module Language.C.Preprocessor.Remover.Internal.Preprocess -- | Parse a module with specific instructions for the C pre-processor. parseModuleWithCpp :: CppOptions -> FilePath -> IO String -- | Invoke GHC's preprocess function at the cpp phase, adding the -- options specified in the first argument. getPreprocessedSrcDirect :: GhcMonad m => CppOptions -> FilePath -> m String -- | This library preprocesses the cpp directives in haskell source code (a -- task not usually done by parsing libraries), to prepare it for static -- analysis, e.g. with haskell-src-exts. -- -- The design of the library is guided by two principles: -- -- -- -- Currently this tool requires the library to have been built -- with stack (it searches for some files generated in -- .stack-work). In the future I'll probably lift this -- restriction (if you need it before, please open a ticket). The files -- marked as internal are exported for documentation purposes only. module Language.C.Preprocessor.Remover -- | Given the path to the cabal file, this returns the paths to all the -- exposed modules of the library section. getLibExposedModulesPath :: CabalFilePath -> IO [FilePath] -- | Given the path to a file in a stack-build project, returns the content -- of the preprocessed file. The line numbering of the original file is -- preserved. preprocessFile :: FilePath -> IO String