From 6591e0fdc4c0a538706a1f1a442ae2ac4054d603 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 21 Mar 2018 20:17:16 -0400 Subject: [PATCH] Compute the list of modules in Semantic.Util. --- src/Control/Abstract/Analysis.hs | 11 ----------- src/Semantic/Util.hs | 9 ++++++++- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Control/Abstract/Analysis.hs b/src/Control/Abstract/Analysis.hs index a8846cba8..b381b602f 100644 --- a/src/Control/Abstract/Analysis.hs +++ b/src/Control/Abstract/Analysis.hs @@ -4,7 +4,6 @@ module Control.Abstract.Analysis ( MonadAnalysis(..) , evaluateTerm , withModules -, withModulesForBlobs , require , load , liftAnalyze @@ -29,11 +28,9 @@ import qualified Data.Abstract.Exports as Export import Data.Abstract.Module import Data.Abstract.ModuleTable as ModuleTable import Data.Abstract.Value -import Data.Blob import Data.Coerce import Prelude hiding (fail) import Prologue -import System.FilePath.Posix -- | A 'Monad' in which one can evaluate some specific term type to some specific value type. -- @@ -64,14 +61,6 @@ evaluateTerm = foldSubterms analyzeTerm withModules :: MonadAnalysis term value m => [Module term] -> m a -> m a withModules = localModuleTable . const . ModuleTable.fromList -modulesForBlobs :: Blob -> [(Blob, term)] -> [Module term] -modulesForBlobs blob = map (uncurry (moduleForBlob (Just rootDir))) - where rootDir = dropFileName (blobPath blob) - --- | 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 = withModules . modulesForBlobs blob - -- | Require/import another term/file and return an Effect. -- diff --git a/src/Semantic/Util.hs b/src/Semantic/Util.hs index c5056af64..7cead35a1 100644 --- a/src/Semantic/Util.hs +++ b/src/Semantic/Util.hs @@ -12,6 +12,7 @@ import Control.Abstract.Analysis import Control.Monad.IO.Class import Data.Abstract.Evaluatable import Data.Abstract.Address +import Data.Abstract.Module import Data.Abstract.Type import Data.Abstract.Value import Data.Blob @@ -27,6 +28,7 @@ import Prologue import Semantic import Semantic.IO as IO import Semantic.Task +import System.FilePath.Posix import qualified Language.Go.Assignment as Go import qualified Language.Python.Assignment as Python @@ -81,7 +83,12 @@ evaluateFiles :: forall term effects -> IO (Final effects Value) evaluateFiles parser paths = do entry:xs <- traverse (parseFile parser) paths - pure . runAnalysis @(Evaluating term Value) . withModulesForBlobs (fst entry) xs $ evaluateModule (snd entry) + let rootDir = dropFileName (blobPath (fst entry)) + pure . runAnalysis @(Evaluating term Value) . withModules (modulesForBlobs (Just rootDir) xs) $ evaluateModule (snd entry) + +modulesForBlobs :: Maybe FilePath -> [(Blob, term)] -> [Module term] +modulesForBlobs = map . uncurry . moduleForBlob + -- Read and parse a file. parseFile :: Parser term -> FilePath -> IO (Blob, term)