Skip to content

Commit

Permalink
incorporate checkTimestamps into fortran-src ModFile module
Browse files Browse the repository at this point in the history
  • Loading branch information
mrd committed Aug 29, 2019
1 parent cb0cb91 commit f320e6e
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/Language/Fortran/Util/ModFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,27 @@ module Language.Fortran.Util.ModFile
, genModFile, regenModFile, encodeModFile, decodeModFile
, StringMap, DeclMap, ParamVarMap, DeclContext(..), extractModuleMap, extractDeclMap
, moduleFilename, combinedStringMap, combinedDeclMap, combinedModuleMap, combinedTypeEnv, combinedParamVarMap
, genUniqNameToFilenameMap )
, genUniqNameToFilenameMap
, TimestampStatus(..), checkTimestamps )
where

import Control.Monad.State
import Data.Binary (Binary, encode, decodeOrFail)
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.Data
import Data.Maybe
import Data.Generics.Uniplate.Operations
import qualified Data.Map.Strict as M
import Data.Binary (Binary, encode, decodeOrFail)
import Control.Monad.State
import Data.Maybe
import GHC.Generics (Generic)
-- import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as LB

import qualified Language.Fortran.Util.Position as P
import qualified Language.Fortran.AST as F
import qualified Language.Fortran.Analysis as FA
import qualified Language.Fortran.Analysis.BBlocks as FAB
import qualified Language.Fortran.Analysis.DataFlow as FAD
import qualified Language.Fortran.Analysis.Renaming as FAR
import qualified Language.Fortran.Analysis.Types as FAT
import qualified Language.Fortran.Analysis.DataFlow as FAD
import qualified Language.Fortran.Analysis.BBlocks as FAB
import qualified Language.Fortran.Util.Position as P
import System.Directory
import System.FilePath

--------------------------------------------------

Expand Down Expand Up @@ -304,3 +305,23 @@ extractParamVarMap pf = M.fromList cvm
, st@F.StParameter {} <- universeBi bs :: [F.Statement (FA.Analysis a)]
, (F.DeclVariable _ _ v _ _) <- universeBi st :: [F.Declarator (FA.Analysis a)]
, Just con <- [FA.constExp (F.getAnnotation v)] ]

-- | Status of mod-file compared to Fortran file.
data TimestampStatus = NoSuchFile | CompileFile | ModFileExists FilePath

-- | Compare the source file timestamp to the fsmod file timestamp, if
-- it exists.
checkTimestamps :: FilePath -> IO TimestampStatus
checkTimestamps path = do
pathExists <- doesFileExist path
modExists <- doesFileExist $ path -<.> modFileSuffix
case (pathExists, modExists) of
(False, _) -> pure NoSuchFile
(True, False) -> pure CompileFile
(True, True) -> do
let modPath = path -<.> modFileSuffix
pathModTime <- getModificationTime path
modModTime <- getModificationTime modPath
if pathModTime < modModTime
then pure $ ModFileExists modPath
else pure CompileFile

0 comments on commit f320e6e

Please sign in to comment.