-- | Parsing of unions.
module Data.GI.GIR.Union
    ( Union(..)
    , parseUnion
    ) where

import Data.Maybe (isJust)
import Data.Text (Text)

import Data.GI.GIR.Allocation (AllocationInfo(..), unknownAllocationInfo)
import Data.GI.GIR.Field (Field, parseFields)
import Data.GI.GIR.Method (Method, MethodType(..), parseMethod)
import Data.GI.GIR.Parser
import Data.GI.GIR.Type (queryCType)

data Union = Union {
    Union -> Bool
unionIsBoxed :: Bool,
    Union -> AllocationInfo
unionAllocationInfo :: AllocationInfo,
    Union -> Documentation
unionDocumentation :: Documentation,
    Union -> Int
unionSize :: Int,
    Union -> Maybe Text
unionTypeInit :: Maybe Text,
    Union -> [Field]
unionFields :: [Field],
    Union -> [Method]
unionMethods :: [Method],
    Union -> Maybe Text
unionCType :: Maybe Text,
    Union -> Maybe DeprecationInfo
unionDeprecated :: Maybe DeprecationInfo }
    deriving Int -> Union -> ShowS
[Union] -> ShowS
Union -> String
(Int -> Union -> ShowS)
-> (Union -> String) -> ([Union] -> ShowS) -> Show Union
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Union] -> ShowS
$cshowList :: [Union] -> ShowS
show :: Union -> String
$cshow :: Union -> String
showsPrec :: Int -> Union -> ShowS
$cshowsPrec :: Int -> Union -> ShowS
Show

parseUnion :: Parser (Name, Union)
parseUnion :: Parser (Name, Union)
parseUnion = do
  Name
name <- Parser Name
parseName
  Maybe DeprecationInfo
deprecated <- Parser (Maybe DeprecationInfo)
parseDeprecation
  Documentation
doc <- Parser Documentation
parseDocumentation
  Maybe Text
typeInit <- GIRXMLNamespace -> Name -> Parser (Maybe Text)
queryAttrWithNamespace GIRXMLNamespace
GLibGIRNS "get-type"
  [Field]
fields <- Parser [Field]
parseFields
  [Method]
constructors <- Text -> Parser Method -> Parser [Method]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "constructor" (MethodType -> Parser Method
parseMethod MethodType
Constructor)
  [Method]
methods <- Text -> Parser Method -> Parser [Method]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "method" (MethodType -> Parser Method
parseMethod MethodType
OrdinaryMethod)
  [Method]
functions <- Text -> Parser Method -> Parser [Method]
forall a. Text -> Parser a -> Parser [a]
parseChildrenWithLocalName "function" (MethodType -> Parser Method
parseMethod MethodType
MemberFunction)
  Maybe Text
ctype <- Parser (Maybe Text)
queryCType

  (Name, Union) -> Parser (Name, Union)
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
name,
          Union :: Bool
-> AllocationInfo
-> Documentation
-> Int
-> Maybe Text
-> [Field]
-> [Method]
-> Maybe Text
-> Maybe DeprecationInfo
-> Union
Union {
            unionIsBoxed :: Bool
unionIsBoxed = Maybe Text -> Bool
forall a. Maybe a -> Bool
isJust Maybe Text
typeInit
          , unionAllocationInfo :: AllocationInfo
unionAllocationInfo = AllocationInfo
unknownAllocationInfo
          , unionDocumentation :: Documentation
unionDocumentation = Documentation
doc
          , unionTypeInit :: Maybe Text
unionTypeInit = Maybe Text
typeInit
          , unionSize :: Int
unionSize = String -> Int
forall a. HasCallStack => String -> a
error ("unfixed union size " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. Show a => a -> String
show Name
name)
          , unionFields :: [Field]
unionFields = [Field]
fields
          , unionMethods :: [Method]
unionMethods = [Method]
constructors [Method] -> [Method] -> [Method]
forall a. [a] -> [a] -> [a]
++ [Method]
methods [Method] -> [Method] -> [Method]
forall a. [a] -> [a] -> [a]
++ [Method]
functions
          , unionCType :: Maybe Text
unionCType = Maybe Text
ctype
          , unionDeprecated :: Maybe DeprecationInfo
unionDeprecated = Maybe DeprecationInfo
deprecated
          })