I*      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~   Safe-Inferred 9:;<=>?9:;<=>?9:;<=?> 9:;<=>?None @A@A@A @ANoneB3The PN is the name as it occurs to the parser, and " corresponds with the GHC.RdrName  type PN = GHC.RdrName D.HsName is a name as it is found in the source , This seems to be quite a close correlation BThe PNT is the unique name, after GHC renaming. It corresponds to D GHC.Name data PNT = PNT GHC.Name deriving (Data,Typeable) -- Note: # GHC.Name has SrcLoc in it already BCDEFGHIJK BCDEFGHIJK KJIHGFEDBCBCDEFGHIJKNoneMReplacement for original getRichTokenStream which will return ) the tokens for a file processed by CPP.  See bug  +http://ghc.haskell.org/trac/ghc/ticket/8265 >Combine the three sets of tokens to produce a single set that @ represents the code compiled, and will regenerate the original  source file.  [ directiveToks]. are the tokens corresponding to preprocessor 5 directives, converted to comments  [ origSrcToks]5 are the tokenised source of the original code, with B the preprocessor directives stripped out so that . the lexer does not complain  [ postCppToks]1 are the tokens that the compiler saw originally ; NOTE: this scheme will only work for cpp in -nomacro mode ?Strip out the CPP directives so that the balance of the source  can tokenised. AThe preprocessed files are placed in a temporary directory, with A a temporary name, and extension .hscpp. Each of these files has ? three lines at the top identifying the original origin of the C files, which is ignored by the later stages of compilation except " to contextualise error messages. ;Get the preprocessor directives as comment tokens from the  source. :Merge two sorted lists using into a single, sorted whole, <allowing the programmer to specify the comparison function. QuickCheck test property: prop_mergeBy xs ys = I mergeBy cmp (sortBy cmp xs) (sortBy cmp ys) == sortBy cmp (xs ++ ys) + where types = xs :: [ (Int, Int) ] 2 cmp (x1,_) (x2,_) = compare x1 x2 LMLMLMLMNoneO?Provide some temporary storage while the refactoring is taking  place S:Result of parsing a Haskell source file. It is simply the $ TypeCheckedModule produced by GHC. U*State for refactoring a single file. Holds/hides the token 9 stream, which gets updated transparently at key points. WSession level settings X@Current Unique creator value, incremented every time it is used Y)Flags for controlling generic traversals ZTemporary storage of values  while refactoring takes place ^$The current module being refactored a,Current traversal has already made a change e-Original Token stream for the current module fJToken stream for the current module, maybe modified, in SrcSpan tree form g,current module has updated the token stream z9Initialise the GHC session, when starting a refactoring. ) This should never be called directly. {=Load a module graph into the GHC session, starting from main |BMake sure the given file is the currently loaded target, and load B it if not. Assumes that all the module graphs had been generated # before, so these are not updated. ANOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~3NOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~3StwvujklmnopqrsUVWXYZ[\]^bcdefgThi_`aORQPN~xyz{|}!NORQPSTU VWXYZ[\]^_`abcdefghij klmnopqrstwvuxyz{|}~ NoneShow a GHC API structure  None3Look up a subterm by means of a maybe-typed filter 2Apply a monadic transformation at least somewhere FApply a monadic transformation at least somewhere, in bottom up order  Monadic variation on everywhere Monadic variation on everywhere' Bottom-up transformation %Top-down version of everywhereStaged KChecks whether the current item is undesirable for analysis in the current  AST Stage. Check the Typeable1 items #Staged variation of SYB.everything E The stage must be provided to avoid trying to modify elements which 5 may not be present at all stages of AST processing.  Note: Top-down order ?Perform a query on the immediate subterms only, avoiding holes  Staged variation of SYB.listify E The stage must be provided to avoid trying to modify elements which 5 may not be present at all stages of AST processing. 0Full type-unifying traversal in top-down order. <Top-down type-unifying traversal that is cut of below nodes ) where the argument strategy succeeds. >Top-down type-preserving traversal that is cut of below nodes ) where the argument strategy succeeds. >Top-down type-preserving traversal that performs its argument  strategy at most once. ?Bottom-up type-preserving traversal that performs its argument  strategy at most once. AApply a generic transformation everywhere in a bottom-up manner. =Open a zipper to the point where the Geneneric query passes. E returns the original zipper if the query does not pass (check this) ;Apply a generic monadic transformation once at the topmost D leftmost successful location, avoiding holes in the GHC structures 5Transform a zipper opened with a given generic query @Monadic transform of a zipper opened with a given generic query 'Climb the tree until a predicate holds BUp the zipper until a predicate holds, and then return the zipper  hole ;Open a zipper to the point where the Generic query passes, @ returning the zipper and a value from the specific part of the C GenericQ that matched. This allows the components of the query to K return a specific transformation routine, to apply to the returned zipper ;Open a zipper to the point where the Generic query passes, E and apply the transformation returned from the specific part of the  GenericQ that matched. $ $None$Returns True if the token ends with '\n'  ++AZ++: is this meaningful? &Returns True if the token starts with `\n`.  ++AZ++: is this meaningful? 2get the last non-ignored token in a token stream. )Remove the extra preceding empty lines. (Remove the following extra empty lines. QGiven a token stream covering multi-lines, calculate the length of the last line ? AZ: should be the last token start col, plus length of token. <get a token stream specified by the start and end position. *Get the start of the line before the pos, @Delete a sequence of tokens specified by the start position and E end position from the token stream, then adjust the remaining token  stream to preserve layout @Adjust the layout to compensate the change in the token stream. =remove at most n white space tokens from the beginning of ts @get all the source locations (use locations) in an AST phrase t 4 according the the occurrence order of identifiers. 8Get all the source locations in a given syntax fragment CExtend the given position backwards to the front of the file while  the supplied condition holds @Extend the given position forwards to the end of the file while  the supplied condition holds  Get the start&5end location of syntax phrase t, then extend the end  location to cover the comment/&white spaces or new line which starts & in the same line as the end location : TODO: deprecate this in favour of startEndLocIncComments 'gets the (row,col) of the start of the  GHC.SrcSpan , or (-1,-1)  if there is an GHC.UnhelpfulSpan %gets the (row,col) of the end of the  GHC.SrcSpan , or (-1,-1)  if there is an GHC.UnhelpfulSpan BGet around lack of instance Eq when simply testing for empty list $ TODO: get rid of this in favour of  built in fn  Get the start&3end location of t in the token stream, then extend A the start and end location to cover the preceding and following  comments. In this routine, 'then','else','do' and 'in' are treated as comments. 3Get the first SrcSpan found, in top down traversal @Adjust token stream to cater for changes in token length due to  token renaming 6K $%'()+,./01234568K('2$)6%.13/04 8 5,+6None@Assuming most recent operation has stashed the old tokens, sync . the given AST to the most recent stash entry =Process the leaf nodes of a tree to remove all deleted spans CAdd new tokens belonging to an AST fragment after a given SrcSpan, 8 and re-sync the AST fragment to match the new location @Convert a simple (start,end) position to a SrcSpan belonging to  the file in the tree @Convert a simple (start,end) position to a SrcSpan belonging to  the file in the given token BSynchronise a located AST fragment to use a newly created SrcSpan  in the token tree. . TODO: Should this indent the tokens as well? TokenTree to be modified "Preceding location for new tokens New tokens to be added /Declaration the tokens belong to, to be synced (updated TokenTree ,SrcSpan location for X -> (Tree (Entry PosToken), GHC.SrcSpan,t) -- ^ updated TokenTree ,SrcSpan location for & the new tokens in the TokenTree, and  updated AST element The AST (or fragment) 1The SrcSpan created in the Tree (Entry PosToken) Updated AST and tokens     None/fetch the possibly modified tokens. Deprecated %fetch the final tokens in Ppr format  fetch the pristine token stream 0Get the current tokens for a given GHC.SrcSpan. 6Get the current tokens preceding a given GHC.SrcSpan. 1Replace a token occurring in a given GHC.SrcSpan CReplace the tokens for a given GHC.SrcSpan, return new GHC.SrcSpan  delimiting new tokens CReplace the tokens for a given GHC.SrcSpan, return new GHC.SrcSpan B delimiting new tokens, and update the AST fragment to reflect it ?Replace the tokens for a given GHC.SrcSpan, return GHC.SrcSpan  they are placed in *Add tokens after a designated GHC.SrcSpan 'Add tokens after a designated position >Add tokens after a designated GHC.SrcSpan, and update the AST  fragment to reflect it /Remove a GHC.SrcSpan and its associated tokens /Remove a GHC.SrcSpan and its associated tokens (Print the Token Tree for debug purposes -Print detailed Token Tree for debug purposes &Get the Token Tree for debug purposes AIndent an AST fragment and its associated tokens by a set amount % Old element  New element pretty printer !Add trailing newline if required Updates the RefactState !Start and end pos of old element  New element pretty printer !Add trailing newline if required Updates the RefactState %%% None 3Return the binds that are directly enclosed in the  given syntax phrase. ) hsValBinds :: t -> [GHC.LHsBind GHC.Name]  5Replace the directly enclosed bind list by the given 5 bind list. Note: This function does not modify the  token stream. + replaceBinds :: t -> [GHC.LHsBind GHC.Name] -> t  ;Return True if the specified identifier is declared in the  given syntax phrase. ' isDeclaredIn :: GHC.Name -> t -> Bool =Return the type class definitions that are directly enclosed 8 in the given syntax phrase. Note: only makes sense for  GHC.RenamedSource ,               )      NonefCRepresents the operation type we want to select on addItemsToImport' Used for addItemsToImport Used for addHiding "Return True if any of the GHC.Name's appear in the given  syntax element ;Returns True is a syntax phrase, say a, is part of another  syntax phrase, say b. / NOTE: very important: only do a shallow check For declared variables For free variables BProcess the inscope relation returned from the parsing and module E analysis pass, and return a list of four-element tuples. Each tuple , contains an identifier name, the identifier's namespace info, the  identifier'/s defining module name and its qualifier name. DThe same identifier may have multiple entries in the result because B it may have different qualifiers. This makes it easier to decide C whether the identifier can be used unqualifiedly by just checking A whether there is an entry for it with the qualifier field being  Nothing. AReturn True if the identifier is inscope and can be used without  a qualifier. AReturn True if the identifier is inscope and can be used without > a qualifier. The identifier name string may have a qualifier  already = NOTE: may require qualification based on name clash with an  existing identifier. Show a PName in a format like: pn(at row:r, col: c). Default expression. AMake a new GHC.Name, using the Unique Int sequence stored in the  RefactState. @Create a new name base on the old name. Suppose the old name is f, then  the new name would be like f_i where i is an integer. @Return True if the current module is exported either by default 1 or by specifying the module name in the export.  AReturn True if an identifier is exported by the module currently  being refactored. !CReturn True if an identifier is explicitly exported by the module. "ECheck if the proposed new name will conflict with an existing export #ACollect the free and declared variables (in the GHC.Name format) D in a given syntax phrase t. In the result, the first list contains ? the free variables, and the second list contains the declared  variables.  Expects RenamedSource $ The same as % except that the returned % variables are in the String format. &ACollect the free and declared variables (in the GHC.Name format) D in a given syntax phrase t. In the result, the first list contains ? the free variables, and the second list contains the declared  variables. 5 TODO: use GHC.NameSet instead of lists for FreeNames/DeclaredNames A NOTE: The GHC fvs fields only carry non-GHC values, as they are  used in the renaming process '2Given a RenamedSource LPAT, return the equivalent  ParsedSource part. D NOTE: returns pristine ParsedSource, since HaRe does not change it (:Given a RenamedSource Located name, return the equivalent  ParsedSource part. D NOTE: returns pristine ParsedSource, since HaRe does not change it ):Given a RenamedSource Located name, return the equivalent  ParsedSource part. D NOTE: returns pristine ParsedSource, since HaRe does not change it +Experiment with GHC fvs stuff .Same as /* except that the returned identifiers are  in String format. /BGiven syntax phrases e and t, if e occurs in t, then return those B variables which are declared in t and accessible to e, otherwise  return []. 0BGiven syntax phrases e and t, if e occurs in t, then return those B variables which are declared in t and accessible to e, otherwise  return []. 1AReturn True if the identifier is unqualifiedly used in the given  syntax phrase. : usedWithoutQualR :: GHC.Name -> GHC.ParsedSource -> Bool 22 is different from % in ! that: given an syntax phrase t, 2 returns not only E the declared variables that are visible from outside of t, but also B those declared variables that are visible to the main expression  inside t. ) NOTE: Expects to be given RenamedSource 3 The same as 2$ except that the returned variables  are in the String format 4!True if the name is a field name 5!True if the name is a field name 6%True if the name is a class instance 7DCollect the identifiers (in PName format) in a given syntax phrase. .Get all the names in the given syntax element 9=Return True if a string is a lexically valid variable name. :?Return True if a string is a lexically valid constructor name. ;<Return True if a string is a lexically valid operator name. 5Returns True if a string lexically is an identifier. ) *This function should not be exported.* <,Return True if a PName is a toplevel PName. =)Return True if a PName is a local PName. >Return True if the name has a  GHC.SrcSpan, i.e. is declared in  source we care about ?$Return True if a PName is a function/pattern name defined in t. @-Return True if a PName is a qualified PName. N AZ:NOTE: this tests the use instance, the underlying name may be qualified. / e.g. used name is zip, GHC.List.zip F NOTE2: not sure if this gives a meaningful result for a GHC.Name A>Return True if a declaration is a type signature declaration. B7Return True if a declaration is a function definition. D4Returns True if a declaration is a pattern binding. F=Return True if a declaration is a pattern binding which only  defines a variable value. GHReturn True if a declaration is a pattern binding but not a simple one. H*Return True if a declaration is a function/pattern definition. I*Return True if a declaration is a function/pattern definition. KBReturns True is a syntax phrase, say a, is part of another syntax  phrase, say b. & Expects to be at least Parser output L Find those declarations(function/pattern binding) which define ; the specified GHC.Names. incTypeSig indicates whether the 0 corresponding type signature will be included. M Find those declarations(function/pattern binding) which define ; the specified GHC.Names. incTypeSig indicates whether the 0 corresponding type signature will be included. N8Find those type signatures for the specified GHC.Names. O>Find those declarations which define the specified GHC.Names. P?Return True if syntax phrases t1 and t2 refer to the same one. QReturn True if the function/pattern binding defines the  specified identifier. SAReturn True if the declaration defines the type signature of the  specified identifier. TFReturn the list of identifiers (in PName format) defined by a function/pattern binding. V@Find the identifier(in GHC.Name format) whose start position is > (row,col) in the file specified by the fileName, and returns  ' if such an identifier does not exist. WCFind the identifier(in GHC.RdrName format) whose start position is > (row,col) in the file specified by the fileName, and returns  ' if such an identifier does not exist. ,Worker for both locToName and locToRdrName. E NOTE: provides for FunBind MatchGroups where only the first name is  retained in the AST X3Find all Located Names in the given Syntax phrase. Y@Find the identifier with the given name. This looks through the C given syntax phrase for the first GHC.Name which matches. Because > it is Renamed source, the GHC.Name will include its defining 5 location. Returns Nothing if the name is not found. Z|Add identifiers to the export list of a module. If the second argument is like: Just p, then do the adding only if p occurs  in the export list, and the new identifiers are added right after p in the export list. Otherwise the new identifiers are add  to the beginning of the export list. In the case that the export list is emport, then if the third argument is True, then create S an explict export list to contain only the new identifiers, otherwise do nothing. `Remove ImportDecl from the imports list, commonly returned from a RenamedSource type, so it can  be further processed. :rmPreludeImports :: [GHC.Located (GHC.ImportDecl GHC.Name)]* -> [GHC.Located (GHC.ImportDecl GHC.Name)] <Make a new set of tokens, originating at (0,0), for a given % declaration and optional signature. @ NOTE: This function returns tokens originating at (0,0), to be . stitched in at the right place by TokenUtils [AAdding a declaration to the declaration list of the given syntax A phrase. If the second argument is Nothing, then the declaration C will be added to the beginning of the declaration list, but after - the data type declarations is there is any. \ATake a list of strings and return a list with the longest prefix  of spaces removed ]<add items to the hiding list of an import declaration which  imports the specified module. 9Creates a new entity for hiding a name in an ImportDecl. ^kAdd identifiers (given by the third argument) to the explicit entity list in the declaration importing the w specified module name. This function does nothing if the import declaration does not have an explicit entity list. kAdd identifiers (given by the third argument) to the explicit entity list in the declaration importing the b specified module name. If the ImportType argument is Hide, then the items will be added to the hiding l list. If it is Import, they will be added to the explicit import entries. This function does nothing if Z the import declaration does not have an explicit entity list and ImportType is Import. AAdd tokens corresponding to the new parameters to the end of the  syntax element provided aDuplicate a function/-pattern binding declaration under a new name > right after the original one. Also updates the token stream. b=Remove the declaration (and the type signature is the second ? parameter is True) that defines the given identifier from the  declaration list. c Remove multiple type signatures d;Remove the type signature that defines the given identifier's ! type from the declaration list. eLRemove the qualifier from the given identifiers in the given syntax phrase. fIReplace all occurences of a top level GHC.Name with a qualified version. g>Rename each occurrences of the identifier in the given syntax ? phrase with the new name. If the Bool parameter is True, then E modify both the AST and the token stream, otherwise only modify the  AST. E TODO: the syntax phrase is required to be GHC.Located, not sure how = to specify this without breaking the everywhereMStaged call >Rename each occurrences of the identifier in the given syntax ? phrase with the new name. If the Bool parameter is True, then E modify both the AST and the token stream, otherwise only modify the  AST. E TODO: the syntax phrase is required to be GHC.Located, not sure how = to specify this without breaking the everywhereMStaged call hQCheck whether the specified identifier is declared in the given syntax phrase t, [ if so, rename the identifier by creating a new name automatically. If the Bool parameter R is True, the token stream will be modified, otherwise only the AST is modified. i<Show a list of entities, the parameter f is a function that $ specifies how to format an entity. kReturn the identifier's defining location.  defineLoc::PNT->SrcLoc lReturn the identifier's source location.  useLoc::PNT->SrcLoc m6Return True if the identifier is used in the RHS if a  function/pattern binding. n5Find all occurrences with location of the given name oAReturn True if the identifier occurs in the given syntax phrase. pAReturn True if the identifier occurs in the given syntax phrase. qMReturn True if any of the specified PNames ocuur in the given syntax phrase. rReturn the type checked  corresponding to the given   t>Given the syntax phrase, find the largest-leftmost expression E contained in the region specified by the start and end position, if  found. wBIf an expression consists of only one identifier then return this F identifier in the GHC.Name format, otherwise return the default Name y>If a pattern consists of only one identifier then return this & identifier, otherwise return Nothing z Compose a pattern from a pName. }/Get the signature and tokens for a declaration ~BNormalise a set of tokens to start at the offset of the first one Remove at most offset* whitespaces from each line in the tokens   Get signature for a declaration     The inscope relation .  The result The identifier name. The inscope relation  The result. The identifier name. ,Existing name, to be excluded from test, if  known  The result. The identifier name.  The result.  The old name 0The set of names which the new name cannot take The posfix value  The result The module name The AST of the module  The result  !The identifier The AST of the module  The result "The original name  The new name The identity of the module The AST of the module  The result #$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLThe specified identifiers. A collection of declarations. *True means to include the type signature. 7True means to look at the local declarations as well.  The result. MThe specified identifiers. A collection of declarations.  The result. NThe specified identifiers. A collection of declarations.  The result. OThe specified identifiers. A collection of declarations.  The result. PQRSTUVThe row and column number The syntax phrase  The result WThe row and column number The syntax phrase  The result The row and column number The syntax phrase  The result XThe syntax phrase  The result YThe name to find The syntax phrase  The result Z qualifier alias [The AST to be updated &If this is Just, then the declaration  will be added right after this  identifier's definition. 6The declaration with optional signatures to be added, 4 in both AST and Token stream format (optional). If 2 signature and tokens provided, the tokens should  include the signature too  True means the declaration is a  toplevel declaration. \]The imported module name The current module The items to be added 'The result (with token stream updated) ^The imported module name The current module The items to be added 8 ->Maybe GHC.Name -- ^ The condition identifier. 'The result (with token stream updated) The imported module name The current module The items to be added 8 ->Maybe GHC.Name -- ^ The condition identifier. IWhether to hide the names or import them. Uses special data for clarity. 'The result (with token stream updated) _4A declaration list where the function is defined and/ or used. The function name. The parameters to be added.  Modify the token stream or not.  The result. `aThe declaration list Any signatures are in here 4The identifier whose definition is to be duplicated "The new name (possibly qualified)  The result b2The identifier whose definition is to be removed. )True means including the type signature. .The AST fragment containting the declarations The result and the removed  declaration, with SrcSpans ! adjusted to reflect the stashed ! tokens and the possibly removed  siganture c9The identifiers whose type signatures are to be removed. The declarations ,The result and removed signatures, if there  were any d6The identifier whose type signature is to be removed. The declarations +The result and removed signature, if there  was one eThe identifiers. The syntax phrase.  The result. fgThe identifier to be renamed. +The new name, including possible qualifier /True means modifying the token stream as well. &True means use the qualified form for  the new name. The syntax phrase The identifier to be renamed. +The new name, including possible qualifier /True means modifying the token stream as well. &True means use the qualified form for  the new name. The syntax phrase h1True means modfiying the token stream as well. The identifier. The syntax phrase.  The result. ijklmnopqrstThe start position. The end position. The syntax phrase.  The result. uvwxyz{|}~  !"#p !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~p !4567J#$%&*+,-/.2309:;<=>@?ABCDEFGHI1mopnqKrsPQRSUj8kltVWY[^]_`ZabdcefghiuvwxyzTLMNOX"|}{~')(\     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~  !"#None?Update the occurrence of one syntax phrase in a given scope by ( another syntax phrase of the same type AThe result of a refactoring is the file, a flag as to whether it = was modified, the updated token stream, and the updated AST 1 type ApplyRefacResult = ((FilePath, Bool), ([Ppr] ,[PosToken], GHC.RenamedSource)) From file name to module name. @Extract the module name from the parsed source, if there is one BOnce the module graph has been loaded, load the given module into  the RefactGhc monad C TODO: relax the equality test, if the file is loaded via cabal it " may have a full filesystem path. AIn the existing GHC session, put the requested TypeCheckedModule ? into the RefactGhc Monad, after ensuring that its originating $ target is the currently loaded one AIn the existing GHC session, put the requested TypeCheckedModule  into the RefactGhc monad .Parse a single source file into a GHC session @Manage a whole refactor session. Initialise the monad, load the : whole project if required, and then apply the individual 2 refactorings, and write out the resulting files. ?It is intended that this forms the umbrella function, in which  applyRefac is called BApply a refactoring (or part of a refactoring) to a single module =Returns True if any of the results has its modified flag set $*Write refactored program source to files. @Return the client modules and file names. The client modules of ? module, say m, are those modules which directly or indirectly  import module m. ?Return the server module and file names. The server modules of C module, say m, are those modules which are directly or indirectly E imported by module m. This can only be called in a live GHC session G TODO: make sure this works with multiple targets. Is that needed? No? %!The syntax phrase to be updated. The new syntax phrase. /The contex where the old syntax phrase occurs.  The result. &'(Identifies the surrounding  project The computation doing the  refactoring. Normally created  via  The refactoring !where to get the module and toks )$*+,-./%&'()$*+,-./None]  !"#$%&'()*+,-./012345678FGNOPQRST_`ajklmnopqrstuvwxyz{|}~    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~]StwvujklmnopqrsT_`aORQPN~xyz{|}*('&72 $)6%.13/04 8 5,+ GF#"!  !4567   J#$%&*+,-/.2309:;<=>@?ABCDEFGHI1mopnqKPrsQRSUj8kltVWY[^]_`ZabdcefghiuvwxyzTLMNOX"|}{~')(\-None.Convert an if expression to a case expression 01230123None>This refactoring duplicates a definition (function binding or G simple pattern binding) at the same level with a new name provided by 3 the user. The new name should not cause name clash/ capture. 45Find the the new definition name in GHC.Name format. 59Do refactoring in the client module. That is to hide the E identifer in the import declaration if it will cause any problem in  the client module. 6:get the module name or alias name by which the duplicated , definition will be imported automatically. 78945:678945:6None#Lift a definition to the top level 4Move a definition one level up from where it is now !Move a definition one level down ;Get the subset of pns) that need to be renamed before lifting. <CDo refactoring in the client module. that is to hide the identifer ? in the import declaration if it will cause any problem in the  client module. =?Test whether an identifier defined in the modules specified by  names% will be exported by current module. >Aget the module name or alias name by which the lifted identifier ! will be imported automatically. & TODO: maybe move this into TypeUtils O willBeUnQualImportedBy::HsName.ModuleName->HsModuleP->Maybe [HsName.ModuleName] ?get the subset of pns', which need to be hided in the import  declaration in module @ B Note: these are newly exported from the module, so we cannot use ' the GHC name resolution i nthis case. A*Fail any signature having a forall in it. 3 TODO: this is unnecesarily restrictive, but needs 0 a) proper reversing of GHC.Type to GHC.LhsType ; b) some serious reverse type inference to ensure that the A constraints are modified properly to merge the old signature  part and the new. B.Do refactoring in the client module, that is: = a) Check whether the identifier is used in the module body > b) If the identifier is not used but is hided by the import 2 declaration, then remove it from the hiding. CDemote the declaration of pn in the context of t. D/substitute an old expression by new expression E%return True if pn is a local function/ pattern name FCDivide a declaration list into three parts (before, parent, after)  according to the PNT, where parent is the first decl containing  the PNT, before are those decls before parent and after are  those decls after parent. GHIJKThe syntax element to update &If specified, add defn after this one "The first one is the decl to move -The signatures to remove. May be multiple if # decl being moved has a patbind.  True if moving to the top level 1The updated syntax element (and tokens in monad) L;M<=>?NOPname of decl being lifted Declared names in parent parent decls being lifted "lifted decls signature if present QRASTUBVWCX(The (list?) function name being demoted 2The RHS of the place to receive the demoted decls ;Binds of original top level entiity, including src and dst The decls being demoted !Signatures being demoted, if any Tokens if provided DEF GHIJKL;M<=>?NOPQRASTUBVWCXDEFNoneRename the given identifier. YBody of the refactoring ZAActually do the renaming, split into the various things that can 2 be renamed. Returns True if the name is exported YZ[\]^YZ[\]^None_`a_`aNone*jklmnopqrstuvwxjklmnopqrstwvux*b !"#$%&'()*+,-./.0.1.2.3.4.5.6.7.8.9.:.;.<.=>?>@>A>B>C>D>E>F>G>H>I>J>K>L>M>N>O>P>Q>RSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~                                                                               ! " #$%&$'' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A BCDEFGHIJKLMNOPQRSTUOVWXYZ[U\]^_`abcdefghijklmnopqrstuvOwxyz{O|}~ HaRe-0.7.2.8(Language.Haskell.Refact.Utils.TokenUtilsLanguage.Haskell.Refact.API&Language.Haskell.Refact.Utils.LocUtils Paths_HaRe,Language.Haskell.Refact.Utils.GhcModuleGraph%Language.Haskell.Refact.Utils.TypeSyn/Language.Haskell.Refact.Utils.GhcBugWorkArounds#Language.Haskell.Refact.Utils.Monad0Language.Haskell.Refact.Utils.GhcVersionSpecific&Language.Haskell.Refact.Utils.GhcUtils,Language.Haskell.Refact.Utils.MonadFunctions#Language.Haskell.Refact.Utils.Binds'Language.Haskell.Refact.Utils.TypeUtils#Language.Haskell.Refact.Utils.Utils(Language.Haskell.Refact.Refactoring.Case*Language.Haskell.Refact.Refactoring.DupDef+Language.Haskell.Refact.Refactoring.MoveDef,Language.Haskell.Refact.Refactoring.Renaming,Language.Haskell.Refact.Refactoring.SwapArgsLanguage.Haskell.Refact.HaRehaskell-token-utils-0.0.0.6&Language.Haskell.TokenUtils.GHC.Layout showSrcSpanF showSrcSpanss2gsgs2ssf2gsgs2f nullSrcSpanmkToken&Language.Haskell.TokenUtils.TokenUtils basicTokenisetokenise newLnToken splitOnNewLngetIndentOffset matchTokenPosreplaceTokNoReAlign reIndentToks PlaceAdjacent PlaceAbsolute PlaceAbsCol PlaceOffset PlaceIndent Positioning!Language.Haskell.TokenUtils.UtilsincreaseSrcSpanaddOffsetToToks tokenPosEndtokenPos tokenColEndtokenColtokenRowgroupTokensByLinenonCommentSpanstartEndLocIncComments' gfromJustgtailglastghead splitToks!Language.Haskell.TokenUtils.Types isWhereOrLetisIgnoredNonComment isIgnoredisWhiteSpaceOrIgnored notWhiteSpaceSimpPosisMarked markTokenlexStringToTokensisWhereisThenisOfisLetisInisElseisDo mkZeroTokenisEmpty isCommenttokenLenversion getBinDir getLibDir getDataDir getLibexecDir getSysconfDirgetDataFileNamegetModulesAsGraphsummaryNodeSummaryPNamePNHsNameExportPosTokenInScopesHsDeclsPHsDeclPHsPatPHsExpPbypassGHCBug7351getRichTokenStreamWA RefactGhc StateStorage StorageSig StorageBind StorageNone ParseResult TargetModule RefactStateRefSt rsSettings rsUniqStatersFlags rsStoragersGraph rsModuleGraphrsCurrentTargetrsModule RefactFlagsRefFlagsrsDone RefactModuleRefModrsTypecheckedModrsOrigTokenStream rsTokenCachersStreamModified RefactStashIdStashRefactSettingsRefSet rsetGhcOptsrsetImportPathsrsetExpandSplicersetLineSeparator rsetMainFilersetCheckTokenUtilsInvariantrsetVerboseLevelrsetEnabledTargets VerboseLevelOffNormalDebugdefaultSettings logSettingsinitGhcSessionloadModuleGraphGhcensureTargetLoadedcanonicalizeGraph runRefactGhcgetRefacSettingslogmshowGhc prettyprint prettyprint2ppTypegetDataConstructors setGhcContexteverythingButStagedsomethingStagedsomewhereMStagedsomewhereMStagedBueverywhereMStagedeverywhereMStaged'everywhereStagedeverywhereStaged'checkItemRenamereverythingStagedonelayerStaged listifyStaged full_tdTUGhc stop_tdTUGhc stop_tdTPGhc allTUGhc' once_tdTPGhc once_buTPGhconeTPGhcallTUGhccheckItemStage'checkItemRenamer'zeverywhereStaged zopenStagedzsomewhereStagedtransZtransZMcheckZipperStagedupUntil findAbove zopenStaged'ztransformStagedM unmodifiedmodifiedsimpPos0isWhitenotWhiteisMultiLineCommentisOpenSquareBracketisCloseSquareBracketisComma isOpenParenisBar endsWithNewLnstartsWithNewLnhasNewLncompressPreNewLnscompressEndNewLnsprettyprintPatList addLocInfolengthOfLastLinegetToks getLineOffset deleteToks doRmWhiteswhiteSpaceTokenssrcLocsgetBiggestStartEndLoc getAllSrcLocsextendBackwardsextendForwardsstartEndLocIncFowComment tokenSrcSpantokenCon getGhcLoc getGhcLocEndgetLocatedStart getLocatedEndgetStartEndLocstartEndLocGhcrealSrcLocFromTokrealSrcLocEndTokfileNameFromTok emptyList nonEmptyListstartEndLocIncComments isWhiteSpace isDoubleColon getSrcSpantoksOnSameLinereSequenceToksrmOffsetFromToksghcSrcSpanToForestSpanputDeclToksInCachesyncAstToLatestCachedeleteGapsToksstripForestLineFromGhcaddDeclToksAfterSrcSpan posToSrcSpanposToSrcSpanTokghcSpanStartEndsyncAST fetchToksfetchLinesFinal fetchOrigToksgetToksForSpangetToksBeforeSpan replaceTokenputToksForSpanputDeclToksForSpan putToksForPosaddToksAfterSpanaddToksAfterPosputDeclToksAfterSpanremoveToksForSpanremoveToksForPos drawTokenTreedrawTokenTreeDetailed getTokenTreeshowLinesDebugsyncDeclToLatestStashindentDeclAndToksgetTypecheckedModulegetRefactStreamModifiedgetRefactInscopesgetRefactRenamedputRefactRenamedgetRefactParsedputParsedModuleclearParsedModulegetRefactFileName getRefactDone setRefactDoneclearRefactDonesetStateStoragegetStateStorageinitRefactModule updateToksupdateToksWithPos HsValBinds hsValBindsreplaceValBinds hsTyDeclsgetValBindSigs emptyValBindshsBinds replaceBinds UsedByRhs usedByRhs findEntity inScopeInfoisInScopeAndUnqualifiedisInScopeAndUnqualifiedGhc inScopeNames showPNwithLoc defaultPN defaultName defaultExp mkRdrName mkNewGhcNamemkNewToplevelName mkNewName modIsExported isExportedisExplicitlyExportedcauseNameClashInExportshsFreeAndDeclaredPNsOldhsFreeAndDeclaredNameStringshsFreeAndDeclaredPNshsFreeAndDeclaredGhcgetParsedForRenamedLPatgetParsedForRenamedLocatedgetParsedForRenamedNamegetDeclaredTypesgetFvs getFreeVarsgetDeclaredVarshsVisibleNames hsVisiblePNs hsVisibleDsusedWithoutQualRhsFDsFromInsidehsFDNamesFromInside isFieldName isClassNameisInstanceNamehsPNs getModuleisVarIdisConId isOperator isTopLevelPN isLocalPNisNonLibraryNameisFunOrPatName isQualifiedPN isTypeSig isFunBindP isFunBindR isPatBindP isPatBindRisSimplePatBindisComplexPatBindisFunOrPatBindPisFunOrPatBindR isDeclaredIn findEntity'definingDeclsNamesdefiningDeclsNames'definingSigsNamesdefiningTyClDeclsNamessameOccurrencedefinesdefinesPdefinesTypeSig definedPNssameBind locToName locToRdrNameallNamesgetName addImportDecladdDeclstripLeadingSpaces addHidingaddItemsToImportaddParamsToDeclsaddActualParamsToRhs duplicateDeclrmDecl rmTypeSigs rmTypeSig rmQualifierqualifyToplevelNamerenamePNautoRenameLocalVar showEntities isMainModule defineLocuseLoc isUsedInRhsfindAllNameOccurencesfindPNTfindPNfindPNs findIdForNamegetTypeForNamelocToExpghcToPNlghcToPN expToName nameToStringpatToPNTpNtoPatgetToksForDeclgetDeclAndToks getSigAndToksremoveToksOffset removeOffsetupdate RefacSourceRSAlreadyLoadedRSModRSFileApplyRefacResultfileNameToModName getModuleName getModuleGhcactivateModulegetModuleDetailsparseSourceFileGhcrunRefacSession applyRefac refactDonefileNameFromModSummaryclientModsAndFilesserverModsAndFilesifToCase duplicateDefliftToTopLevel liftOneLeveldemoterenameswapArgscatchIObindirlibdirdatadir libexecdir sysconfdirNodeMapNodeKey SummaryNodesummaryNodeKeymoduleGraphNodes home_impsms_home_srcimps ms_home_imps$fShowNameSpace$fOutputableConDeclField$fOutputableHsTupArg$fOutputableGRHS$fOutputableGRHSs$fOutputableMatch$fOutputableMatchGroup$fOutputableNameSpace combineTokensstripPreprocessorDirectivesgetPreprocessedSrcgetPreprocessorAsCommentsmergeBytokeniseOriginalSrc sbufToString getSuffixgetOriginalFile parseErrorgetModuleSourceAndFlags getTempDir TargetGraphgetCabalAllTargets loadTargetgetEnabledTargets timeStamp $fShowModule$fShowModSummary$fMonadPlusGhcT$fMonadTransGhcT$fMonadStateRefactStateGhcT$fExceptionMonadStateT$fMonadIOStateT $fMonadIOGhcT$fShowStateStoragecheckItemStagecheckItemStage2checkItemStage1allTPGhclastNonSpaceToken adjustLayoutbaseGHC.Listnull defaultTokenreplaceTabBySpacesgoDeleteGapsToksaddOffsetToSrcSpan unionBinds$fHsValBindsHsIPBinds$fHsValBindsGenLocated$fHsValBinds[]$fHsValBindsGenLocated0$fHsValBinds[]0$fHsValBindsGenLocated1$fHsValBindsGenLocated2$fHsValBinds[]1$fHsValBindsGenLocated3$fHsValBinds[]2$fHsValBinds[]3$fHsValBinds[]4$fHsValBindsName$fHsValBindsGenLocated4$fHsValBinds[]5$fHsValBindsGenLocated5$fHsValBinds[]6$fHsValBindsGenLocated6$fHsValBinds[]7$fHsValBindsGenLocated7$fHsValBinds[]8$fHsValBindsGenLocated8$fHsValBindsBag$fHsValBindsStmtLR$fHsValBindsHsExpr$fHsValBindsHsBindLR$fHsValBindsMatch$fHsValBindsGenLocated9$fHsValBinds[]9$fHsValBindsMatchGroup$fHsValBindsGRHSs$fHsValBindsHsLocalBindsLR$fHsValBindsHsGroup$fHsValBindsHsValBindsLR$fHsValBinds(,,,) ImportTypeImportHide DeclaredNames FreeNameshsNamessisId Data.MaybeNothing locToName'rmPreludeImports makeNewToksmkNewEntaddItemsToImport'addFormalParamsrenamePNworker ghc-7.6.3VarIdNamegetSig FindEntityDNFNemptyFDhsFreeAndDeclaredPNs' getHsTyDefn isEmptyGroup$fUsedByRhsStmtLR$fUsedByRhsHsExpr$fUsedByRhsGenLocated$fUsedByRhsGenLocated0$fUsedByRhsHsBindLR $fUsedByRhs[]$fUsedByRhsMatch$fUsedByRhsHsValBindsLR$fUsedByRhsBag$fUsedByRhs(,,,)$fFindEntityGenLocated$fFindEntityGenLocated0$fFindEntityGenLocated1$fFindEntityGenLocated2$fFindEntityName$fMonoidDeclaredNames$fMonoidFreeNames$fShowDeclaredNames$fShowFreeNameswriteRefactoredFilesUpdategetModuleMaybeidentifyTargetModule findInTarget modifiedFilesmycomp$fShowModuleName$fUpdateGenLocatedt$fUpdateGenLocatedt0$fUpdateGenLocatedt1$fUpdateGenLocatedt2compdoIfToCaseInternalreallyDoIfToCaseifToCaseTransform findNewPNamerefactorInClientModwillBeUnQualImportedBy doDuplicatingreallyDoDuplicatingdoDuplicatingClientpnsNeedRenamingliftingInClientModwillBeExportedByClientModnamesNeedToBeHidedGHC.RealmodisNewSignatureOkdemotingInClientMod doDemoting'replaceExpWithUpdToksisLocalFunOrPatName divideDeclscompLiftToTopLevelcompLiftOneLevel compDemoteliftToTopLevel' moveDecl1askRenamingMsgaddParamsToParent liftOneLevel'liftedToTopLeveladdParamsToParentAndLiftedDecladdParamsToSigsprintSigComponent typeToHsTypetyConAppToHsTypedemote'doDemotingInClientMod doDemoting foldParams doRenamingrenameTopLevelVarNamerenameInClientModcauseAmbiguityInExportsisValidNewNamedoSwap reallyDoSwap