From fad3e6e4efd9fb350c4d2f54eceee8648acbbc8f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 2 Apr 2018 10:59:19 -0400 Subject: [PATCH] Add edges for symbols. Co-Authored-By: Josh Vera --- src/Analysis/Abstract/ImportGraph.hs | 31 +++++++++++++++++++++------- src/Semantic/Util.hs | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Analysis/Abstract/ImportGraph.hs b/src/Analysis/Abstract/ImportGraph.hs index 112d84e6f..ac79b6f7c 100644 --- a/src/Analysis/Abstract/ImportGraph.hs +++ b/src/Analysis/Abstract/ImportGraph.hs @@ -10,10 +10,14 @@ import qualified Algebra.Graph as G import Algebra.Graph.Class import Algebra.Graph.Export.Dot import Control.Abstract.Analysis +import Data.Abstract.Address import Data.Abstract.Evaluatable (LoadError (..)) import Data.Abstract.FreeVariables +import Data.Abstract.Located import Data.Abstract.Module import Data.Abstract.Origin +import qualified Data.Syntax as Syntax +import Data.Term import Prologue hiding (empty) -- | 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 , Member (Reader (SomeOrigin term)) effects - , Member (State ImportGraph) effects - , MonadAnalysis location term value (m 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 - type Effects location term value (ImportGraphing m effects) = State ImportGraph ': Effects location term value (m effects) + => MonadAnalysis (Located location term) term value (ImportGraphing m effects) where + type Effects (Located location term) term value (ImportGraphing m effects) = State ImportGraph ': Effects (Located location term) term value (m effects) - analyzeTerm eval term = resumeException - @(LoadError term value) - (liftAnalyze analyzeTerm eval term) - (\yield (LoadError name) -> insertVertexName name >> yield []) + analyzeTerm eval term@(In _ syntax) = do + case prj syntax of + Just (Syntax.Identifier name) -> do + 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 insertVertexName (moduleName (moduleInfo m)) diff --git a/src/Semantic/Util.hs b/src/Semantic/Util.hs index c3022e230..405da75ac 100644 --- a/src/Semantic/Util.hs +++ b/src/Semantic/Util.hs @@ -45,7 +45,7 @@ import qualified Language.TypeScript.Assignment as TypeScript -- Ruby evaluateRubyFile = evaluateWithPrelude 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 -- Go