packages feed

fortran-src 0.16.2 → 0.16.3

raw patch · 13 files changed

+64/−42 lines, 13 filesdep ~bytestringdep ~deepseqdep ~singletonsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: bytestring, deepseq, singletons, singletons-base, singletons-th, text

API changes (from Hackage documentation)

- Language.Fortran.Util.ModFile: genUniqNameToFilenameMap :: FilePath -> ModFiles -> Map Name String
+ Language.Fortran.Util.ModFile: genUniqNameToFilenameMap :: FilePath -> ModFiles -> Map Name (String, Maybe Name)
- Language.Fortran.Util.ModFile: type DeclMap = Map Name (DeclContext, SrcSpan)
+ Language.Fortran.Util.ModFile: type DeclMap = Map Name (DeclContext, Name, SrcSpan)

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+### 0.16.3 (Sep 30, 2024)+  * Store source names for local declarations in .fsmod files.+  * Constant evaluator now handles real-integer exponent and real-real exponent expression+ ### 0.16.2 (Sep 13, 2024)   * Small change to allow a path to be added when building mod-file naming map   * Improvements to the power of constant propagation and constant expression evaluation.
app/Main.hs view
@@ -51,7 +51,7 @@ programName = "fortran-src"  showVersion :: String-showVersion = "0.16.2"+showVersion = "0.16.3"  main :: IO () main = do
fortran-src.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.37.0.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack  name:           fortran-src-version:        0.16.2+version:        0.16.3 synopsis:       Parsers and analyses for Fortran standards 66, 77, 90, 95 and 2003 (partial). description:    Provides lexing, parsing, and basic analyses of Fortran code covering standards: FORTRAN 66, FORTRAN 77, Fortran 90, Fortran 95, Fortran 2003 (partial) and some legacy extensions. Includes data flow and basic block analysis, a renamer, and type analysis. For example usage, see the @<https://hackage.haskell.org/package/camfort CamFort>@ project, which uses fortran-src as its front end. category:       Language@@ -190,9 +190,9 @@     , array ==0.5.*     , base >=4.6 && <5     , binary >=0.8.3.0 && <0.11-    , bytestring >=0.10 && <0.12+    , bytestring >=0.10 && <0.13     , containers >=0.5 && <0.7-    , deepseq ==1.4.*+    , deepseq >=1.4 && <1.6     , directory >=1.2 && <2     , either >=5.0.1.1 && <5.1     , fgl ==5.*@@ -200,11 +200,11 @@     , mtl >=2.2 && <3     , pretty >=1.1 && <2     , process >=1.2.0.0-    , singletons >=3.0 && <3.2-    , singletons-base >=3.0 && <3.2-    , singletons-th >=3.0 && <3.2+    , singletons ==3.0.*+    , singletons-base >=3.0 && <3.4+    , singletons-th >=3.0 && <3.4     , temporary >=1.2 && <1.4-    , text >=1.2 && <2.1+    , text >=1.2 && <2.2     , uniplate >=1.6 && <2   default-language: Haskell2010   if os(windows)@@ -253,9 +253,9 @@     , array ==0.5.*     , base >=4.6 && <5     , binary >=0.8.3.0 && <0.11-    , bytestring >=0.10 && <0.12+    , bytestring >=0.10 && <0.13     , containers >=0.5 && <0.7-    , deepseq ==1.4.*+    , deepseq >=1.4 && <1.6     , directory >=1.2 && <2     , either >=5.0.1.1 && <5.1     , fgl ==5.*@@ -264,11 +264,11 @@     , mtl >=2.2 && <3     , pretty >=1.1 && <2     , process >=1.2.0.0-    , singletons >=3.0 && <3.2-    , singletons-base >=3.0 && <3.2-    , singletons-th >=3.0 && <3.2+    , singletons ==3.0.*+    , singletons-base >=3.0 && <3.4+    , singletons-th >=3.0 && <3.4     , temporary >=1.2 && <1.4-    , text >=1.2 && <2.1+    , text >=1.2 && <2.2     , uniplate >=1.6 && <2   default-language: Haskell2010   if os(windows)@@ -351,9 +351,9 @@     , array ==0.5.*     , base >=4.6 && <5     , binary >=0.8.3.0 && <0.11-    , bytestring >=0.10 && <0.12+    , bytestring >=0.10 && <0.13     , containers >=0.5 && <0.7-    , deepseq ==1.4.*+    , deepseq >=1.4 && <1.6     , directory >=1.2 && <2     , either >=5.0.1.1 && <5.1     , fgl ==5.*@@ -363,11 +363,11 @@     , mtl >=2.2 && <3     , pretty >=1.1 && <2     , process >=1.2.0.0-    , singletons >=3.0 && <3.2-    , singletons-base >=3.0 && <3.2-    , singletons-th >=3.0 && <3.2+    , singletons ==3.0.*+    , singletons-base >=3.0 && <3.4+    , singletons-th >=3.0 && <3.4     , temporary >=1.2 && <1.4-    , text >=1.2 && <2.1+    , text >=1.2 && <2.2     , uniplate >=1.6 && <2   default-language: Haskell2010   if os(windows)
src/Language/Fortran/Analysis/BBlocks.hs view
@@ -13,6 +13,7 @@ import Control.Monad import Control.Monad.State.Lazy hiding (fix) import Control.Monad.Writer hiding (fix)+import Control.Monad ( forM_ ) -- required for mtl-2.3 (GHC 9.6) import Text.PrettyPrint.GenericPretty (pretty, Out) import Text.PrettyPrint               (render) import Language.Fortran.Analysis
src/Language/Fortran/Analysis/DataFlow.hs view
@@ -42,6 +42,7 @@ import Data.Maybe import Data.List (foldl', foldl1', (\\), union, intersect) import Control.Monad.Writer hiding (fix)+import Control.Monad -- required for mtl-2.3 (GHC 9.6)  import qualified Language.Fortran.Repr as Repr import qualified Language.Fortran.Repr.Eval.Value as Repr
src/Language/Fortran/Analysis/ModGraph.hs view
@@ -10,8 +10,8 @@ import Language.Fortran.Util.Files  import Prelude hiding (mod)-import Control.Monad import Control.Monad.State.Strict+import Control.Monad ( forM_ ) -- required for mtl-2.3 (GHC 9.6) import Data.Data import Data.Generics.Uniplate.Data import Data.Graph.Inductive hiding (version)
src/Language/Fortran/Analysis/Renaming.hs view
@@ -20,6 +20,7 @@ import Data.Map (insert, empty, lookup, Map) import qualified Data.Map.Strict as M import Control.Monad.State.Strict+import Control.Monad -- required for mtl-2.3 (GHC 9.6) import Data.Generics.Uniplate.Data import Data.Data import Data.Functor.Identity (Identity)
src/Language/Fortran/Analysis/Types.hs view
@@ -23,6 +23,7 @@ import Data.List (find, foldl') import Control.Monad.State.Strict import Control.Monad.Reader+import Control.Monad -- required for mtl-2.3 (GHC 9.6) import Data.Generics.Uniplate.Data import Data.Data import Language.Fortran.Analysis
src/Language/Fortran/Parser.hs view
@@ -23,7 +23,6 @@    -- * Other parsers   , f90Expr-  , f77lIncludesNoTransform   , byVerFromFilename    -- ** Statement
src/Language/Fortran/Repr/Eval/Value.hs view
@@ -272,6 +272,13 @@         case (l', r') of           (FSVInt li, FSVInt ri) ->             pure $ MkFScalarValue $ FSVInt $ fIntBOpInplace (^) li ri+          (FSVReal lr, FSVReal ri) ->+            pure $ MkFScalarValue $ FSVReal $ fRealBOpInplace' (**) (**) lr ri+          (FSVReal lr, FSVInt ri) ->+            -- Handle case of a real raised to an integer power.+            pure $ MkFScalarValue $ FSVReal $ fRealBOpInplace' (**) (**) lr (FReal8 $ withFInt ri)++--          _ -> err $ ELazy "exponentiation: unsupported types"        F.Concatenation  ->         case (l', r') of
src/Language/Fortran/Util/ModFile.hs view
@@ -71,6 +71,7 @@ import           Language.Fortran.Util.Files ( getDirContents )  import Control.Monad.State+import Control.Monad -- required for mtl-2.3 (GHC 9.6) import Data.Binary (Binary, encode, decodeOrFail) import qualified Data.ByteString.Lazy.Char8 as LB import Data.Data@@ -103,8 +104,9 @@ instance Binary DeclContext  -- | Map of unique variable name to the unique name of the program--- unit where it was defined, and the corresponding SrcSpan.-type DeclMap = M.Map F.Name (DeclContext, P.SrcSpan)+-- unit where it was defined, its source name,+-- and the corresponding SrcSpan.+type DeclMap = M.Map F.Name (DeclContext, F.Name, P.SrcSpan)  -- | A map of aliases => strings, in order to save space and share -- structure for repeated strings.@@ -120,7 +122,8 @@                        , mfDeclMap     :: DeclMap                        , mfTypeEnv     :: FAT.TypeEnv                        , mfParamVarMap :: ParamVarMap-                       , mfOtherData   :: M.Map String LB.ByteString }+                       , mfOtherData   :: M.Map String LB.ByteString+                      }   deriving (Eq, Show, Data, Typeable, Generic)  instance Binary ModFile@@ -250,18 +253,23 @@  -- | Create a map that links all unique variable/function names in the -- ModFiles to their corresponding *originating* filename (i.e., where they are declared)-genUniqNameToFilenameMap :: FilePath -> ModFiles -> M.Map F.Name String-genUniqNameToFilenameMap localPath = M.unions . map perMF+-- paired with their source name (maybe)+genUniqNameToFilenameMap :: FilePath -> ModFiles -> M.Map F.Name (String, Maybe F.Name)+genUniqNameToFilenameMap localPath m = M.unions . map perMF $ m   where     perMF mf = M.fromList-                [ (n, normalise $ localPath </> fname)-                   | modEnv <- M.elems localModuleMap-                   , (n, _) <- M.elems modEnv ]+                $ [ (n, (fname, Nothing))+                     | (_p, modEnv) <- M.toList localModuleMap+                     , (n, _) <- M.elems modEnv ]+              -- decl map information+               <>  [(n, (fname, Just srcName)) | (n, (_dc, srcName, _)) <- M.toList declMap ]+       where         -- Make sure that we remove imported declarations so we can         -- properly localise declarations to the originator file.         localModuleMap = localisedModuleMap $ mfModuleMap mf-        fname = mfFilename mf+        declMap        = mfDeclMap mf+        fname = normalise $ localPath </> mfFilename mf  -------------------------------------------------- @@ -288,28 +296,28 @@   where     -- Extract variable names, source spans from declarations (and     -- from function return variable if present)-    blockDecls :: (DeclContext, Maybe (F.Name, P.SrcSpan), [F.Block (FA.Analysis a)]) -> [(F.Name, (DeclContext, P.SrcSpan))]+    blockDecls :: (DeclContext, Maybe (F.Name, F.Name, P.SrcSpan), [F.Block (FA.Analysis a)]) -> [(F.Name, (DeclContext, F.Name, P.SrcSpan))]     blockDecls (dc, mret, bs)       | Nothing        <- mret = map decls (universeBi bs)-      | Just (ret, ss) <- mret = (ret, (dc, ss)):map decls (universeBi bs)+      | Just (ret, srcName, ss) <- mret = (ret, (dc, srcName, ss)):map decls (universeBi bs)       where-        decls d = let (v, ss) = declVarName d in (v, (dc, ss))+        decls d = let (v, srcName, ss) = declVarName d in (v, (dc, srcName, ss))      -- Extract variable name and source span from declaration-    declVarName :: F.Declarator (FA.Analysis a) -> (F.Name, P.SrcSpan)-    declVarName (F.Declarator _ _ e _ _ _)  = (FA.varName e, P.getSpan e)+    declVarName :: F.Declarator (FA.Analysis a) -> (F.Name, F.Name, P.SrcSpan)+    declVarName (F.Declarator _ _ e _ _ _)  = (FA.varName e, FA.srcName e, P.getSpan e)      -- Extract context identifier, a function return value (+ source     -- span) if present, and a list of contained blocks-    nameAndBlocks :: F.ProgramUnit (FA.Analysis a) -> (DeclContext, Maybe (F.Name, P.SrcSpan), [F.Block (FA.Analysis a)])+    nameAndBlocks :: F.ProgramUnit (FA.Analysis a) -> (DeclContext, Maybe (F.Name, F.Name, P.SrcSpan), [F.Block (FA.Analysis a)])     nameAndBlocks pu = case pu of       F.PUMain       _ _ _ b _            -> (DCMain, Nothing, b)       F.PUModule     _ _ _ b _            -> (DCModule $ FA.puName pu, Nothing, b)       F.PUSubroutine _ _ _ _ _ b _        -> (DCSubroutine (FA.puName pu, FA.puSrcName pu), Nothing, b)       F.PUFunction   _ _ _ _ _ _ mret b _         | Nothing   <- mret-        , F.Named n <- FA.puName pu       -> (DCFunction (FA.puName pu, FA.puSrcName pu), Just (n, P.getSpan pu), b)-        | Just ret <- mret                -> (DCFunction (FA.puName pu, FA.puSrcName pu), Just (FA.varName ret, P.getSpan ret), b)+        , F.Named n <- FA.puName pu       -> (DCFunction (FA.puName pu, FA.puSrcName pu), Just (n, n, P.getSpan pu), b)+        | Just ret <- mret                -> (DCFunction (FA.puName pu, FA.puSrcName pu), Just (FA.varName ret, FA.srcName ret, P.getSpan ret), b)         | otherwise                       -> error $ "nameAndBlocks: un-named function with no return value! " ++ show (FA.puName pu) ++ " at source-span " ++ show (P.getSpan pu)       F.PUBlockData  _ _ _ b              -> (DCBlockData, Nothing, b)       F.PUComment    {}                   -> (DCBlockData, Nothing, []) -- no decls inside of comments, so ignore it
test/Language/Fortran/Analysis/ModFileSpec.hs view
@@ -42,6 +42,6 @@     -- get unique name to filemap     let mmap = genUniqNameToFilenameMap "" modFiles     -- check that `constant` is declared in leaf.f90-    let Just leaf = M.lookup "leaf_constant_1" mmap+    let Just (leaf, _) = M.lookup "leaf_constant_1" mmap     leaf `shouldBe` ("test-data" </> "module" </> "leaf.f90") 
test/Language/Fortran/Parser/Free/Fortran95Spec.hs view
@@ -15,7 +15,7 @@ import qualified Language.Fortran.Parser.Free.Lexer     as Free  import qualified Data.List as List-import Data.Foldable(forM_)+import Control.Monad ( forM_ ) import qualified Data.ByteString.Char8 as B import Control.Exception (evaluate)