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
|
module Curry.Files where
import Directory ( doesFileExist )
import FileGoodies ( getFileInPath, lookupFileInPath )
import FilePath ( takeFileName, (</>), (<.>) )
import ReadShowTerm ( readUnqualifiedTerm )
import System.CurryPath ( lookupModuleSourceInLoadPath, getLoadPathForModule
, inCurrySubdir, stripCurrySuffix )
import System.FrontendExec ( FrontendParams, FrontendTarget (..), defaultParams
, setQuiet, callFrontend, callFrontendWithParams
)
import Curry.Types
readShortAST :: String -> IO (Module ())
readShortAST progname =
readShortASTWithParseOptions progname (setQuiet True defaultParams)
readFullAST :: String -> IO (Module ())
readFullAST progname =
readFullASTWithParseOptions progname (setQuiet True defaultParams)
readShortASTWithParseOptions :: String -> FrontendParams -> IO (Module ())
readShortASTWithParseOptions progname options = do
mbsrc <- lookupModuleSourceInLoadPath progname
case mbsrc of
Nothing -> do
loadpath <- getLoadPathForModule progname
filename <- getFileInPath (shortASTFileName (takeFileName progname))
[""] loadpath
readASTFile filename
Just (dir,_) -> do
callFrontendWithParams SAST options progname
readASTFile (shortASTFileName (dir </> takeFileName progname))
readFullASTWithParseOptions :: String -> FrontendParams -> IO (Module ())
readFullASTWithParseOptions progname options = do
mbsrc <- lookupModuleSourceInLoadPath progname
case mbsrc of
Nothing -> do
loadpath <- getLoadPathForModule progname
filename <- getFileInPath (fullASTFileName (takeFileName progname))
[""] loadpath
readASTFile filename
Just (dir,_) -> do
callFrontendWithParams AST options progname
readASTFile (fullASTFileName (dir </> takeFileName progname))
shortASTFileName :: String -> String
shortASTFileName prog = inCurrySubdir (stripCurrySuffix prog) <.> "sast"
fullASTFileName :: String -> String
fullASTFileName prog = inCurrySubdir (stripCurrySuffix prog) <.> "ast"
readASTFile :: String -> IO (Module ())
readASTFile filename = do
filecontents <- readShortASTFileRaw filename
return (readUnqualifiedTerm ["Curry.Types", "Curry.Ident", "Curry.Position",
"Curry.Span", "Curry.SpanInfo", "Prelude"]
filecontents)
readShortASTFileRaw :: String -> IO String
readShortASTFileRaw filename = do
extfcy <- doesFileExist filename
if extfcy
then readFile filename
else do let subdirfilename = inCurrySubdir filename
exdirtfcy <- doesFileExist subdirfilename
if exdirtfcy
then readFile subdirfilename
else error ("EXISTENCE ERROR: AST file '" ++ filename ++
"' does not exist")
|