-- | Definitions for representing Fortran values and types.

module Language.Fortran.Vars.Rep
  (
  -- * Types
    F.SemType(..)
  , F.Kind
  , F.CharacterLen(..)
  , F.Dimensions, F.Dim(..), F.Dims(..)

  -- ** Compatibility
  , F.dimensionsToTuples
  , Type

  -- * Values
  , ExpVal(..)
  ) where

import qualified Language.Fortran.Analysis.SemanticTypes as F
import qualified Language.Fortran.AST.Literal.Boz as F
import Language.Fortran.Extras.JSON.Literals()

import Language.Fortran.Vars.Orphans()

import Data.Aeson ( ToJSON, FromJSON )
import Control.DeepSeq ( NFData )
import GHC.Generics ( Generic )
import Data.Data ( Data )

-- TODO raehik 2023-05-15: consider deprecating. GHC is very gradually changing
-- the kind of concrete types from @*@ to @Type@. Language extension
-- @NoStarIsType@ makes that change, and will eventually become default. @type
-- Type@ will probably break with that on (due to the way kind/type/term
-- namespaces are searched).
type Type = F.SemType

-- | The evaluated value of a FORTRAN expression.
data ExpVal
  = Int     Int
  | Real    Double
  | Str     String
  | Logical Bool
  | Boz     F.Boz
    deriving stock (ExpVal -> ExpVal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExpVal -> ExpVal -> Bool
$c/= :: ExpVal -> ExpVal -> Bool
== :: ExpVal -> ExpVal -> Bool
$c== :: ExpVal -> ExpVal -> Bool
Eq, Eq ExpVal
ExpVal -> ExpVal -> Bool
ExpVal -> ExpVal -> Ordering
ExpVal -> ExpVal -> ExpVal
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ExpVal -> ExpVal -> ExpVal
$cmin :: ExpVal -> ExpVal -> ExpVal
max :: ExpVal -> ExpVal -> ExpVal
$cmax :: ExpVal -> ExpVal -> ExpVal
>= :: ExpVal -> ExpVal -> Bool
$c>= :: ExpVal -> ExpVal -> Bool
> :: ExpVal -> ExpVal -> Bool
$c> :: ExpVal -> ExpVal -> Bool
<= :: ExpVal -> ExpVal -> Bool
$c<= :: ExpVal -> ExpVal -> Bool
< :: ExpVal -> ExpVal -> Bool
$c< :: ExpVal -> ExpVal -> Bool
compare :: ExpVal -> ExpVal -> Ordering
$ccompare :: ExpVal -> ExpVal -> Ordering
Ord, Int -> ExpVal -> ShowS
[ExpVal] -> ShowS
ExpVal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExpVal] -> ShowS
$cshowList :: [ExpVal] -> ShowS
show :: ExpVal -> String
$cshow :: ExpVal -> String
showsPrec :: Int -> ExpVal -> ShowS
$cshowsPrec :: Int -> ExpVal -> ShowS
Show, Typeable ExpVal
ExpVal -> DataType
ExpVal -> Constr
(forall b. Data b => b -> b) -> ExpVal -> ExpVal
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ExpVal -> u
forall u. (forall d. Data d => d -> u) -> ExpVal -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ExpVal -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ExpVal -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ExpVal
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ExpVal -> c ExpVal
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ExpVal)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ExpVal)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ExpVal -> m ExpVal
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ExpVal -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ExpVal -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ExpVal -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ExpVal -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ExpVal -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ExpVal -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ExpVal -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ExpVal -> r
gmapT :: (forall b. Data b => b -> b) -> ExpVal -> ExpVal
$cgmapT :: (forall b. Data b => b -> b) -> ExpVal -> ExpVal
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ExpVal)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ExpVal)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ExpVal)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ExpVal)
dataTypeOf :: ExpVal -> DataType
$cdataTypeOf :: ExpVal -> DataType
toConstr :: ExpVal -> Constr
$ctoConstr :: ExpVal -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ExpVal
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ExpVal
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ExpVal -> c ExpVal
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ExpVal -> c ExpVal
Data, forall x. Rep ExpVal x -> ExpVal
forall x. ExpVal -> Rep ExpVal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExpVal x -> ExpVal
$cfrom :: forall x. ExpVal -> Rep ExpVal x
Generic)
    deriving anyclass (ExpVal -> ()
forall a. (a -> ()) -> NFData a
rnf :: ExpVal -> ()
$crnf :: ExpVal -> ()
NFData, [ExpVal] -> Encoding
[ExpVal] -> Value
ExpVal -> Encoding
ExpVal -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ExpVal] -> Encoding
$ctoEncodingList :: [ExpVal] -> Encoding
toJSONList :: [ExpVal] -> Value
$ctoJSONList :: [ExpVal] -> Value
toEncoding :: ExpVal -> Encoding
$ctoEncoding :: ExpVal -> Encoding
toJSON :: ExpVal -> Value
$ctoJSON :: ExpVal -> Value
ToJSON, Value -> Parser [ExpVal]
Value -> Parser ExpVal
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ExpVal]
$cparseJSONList :: Value -> Parser [ExpVal]
parseJSON :: Value -> Parser ExpVal
$cparseJSON :: Value -> Parser ExpVal
FromJSON)