{-# OPTIONS -fno-warn-name-shadowing #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE NoImplicitPrelude  #-}
-- | This module is designed to be imported qualified.
module Language.Haskell.Names.GlobalSymbolTable
  ( Table
  , empty
  , Result(..)
  , lookupValue
  , lookupType
  , fromLists
  , types
  , values
  , toSymbols
  ) where

import           Fay.Compiler.Prelude               hiding (empty)
import           Language.Haskell.Names.SyntaxUtils
import           Language.Haskell.Names.Types

import           Data.Lens.Light
import qualified Data.Map                           as Map
import qualified Data.Set                           as Set
import           Language.Haskell.Exts    as HSE
import           Data.Semigroup (Semigroup)

-- | Global symbol table — contains global names
data Table =
  Table
    (Map.Map GName (Set.Set (SymValueInfo OrigName)))
    (Map.Map GName (Set.Set (SymTypeInfo  OrigName)))
    deriving (Table -> Table -> Bool
(Table -> Table -> Bool) -> (Table -> Table -> Bool) -> Eq Table
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Table -> Table -> Bool
$c/= :: Table -> Table -> Bool
== :: Table -> Table -> Bool
$c== :: Table -> Table -> Bool
Eq, Eq Table
Eq Table =>
(Table -> Table -> Ordering)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Table)
-> (Table -> Table -> Table)
-> Ord Table
Table -> Table -> Bool
Table -> Table -> Ordering
Table -> Table -> Table
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 :: Table -> Table -> Table
$cmin :: Table -> Table -> Table
max :: Table -> Table -> Table
$cmax :: Table -> Table -> Table
>= :: Table -> Table -> Bool
$c>= :: Table -> Table -> Bool
> :: Table -> Table -> Bool
$c> :: Table -> Table -> Bool
<= :: Table -> Table -> Bool
$c<= :: Table -> Table -> Bool
< :: Table -> Table -> Bool
$c< :: Table -> Table -> Bool
compare :: Table -> Table -> Ordering
$ccompare :: Table -> Table -> Ordering
$cp1Ord :: Eq Table
Ord, Int -> Table -> ShowS
[Table] -> ShowS
Table -> String
(Int -> Table -> ShowS)
-> (Table -> String) -> ([Table] -> ShowS) -> Show Table
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Table] -> ShowS
$cshowList :: [Table] -> ShowS
show :: Table -> String
$cshow :: Table -> String
showsPrec :: Int -> Table -> ShowS
$cshowsPrec :: Int -> Table -> ShowS
Show, Typeable Table
DataType
Constr
Typeable Table =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Table -> c Table)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Table)
-> (Table -> Constr)
-> (Table -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Table))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table))
-> ((forall b. Data b => b -> b) -> Table -> Table)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r)
-> (forall u. (forall d. Data d => d -> u) -> Table -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Table -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Table -> m Table)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Table -> m Table)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Table -> m Table)
-> Data Table
Table -> DataType
Table -> Constr
(forall b. Data b => b -> b) -> Table -> Table
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
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) -> Table -> u
forall u. (forall d. Data d => d -> u) -> Table -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Table -> m Table
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table -> m Table
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Table)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table)
$cTable :: Constr
$tTable :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Table -> m Table
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table -> m Table
gmapMp :: (forall d. Data d => d -> m d) -> Table -> m Table
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table -> m Table
gmapM :: (forall d. Data d => d -> m d) -> Table -> m Table
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Table -> m Table
gmapQi :: Int -> (forall d. Data d => d -> u) -> Table -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Table -> u
gmapQ :: (forall d. Data d => d -> u) -> Table -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Table -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
gmapT :: (forall b. Data b => b -> b) -> Table -> Table
$cgmapT :: (forall b. Data b => b -> b) -> Table -> Table
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Table)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Table)
dataTypeOf :: Table -> DataType
$cdataTypeOf :: Table -> DataType
toConstr :: Table -> Constr
$ctoConstr :: Table -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
$cp1Data :: Typeable Table
Data, Typeable)

valLens :: Lens Table (Map.Map GName (Set.Set (SymValueInfo OrigName)))
valLens :: Lens Table (Map GName (Set (SymValueInfo OrigName)))
valLens = (Table -> Map GName (Set (SymValueInfo OrigName)))
-> (Map GName (Set (SymValueInfo OrigName)) -> Table -> Table)
-> Lens Table (Map GName (Set (SymValueInfo OrigName)))
forall a b. (a -> b) -> (b -> a -> a) -> Lens a b
lens (\(Table vs :: Map GName (Set (SymValueInfo OrigName))
vs _) -> Map GName (Set (SymValueInfo OrigName))
vs) (\vs :: Map GName (Set (SymValueInfo OrigName))
vs (Table _ ts :: Map GName (Set (SymTypeInfo OrigName))
ts) -> Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
Table Map GName (Set (SymValueInfo OrigName))
vs Map GName (Set (SymTypeInfo OrigName))
ts)

tyLens :: Lens Table (Map.Map GName (Set.Set (SymTypeInfo OrigName)))
tyLens :: Lens Table (Map GName (Set (SymTypeInfo OrigName)))
tyLens = (Table -> Map GName (Set (SymTypeInfo OrigName)))
-> (Map GName (Set (SymTypeInfo OrigName)) -> Table -> Table)
-> Lens Table (Map GName (Set (SymTypeInfo OrigName)))
forall a b. (a -> b) -> (b -> a -> a) -> Lens a b
lens (\(Table _ ts :: Map GName (Set (SymTypeInfo OrigName))
ts) -> Map GName (Set (SymTypeInfo OrigName))
ts) (\ts :: Map GName (Set (SymTypeInfo OrigName))
ts (Table vs :: Map GName (Set (SymValueInfo OrigName))
vs _) -> Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
Table Map GName (Set (SymValueInfo OrigName))
vs Map GName (Set (SymTypeInfo OrigName))
ts)

instance Semigroup Table where
  (Table vs1 :: Map GName (Set (SymValueInfo OrigName))
vs1 ts1 :: Map GName (Set (SymTypeInfo OrigName))
ts1) <> :: Table -> Table -> Table
<> (Table vs2 :: Map GName (Set (SymValueInfo OrigName))
vs2 ts2 :: Map GName (Set (SymTypeInfo OrigName))
ts2) =
    Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
Table (Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymValueInfo OrigName))
forall i k.
(Ord i, Ord k) =>
Map k (Set i) -> Map k (Set i) -> Map k (Set i)
j Map GName (Set (SymValueInfo OrigName))
vs1 Map GName (Set (SymValueInfo OrigName))
vs2) (Map GName (Set (SymTypeInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName))
forall i k.
(Ord i, Ord k) =>
Map k (Set i) -> Map k (Set i) -> Map k (Set i)
j Map GName (Set (SymTypeInfo OrigName))
ts1 Map GName (Set (SymTypeInfo OrigName))
ts2)
    where
      j :: (Ord i, Ord k)
        => Map.Map k (Set.Set i)
        -> Map.Map k (Set.Set i)
        -> Map.Map k (Set.Set i)
      j :: Map k (Set i) -> Map k (Set i) -> Map k (Set i)
j = (Set i -> Set i -> Set i)
-> Map k (Set i) -> Map k (Set i) -> Map k (Set i)
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith Set i -> Set i -> Set i
forall a. Ord a => Set a -> Set a -> Set a
Set.union
instance Monoid Table where
  mempty :: Table
mempty = Table
empty
  mappend :: Table -> Table -> Table
mappend = Table -> Table -> Table
forall a. Semigroup a => a -> a -> a
(<>)

toGName :: QName l -> GName
toGName :: QName l -> GName
toGName (UnQual _ n :: Name l
n) = String -> String -> GName
GName "" (Name l -> String
forall l. Name l -> String
nameToString Name l
n)
toGName (Qual _ (ModuleName _ m :: String
m) n :: Name l
n) = String -> String -> GName
GName String
m (Name l -> String
forall l. Name l -> String
nameToString Name l
n)
toGName (HSE.Special _ _) = String -> GName
forall a. HasCallStack => String -> a
error "toGName: Special"

empty :: Table
empty :: Table
empty = Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
Table Map GName (Set (SymValueInfo OrigName))
forall k a. Map k a
Map.empty Map GName (Set (SymTypeInfo OrigName))
forall k a. Map k a
Map.empty

lookupL
  :: HasOrigName i
  => Lens Table (Map.Map GName (Set.Set (i OrigName)))
  -> QName l
  -> Table
  -> Result l (i OrigName)
lookupL :: Lens Table (Map GName (Set (i OrigName)))
-> QName l -> Table -> Result l (i OrigName)
lookupL _ (HSE.Special {}) _ =
  Result l (i OrigName)
forall l a. Result l a
Language.Haskell.Names.GlobalSymbolTable.Special
lookupL lens :: Lens Table (Map GName (Set (i OrigName)))
lens qn :: QName l
qn tbl :: Table
tbl =
  case Set (i OrigName) -> [i OrigName]
forall a. Set a -> [a]
Set.toList (Set (i OrigName) -> [i OrigName])
-> Maybe (Set (i OrigName)) -> Maybe [i OrigName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GName -> Map GName (Set (i OrigName)) -> Maybe (Set (i OrigName))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (QName l -> GName
forall l. QName l -> GName
toGName QName l
qn) (Map GName (Set (i OrigName)) -> Maybe (Set (i OrigName)))
-> Map GName (Set (i OrigName)) -> Maybe (Set (i OrigName))
forall a b. (a -> b) -> a -> b
$ Lens Table (Map GName (Set (i OrigName)))
-> Table -> Map GName (Set (i OrigName))
forall a b. Lens a b -> a -> b
getL Lens Table (Map GName (Set (i OrigName)))
lens Table
tbl) of
    Nothing -> Error l -> Result l (i OrigName)
forall l a. Error l -> Result l a
Error (Error l -> Result l (i OrigName))
-> Error l -> Result l (i OrigName)
forall a b. (a -> b) -> a -> b
$ QName l -> Error l
forall l. QName l -> Error l
ENotInScope QName l
qn
    Just [] -> Error l -> Result l (i OrigName)
forall l a. Error l -> Result l a
Error (Error l -> Result l (i OrigName))
-> Error l -> Result l (i OrigName)
forall a b. (a -> b) -> a -> b
$ QName l -> Error l
forall l. QName l -> Error l
ENotInScope QName l
qn
    Just [i :: i OrigName
i] -> i OrigName -> Result l (i OrigName)
forall l a. a -> Result l a
Result i OrigName
i
    Just is :: [i OrigName]
is -> Error l -> Result l (i OrigName)
forall l a. Error l -> Result l a
Error (Error l -> Result l (i OrigName))
-> Error l -> Result l (i OrigName)
forall a b. (a -> b) -> a -> b
$ QName l -> [OrigName] -> Error l
forall l. QName l -> [OrigName] -> Error l
EAmbiguous QName l
qn ((i OrigName -> OrigName) -> [i OrigName] -> [OrigName]
forall a b. (a -> b) -> [a] -> [b]
map i OrigName -> OrigName
forall (i :: * -> *) n. HasOrigName i => i n -> n
origName [i OrigName]
is)

data Result l a
  = Result a
  | Error (Error l)
  | Special

lookupValue :: QName l -> Table -> Result l (SymValueInfo OrigName)
lookupValue :: QName l -> Table -> Result l (SymValueInfo OrigName)
lookupValue = Lens Table (Map GName (Set (SymValueInfo OrigName)))
-> QName l -> Table -> Result l (SymValueInfo OrigName)
forall (i :: * -> *) l.
HasOrigName i =>
Lens Table (Map GName (Set (i OrigName)))
-> QName l -> Table -> Result l (i OrigName)
lookupL Lens Table (Map GName (Set (SymValueInfo OrigName)))
valLens

lookupType :: QName l -> Table -> Result l (SymTypeInfo OrigName)
lookupType :: QName l -> Table -> Result l (SymTypeInfo OrigName)
lookupType  = Lens Table (Map GName (Set (SymTypeInfo OrigName)))
-> QName l -> Table -> Result l (SymTypeInfo OrigName)
forall (i :: * -> *) l.
HasOrigName i =>
Lens Table (Map GName (Set (i OrigName)))
-> QName l -> Table -> Result l (i OrigName)
lookupL Lens Table (Map GName (Set (SymTypeInfo OrigName)))
tyLens

fromMaps
  :: Map.Map GName (Set.Set (SymValueInfo OrigName))
  -> Map.Map GName (Set.Set (SymTypeInfo  OrigName))
  -> Table
fromMaps :: Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
fromMaps = Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
Table

fromLists
  :: ([(GName, SymValueInfo OrigName)],
      [(GName, SymTypeInfo OrigName)])
  -> Table
fromLists :: ([(GName, SymValueInfo OrigName)], [(GName, SymTypeInfo OrigName)])
-> Table
fromLists (vs :: [(GName, SymValueInfo OrigName)]
vs, ts :: [(GName, SymTypeInfo OrigName)]
ts) =
  Map GName (Set (SymValueInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName)) -> Table
fromMaps
    ((Set (SymValueInfo OrigName)
 -> Set (SymValueInfo OrigName) -> Set (SymValueInfo OrigName))
-> [(GName, Set (SymValueInfo OrigName))]
-> Map GName (Set (SymValueInfo OrigName))
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith Set (SymValueInfo OrigName)
-> Set (SymValueInfo OrigName) -> Set (SymValueInfo OrigName)
forall a. Ord a => Set a -> Set a -> Set a
Set.union ([(GName, Set (SymValueInfo OrigName))]
 -> Map GName (Set (SymValueInfo OrigName)))
-> [(GName, Set (SymValueInfo OrigName))]
-> Map GName (Set (SymValueInfo OrigName))
forall a b. (a -> b) -> a -> b
$ ((GName, SymValueInfo OrigName)
 -> (GName, Set (SymValueInfo OrigName)))
-> [(GName, SymValueInfo OrigName)]
-> [(GName, Set (SymValueInfo OrigName))]
forall a b. (a -> b) -> [a] -> [b]
map ((SymValueInfo OrigName -> Set (SymValueInfo OrigName))
-> (GName, SymValueInfo OrigName)
-> (GName, Set (SymValueInfo OrigName))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SymValueInfo OrigName -> Set (SymValueInfo OrigName)
forall a. a -> Set a
Set.singleton) [(GName, SymValueInfo OrigName)]
vs)
    ((Set (SymTypeInfo OrigName)
 -> Set (SymTypeInfo OrigName) -> Set (SymTypeInfo OrigName))
-> [(GName, Set (SymTypeInfo OrigName))]
-> Map GName (Set (SymTypeInfo OrigName))
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith Set (SymTypeInfo OrigName)
-> Set (SymTypeInfo OrigName) -> Set (SymTypeInfo OrigName)
forall a. Ord a => Set a -> Set a -> Set a
Set.union ([(GName, Set (SymTypeInfo OrigName))]
 -> Map GName (Set (SymTypeInfo OrigName)))
-> [(GName, Set (SymTypeInfo OrigName))]
-> Map GName (Set (SymTypeInfo OrigName))
forall a b. (a -> b) -> a -> b
$ ((GName, SymTypeInfo OrigName)
 -> (GName, Set (SymTypeInfo OrigName)))
-> [(GName, SymTypeInfo OrigName)]
-> [(GName, Set (SymTypeInfo OrigName))]
forall a b. (a -> b) -> [a] -> [b]
map ((SymTypeInfo OrigName -> Set (SymTypeInfo OrigName))
-> (GName, SymTypeInfo OrigName)
-> (GName, Set (SymTypeInfo OrigName))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SymTypeInfo OrigName -> Set (SymTypeInfo OrigName)
forall a. a -> Set a
Set.singleton) [(GName, SymTypeInfo OrigName)]
ts)

values :: Table -> Map.Map GName (Set.Set (SymValueInfo OrigName))
types  :: Table -> Map.Map GName (Set.Set (SymTypeInfo  OrigName))
values :: Table -> Map GName (Set (SymValueInfo OrigName))
values = Lens Table (Map GName (Set (SymValueInfo OrigName)))
-> Table -> Map GName (Set (SymValueInfo OrigName))
forall a b. Lens a b -> a -> b
getL Lens Table (Map GName (Set (SymValueInfo OrigName)))
valLens
types :: Table -> Map GName (Set (SymTypeInfo OrigName))
types = Lens Table (Map GName (Set (SymTypeInfo OrigName)))
-> Table -> Map GName (Set (SymTypeInfo OrigName))
forall a b. Lens a b -> a -> b
getL Lens Table (Map GName (Set (SymTypeInfo OrigName)))
tyLens

toSymbols :: Table -> Symbols
toSymbols :: Table -> Symbols
toSymbols tbl :: Table
tbl =
  Set (SymValueInfo OrigName)
-> Set (SymTypeInfo OrigName) -> Symbols
Symbols
    (Map GName (Set (SymValueInfo OrigName))
-> Set (SymValueInfo OrigName)
forall a k. Ord a => Map k (Set a) -> Set a
gather (Map GName (Set (SymValueInfo OrigName))
 -> Set (SymValueInfo OrigName))
-> Map GName (Set (SymValueInfo OrigName))
-> Set (SymValueInfo OrigName)
forall a b. (a -> b) -> a -> b
$ Table -> Map GName (Set (SymValueInfo OrigName))
values Table
tbl)
    (Map GName (Set (SymTypeInfo OrigName))
-> Set (SymTypeInfo OrigName)
forall a k. Ord a => Map k (Set a) -> Set a
gather (Map GName (Set (SymTypeInfo OrigName))
 -> Set (SymTypeInfo OrigName))
-> Map GName (Set (SymTypeInfo OrigName))
-> Set (SymTypeInfo OrigName)
forall a b. (a -> b) -> a -> b
$ Table -> Map GName (Set (SymTypeInfo OrigName))
types  Table
tbl)
  where
    gather :: Ord a => Map.Map k (Set.Set a) -> Set.Set a
    gather :: Map k (Set a) -> Set a
gather = (Set a -> Set a -> Set a) -> Set a -> Map k (Set a) -> Set a
forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
Set.union Set a
forall a. Set a
Set.empty