1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 23:11:50 +03:00

Compute the list of modules in Semantic.Util.

This commit is contained in:
Rob Rix 2018-03-21 20:17:16 -04:00
parent 02dbaf964f
commit 6591e0fdc4
2 changed files with 8 additions and 12 deletions

View File

@ -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.
--

View File

@ -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)