{-# LANGUAGE OverloadedStrings #-}
module Camfort.Specification.Hoare (check, HoareCheckResults(..), PrimReprOption(..)) where
import Camfort.Analysis
import Camfort.Analysis.Annotations
import Camfort.Specification.Hoare.Annotation
import Camfort.Specification.Hoare.CheckBackend
import Camfort.Specification.Hoare.CheckFrontend
import Control.DeepSeq
import Data.List (intersperse)
import qualified Language.Fortran.AST as F
import qualified Language.Fortran.Analysis as FA
import qualified Language.Fortran.Analysis.BBlocks as FAB
import qualified Language.Fortran.Analysis.Renaming as FAR
import Language.Fortran.Model.Repr.Prim
newtype HoareCheckResults = HoareCheckResults [HoareCheckResult]
instance NFData HoareCheckResults where
rnf :: HoareCheckResults -> ()
rnf HoareCheckResults
_ = ()
instance ExitCodeOfReport HoareCheckResults where
exitCodeOf :: HoareCheckResults -> Int
exitCodeOf (HoareCheckResults [HoareCheckResult]
rs) = [HoareCheckResult] -> Int
forall a. ExitCodeOfReport a => [a] -> Int
exitCodeOfSet [HoareCheckResult]
rs
instance Describe HoareCheckResults where
describeBuilder :: HoareCheckResults -> Builder
describeBuilder (HoareCheckResults [HoareCheckResult]
rs) =
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder)
-> ([HoareCheckResult] -> [Builder])
-> [HoareCheckResult]
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
intersperse Builder
"\n" ([Builder] -> [Builder])
-> ([HoareCheckResult] -> [Builder])
-> [HoareCheckResult]
-> [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HoareCheckResult -> Builder) -> [HoareCheckResult] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map HoareCheckResult -> Builder
forall a. Describe a => a -> Builder
describeBuilder ([HoareCheckResult] -> Builder) -> [HoareCheckResult] -> Builder
forall a b. (a -> b) -> a -> b
$ [HoareCheckResult]
rs
data PrimReprOption = PROIdealized | PROPrecise
check :: PrimReprOption
-> F.ProgramFile Annotation
-> HoareAnalysis HoareCheckResults
check :: PrimReprOption
-> ProgramFile Annotation -> HoareAnalysis HoareCheckResults
check PrimReprOption
pro = ([HoareCheckResult] -> HoareCheckResults)
-> AnalysisT
HoareFrontendError HoareFrontendWarning IO [HoareCheckResult]
-> HoareAnalysis HoareCheckResults
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [HoareCheckResult] -> HoareCheckResults
HoareCheckResults (AnalysisT
HoareFrontendError HoareFrontendWarning IO [HoareCheckResult]
-> HoareAnalysis HoareCheckResults)
-> (ProgramFile Annotation
-> AnalysisT
HoareFrontendError HoareFrontendWarning IO [HoareCheckResult])
-> ProgramFile Annotation
-> HoareAnalysis HoareCheckResults
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimReprSpec
-> ProgramFile HA
-> AnalysisT
HoareFrontendError HoareFrontendWarning IO [HoareCheckResult]
invariantChecking (PrimReprOption -> PrimReprSpec
fromPrimReprOption PrimReprOption
pro) (ProgramFile HA
-> AnalysisT
HoareFrontendError HoareFrontendWarning IO [HoareCheckResult])
-> (ProgramFile Annotation -> ProgramFile HA)
-> ProgramFile Annotation
-> AnalysisT
HoareFrontendError HoareFrontendWarning IO [HoareCheckResult]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProgramFile Annotation -> ProgramFile HA
getBlocks
getBlocks :: F.ProgramFile A -> F.ProgramFile (FA.Analysis (HoareAnnotation A))
getBlocks :: ProgramFile Annotation -> ProgramFile HA
getBlocks =
ProgramFile HA -> ProgramFile HA
forall a.
Data a =>
ProgramFile (Analysis a) -> ProgramFile (Analysis a)
FAB.analyseBBlocks (ProgramFile HA -> ProgramFile HA)
-> (ProgramFile Annotation -> ProgramFile HA)
-> ProgramFile Annotation
-> ProgramFile HA
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProgramFile HA -> ProgramFile HA
forall a.
Data a =>
ProgramFile (Analysis a) -> ProgramFile (Analysis a)
FAR.analyseRenames (ProgramFile HA -> ProgramFile HA)
-> (ProgramFile Annotation -> ProgramFile HA)
-> ProgramFile Annotation
-> ProgramFile HA
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ProgramFile (HoareAnnotation Annotation) -> ProgramFile HA
forall (b :: * -> *) a. Functor b => b a -> b (Analysis a)
FA.initAnalysis (ProgramFile (HoareAnnotation Annotation) -> ProgramFile HA)
-> (ProgramFile Annotation
-> ProgramFile (HoareAnnotation Annotation))
-> ProgramFile Annotation
-> ProgramFile HA
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Annotation -> HoareAnnotation Annotation)
-> ProgramFile Annotation
-> ProgramFile (HoareAnnotation Annotation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Annotation -> HoareAnnotation Annotation
forall a. a -> HoareAnnotation a
hoareAnn0
fromPrimReprOption :: PrimReprOption -> PrimReprSpec
fromPrimReprOption :: PrimReprOption -> PrimReprSpec
fromPrimReprOption PrimReprOption
PROIdealized = PrimReprSpec
prsIdealized
fromPrimReprOption PrimReprOption
PROPrecise = PrimReprSpec
prsPrecise