1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

Move Hole into its own module.

This commit is contained in:
Rob Rix 2018-08-13 09:37:39 -04:00
parent 16964350b0
commit 8cd4d8808f
4 changed files with 60 additions and 60 deletions

View File

@ -18,6 +18,7 @@ module Analysis.Abstract.Graph
import Algebra.Graph.Export.Dot hiding (vertexName)
import Control.Abstract hiding (Function(..))
import Data.Abstract.Address.Hole
import Data.Abstract.Address.Located
import Data.Abstract.BaseError
import Data.Abstract.Ref

View File

@ -1,65 +1,6 @@
{-# LANGUAGE GADTs, RankNTypes, TypeOperators #-}
module Control.Abstract.Hole
( AbstractHole (..)
, Hole (..)
, toMaybe
) where
import Control.Abstract.Addressable
import Control.Abstract.Evaluator
import Control.Abstract.Heap
import Prologue
class AbstractHole a where
hole :: a
data Hole context a = Partial context | Total a
deriving (Foldable, Functor, Eq, Ord, Show, Traversable)
instance Lower context => AbstractHole (Hole context a) where
hole = Partial lowerBound
toMaybe :: Hole context a -> Maybe a
toMaybe (Partial _) = Nothing
toMaybe (Total a) = Just a
instance (Allocatable address effects, Ord context, Show context) => Allocatable (Hole context address) effects where
allocCell name = relocate (Total <$> allocCell name)
instance (Derefable address effects, Ord context, Show context) => Derefable (Hole context address) effects where
derefCell (Total loc) = relocate . derefCell loc
derefCell (Partial _) = const (pure Nothing)
assignCell (Total loc) value = relocate . assignCell loc value
assignCell (Partial _) _ = pure
relocate :: Evaluator address1 value effects a -> Evaluator address2 value effects a
relocate = raiseEff . lowerEff
runAllocator :: PureEffects effects
=> (forall x. Allocator address (Eff (Allocator address ': effects)) x -> Evaluator address value effects x)
-> Evaluator (Hole context address) value (Allocator (Hole context address) ': effects) a
-> Evaluator (Hole context address) value effects a
runAllocator handler = interpret (handleAllocator handler)
handleAllocator :: (forall x. Allocator address (Eff (Allocator address ': effects)) x -> Evaluator address value effects x)
-> Allocator (Hole context address) (Eff (Allocator (Hole context address) ': effects)) a
-> Evaluator (Hole context address) value effects a
handleAllocator handler (Alloc name) = relocate (Total <$> handler (Alloc name))
runDeref :: PureEffects effects
=> (forall x. Deref address value (Eff (Deref address value ': effects)) x -> Evaluator address value effects x)
-> Evaluator (Hole context address) value (Deref (Hole context address) value ': effects) a
-> Evaluator (Hole context address) value effects a
runDeref handler = interpret (handleDeref handler)
handleDeref :: (forall x. Deref address value (Eff (Deref address value ': effects)) x -> Evaluator address value effects x)
-> Deref (Hole context address) value (Eff (Deref (Hole context address) value ': effects)) a
-> Evaluator (Hole context address) value effects a
handleDeref handler (DerefCell (Total address) cell) = relocate (handler (DerefCell address cell))
handleDeref _ (DerefCell (Partial _) _) = pure Nothing
handleDeref handler (AssignCell (Total address) value cell) = relocate (handler (AssignCell address value cell))
handleDeref _ (AssignCell (Partial _) _ cell) = pure cell

View File

@ -1 +1,58 @@
module Data.Abstract.Address.Hole where
{-# LANGUAGE GADTs, RankNTypes, TypeOperators #-}
module Data.Abstract.Address.Hole
( Hole(..)
, toMaybe
) where
import Control.Abstract
import Prologue
data Hole context a = Partial context | Total a
deriving (Foldable, Functor, Eq, Ord, Show, Traversable)
instance Lower context => AbstractHole (Hole context a) where
hole = Partial lowerBound
toMaybe :: Hole context a -> Maybe a
toMaybe (Partial _) = Nothing
toMaybe (Total a) = Just a
instance (Allocatable address effects, Ord context, Show context) => Allocatable (Hole context address) effects where
allocCell name = relocate (Total <$> allocCell name)
instance (Derefable address effects, Ord context, Show context) => Derefable (Hole context address) effects where
derefCell (Total loc) = relocate . derefCell loc
derefCell (Partial _) = const (pure Nothing)
assignCell (Total loc) value = relocate . assignCell loc value
assignCell (Partial _) _ = pure
relocate :: Evaluator address1 value effects a -> Evaluator address2 value effects a
relocate = raiseEff . lowerEff
runAllocator :: PureEffects effects
=> (forall x. Allocator address (Eff (Allocator address ': effects)) x -> Evaluator address value effects x)
-> Evaluator (Hole context address) value (Allocator (Hole context address) ': effects) a
-> Evaluator (Hole context address) value effects a
runAllocator handler = interpret (handleAllocator handler)
handleAllocator :: (forall x. Allocator address (Eff (Allocator address ': effects)) x -> Evaluator address value effects x)
-> Allocator (Hole context address) (Eff (Allocator (Hole context address) ': effects)) a
-> Evaluator (Hole context address) value effects a
handleAllocator handler (Alloc name) = relocate (Total <$> handler (Alloc name))
runDeref :: PureEffects effects
=> (forall x. Deref address value (Eff (Deref address value ': effects)) x -> Evaluator address value effects x)
-> Evaluator (Hole context address) value (Deref (Hole context address) value ': effects) a
-> Evaluator (Hole context address) value effects a
runDeref handler = interpret (handleDeref handler)
handleDeref :: (forall x. Deref address value (Eff (Deref address value ': effects)) x -> Evaluator address value effects x)
-> Deref (Hole context address) value (Eff (Deref (Hole context address) value ': effects)) a
-> Evaluator (Hole context address) value effects a
handleDeref handler (DerefCell (Total address) cell) = relocate (handler (DerefCell address cell))
handleDeref _ (DerefCell (Partial _) _) = pure Nothing
handleDeref handler (AssignCell (Total address) value cell) = relocate (handler (AssignCell address value cell))
handleDeref _ (AssignCell (Partial _) _ cell) = pure cell

View File

@ -29,6 +29,7 @@ import Analysis.Abstract.Caching
import Analysis.Abstract.Collecting
import Analysis.Abstract.Graph as Graph
import Control.Abstract
import Data.Abstract.Address.Hole
import Data.Abstract.Address.Located
import Data.Abstract.Address.Monovariant
import Data.Abstract.Address.Precise