From 30a85b576de26d38c03e7058a3a8438085d877b2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 May 2018 09:55:11 -0400 Subject: [PATCH] Define a helper to dereference qualified names in values. --- test/SpecHelpers.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/SpecHelpers.hs b/test/SpecHelpers.hs index 7d3da3075..86eacb315 100644 --- a/test/SpecHelpers.hs +++ b/test/SpecHelpers.hs @@ -6,6 +6,7 @@ module SpecHelpers , testEvaluating , ns , addr +, derefQName , verbatim , Verbatim(..) ) where @@ -15,17 +16,20 @@ import Analysis.Abstract.Evaluating as X (EvaluatingState(..)) import Control.Abstract.Addressable import Control.Abstract.Value import Control.Effect as X (runIgnoringTraces) +import Control.Monad ((>=>)) import Data.Abstract.Address as X +import Data.Abstract.Environment as Env import Data.Abstract.Evaluatable import Data.Abstract.FreeVariables as X hiding (dropExtension) import Data.Abstract.Heap as X import Data.Abstract.ModuleTable as X hiding (lookup) -import Data.Abstract.Value (Namespace(..), Value, ValueError, injValue, runValueError) +import Data.Abstract.Value (Namespace(..), Value, ValueError, injValue, prjValue, runValueError) import Data.Bifunctor (first) import Data.Blob as X import Data.File as X import Data.Functor.Listable as X import Data.Language as X +import Data.List.NonEmpty as X (NonEmpty(..)) import Data.Output as X import Data.Range as X import Data.Record as X @@ -85,6 +89,12 @@ testEvaluating ns n = Just . Latest . Just . injValue . Namespace n addr = Address . Precise +derefQName :: Heap Precise (Value Precise) -> NonEmpty Name -> Environment Precise (Value Precise) -> Maybe (Value Precise) +derefQName heap = go + where go (n1 :| ns) env = Env.lookup n1 env >>= flip heapLookup heap >>= unLatest >>= case ns of + [] -> Just + (n2 : ns) -> fmap namespaceScope . prjValue @(Namespace Precise) >=> go (n2 :| ns) + newtype Verbatim = Verbatim ByteString deriving (Eq)