module FFICXX.Generate.Type.Module where

--
import FFICXX.Generate.Type.Cabal (AddCInc, AddCSrc)
import FFICXX.Generate.Type.Class (Class, TemplateClass, TopLevel)
import FFICXX.Runtime.CodeGen.Cxx (HeaderName (..), Namespace (..))

--
-- Import/Header
--
--   HPkg is generated C++ headers by fficxx, CPkg is original C++ headers
data ClassImportHeader = ClassImportHeader
  { ClassImportHeader -> Class
cihClass :: Class,
    -- | fficxx-side main header
    ClassImportHeader -> HeaderName
cihSelfHeader :: HeaderName,
    ClassImportHeader -> [Namespace]
cihNamespace :: [Namespace],
    ClassImportHeader -> String
cihSelfCpp :: String,
    -- | Dependencies TODO: clarify this.
    ClassImportHeader -> [Either TemplateClass Class]
cihImportedClasses :: [Either TemplateClass Class],
    ClassImportHeader -> [HeaderName]
cihIncludedHPkgHeadersInH :: [HeaderName], -- TODO: Explain why we need to have these two
    ClassImportHeader -> [HeaderName]
cihIncludedHPkgHeadersInCPP :: [HeaderName], --       separately.

    -- | C++-side headers
    ClassImportHeader -> [HeaderName]
cihIncludedCPkgHeaders :: [HeaderName]
  }
  deriving (Int -> ClassImportHeader -> ShowS
[ClassImportHeader] -> ShowS
ClassImportHeader -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClassImportHeader] -> ShowS
$cshowList :: [ClassImportHeader] -> ShowS
show :: ClassImportHeader -> String
$cshow :: ClassImportHeader -> String
showsPrec :: Int -> ClassImportHeader -> ShowS
$cshowsPrec :: Int -> ClassImportHeader -> ShowS
Show)

--
-- Submodule
--

data ClassSubmoduleType
  = CSTRawType
  | CSTInterface
  | CSTImplementation
  | CSTFFI
  | CSTCast
  deriving (Int -> ClassSubmoduleType -> ShowS
[ClassSubmoduleType] -> ShowS
ClassSubmoduleType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClassSubmoduleType] -> ShowS
$cshowList :: [ClassSubmoduleType] -> ShowS
show :: ClassSubmoduleType -> String
$cshow :: ClassSubmoduleType -> String
showsPrec :: Int -> ClassSubmoduleType -> ShowS
$cshowsPrec :: Int -> ClassSubmoduleType -> ShowS
Show)

data TemplateClassSubmoduleType
  = TCSTTH
  | TCSTTemplate
  deriving (Int -> TemplateClassSubmoduleType -> ShowS
[TemplateClassSubmoduleType] -> ShowS
TemplateClassSubmoduleType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemplateClassSubmoduleType] -> ShowS
$cshowList :: [TemplateClassSubmoduleType] -> ShowS
show :: TemplateClassSubmoduleType -> String
$cshow :: TemplateClassSubmoduleType -> String
showsPrec :: Int -> TemplateClassSubmoduleType -> ShowS
$cshowsPrec :: Int -> TemplateClassSubmoduleType -> ShowS
Show)

-- | UClass = Unified Class, either template class or ordinary class
type UClass = Either TemplateClass Class

type UClassSubmodule =
  Either (TemplateClassSubmoduleType, TemplateClass) (ClassSubmoduleType, Class)

-- | Dependency cycle information. Currently just a string
--                  self,    former,   latter
type DepCycles = [[(String, ([String], [String]))]]

--
-- Module
--

data ClassModule = ClassModule
  { ClassModule -> String
cmModule :: String,
    ClassModule -> ClassImportHeader
cmCIH :: ClassImportHeader,
    -- | imported submodules for Interface.hs
    ClassModule -> [UClassSubmodule]
cmImportedSubmodulesForInterface :: [UClassSubmodule],
    -- | imported submodules for FFI.hs
    ClassModule -> [UClassSubmodule]
cmImportedSubmodulesForFFI :: [UClassSubmodule],
    -- | imported submodules for Cast.hs
    ClassModule -> [UClassSubmodule]
cmImportedSubmodulesForCast,
    -- imported submodules for Implementation.hs
    ClassModule -> [UClassSubmodule]
cmImportedSubmodulesForImplementation ::
      [UClassSubmodule],
    ClassModule -> [String]
cmExtraImport :: [String]
  }
  deriving (Int -> ClassModule -> ShowS
[ClassModule] -> ShowS
ClassModule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClassModule] -> ShowS
$cshowList :: [ClassModule] -> ShowS
show :: ClassModule -> String
$cshow :: ClassModule -> String
showsPrec :: Int -> ClassModule -> ShowS
$cshowsPrec :: Int -> ClassModule -> ShowS
Show)

data TemplateClassModule = TCM
  { TemplateClassModule -> String
tcmModule :: String,
    TemplateClassModule -> TemplateClassImportHeader
tcmTCIH :: TemplateClassImportHeader
  }
  deriving (Int -> TemplateClassModule -> ShowS
[TemplateClassModule] -> ShowS
TemplateClassModule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemplateClassModule] -> ShowS
$cshowList :: [TemplateClassModule] -> ShowS
show :: TemplateClassModule -> String
$cshow :: TemplateClassModule -> String
showsPrec :: Int -> TemplateClassModule -> ShowS
$cshowsPrec :: Int -> TemplateClassModule -> ShowS
Show)

data TemplateClassImportHeader = TCIH
  { TemplateClassImportHeader -> TemplateClass
tcihTClass :: TemplateClass,
    -- | C++-side headers
    TemplateClassImportHeader -> [HeaderName]
tcihCxxHeaders :: [HeaderName]
  }
  deriving (Int -> TemplateClassImportHeader -> ShowS
[TemplateClassImportHeader] -> ShowS
TemplateClassImportHeader -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemplateClassImportHeader] -> ShowS
$cshowList :: [TemplateClassImportHeader] -> ShowS
show :: TemplateClassImportHeader -> String
$cshow :: TemplateClassImportHeader -> String
showsPrec :: Int -> TemplateClassImportHeader -> ShowS
$cshowsPrec :: Int -> TemplateClassImportHeader -> ShowS
Show)

data TopLevelImportHeader = TopLevelImportHeader
  { TopLevelImportHeader -> String
tihHeaderFileName :: String,
    TopLevelImportHeader -> [ClassImportHeader]
tihClassDep :: [ClassImportHeader],
    -- | Extra class dependencies outside current package.
    --   NOTE: we cannot fully construct ClassImportHeader for them.
    TopLevelImportHeader -> [Either TemplateClass Class]
tihExtraClassDep :: [Either TemplateClass Class],
    TopLevelImportHeader -> [TopLevel]
tihFuncs :: [TopLevel],
    TopLevelImportHeader -> [Namespace]
tihNamespaces :: [Namespace],
    TopLevelImportHeader -> [HeaderName]
tihExtraHeadersInH :: [HeaderName],
    TopLevelImportHeader -> [HeaderName]
tihExtraHeadersInCPP :: [HeaderName]
  }
  deriving (Int -> TopLevelImportHeader -> ShowS
[TopLevelImportHeader] -> ShowS
TopLevelImportHeader -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopLevelImportHeader] -> ShowS
$cshowList :: [TopLevelImportHeader] -> ShowS
show :: TopLevelImportHeader -> String
$cshow :: TopLevelImportHeader -> String
showsPrec :: Int -> TopLevelImportHeader -> ShowS
$cshowsPrec :: Int -> TopLevelImportHeader -> ShowS
Show)

--
-- Package-level
--

data PackageConfig = PkgConfig
  { PackageConfig -> [ClassModule]
pcfg_classModules :: [ClassModule],
    PackageConfig -> [ClassImportHeader]
pcfg_classImportHeaders :: [ClassImportHeader],
    PackageConfig -> TopLevelImportHeader
pcfg_topLevelImportHeader :: TopLevelImportHeader,
    PackageConfig -> [TemplateClassModule]
pcfg_templateClassModules :: [TemplateClassModule],
    PackageConfig -> [TemplateClassImportHeader]
pcfg_templateClassImportHeaders :: [TemplateClassImportHeader],
    PackageConfig -> [AddCInc]
pcfg_additional_c_incs :: [AddCInc],
    PackageConfig -> [AddCSrc]
pcfg_additional_c_srcs :: [AddCSrc]
  }