From b08969b44c5897b1606099b90cf81a9296b6128a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 21 Mar 2018 20:01:13 -0400 Subject: [PATCH] Define a withModules function running an action with a module table constructed from a list of modules. --- src/Control/Abstract/Analysis.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Control/Abstract/Analysis.hs b/src/Control/Abstract/Analysis.hs index 2550c09e1..c5f2cc422 100644 --- a/src/Control/Abstract/Analysis.hs +++ b/src/Control/Abstract/Analysis.hs @@ -3,6 +3,7 @@ module Control.Abstract.Analysis ( MonadAnalysis(..) , evaluateTerm +, withModules , withModulesForBlobs , require , load @@ -60,6 +61,10 @@ evaluateTerm :: MonadAnalysis term value m => term -> m value evaluateTerm = foldSubterms analyzeTerm +withModules :: MonadAnalysis term value m => [Module term] -> m a -> m a +withModules modules = localModuleTable (const moduleTable) + where moduleTable = ModuleTable (Map.fromListWith (<>) (map ((,) . moduleName <*> pure) modules)) + -- | Run an action with the passed ('Blob', @term@) pairs available for imports. withModulesForBlobs :: MonadAnalysis term value m => Blob -> [(Blob, term)] -> m a -> m a withModulesForBlobs blob pairs = localModuleTable (const moduleTable)