1
1
mirror of https://github.com/github/semantic.git synced 2024-12-15 01:51:39 +03:00

Add AbstractHole instances for Path, Scope, Address

Co-Authored-By: Rick Winfrey <rick.winfrey@gmail.com>
This commit is contained in:
joshvera 2018-11-09 11:37:45 -05:00
parent eebcc9c9ee
commit 244109310a
2 changed files with 22 additions and 5 deletions

View File

@ -24,6 +24,7 @@ module Data.Abstract.ScopeGraph
, scopeOfRef , scopeOfRef
) where ) where
import Control.Abstract.Hole
import Data.Abstract.Name import Data.Abstract.Name
import qualified Data.Map.Strict as Map import qualified Data.Map.Strict as Map
import Data.Span import Data.Span
@ -41,6 +42,15 @@ data Scope scopeAddress = Scope {
, declarations :: Seq (Declaration, (Span, Maybe scopeAddress)) , declarations :: Seq (Declaration, (Span, Maybe scopeAddress))
} deriving (Eq, Show, Ord, Generic, NFData) } deriving (Eq, Show, Ord, Generic, NFData)
instance Lower (Scope scopeAddress) where
lowerBound = Scope mempty mempty mempty
instance AbstractHole (Scope scopeAddress) where
hole = lowerBound
instance AbstractHole address => AbstractHole (Address address) where
hole = Address hole (Position 0)
newtype Position = Position { unPosition :: Int } newtype Position = Position { unPosition :: Int }
deriving (Eq, Show, Ord, Generic, NFData) deriving (Eq, Show, Ord, Generic, NFData)
@ -57,10 +67,14 @@ deriving instance NFData scope => NFData (ScopeGraph scope)
data Path scope where data Path scope where
-- | Construct a direct path to a declaration. -- | Construct a direct path to a declaration.
Hole :: Path scope
DPath :: Declaration -> Position -> Path scope DPath :: Declaration -> Position -> Path scope
-- | Construct an edge from a scope to another declaration path. -- | Construct an edge from a scope to another declaration path.
EPath :: EdgeLabel -> scope -> Path scope -> Path scope EPath :: EdgeLabel -> scope -> Path scope -> Path scope
instance AbstractHole (Path scope) where
hole = Hole
deriving instance Eq scope => Eq (Path scope) deriving instance Eq scope => Eq (Path scope)
deriving instance Show scope => Show (Path scope) deriving instance Show scope => Show (Path scope)
deriving instance Ord scope => Ord (Path scope) deriving instance Ord scope => Ord (Path scope)

View File

@ -422,17 +422,20 @@ resumingHeapError = runHeapErrorWith (\ baseError -> traceError "ScopeError" bas
resumingScopeError :: ( Carrier sig m resumingScopeError :: ( Carrier sig m
, Member Trace sig , Member Trace sig
, AbstractHole (Address address)
, AbstractHole (Scope address)
, AbstractHole (Path address)
, AbstractHole address
, Show address , Show address
, Ord address , Ord address
) )
=> Evaluator term address value (ResumableWithC (BaseError (ScopeError address)) (Eff m)) a => Evaluator term address value (ResumableWithC (BaseError (ScopeError address)) (Eff m)) a
-> Evaluator term address value m a -> Evaluator term address value m a
resumingScopeError = runScopeErrorWith (\ baseError -> traceError "ScopeError" baseError *> case baseErrorException baseError of resumingScopeError = runScopeErrorWith (\ baseError -> traceError "ScopeError" baseError *> case baseErrorException baseError of
ex -> undefined) ScopeError decl span -> pure hole
-- LookupError :: address -> HeapError address address LookupScopeError -> pure hole
-- LookupLinksError :: address -> HeapError address (Map EdgeLabel (Map address address)) LookupPathError decl -> pure hole
-- LookupPathError :: Path address -> HeapError address address CurrentScopeError -> pure hole)
resumingTypeError :: ( Carrier sig m resumingTypeError :: ( Carrier sig m
, Member NonDet sig , Member NonDet sig