,      !"#$%&'()*+ All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Inferred,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). -smart; constructor to avoid warnings from ghc (undefined fields) .Expand an instance of a macro. 0 Precondition: got a match on the macro name. /Parse a # define, or #undef, ignoring other # directives 0CPretty-print hash defines to a simpler format, as key-value pairs. ,123456789:;<=>-./0,123456789:;<=>./0,3214=<:85>>>;>9;>67;-./0 Safe-Inferred?The parser monad (?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdef$?@BCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abc'?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefAllStable/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Inferredg(Index Trees (storing indexes at nodes). h?Symbol Table. Stored values are polymorphic, but the keys are  always strings. ijkglmhnopqrstuvwxyghnopqrsijkgmlhnopqrstuvwxy Safe-Inferred: takes a filename (for error reports), and transforms the K given string, to eliminate the literate comments from the program text. z{|}~z~}|{All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-InferredARaw command-line options. This is an internal intermediate data / structure, used during option parsing only. #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. GParse a single raw command-line option. Parse failure is indicated by  result Nothing. >Trim trailing elements of the second list that match any from = the first list. Typically used to remove trailing forward/back " slashes from a directory path. 8Convert a list of RawOption to a BoolOptions structure.  Parse all command-line options. ,     All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Inferred: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. BStrip non-directory suffix from file name (analogous to the shell  command of the same name).  !"#$%& !"#$%& !"#$%&All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-InferredIAttempt 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.)  filename inclusion point  search path report warnings? 'discovered filepath, and file contents  All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> Safe-Inferred9Each 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. @Submodes are required to deal correctly with nesting of lexical  structures. FA Mode value describes whether to tokenise a la Haskell, or a la Cpp. D The main difference is that in Cpp mode we should recognise line  continuation characters. :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. +Put back the line-continuation characters. ;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). IParse a possible macro call, returning argument list and remaining input    All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>None'LWalk through the document, replacing calls of macros with the expanded RHS.  auxiliary (LWalk through the document, replacing calls of macros with the expanded RHS. B Additionally returns the active symbol table after processing. $Turn command-line definitions (from -D) into 4s. 5Turn a string representing a macro definition into a 4. FTrundle through the document, one word at a time, using the WordStyle  classification introduced by  to decide whether to expand a " word or macro. Encountering a # define or #undef causes that symbol to K be overwritten in the symbol table. Any other remaining cpp directives 6 are discarded and replaced with blanks, except for #line markers. F All valid identifiers are checked for the presence of a definition H of that name in the symbol table, and if so, expanded appropriately. J (Bool arguments are: keep pragmas? retain layout? haskell language?) I The result lazily intersperses output text with symbol tables. Lines I are emitted as they are encountered. A symbol table is emitted after L each change to the defined symbols, and always at the end of processing. Useful helper function. Useful helper function. '%Pre-defined symbols and their values $Options that alter processing style The input file content The file after processing (%Pre-defined symbols and their values $Options that alter processing style The input file content +The file and symbol table after processing '( '( All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>None<Internal state for whether lines are being kept or dropped.  In  Drop n b ps, n is the depth of nesting, b is whether A we have already succeeded in keeping some lines in a chain of  elif's, and ps# is the stack of positions of open #if contexts, < used for error messages in case EOF is reached too soon. )$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. FReturn just the list of lines that the real cpp would decide to keep. Auxiliary IO functions Determine filename in #include )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) )) None*+*+*+All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>None+  !"#$%&'()*++*+)'(  $%&"!#  !"#$%&'()*+,-./01 2 3 4 5 6789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~=G                   cpphs-1.17Language.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 macroPassmacroPassReturningSymTabcppIfdefrunCpphsrunCpphsReturningSymTab ArgOrTextsymbolReplacement expandMacroparseHashDefinesimplifyHashDefinesStrTextArg HashDefineMacroExpansion arguments expansionSymbolReplacement replacement AntiDefined linebreaksPragmaLineDropnameParserPTokenitemfirstpapply+++satmanymany1sepbysepby1chainlchainl1chainrchainr1opsbracketchardigitlowerupperletteralphanumstringidentnatintspacescommentjunkskiptokennaturalintegersymbol identifier$fMonadPlusParser $fMonadParser$fFunctorParserIndTreeSymTabHashable hashWithMaxhashForkLeafemptySTinsertSTdeleteSTlookupST definedST flattenSTitgenitiapitinditfoldmaxHash $fHashable[] ClassifiedPreIncludeCommentBlankProgramclassify unclassifyadjacentmessageinlines RawOption rawOptiontrailingboolOptsIgnoredForCompatibility PreIncludePathMacroSuppressWarningsUnlitLayoutAnsiStripEolStrip LinePragmaNoLineNoMacroflagsdirname $fShowPosn readFirst WordStyleSubModeModelinesCppreslashtokeniseparseMacroCallCmdOtherIdent CLineCommentCComment NestComment LineCommentStringPredAnyCppHaskellother deWordStyle onlyRights preDefine defineMacro macroProcessemit emitSymTabnoPos KeepStatecppemitOnefileDropKeepemitMany gatherDefined parseBoolExp parseExp1 parseExp0parseOpparseSymOrCallrecursivelyExpandparseSymparens