1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

🔥 the Bad* modules.

This commit is contained in:
Rob Rix 2018-05-06 17:16:10 -04:00
parent 1af56342bf
commit 5f0d80a6b1
6 changed files with 1 additions and 98 deletions

View File

@ -15,12 +15,7 @@ library
hs-source-dirs: src
exposed-modules:
-- Analyses & term annotations
Analysis.Abstract.BadAddresses
, Analysis.Abstract.BadSyntax
, Analysis.Abstract.BadModuleResolutions
, Analysis.Abstract.BadVariables
, Analysis.Abstract.BadValues
, Analysis.Abstract.Caching
Analysis.Abstract.Caching
, Analysis.Abstract.Collecting
, Analysis.Abstract.Dead
, Analysis.Abstract.Evaluating

View File

@ -1,16 +0,0 @@
{-# LANGUAGE GADTs, TypeOperators #-}
module Analysis.Abstract.BadAddresses
( resumingBadAddresses
) where
import Control.Abstract.Addressable
import Control.Abstract.Evaluator
import Control.Abstract.Value
import Data.Abstract.Address
import Data.Semilattice.Lower
import Prologue
resumingBadAddresses :: (AbstractHole value, Lower (Cell location value), Show location) => Evaluator location term value (Resumable (AddressError location value) ': effects) a -> Evaluator location term value effects a
resumingBadAddresses = runAddressErrorWith (\ err -> traceM ("AddressError:" <> show err) *> case err of
UnallocatedAddress _ -> pure lowerBound
UninitializedAddress _ -> pure hole)

View File

@ -1,13 +0,0 @@
{-# LANGUAGE GADTs, TypeOperators #-}
module Analysis.Abstract.BadModuleResolutions
( resumingBadModuleResolutions
) where
import Control.Abstract.Evaluator
import Data.Abstract.Evaluatable
import Prologue
resumingBadModuleResolutions :: (Applicative (m effects), Effectful m) => m (Resumable ResolutionError ': effects) a -> m effects a
resumingBadModuleResolutions = runResolutionErrorWith (\ err -> traceM ("ResolutionError:" <> show err) *> case err of
NotFoundError nameToResolve _ _ -> pure nameToResolve
GoImportError pathToResolve -> pure [pathToResolve])

View File

@ -1,16 +0,0 @@
{-# LANGUAGE GADTs, TypeOperators #-}
module Analysis.Abstract.BadSyntax
( resumingBadSyntax
) where
import Control.Abstract.Evaluator
import Data.Abstract.Evaluatable
import Prologue
-- | An analysis which resumes 'Unspecialized' exceptions instead of failing.
--
-- Use it by composing it onto an analysis:
--
-- > resumingBadSyntax . …
resumingBadSyntax :: AbstractHole value => Evaluator location term value (Resumable (Unspecialized value) ': effects) a -> Evaluator location term value effects a
resumingBadSyntax = runUnspecializedWith (\ err@(Unspecialized _) -> traceM ("Unspecialized:" <> show err) *> pure hole)

View File

@ -1,26 +0,0 @@
{-# LANGUAGE GADTs, TypeOperators #-}
module Analysis.Abstract.BadValues
( resumingBadValues
) where
import Control.Abstract.Evaluator
import Control.Abstract.Value
import Data.Abstract.Value (ValueError(..), runValueErrorWith)
import Data.ByteString.Char8 (pack)
import Prologue
resumingBadValues :: (AbstractHole value, Member (State (Environment location value)) effects, Show value) => Evaluator location term value (Resumable (ValueError location value) ': effects) a -> Evaluator location term value effects a
resumingBadValues = runValueErrorWith (\ err -> traceM ("ValueError" <> show err) *> case err of
CallError val -> pure val
StringError val -> pure (pack (show val))
BoolError{} -> pure True
BoundsError{} -> pure hole
IndexError{} -> pure hole
NumericError{} -> pure hole
Numeric2Error{} -> pure hole
ComparisonError{} -> pure hole
NamespaceError{} -> getEnv
BitwiseError{} -> pure hole
Bitwise2Error{} -> pure hole
KeyValueError{} -> pure (hole, hole)
ArithmeticError{} -> pure hole)

View File

@ -1,21 +0,0 @@
{-# LANGUAGE GADTs, TypeOperators #-}
module Analysis.Abstract.BadVariables
( resumingBadVariables
) where
import Control.Abstract.Evaluator
import Data.Abstract.Evaluatable
import Prologue
resumingBadVariables :: (AbstractHole value, Show value) => Evaluator location term value (Resumable (EvalError value) ': State [Name] ': effects) a -> Evaluator location term value effects (a, [Name])
resumingBadVariables
= runState []
. runEvalErrorWith (\ err -> traceM ("EvalError" <> show err) *> case err of
EnvironmentLookupError{} -> pure hole
DefaultExportError{} -> pure ()
ExportError{} -> pure ()
IntegerFormatError{} -> pure 0
FloatFormatError{} -> pure 0
RationalFormatError{} -> pure 0
FreeVariableError name -> raise (modify' (name :)) *> pure hole
FreeVariablesError names -> raise (modify' (names <>)) *> pure (fromMaybeLast "unknown" names))