Commit 716c320e authored by Michael Hanus 's avatar Michael Hanus
Browse files

Makefiles improved, ImportCalls added

parent a65d1eab
......@@ -2,3 +2,8 @@
*~
.curry
*.state
# executables
currydoc/CurryDoc
genint/GenInt
importcalls/ImportCalls
......@@ -6,11 +6,13 @@
.PHONY: all
all:
@cd currydoc ; $(MAKE)
@cd genint ; $(MAKE)
@cd currydoc ; $(MAKE)
@cd genint ; $(MAKE)
@cd importcalls ; $(MAKE)
.PHONY: clean
clean:
cd analysis ; $(ROOT)/bin/cleancurry
cd currydoc ; $(MAKE) clean
cd genint ; $(MAKE) clean
cd analysis ; $(ROOT)/bin/cleancurry
cd currydoc ; $(MAKE) clean
cd genint ; $(MAKE) clean
cd importcalls ; $(MAKE) clean
......@@ -3,14 +3,16 @@ that are used by different Curry systems, like PAKCS or KiCS2.
Currently it contains:
analysis:
A directory containing various analyzers for Curry program.
`analysis`:
A directory containing various analyzers for Curry program.
currydoc:
A documentation generator for Curry programs.
`currydoc`:
A documentation generator for Curry programs.
genint:
A program for generating module interfaces and source code
of a Curry module (used by the commands ":interface" and ":show"
of some Curry systems).
`genint`:
A program for generating module interfaces and source code
of a Curry module (used by the commands ":interface" and ":show"
of some Curry systems).
`importcalls`:
A tool to show all calls to imported functions in a module.
......@@ -8,18 +8,6 @@ LIB=$(ROOT)/lib
META=$(LIB)/meta
ANADIR=../analysis
.PHONY: all
all:
$(MAKE) CurryDoc4$(CURRYSYSTEM)
.PHONY: CurryDoc4pakcs
CurryDoc4pakcs:
$(MAKE) CurryDoc.state
.PHONY: CurryDoc4kics2
CurryDoc4kics2:
$(MAKE) CurryDoc
# Source modules of currydoc:
DEPS = CurryDoc.curry CurryDocRead.curry CurryDocHtml.curry \
CurryDocTeX.curry CurryDocParams.curry \
......@@ -34,15 +22,9 @@ DEPS = CurryDoc.curry CurryDocRead.curry CurryDocHtml.curry \
$(ANADIR)/AnaDependency.curry
# generate saved PAKCS state for currydoc program:
CurryDoc.state: $(DEPS)
(echo ":set path $(ANADIR)" ; echo ":l CurryDoc" ; echo ":set path" ; \
echo ":save main" ) | $(ROOT)/bin/pakcs
(cd $(ROOT)/bin ; rm -f currydoc ; \
ln -s ../currytools/currydoc/CurryDoc.state currydoc)
# generate KiCS2 executable for currydoc program:
CurryDoc: $(DEPS)
$(ROOT)/bin/kics2 $(REPL_OPTS) :set path $(ANADIR) :l CurryDoc :save :q
$(ROOT)/bin/$(CURRYSYSTEM) $(REPL_OPTS) :set path $(ANADIR) \
:l CurryDoc :save :q
(cd $(ROOT)/bin ; rm -f currydoc ; \
ln -s ../currytools/currydoc/CurryDoc currydoc)
......
......@@ -7,30 +7,14 @@
LIB=$(ROOT)/lib
META=$(LIB)/meta
.PHONY: all
all:
$(MAKE) GenInt4$(CURRYSYSTEM)
.PHONY: GenInt4pakcs
GenInt4pakcs:
$(MAKE) GenInt.state
.PHONY: GenInt4kics2
GenInt4kics2:
$(MAKE) GenInt
# Source modules of currydoc:
DEPS = GenInt.curry $(META)/FlatCurry.curry \
$(META)/FlatCurryShow.curry $(META)/FlexRigid.curry \
$(LIB)/List.curry
# generate saved PAKCS state for currydoc program:
GenInt.state: $(DEPS)
$(ROOT)/bin/pakcs -s GenInt
# generate KiCS2 executable for currydoc program:
# generate executable for currydoc program:
GenInt: $(DEPS)
$(ROOT)/bin/kics2 $(REPL_OPTS) :l GenInt :save :q
$(ROOT)/bin/$(CURRYSYSTEM) $(REPL_OPTS) :l GenInt :save :q
.PHONY: clean
clean:
......
-----------------------------------------------------------------------------
-- Show all calls to imported functions in a module
--
-- Michael Hanus, November 2003
-----------------------------------------------------------------------------
module ImportCalls(main,showImportCalls) where
import FlatCurry
import Char
import List
import Sort
import System
import Directory
import FileGoodies
import Distribution
m1 = showAllImportedCalls "ImportCalls"
-- Check arguments and call main function:
main = do
args <- getArgs
if length args /= 1
then putStrLn $ "ERROR: Illegal arguments: " ++
concat (intersperse " " args) ++ "\n" ++
"Usage: importcalls <module_name>"
else showAllImportedCalls (stripSuffix (head args))
showAllImportedCalls modname = do
prog <- readCurrentFlatCurry modname
putStrLn ("Calls to imported functions/constructors in module \""++modname++"\":\n")
putStrLn (showImportCalls prog)
showImportCalls :: Prog -> String
showImportCalls = formatImpCalls . getAllImpCalls
-- format import calls as import declarations:
formatImpCalls :: [(String,[String])] -> String
formatImpCalls impcalls =
concatMap (\(mod,imps)->"import "++mod++"("++
concat (intersperse "," (map showName imps))++")\n")
impcalls
where
showName name = if isAlpha (head name) then name else '(':name++")"
getAllImpCalls :: Prog -> [(String,[String])]
getAllImpCalls (Prog mod imps _ funs _) =
calls2impCalls imps
(mergeSort (\ (_,n1) (_,n2) -> n1 <= n2)
(allFunCalls mod funs))
calls2impCalls :: [String] -> [QName] -> [(String,[String])]
calls2impCalls [] _ = []
calls2impCalls (mod:mods) funs =
(mod, map snd (filter (\(m,_)->m==mod) funs)) : calls2impCalls mods funs
-- Computes the list of called functions in a list of function declarations
allFunCalls :: String -> [FuncDecl] -> [QName]
allFunCalls _ [] = []
allFunCalls mod (Func _ _ _ _ (Rule _ e) : funs) =
union (globalFunsInExpr mod e) (allFunCalls mod funs)
allFunCalls mod (Func _ _ _ _ (External _) : funs) = allFunCalls mod funs
-- Gets a list of all functions called in an expression that are not defined
-- in a module (first argument):
globalFunsInExpr :: String -> Expr -> [QName]
globalFunsInExpr mod exp = funsInExpr exp
where
funsInExpr (Var _) = []
funsInExpr (Lit _) = []
funsInExpr (Comb _ (m,f) es) =
if m==mod || (m=="Prelude" && f `elem` ["commit","apply","cond"])
then nub (concatMap funsInExpr es)
else nub ((m,f) : concatMap funsInExpr es)
funsInExpr (Free _ e) = funsInExpr e
funsInExpr (Let bs e) = union (nub (concatMap (funsInExpr . snd) bs)) (funsInExpr e)
funsInExpr (Or e1 e2) = union (funsInExpr e1) (funsInExpr e2)
funsInExpr (Case _ e bs) = union (funsInExpr e)
(nub (concatMap funsInBranch bs))
where funsInBranch (Branch _ be) = funsInExpr be
----------------- Auxiliaries:
-- Read a FlatCurry program (parse only if necessary):
readCurrentFlatCurry :: String -> IO Prog
readCurrentFlatCurry modname = do
progname <- findSourceFileInLoadPath modname
let fcyprogname = flatCurryFileName progname
fcyexists <- doesFileExist fcyprogname
if not fcyexists
then readFlatCurry progname
else do ctime <- getSourceModificationTime progname
ftime <- getModificationTime fcyprogname
if ctime>ftime
then readFlatCurry progname
else readFlatCurryFile fcyprogname
getSourceModificationTime progname = do
lexists <- doesFileExist (progname++".lcurry")
if lexists then getModificationTime (progname++".lcurry")
else getModificationTime (progname++".curry")
-- add a directory name for a Curry source file by looking up the
-- current load path (CURRYPATH):
findSourceFileInLoadPath modname = do
loadpath <- getLoadPathForFile modname
mbfname <- lookupFileInPath (baseName modname) [".lcurry",".curry"] loadpath
maybe (error ("Curry file for module \""++modname++"\" not found!"))
(return . stripSuffix)
mbfname
# Makefile for generating ImportCalls tool
# Required:
# - installed Curry System (PAKCS or KiCS2) specified by variable CURRYSYSTEM
# - root location of the Curry System specified by variable ROOT
LIB=$(ROOT)/lib
META=$(LIB)/meta
# generate executable for import calls tools:
ImportCalls: ImportCalls.curry $(META)/FlatCurry.curry \
$(LIB)/System.curry $(LIB)/List.curry
$(ROOT)/bin/$(CURRYSYSTEM) $(REPL_OPTS) :l ImportCalls :save :q
.PHONY: clean
clean:
$(ROOT)/bin/cleancurry
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment