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
|
module CPM.AbstractCurry
( loadPathForPackage
, readAbstractCurryFromPackagePath
, readAbstractCurryFromDeps
, transformAbstractCurryInDeps
, applyModuleRenames
) where
import List ( intercalate, nub )
import FilePath ( (</>), (<.>), takeFileName, replaceExtension )
import System
import AbstractCurry.Files ( readAbstractCurryFile, writeAbstractCurryFile )
import AbstractCurry.Pretty ( showCProg )
import AbstractCurry.Select ( imports )
import AbstractCurry.Transform
import AbstractCurry.Types
import System.CurryPath ( sysLibPath, inCurrySubdir, modNameToPath
, inCurrySubdirModule, lookupModuleSource )
import System.FrontendExec ( FrontendTarget (..), FrontendParams (..)
, defaultParams, callFrontendWithParams
, setQuiet, setFullPath )
import CPM.ErrorLogger
import qualified CPM.PackageCache.Runtime as RuntimeCache
import CPM.Package (Package, loadPackageSpec, sourceDirsOf)
loadPathForPackage :: Package -> String -> [Package] -> [String]
loadPathForPackage pkg pkgDir deps =
(map (pkgDir </>) (sourceDirsOf pkg) ++
RuntimeCache.dependencyPathsSeparate deps pkgDir)
fullLoadPathForPackage :: Package -> String -> [Package] -> [String]
fullLoadPathForPackage pkg pkgDir deps =
loadPathForPackage pkg pkgDir deps ++ sysLibPath
readAbstractCurryFromPackagePath :: Package -> String -> [Package] -> String
-> IO CurryProg
readAbstractCurryFromPackagePath pkg pkgDir deps modname = do
let loadPath = fullLoadPathForPackage pkg pkgDir deps
params <- return $ setQuiet True (setFullPath loadPath defaultParams)
callFrontendWithParams ACY params modname
src <- lookupModuleSource loadPath modname
acyName <- return $ case src of
Nothing -> error $ "Module not found: " ++ modname
Just (_, file) -> replaceExtension (inCurrySubdirModule modname file) ".acy"
readAbstractCurryFile acyName >>= return . addPrimTypes
where
addPrimTypes p@(CurryProg mname imports dfltdecl clsdecls instdecls
typedecls funcdecls opdecls)
| mname == pre && primType "Int" `notElem` typedecls
= CurryProg mname imports dfltdecl clsdecls instdecls
(map primType ["Int","Float","Char"] ++ typedecls)
funcdecls opdecls
| otherwise = p
where pre = "Prelude"
primType n = CType ("Prelude",n) Public [] [] []
readAbstractCurryFromDeps :: String -> [Package] -> String -> IO CurryProg
readAbstractCurryFromDeps pkgDir deps modname = do
pkg <- fromErrorLogger (loadPackageSpec pkgDir)
readAbstractCurryFromPackagePath pkg pkgDir deps modname
transformAbstractCurryInDeps :: String -> [Package] -> (CurryProg -> CurryProg)
-> String -> String -> IO ()
transformAbstractCurryInDeps pkgDir deps transform modname destFile = do
acy <- readAbstractCurryFromDeps pkgDir deps modname
writeFile destFile $ showCProg (transform acy)
applyModuleRenames :: [(String, String)] -> CurryProg -> CurryProg
applyModuleRenames names prog =
updCProg maybeRename (map maybeRename) id id id id id id
(updQNamesInCProg rnm prog)
where
maybeRename n = case lookup n names of
Just n' -> n'
Nothing -> n
rnm mn@(mod, n) = case lookup mod names of
Just mod' -> (mod', n)
Nothing -> mn
|