Commit 7cac53e1 authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

Patching of module identifier inserted for dependency parsing

parent 39934463
......@@ -32,7 +32,7 @@ import Curry.Base.Ident
import Curry.Base.MessageMonad
import Curry.Files.Filenames
import Curry.Files.PathUtils
import Curry.Syntax (Module (..), ImportDecl (..), parseHeader)
import Curry.Syntax (Module (..), ImportDecl (..), parseHeader, patchModuleId)
import Base.Messages (internalError)
import Base.SCC (scc)
......@@ -86,7 +86,7 @@ targetDeps opts paths sEnv fn = do
-- |Retrieve the dependencies of a given source file
sourceDeps :: Options -> [FilePath] -> SourceEnv -> FilePath -> IO SourceEnv
sourceDeps opts paths sEnv fn = do
hdr <- (ok . parseHeader fn) `liftM` readModule fn
hdr <- patchModuleId fn `liftM` (ok . parseHeader fn) `liftM` readModule fn
moduleDeps opts paths sEnv fn hdr
-- |Retrieve the dependencies of a given module
......@@ -120,7 +120,8 @@ moduleIdentDeps opts paths sEnv m = case Map.lookup m sEnv of
where
libraryPaths = optImportPaths opts
checkModuleHeader fn = do
hdr@(Module m' _ _ _) <- (ok . parseHeader fn) `liftM` readModule fn
hdr@(Module m' _ _ _) <- patchModuleId fn `liftM` (ok . parseHeader fn)
`liftM` readModule fn
unless (m == m') $ error $ errWrongModule m m'
moduleDeps opts paths sEnv fn hdr
......@@ -149,7 +150,6 @@ flattenDeps = fdeps . sortDeps
errWrongModule :: ModuleIdent -> ModuleIdent -> String
errWrongModule m m' =
"Expected module for " ++ show m ++ " but found " ++ show m'
++ show (moduleQualifiers m, moduleQualifiers m')
errCyclicImport :: [ModuleIdent] -> String
errCyclicImport [] = internalError "CurryDeps.errCyclicImport: empty list"
......
......@@ -114,7 +114,7 @@ loadModule opts fn = do
checkModuleHeader :: Options -> FilePath -> CS.Module -> (CS.Module, [String])
checkModuleHeader opts fn = checkModuleId fn
. importPrelude opts
. patchModuleId fn
. CS.patchModuleId fn
-- |Check whether the 'ModuleIdent' and the 'FilePath' fit together
checkModuleId :: FilePath -> CS.Module -> (CS.Module, [String])
......@@ -147,17 +147,6 @@ importPrelude opts m@(CS.Module mid es is ds)
Nothing -- no selection of types, functions, etc.
imported = [imp | (CS.ImportDecl _ imp _ _ _) <- is]
-- A module which doesn't contain a \texttt{module ... where} declaration
-- obtains its filename as module identifier (unlike the definition in
-- Haskell and original MCC where a module obtains \texttt{main}).
patchModuleId :: FilePath -> CS.Module -> CS.Module
patchModuleId fn m@(CS.Module mid es is ds)
| mid == mainMIdent
= CS.Module (mkMIdent [takeBaseName fn]) es is ds
| otherwise
= m
-- ---------------------------------------------------------------------------
-- Checking a module
-- ---------------------------------------------------------------------------
......
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