[bUO*      !"#$%&'() All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Infered*KMacro expansion text is divided into sections, each of which is classified F as one of three kinds: a formal argument (Arg), plain text (Text), * or a stringised formal argument (Str). +Expand an instance of a macro. 0 Precondition: got a match on the macro name. ,Parse a # define, or #undef, ignoring other # directives *-./0123456789:+,*-./0123456789:+,*/.-098641:::7:57:237+, Safe-Infered;The parser monad ';<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`a$;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^&;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`aAllStable/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Inferedb(Index Trees (storing indexes at nodes). c?Symbol Table. Stored values are polymorphic, but the keys are  always strings. bcdefghibcdefghbcdefghi Safe-Infered: takes a filename (for error reports), and transforms the K given string, to eliminate the literate comments from the program text. All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Infered#Options representable as Booleans. Leave # define and #undef in output of ifdef? Place #line droppings in output? Write  line or {- LINE #-} ? Keep #pragma in final output? Remove C eol (//) comments everywhere? Remove C inline (/**/) comments everywhere? Lex input as Haskell code? Permit stringise # and catenate ## operators? %Retain newlines in macro expansions? Remove literate markup? Issue warnings? Cpphs options structure.  Files to #include before anything else Default options. %Default settings of boolean options.  Parse all command-line options.     All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Infered :Source positions contain a filename, line, column, and an = inclusion point, which is itself another source position,  recursively. $Constructor. Argument is filename. +Increment column number by given quantity. )Increment row number, reset column to 1. 6Increment column number, tab stops are every 8 chars. (Increment row number by given quantity. 7Update position with a new row, and possible filename. !Project the line number. "Project the filename. #'Project the directory of the filename. $$cpp-style printing of file position %(haskell-style printing of file position &Conversion from a cpp-style #line to haskell-style pragma.  !"#$%&j !"#$%& !"#$%&jAll experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-InferedkIAttempt to read the given file from any location within the search path. I The first location found is returned, together with the file content. E (The directory of the calling file is always searched first, then ? the current directory, finally any specified search path.) k filename inclusion point  search path report warnings? 'discovered filepath, and file contents kk All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Inferedl9Each token is classified as one of Ident, Other, or Cmd: @ * Ident is a word that could potentially match a macro name. & * Cmd is a complete cpp directive (# define etc).  * Other is anything else. m:linesCpp is, broadly speaking, Prelude.lines, except that  on a line beginning with a ##, line continuation characters are A recognised. In a line continuation, the newline character is ( preserved, but the backslash is not. n+Put back the line-continuation characters. o;tokenise is, broadly-speaking, Prelude.words, except that: . * the input is already divided into lines  * each word-like token, is categorised as one of {Ident,Other,Cmd}  * #define'<s are parsed and returned out-of-band using the Cmd variant 4 * All whitespace is preserved intact as tokens. I * C-comments are converted to white-space (depending on first param) 7 * Parens and commas are tokens in their own right. 0 * Any cpp line continuations are respected.  No errors can be raised. 7 The inverse of tokenise is (concatMap deWordStyle). pIParse a possible macro call, returning argument list and remaining input lqrsmntop lqrsmntoplsrqmntop All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Infered'LWalk through the document, replacing calls of macros with the expanded RHS. u$Turn command-line definitions (from -D) into 0s. v5Turn a string representing a macro definition into a 0. '%Pre-defined symbols and their values $Options that alter processing style The input file content The file after processing uv'uv'uv All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Infered($Run a first pass of cpp, evaluating #ifdef's and processing #include's,  whilst taking account of #define's and #undef's as we encounter them. (File for error reports %Pre-defined symbols and their values Search path for # includes !Options controlling output style The input file content %The file after processing (in lines) ((  Safe-Infered)))All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Infered)  !"#$%&'()))('  $%&"!#w  !"#$%&'()*+,-./01 2 3 456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuv w x y z { | } ~  cpphs-1.13.3Language.Preprocessor.UnlitLanguage.Preprocessor.Cpphs&Language.Preprocessor.Cpphs.HashDefine#Text.ParserCombinators.HuttonMeijer"Language.Preprocessor.Cpphs.SymTab#Language.Preprocessor.Cpphs.Options$Language.Preprocessor.Cpphs.Position%Language.Preprocessor.Cpphs.ReadFirst$Language.Preprocessor.Cpphs.Tokenise%Language.Preprocessor.Cpphs.MacroPass$Language.Preprocessor.Cpphs.CppIfdef$Language.Preprocessor.Cpphs.RunCpphsunlit BoolOptionsmacros locationshashlinepragmastripEolstripC89langansilayoutliteratewarnings CpphsOptionsinfilesoutfilesdefinesincludes preIncludebooloptsdefaultCpphsOptionsdefaultBoolOptions parseOptionsPosnPnnewfileaddcolnewlinetabnewlinesnewposlinenofilename directorycpplinehasklinecpp2hask macroPasscppIfdefrunCpphs ArgOrText expandMacroparseHashDefineStrTextArg HashDefineMacroExpansion arguments expansionSymbolReplacement replacement AntiDefined linebreaksPragmaLineDropnameParserPitemfirstpapply+++satmanymany1sepbysepby1chainlchainl1chainrchainr1opsbracketchardigitlowerupperletteralphanumstringidentnatintspacescommentjunkskiptokennaturalintegersymbol identifier$fMonadPlusParser $fMonadParser$fFunctorParserIndTreeSymTabemptySTinsertSTdeleteSTlookupST definedST $fHashable[] $fShowPosn readFirst WordStylelinesCppreslashtokeniseparseMacroCallCmdOtherIdent deWordStyle preDefine defineMacro