mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Compose runAnalysis and project parsing
This commit is contained in:
parent
633d20fa2a
commit
a291a5c3f6
@ -45,48 +45,65 @@ import qualified Language.Ruby.Assignment as Ruby
|
|||||||
import qualified Language.TypeScript.Assignment as TypeScript
|
import qualified Language.TypeScript.Assignment as TypeScript
|
||||||
|
|
||||||
-- Ruby
|
-- Ruby
|
||||||
evalRubyProject = evaluateProjectWithPrelude rubyParser ["rb"]
|
evalRubyProject path = runEvaluating <$> (withPrelude <$> parsePrelude rubyParser <*> (evaluatePackageBody <$> parseProject rubyParser ["rb"] path))
|
||||||
evalRubyFile = evaluateWithPrelude rubyParser
|
evalRubyFile path = runEvaluating <$> (withPrelude <$> parsePrelude rubyParser <*> (evaluateModule <$> parseFile rubyParser Nothing path))
|
||||||
|
|
||||||
evaluateRubyImportGraph paths = runAnalysis @(ImportGraphing (BadVariables (BadValues (Quietly (Evaluating Precise Ruby.Term (Value Precise)))))) . evaluateModules <$> parseFiles rubyParser (dropFileName (head paths)) paths
|
evaluateRubyImportGraph paths = runAnalysis @(ImportGraphing (BadVariables (BadValues (Quietly (Evaluating Precise Ruby.Term (Value Precise)))))) . evaluateModules <$> parseFiles rubyParser (dropFileName (head paths)) paths
|
||||||
evaluateRubyBadVariables paths = runAnalysis @(BadVariables (Evaluating Precise Ruby.Term (Value Precise))) . evaluateModules <$> parseFiles rubyParser (dropFileName (head paths)) paths
|
evaluateRubyBadVariables paths = runAnalysis @(BadVariables (Evaluating Precise Ruby.Term (Value Precise))) . evaluateModules <$> parseFiles rubyParser (dropFileName (head paths)) paths
|
||||||
|
|
||||||
-- Go
|
-- Go
|
||||||
evalGoProject = evaluateProject goParser ["go"]
|
evalGoProject path = runEvaluating . evaluatePackageBody <$> parseProject goParser ["go"] path
|
||||||
evalGoFile = evaluateFile goParser
|
evalGoFile path = runEvaluating . evaluateModule <$> parseFile goParser Nothing path
|
||||||
|
|
||||||
typecheckGoFile path = runAnalysis @(Caching (Evaluating Monovariant Go.Term Type)) . evaluateModule <$> parseFile goParser Nothing path
|
typecheckGoFile path = runAnalysis @(Caching (Evaluating Monovariant Go.Term Type)) . evaluateModule <$> parseFile goParser Nothing path
|
||||||
|
|
||||||
-- Python
|
-- Python
|
||||||
evalPythonProject = evaluateProject pythonParser ["py"]
|
evalPythonProject path = runEvaluating . evaluatePackageBody <$> parseProject pythonParser ["py"] path
|
||||||
evalPythonFile = evaluateWithPrelude pythonParser
|
evalPythonFile path = runEvaluating <$> (withPrelude <$> parsePrelude pythonParser <*> (evaluateModule <$> parseFile pythonParser Nothing path))
|
||||||
|
|
||||||
typecheckPythonFile path = runAnalysis @(Caching (Evaluating Monovariant Python.Term Type)) . evaluateModule <$> parseFile pythonParser Nothing path
|
typecheckPythonFile path = runAnalysis @(Caching (Evaluating Monovariant Python.Term Type)) . evaluateModule <$> parseFile pythonParser Nothing path
|
||||||
tracePythonFile path = runAnalysis @(Tracing [] (Evaluating Precise Python.Term (Value Precise))) . evaluateModule <$> parseFile pythonParser Nothing path
|
tracePythonFile path = runAnalysis @(Tracing [] (Evaluating Precise Python.Term (Value Precise))) . evaluateModule <$> parseFile pythonParser Nothing path
|
||||||
evaluateDeadTracePythonFile path = runAnalysis @(DeadCode (Tracing [] (Evaluating Precise Python.Term (Value Precise)))) . evaluateModule <$> parseFile pythonParser Nothing path
|
evaluateDeadTracePythonFile path = runAnalysis @(DeadCode (Tracing [] (Evaluating Precise Python.Term (Value Precise)))) . evaluateModule <$> parseFile pythonParser Nothing path
|
||||||
|
|
||||||
-- PHP
|
-- PHP
|
||||||
evalPHPProject = evaluateProject phpParser ["php"]
|
evalPHPProject path = runEvaluating . evaluatePackageBody <$> parseProject phpParser ["php"] path
|
||||||
evalPHPFile = evaluateFile phpParser
|
evalPHPFile path = runEvaluating . evaluateModule <$> parseFile phpParser Nothing path
|
||||||
|
|
||||||
-- TypeScript
|
-- TypeScript
|
||||||
evalTypeScriptProject = evaluateProject typescriptParser ["ts", "tsx"]
|
evalTypeScriptProject path = runEvaluating . evaluatePackageBody <$> parseProject typescriptParser ["ts", "tsx"] path
|
||||||
evalTypeScriptFile = evaluateFile typescriptParser
|
|
||||||
|
-- TODO: Remove this by exporting EvaluatingEffects
|
||||||
|
runEvaluating :: forall term effects a. (Effects Precise term (Value Precise) (Evaluating Precise term (Value Precise) effects) ~ effects, Corecursive term, Recursive term, Evaluatable (Base term), FreeVariables term)
|
||||||
|
=> Evaluating Precise term (Value Precise) effects a
|
||||||
|
-> Final effects a
|
||||||
|
runEvaluating = runAnalysis @(Evaluating Precise term (Value Precise))
|
||||||
|
|
||||||
|
parsePrelude :: forall term. TypeLevel.KnownSymbol (PreludePath term) => Parser term -> IO (Module term)
|
||||||
|
parsePrelude parser = do
|
||||||
|
let preludePath = TypeLevel.symbolVal (Proxy :: Proxy (PreludePath term))
|
||||||
|
parseFile parser Nothing preludePath
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
evalTypeScriptFile path = runEvaluating . evaluateModule <$> parseFile typescriptParser Nothing path
|
||||||
typecheckTypeScriptFile path = runAnalysis @(Caching (Evaluating Monovariant TypeScript.Term Type)) . evaluateModule <$> parseFile typescriptParser Nothing path
|
typecheckTypeScriptFile path = runAnalysis @(Caching (Evaluating Monovariant TypeScript.Term Type)) . evaluateModule <$> parseFile typescriptParser Nothing path
|
||||||
|
|
||||||
evaluateProject :: forall term effects
|
parseProject :: Parser term
|
||||||
. ( Corecursive term
|
-> [Prelude.String]
|
||||||
, Evaluatable (Base term)
|
|
||||||
, FreeVariables term
|
|
||||||
, effects ~ Effects Precise term (Value Precise) (Evaluating Precise term (Value Precise) effects)
|
|
||||||
, MonadAddressable Precise (Evaluating Precise term (Value Precise) effects)
|
|
||||||
, Recursive term
|
|
||||||
)
|
|
||||||
=> Parser term
|
|
||||||
-> [FilePath]
|
|
||||||
-> FilePath
|
-> FilePath
|
||||||
-> IO (Final effects (Value Precise))
|
-> IO (PackageBody term)
|
||||||
evaluateProject parser exts entryPoint = do
|
parseProject parser exts entryPoint = do
|
||||||
let rootDir = takeDirectory entryPoint
|
let rootDir = takeDirectory entryPoint
|
||||||
paths <- filter (/= entryPoint) <$> getPaths exts rootDir
|
paths <- getPaths exts rootDir
|
||||||
evaluateFiles parser rootDir (entryPoint : paths)
|
modules <- parseFiles parser rootDir paths
|
||||||
|
pure $ fromModulesWithEntryPoint modules entryPoint
|
||||||
|
|
||||||
|
withPrelude prelude a = do
|
||||||
|
preludeEnv <- evaluateModule prelude *> getEnv
|
||||||
|
withDefaultEnvironment preludeEnv a
|
||||||
|
|
||||||
|
|
||||||
|
getPaths exts = fmap fold . globDir (compile . mappend "**/*." <$> exts)
|
||||||
|
|
||||||
evaluateProjectWithPrelude :: forall term effects
|
evaluateProjectWithPrelude :: forall term effects
|
||||||
. ( Corecursive term
|
. ( Corecursive term
|
||||||
@ -106,22 +123,6 @@ evaluateProjectWithPrelude parser exts entryPoint = do
|
|||||||
paths <- filter (/= entryPoint) <$> getPaths exts rootDir
|
paths <- filter (/= entryPoint) <$> getPaths exts rootDir
|
||||||
evaluateFilesWithPrelude parser rootDir (entryPoint : paths)
|
evaluateFilesWithPrelude parser rootDir (entryPoint : paths)
|
||||||
|
|
||||||
getPaths exts = fmap fold . globDir (compile . mappend "**/*." <$> exts)
|
|
||||||
|
|
||||||
-- Evalute a single file.
|
|
||||||
evaluateFile :: forall term effects
|
|
||||||
. ( Corecursive term
|
|
||||||
, Evaluatable (Base term)
|
|
||||||
, FreeVariables term
|
|
||||||
, effects ~ Effects Precise term (Value Precise) (Evaluating Precise term (Value Precise) effects)
|
|
||||||
, MonadAddressable Precise (Evaluating Precise term (Value Precise) effects)
|
|
||||||
, Recursive term
|
|
||||||
)
|
|
||||||
=> Parser term
|
|
||||||
-> FilePath
|
|
||||||
-> IO (Final effects (Value Precise))
|
|
||||||
evaluateFile parser path = runAnalysis @(Evaluating Precise term (Value Precise)) . evaluateModule <$> parseFile parser Nothing path
|
|
||||||
|
|
||||||
evaluateWith :: forall location value term effects
|
evaluateWith :: forall location value term effects
|
||||||
. ( Corecursive term
|
. ( Corecursive term
|
||||||
, effects ~ Effects location term value (Evaluating location term value effects)
|
, effects ~ Effects location term value (Evaluating location term value effects)
|
||||||
@ -145,6 +146,7 @@ evaluateWith prelude m = runAnalysis @(Evaluating location term value) $ do
|
|||||||
preludeEnv <- evaluateModule prelude *> getEnv
|
preludeEnv <- evaluateModule prelude *> getEnv
|
||||||
withDefaultEnvironment preludeEnv (evaluateModule m)
|
withDefaultEnvironment preludeEnv (evaluateModule m)
|
||||||
|
|
||||||
|
|
||||||
evaluateWithPrelude :: forall term effects
|
evaluateWithPrelude :: forall term effects
|
||||||
. ( Corecursive term
|
. ( Corecursive term
|
||||||
, Evaluatable (Base term)
|
, Evaluatable (Base term)
|
||||||
@ -164,21 +166,6 @@ evaluateWithPrelude parser path = do
|
|||||||
pure $ evaluateWith @Precise prelude m
|
pure $ evaluateWith @Precise prelude m
|
||||||
|
|
||||||
|
|
||||||
-- Evaluate a list of files (head of file list is considered the entry point).
|
|
||||||
evaluateFiles :: forall term effects
|
|
||||||
. ( Corecursive term
|
|
||||||
, Evaluatable (Base term)
|
|
||||||
, FreeVariables term
|
|
||||||
, effects ~ Effects Precise term (Value Precise) (Evaluating Precise term (Value Precise) effects)
|
|
||||||
, MonadAddressable Precise (Evaluating Precise term (Value Precise) effects)
|
|
||||||
, Recursive term
|
|
||||||
)
|
|
||||||
=> Parser term
|
|
||||||
-> FilePath
|
|
||||||
-> [FilePath]
|
|
||||||
-> IO (Final effects (Value Precise))
|
|
||||||
evaluateFiles parser rootDir paths = runAnalysis @(Evaluating Precise term (Value Precise)) . evaluateModules <$> parseFiles parser rootDir paths
|
|
||||||
|
|
||||||
-- | Evaluate terms and an entry point to a value with a given prelude.
|
-- | Evaluate terms and an entry point to a value with a given prelude.
|
||||||
evaluatesWith :: forall location value term effects
|
evaluatesWith :: forall location value term effects
|
||||||
. ( Corecursive term
|
. ( Corecursive term
|
||||||
|
Loading…
Reference in New Issue
Block a user