@@ -8,7 +8,6 @@ module Clang.HighLevel.Fold (
88 -- * Construction
99 , simpleFold
1010 , foldWithHandler
11- , runFold
1211 -- * Fold-specific operations
1312 , foldBreak
1413 , foldBreakWith
@@ -177,23 +176,6 @@ foldWithHandler handler foldNext =
177176 Just e' -> handler curr e'
178177 Nothing -> liftIO $ throwIO e
179178
180- -- | Run 'Fold'
181- --
182- -- If the fold has an associated exception handler, it will get a chance to
183- -- catch any exceptions thrown. See 'foldWithHandler' for detailed discussion.
184- runFold :: MonadUnliftIO m => Fold m a -> CXCursor -> m (Next m a )
185- runFold fold curr = withRunInIO $ \ runInIO -> runFoldUsing runInIO fold curr
186-
187- -- | Internal generalization of 'runFold'
188- runFoldUsing ::
189- ( MonadIO n
190- , Functor m
191- )
192- => RunInIO m -> Fold m a -> CXCursor -> n (Next m a )
193- runFoldUsing runInIO Fold {foldNext, foldHandler} curr =
194- handleUnliftUsing runInIO (fmap Continue . foldHandler curr) $
195- foldNext curr
196-
197179-- | Result of visiting one node
198180--
199181-- This is the equivalent of 'CXChildVisitResult'
@@ -487,25 +469,34 @@ clang_visitChildren root topLevelFold = withRunInIO $ \runInIO -> do
487469 -> IO (SimpleEnum CXChildVisitResult )
488470 visitor runInIO someStack current parent = do
489471 popUntil runInIO someStack parent
490- SomeStack stack <- readIORef someStack
491- let p = topProcessing stack
492- previousException <- partialResultsIsException (partialResults p)
472+ SomeStack (stack :: Stack m x ) <- readIORef someStack
473+
474+ let foldHandler :: CXCursor -> SomeException -> m (Maybe x )
475+ foldNext :: CXCursor -> m (Next m x )
476+ partialResults :: PartialResults x
477+ Processing {
478+ currentFold = Fold {foldHandler, foldNext}
479+ , partialResults
480+ } = topProcessing stack
493481
482+ previousException <- partialResultsIsException partialResults
494483 if previousException then
495484 return $ simpleEnum CXChildVisit_Continue
496485 else do
497- next <- Base. try $ runFoldUsing runInIO (currentFold p) current
486+ next <- Base. try $
487+ handleUnliftUsing runInIO (fmap Continue . foldHandler current) $
488+ foldNext current
498489 case next of
499490 Right (Break ma) -> do
500- forM_ ma $ addPartialResult ( partialResults p)
491+ forM_ ma $ addPartialResult partialResults
501492 return $ simpleEnum CXChildVisit_Break
502493 Right (Continue ma) -> do
503- forM_ ma $ addPartialResult ( partialResults p)
494+ forM_ ma $ addPartialResult partialResults
504495 return $ simpleEnum CXChildVisit_Continue
505496 Right (Recurse fold summarize) -> do
506497 stack' <- push current fold summarize stack
507498 writeIORef someStack $ SomeStack stack'
508499 return $ simpleEnum CXChildVisit_Recurse
509500 Left ex -> do
510- recordException ( partialResults p) ex
501+ recordException partialResults ex
511502 return $ simpleEnum CXChildVisit_Continue
0 commit comments