1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Add edges for symbols.

Co-Authored-By: Josh Vera <vera@github.com>
This commit is contained in:
Rob Rix 2018-04-02 10:59:19 -04:00
parent 78997cdeb3
commit fad3e6e4ef
2 changed files with 24 additions and 9 deletions

View File

@ -10,10 +10,14 @@ import qualified Algebra.Graph as G
import Algebra.Graph.Class import Algebra.Graph.Class
import Algebra.Graph.Export.Dot import Algebra.Graph.Export.Dot
import Control.Abstract.Analysis import Control.Abstract.Analysis
import Data.Abstract.Address
import Data.Abstract.Evaluatable (LoadError (..)) import Data.Abstract.Evaluatable (LoadError (..))
import Data.Abstract.FreeVariables import Data.Abstract.FreeVariables
import Data.Abstract.Located
import Data.Abstract.Module import Data.Abstract.Module
import Data.Abstract.Origin import Data.Abstract.Origin
import qualified Data.Syntax as Syntax
import Data.Term
import Prologue hiding (empty) import Prologue hiding (empty)
-- | The graph of function definitions to symbols used in a given program. -- | The graph of function definitions to symbols used in a given program.
@ -36,17 +40,28 @@ deriving instance MonadEvaluator location term value (m effects) => MonadEvalu
instance ( Effectful m instance ( Effectful m
, Member (Reader (SomeOrigin term)) effects , Member (Reader (SomeOrigin term)) effects
, Member (State ImportGraph) effects
, MonadAnalysis location term value (m effects)
, Member (Resumable (LoadError term value)) effects , Member (Resumable (LoadError term value)) effects
, Member (State ImportGraph) effects
, Member Syntax.Identifier syntax
, MonadAnalysis (Located location term) term value (m effects)
, term ~ Term (Union syntax) ann
) )
=> MonadAnalysis location term value (ImportGraphing m effects) where => MonadAnalysis (Located location term) term value (ImportGraphing m effects) where
type Effects location term value (ImportGraphing m effects) = State ImportGraph ': Effects location term value (m effects) type Effects (Located location term) term value (ImportGraphing m effects) = State ImportGraph ': Effects (Located location term) term value (m effects)
analyzeTerm eval term = resumeException analyzeTerm eval term@(In _ syntax) = do
@(LoadError term value) case prj syntax of
(liftAnalyze analyzeTerm eval term) Just (Syntax.Identifier name) -> do
(\yield (LoadError name) -> insertVertexName name >> yield []) o <- lookupEnv name -- (\ (Address (Located _ origin)) -> pure origin) name
case o >>= originModule . origin . unAddress of
Just ModuleInfo{..} -> modifyImportGraph (vertex moduleName >< vertex name <>)
Nothing -> pure ()
pure ()
_ -> pure ()
resumeException
@(LoadError term value)
(liftAnalyze analyzeTerm eval term)
(\yield (LoadError name) -> insertVertexName name >> yield [])
analyzeModule recur m = do analyzeModule recur m = do
insertVertexName (moduleName (moduleInfo m)) insertVertexName (moduleName (moduleInfo m))

View File

@ -45,7 +45,7 @@ import qualified Language.TypeScript.Assignment as TypeScript
-- Ruby -- Ruby
evaluateRubyFile = evaluateWithPrelude rubyParser evaluateRubyFile = evaluateWithPrelude rubyParser
evaluateRubyFiles = evaluateFilesWithPrelude rubyParser evaluateRubyFiles = evaluateFilesWithPrelude rubyParser
evaluateRubyImportGraph paths = runAnalysis @(ImportGraphing (Evaluating Precise Ruby.Term (Value Precise))) . evaluateModules <$> parseFiles rubyParser paths evaluateRubyImportGraph paths = runAnalysis @(ImportGraphing (Evaluating (Located Precise Ruby.Term) Ruby.Term (Value (Located Precise Ruby.Term)))) . evaluateModules <$> parseFiles rubyParser paths
evaluateRubyBadVariables paths = runAnalysis @(BadVariables (Evaluating Precise Ruby.Term (Value Precise))) . evaluateModules <$> parseFiles rubyParser paths evaluateRubyBadVariables paths = runAnalysis @(BadVariables (Evaluating Precise Ruby.Term (Value Precise))) . evaluateModules <$> parseFiles rubyParser paths
-- Go -- Go