module Language.Drasil.CodeExpr.Extract (
    eDep, eDep',
    eNamesRI, eNamesRI'
) where

import Language.Drasil.Space (RealInterval(..))
import Language.Drasil.UID (UID)

import Language.Drasil.CodeExpr.Lang (CodeExpr(..))

import Data.Containers.ListUtils (nubOrd)

-- | Generic traverse of all expressions that could lead to names.
eNames :: CodeExpr -> [UID]
eNames :: CodeExpr -> [UID]
eNames (AssocA AssocArithOper
_ [CodeExpr]
l)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
l
eNames (AssocB AssocBoolOper
_ [CodeExpr]
l)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
l
eNames (AssocC AssocConcatOper
_ [CodeExpr]
l)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
l
eNames (C UID
c)                 = [UID
c]
eNames Lit{}                 = []
eNames (FCall UID
f [CodeExpr]
x [(UID, CodeExpr)]
ns)        = UID
f UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
x [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                              ((UID, CodeExpr) -> [UID]) -> [(UID, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((UID, CodeExpr) -> CodeExpr) -> (UID, CodeExpr) -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(UID, CodeExpr)]
ns
eNames (New UID
c [CodeExpr]
x [(UID, CodeExpr)]
ns)          = UID
c UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
x [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                              ((UID, CodeExpr) -> [UID]) -> [(UID, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((UID, CodeExpr) -> CodeExpr) -> (UID, CodeExpr) -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(UID, CodeExpr)]
ns
eNames (Message UID
a UID
m [CodeExpr]
x [(UID, CodeExpr)]
ns)    = UID
a UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: UID
m UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
x [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                              ((UID, CodeExpr) -> [UID]) -> [(UID, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((UID, CodeExpr) -> CodeExpr) -> (UID, CodeExpr) -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(UID, CodeExpr)]
ns
eNames (Field UID
o UID
f)           = [UID
o, UID
f]
eNames (Case Completeness
_ [(CodeExpr, CodeExpr)]
ls)           = ((CodeExpr, CodeExpr) -> [UID]) -> [(CodeExpr, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((CodeExpr, CodeExpr) -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr, CodeExpr) -> CodeExpr
forall a b. (a, b) -> a
fst) [(CodeExpr, CodeExpr)]
ls [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((CodeExpr, CodeExpr) -> [UID]) -> [(CodeExpr, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((CodeExpr, CodeExpr) -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(CodeExpr, CodeExpr)]
ls
eNames (UnaryOp UFunc
_ CodeExpr
u)         = CodeExpr -> [UID]
eNames CodeExpr
u
eNames (UnaryOpB UFuncB
_ CodeExpr
u)        = CodeExpr -> [UID]
eNames CodeExpr
u
eNames (UnaryOpVV UFuncVV
_ CodeExpr
u)       = CodeExpr -> [UID]
eNames CodeExpr
u
eNames (UnaryOpVN UFuncVN
_ CodeExpr
u)       = CodeExpr -> [UID]
eNames CodeExpr
u
eNames (ArithBinaryOp ArithBinOp
_ CodeExpr
a CodeExpr
b) = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (BoolBinaryOp BoolBinOp
_ CodeExpr
a CodeExpr
b)  = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (EqBinaryOp EqBinOp
_ CodeExpr
a CodeExpr
b)    = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (LABinaryOp LABinOp
_ CodeExpr
a CodeExpr
b)    = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (OrdBinaryOp OrdBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (VVVBinaryOp VVVBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (VVNBinaryOp VVNBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (NVVBinaryOp NVVBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
b
eNames (ESSBinaryOp ESSBinOp
_ CodeExpr
_ CodeExpr
s)   = CodeExpr -> [UID]
eNames CodeExpr
s
eNames (ESBBinaryOp ESBBinOp
_ CodeExpr
_ CodeExpr
s)   = CodeExpr -> [UID]
eNames CodeExpr
s
eNames (Operator AssocArithOper
_ DiscreteDomainDesc CodeExpr CodeExpr
_ CodeExpr
e)      = CodeExpr -> [UID]
eNames CodeExpr
e
eNames (Matrix [[CodeExpr]]
a)            = ([CodeExpr] -> [UID]) -> [[CodeExpr]] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames) [[CodeExpr]]
a
eNames (Set Space
_ [CodeExpr]
a)             = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames [CodeExpr]
a
eNames (Variable String
_ CodeExpr
e)        = CodeExpr -> [UID]
eNames CodeExpr
e
eNames (RealI UID
c RealInterval CodeExpr CodeExpr
b)           = UID
c UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: RealInterval CodeExpr CodeExpr -> [UID]
eNamesRI RealInterval CodeExpr CodeExpr
b

-- | Generic traversal of everything that could come from an interval to names (similar to 'eNames').
eNamesRI :: RealInterval CodeExpr CodeExpr -> [UID]
eNamesRI :: RealInterval CodeExpr CodeExpr -> [UID]
eNamesRI (Bounded (Inclusive
_, CodeExpr
il) (Inclusive
_, CodeExpr
iu)) = CodeExpr -> [UID]
eNames CodeExpr
il [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames CodeExpr
iu
eNamesRI (UpTo (Inclusive
_, CodeExpr
iu))           = CodeExpr -> [UID]
eNames CodeExpr
iu
eNamesRI (UpFrom (Inclusive
_, CodeExpr
il))         = CodeExpr -> [UID]
eNames CodeExpr
il

-- | Generic traverse of all positions that could lead to 'eNames' without
-- functions.  FIXME : this should really be done via post-facto filtering, but
-- right now the information needed to do this is not available!
eNames' :: CodeExpr -> [UID]
eNames' :: CodeExpr -> [UID]
eNames' (AssocA AssocArithOper
_ [CodeExpr]
l)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
l
eNames' (AssocB AssocBoolOper
_ [CodeExpr]
l)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
l
eNames' (AssocC AssocConcatOper
_ [CodeExpr]
l)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
l
eNames' (C UID
c)                 = [UID
c]
eNames' Lit{}                 = []
eNames' (FCall UID
_ [CodeExpr]
x [(UID, CodeExpr)]
ns)        = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
x [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                               ((UID, CodeExpr) -> [UID]) -> [(UID, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((UID, CodeExpr) -> CodeExpr) -> (UID, CodeExpr) -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(UID, CodeExpr)]
ns
eNames' (New UID
_ [CodeExpr]
x [(UID, CodeExpr)]
ns)          = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
x [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                               ((UID, CodeExpr) -> [UID]) -> [(UID, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((UID, CodeExpr) -> CodeExpr) -> (UID, CodeExpr) -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(UID, CodeExpr)]
ns
eNames' (Message UID
a UID
_ [CodeExpr]
x [(UID, CodeExpr)]
ns)    = UID
a UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
x [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ ((UID, CodeExpr) -> UID) -> [(UID, CodeExpr)] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (UID, CodeExpr) -> UID
forall a b. (a, b) -> a
fst [(UID, CodeExpr)]
ns [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                               ((UID, CodeExpr) -> [UID]) -> [(UID, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames (CodeExpr -> [UID])
-> ((UID, CodeExpr) -> CodeExpr) -> (UID, CodeExpr) -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(UID, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(UID, CodeExpr)]
ns
eNames' (Field UID
o UID
f)           = [UID
o, UID
f]
eNames' (Case Completeness
_ [(CodeExpr, CodeExpr)]
ls)           = ((CodeExpr, CodeExpr) -> [UID]) -> [(CodeExpr, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames' (CodeExpr -> [UID])
-> ((CodeExpr, CodeExpr) -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr, CodeExpr) -> CodeExpr
forall a b. (a, b) -> a
fst) [(CodeExpr, CodeExpr)]
ls [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ 
                               ((CodeExpr, CodeExpr) -> [UID]) -> [(CodeExpr, CodeExpr)] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CodeExpr -> [UID]
eNames' (CodeExpr -> [UID])
-> ((CodeExpr, CodeExpr) -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd) [(CodeExpr, CodeExpr)]
ls
eNames' (UnaryOp UFunc
_ CodeExpr
u)         = CodeExpr -> [UID]
eNames' CodeExpr
u
eNames' (UnaryOpB UFuncB
_ CodeExpr
u)        = CodeExpr -> [UID]
eNames' CodeExpr
u
eNames' (UnaryOpVV UFuncVV
_ CodeExpr
u)       = CodeExpr -> [UID]
eNames' CodeExpr
u
eNames' (UnaryOpVN UFuncVN
_ CodeExpr
u)       = CodeExpr -> [UID]
eNames' CodeExpr
u
eNames' (ArithBinaryOp ArithBinOp
_ CodeExpr
a CodeExpr
b) = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (BoolBinaryOp BoolBinOp
_ CodeExpr
a CodeExpr
b)  = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (EqBinaryOp EqBinOp
_ CodeExpr
a CodeExpr
b)    = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (LABinaryOp LABinOp
_ CodeExpr
a CodeExpr
b)    = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (OrdBinaryOp OrdBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (VVVBinaryOp VVVBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (VVNBinaryOp VVNBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (NVVBinaryOp NVVBinOp
_ CodeExpr
a CodeExpr
b)   = CodeExpr -> [UID]
eNames' CodeExpr
a [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' CodeExpr
b
eNames' (ESSBinaryOp ESSBinOp
_ CodeExpr
_ CodeExpr
s)   = CodeExpr -> [UID]
eNames' CodeExpr
s
eNames' (ESBBinaryOp ESBBinOp
_ CodeExpr
_ CodeExpr
s)   = CodeExpr -> [UID]
eNames' CodeExpr
s
eNames' (Operator AssocArithOper
_ DiscreteDomainDesc CodeExpr CodeExpr
_ CodeExpr
e)      = CodeExpr -> [UID]
eNames' CodeExpr
e
eNames' (Matrix [[CodeExpr]]
a)            = ([CodeExpr] -> [UID]) -> [[CodeExpr]] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames') [[CodeExpr]]
a
eNames' (Set Space
_ [CodeExpr]
a)             = (CodeExpr -> [UID]) -> [CodeExpr] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CodeExpr -> [UID]
eNames' [CodeExpr]
a
eNames' (Variable String
_ CodeExpr
e)        = CodeExpr -> [UID]
eNames' CodeExpr
e
eNames' (RealI UID
c RealInterval CodeExpr CodeExpr
b)           = UID
c UID -> [UID] -> [UID]
forall a. a -> [a] -> [a]
: RealInterval CodeExpr CodeExpr -> [UID]
eNamesRI' RealInterval CodeExpr CodeExpr
b

-- | Generic traversal of everything that could come from an interval to names without functions (similar to 'eNames'').
eNamesRI' :: RealInterval CodeExpr CodeExpr -> [UID]
eNamesRI' :: RealInterval CodeExpr CodeExpr -> [UID]
eNamesRI' (Bounded (Inclusive, CodeExpr)
il (Inclusive, CodeExpr)
iu) = CodeExpr -> [UID]
eNames' ((Inclusive, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd (Inclusive, CodeExpr)
il) [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ CodeExpr -> [UID]
eNames' ((Inclusive, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd (Inclusive, CodeExpr)
iu)
eNamesRI' (UpTo (Inclusive, CodeExpr)
iu)       = CodeExpr -> [UID]
eNames' ((Inclusive, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd (Inclusive, CodeExpr)
iu)
eNamesRI' (UpFrom (Inclusive, CodeExpr)
il)     = CodeExpr -> [UID]
eNames' ((Inclusive, CodeExpr) -> CodeExpr
forall a b. (a, b) -> b
snd (Inclusive, CodeExpr)
il)

---------------------------------------------------------------------------
-- And now implement the exported traversals all in terms of the above

-- | Get dependencies from an equation.
eDep :: CodeExpr -> [UID]
eDep :: CodeExpr -> [UID]
eDep = [UID] -> [UID]
forall a. Ord a => [a] -> [a]
nubOrd ([UID] -> [UID]) -> (CodeExpr -> [UID]) -> CodeExpr -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeExpr -> [UID]
eNames

-- | Get dependencies from an equation, without functions.
eDep' :: CodeExpr -> [UID]
eDep' :: CodeExpr -> [UID]
eDep' = [UID] -> [UID]
forall a. Ord a => [a] -> [a]
nubOrd ([UID] -> [UID]) -> (CodeExpr -> [UID]) -> CodeExpr -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeExpr -> [UID]
eNames'