1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
module FlatCurry.Typed.Read where
import Control.Monad ( unless, when )
import Control.Monad.Trans.Class ( lift )
import Control.Monad.Trans.State ( gets )
import Data.List ( find, nub )
import Data.Maybe ( fromMaybe, fromJust )
import System.Directory ( doesFileExist, removeFile )
import FlatCurry.TypeAnnotated.Files ( readTypeAnnotatedFlatCurry
, readTypeAnnotatedFlatCurryFile
, typeAnnotatedFlatCurryFileName )
import FlatCurry.Annotated.Goodies
import System.CurryPath ( getLoadPathForModule, inCurrySubdir
, lookupModuleSource )
import System.FilePath ( (</>) )
import System.FrontendExec ( FrontendTarget(TAFCY)
, callFrontendWithParams, defaultParams
, setQuiet )
import FlatCurry.Typed.Goodies
import FlatCurry.Typed.Names
import FlatCurry.Typed.Simplify
import FlatCurry.Typed.Types
import PackageConfig ( packagePath )
import ToolOptions
import VerifierState
readSimpTypedFlatCurryWithSpec :: String -> VStateM TAProg
readSimpTypedFlatCurryWithSpec mname =
readTypedFlatCurryWithSpec mname >>= return . simpProg
readTypedFlatCurryWithSpec :: String -> VStateM TAProg
readTypedFlatCurryWithSpec mname = do
printWhenStatus $ "Loading typed FlatCurry program '" ++ mname ++ "'"
prog <- lift $ readTypedFlatCurryWithoutForall mname
mbspec <- lift $ readTypedFlatCurryFromPath "include" specName
case mbspec of
Nothing -> return prog
Just specprog -> do
printWhenStatus $ "Adding '" ++ specName ++ "'"
return $ unionTAProg prog $ rnmProg mname specprog
where
specName = mname ++ "_SPEC"
readTypedFlatCurryFromPath :: String -> String -> IO (Maybe TAProg)
readTypedFlatCurryFromPath path mname = do
loadpath <- getLoadPathForModule mname
let path' = if null path then loadpath else (packagePath </> path) : loadpath
mbsource <- lookupModuleSource path' mname
case mbsource of
Nothing -> return Nothing
Just (dir, filepath) -> do
let afcyfile = inCurrySubdir dir </> (mname ++ ".afcy")
unless (mname == "Prelude") $
doesFileExist afcyfile >>= flip when (removeFile afcyfile)
callFrontendWithParams TAFCY (setQuiet True defaultParams) filepath
readTypeAnnotatedFlatCurryFile
(dir </> typeAnnotatedFlatCurryFileName mname)
>>= return . Just . updProgFuncs (map (updFuncType stripForall))
readTypedFlatCurryWithoutForall :: String -> IO TAProg
readTypedFlatCurryWithoutForall mname =
readTypedFlatCurryFromPath "" mname
>>= return . fromMaybe
(error $ "Typed FlatCurry program '" ++ mname ++ "' could not be found")
stripForall :: TypeExpr -> TypeExpr
stripForall texp = case texp of
ForallType _ te -> stripForall te
_ -> texp
getAllFunctions :: [TAFuncDecl] -> [QName] -> VStateM [TAFuncDecl]
getAllFunctions currfuncs newfuns = do
currmods <- gets currTAProgs
getAllFuncs currmods newfuns
where
getAllFuncs _ [] = return $ reverse currfuncs
getAllFuncs currmods (newfun : newfuncs)
| newfun `elem` map (pre . fst) transPrimCons ++ map funcName currfuncs
|| isPrimOp newfun
= getAllFunctions currfuncs newfuncs
| fst newfun `elem` map progName currmods
= maybe
(getAllFunctions currfuncs newfuncs)
(\fdecl -> getAllFunctions
(fdecl : currfuncs)
(newfuncs ++ nub (funcsOfFuncDecl fdecl)))
(find (\fd -> funcName fd == newfun)
(progFuncs
(fromJust (find (\m -> progName m == fst newfun) currmods))))
| otherwise
= do let mname = fst newfun
printWhenStatus $
"Loading module '" ++ mname ++ "' for '"++ snd newfun ++"'"
newmod <- lift $ readTypedFlatCurryWithoutForall mname
>>= return . simpProg
addProgsToState [newmod]
getAllFunctions currfuncs (newfun : newfuncs)
|