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:
commit
daab0f421a
@ -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
|
||||
|
77
src/Data/Abstract/Value/Abstract.hs
Normal file
77
src/Data/Abstract/Value/Abstract.hs
Normal 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
|
@ -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)
|
@ -1,5 +1,5 @@
|
||||
{-# LANGUAGE GADTs, RankNTypes, TypeFamilies, TypeOperators, UndecidableInstances, LambdaCase #-}
|
||||
module Data.Abstract.Type
|
||||
module Data.Abstract.Value.Type
|
||||
( Type (..)
|
||||
, TypeError (..)
|
||||
, runTypes
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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(..))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user