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

Merge pull request #2012 from github/abstract-abstract-semantics

Abstract abstract semantics
This commit is contained in:
Rob Rix 2018-07-06 10:48:00 -04:00 committed by GitHub
commit daab0f421a
11 changed files with 90 additions and 12 deletions

View File

@ -65,8 +65,9 @@ library
, Data.Abstract.Package
, Data.Abstract.Path
, Data.Abstract.Ref
, Data.Abstract.Type
, Data.Abstract.Value
, Data.Abstract.Value.Abstract
, Data.Abstract.Value.Concrete
, Data.Abstract.Value.Type
-- General datatype definitions & generic algorithms
, Data.Algebra
, Data.AST

View File

@ -0,0 +1,77 @@
{-# LANGUAGE GADTs, UndecidableInstances #-}
module Data.Abstract.Value.Abstract where
import Control.Abstract
import Data.Abstract.Environment as Env
import Prologue
data Abstract = Abstract
deriving (Eq, Ord, Show)
instance Ord address => ValueRoots address Abstract where
valueRoots = mempty
instance AbstractHole Abstract where
hole = Abstract
instance AbstractIntro Abstract where
unit = Abstract
integer _ = Abstract
boolean _ = Abstract
string _ = Abstract
float _ = Abstract
symbol _ = Abstract
rational _ = Abstract
hash _ = Abstract
kvPair _ _ = Abstract
null = Abstract
instance ( Member (Allocator address Abstract) effects
, Member (Env address) effects
, Member (Exc (Return address)) effects
)
=> AbstractFunction address Abstract effects where
closure names _ body = do
env <- foldr (\ name rest -> do
addr <- alloc name
assign addr Abstract
Env.insert name addr <$> rest) (pure lowerBound) names
addr <- locally (bindAll env *> catchReturn body)
deref addr
call Abstract params = do
traverse_ (>>= deref) params
box Abstract
instance ( Member (Allocator address Abstract) effects
, Member (Env address) effects
, Member (Exc (Return address)) effects
, Member NonDet effects
)
=> AbstractValue address Abstract effects where
array _ = pure Abstract
tuple _ = pure Abstract
klass _ _ _ = pure Abstract
namespace _ _ = pure Abstract
scopedEnvironment _ = pure lowerBound
asString _ = pure ""
asPair _ = pure (Abstract, Abstract)
index _ _ = box Abstract
ifthenelse _ if' else' = if' <|> else'
liftNumeric _ _ = pure Abstract
liftNumeric2 _ _ _ = pure Abstract
liftBitwise _ _ = pure Abstract
liftBitwise2 _ _ _ = pure Abstract
liftComparison _ _ _ = pure Abstract
loop f = f empty

View File

@ -1,5 +1,5 @@
{-# LANGUAGE GADTs, RankNTypes, TypeOperators, UndecidableInstances #-}
module Data.Abstract.Value where
module Data.Abstract.Value.Concrete where
import Control.Abstract
import Data.Abstract.Environment (Environment, mergeEnvs)

View File

@ -1,5 +1,5 @@
{-# LANGUAGE GADTs, RankNTypes, TypeFamilies, TypeOperators, UndecidableInstances, LambdaCase #-}
module Data.Abstract.Type
module Data.Abstract.Value.Type
( Type (..)
, TypeError (..)
, runTypes

View File

@ -29,7 +29,7 @@ import Data.Abstract.Evaluatable
import Data.Abstract.Module
import qualified Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Package as Package
import Data.Abstract.Value (Value, ValueError (..), runValueErrorWith)
import Data.Abstract.Value.Concrete (Value, ValueError (..), runValueErrorWith)
import Data.Graph
import Data.Project
import Data.Record

View File

@ -10,11 +10,11 @@ import Control.Abstract
import Control.Monad.Effect.Trace (runPrintingTrace)
import Data.Abstract.Address
import Data.Abstract.Evaluatable
import Data.Abstract.Value
import Data.Abstract.Module
import qualified Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Package
import Data.Abstract.Type
import Data.Abstract.Value.Concrete
import Data.Abstract.Value.Type
import Data.Blob
import Data.Functor.Foldable
import Data.Graph (topologicalSort)

View File

@ -3,7 +3,7 @@ module Analysis.Python.Spec (spec) where
import Data.Abstract.Environment as Env
import Data.Abstract.Evaluatable (EvalError(..))
import qualified Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Value
import Data.Abstract.Value.Concrete
import qualified Language.Python.Assignment as Python
import qualified Data.Language as Language

View File

@ -2,9 +2,9 @@ module Analysis.Ruby.Spec (spec) where
import Data.Abstract.Environment as Env
import Data.Abstract.Evaluatable
import Data.Abstract.Value as Value
import qualified Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Number as Number
import Data.Abstract.Value.Concrete as Value
import Data.AST
import Control.Monad.Effect (SomeExc(..))
import Data.List.NonEmpty (NonEmpty(..))

View File

@ -3,9 +3,9 @@ module Analysis.TypeScript.Spec (spec) where
import Control.Arrow ((&&&))
import Data.Abstract.Environment as Env
import Data.Abstract.Evaluatable
import Data.Abstract.Value as Value
import Data.Abstract.Number as Number
import qualified Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Value.Concrete as Value
import qualified Data.Language as Language
import qualified Data.List.NonEmpty as NonEmpty
import Data.Sum

View File

@ -8,7 +8,7 @@ import Control.Abstract
import Data.Abstract.Module
import qualified Data.Abstract.Number as Number
import Data.Abstract.Package
import Data.Abstract.Value as Value
import Data.Abstract.Value.Concrete as Value
import Data.Algebra
import Data.Bifunctor (first)
import Data.Functor.Const

View File

@ -25,7 +25,7 @@ import Data.Abstract.Heap as X
import Data.Abstract.Module as X
import Data.Abstract.ModuleTable as X hiding (lookup)
import Data.Abstract.Name as X
import Data.Abstract.Value (Value(..), ValueError, runValueError)
import Data.Abstract.Value.Concrete (Value(..), ValueError, runValueError)
import Data.Bifunctor (first)
import Data.Blob as X
import Data.ByteString.Builder (toLazyByteString)