xcb-types-0.1.0: Data/XCB/Types.hs
-- |
-- Module : Data.XCB.Types
-- Copyright : (c) Antoine Latter 2008
-- License : BSD3
--
-- Maintainer: Antoine Latter <aslatter@gmail.com>
-- Stability : provisional
-- Portability: portable
--
-- Defines types inteneded to be equivalent to the schema used by
-- the XCB project in their XML protocol description.
--
module Data.XCB.Types where
import qualified Data.List as L
import Control.Monad
-- 'xheader_header' is the name gauranteed to exist, and is used in
-- imports and in type qualifiers.
--
-- 'xheader_name' is the InterCaps name, and should be prefered in the naming
-- of types, functions and haskell modules when available.
-- |This is what a single XML file maps to. It contains some meta-data
-- then declarations.
data XHeader = XHeader {xheader_header :: Name -- ^Name of module. Used in the other modules as a reference.
,xheader_xname :: Maybe Name -- ^Name used to indentify extensions between the X client and server.
,xheader_name :: Maybe Name -- ^InterCaps name.
,xheader_multiword :: Maybe Bool
,xheader_major_version :: Maybe Int
,xheader_minor_version :: Maybe Int
,xheader_decls :: [XDecl] -- ^Declarations contained in this module.
}
deriving (Show)
-- |The different types of declarations which can be made in one of the
-- XML files.
data XDecl = XStruct Name [StructElem]
| XTypeDef Name Type
| XEvent Name Int [StructElem]
| XRequest Name Int [StructElem] (Maybe XReply)
| XidType Name
| XidUnion Name [XidUnionElem]
| XEnum Name [EnumElem]
| XUnion Name [StructElem]
| XImport Name
| XError Name Int [StructElem]
deriving (Show)
data StructElem = Pad Int
| List Name Type (Maybe Expression)
| SField Name Type
| ExprField Name Type Expression
| ValueParam Type MaskName ListName
deriving (Show)
type Name = String
type XReply = [StructElem]
type Ref = String
-- |Types may include a reference to the containing module.
data Type = UnQualType Name
| QualType Name Name
deriving Show
type MaskName = Name
type ListName = Name
data ExInfo = ExInfo Name Name Version
deriving (Show)
type Version = (String,String)
data XidUnionElem = XidUnionElem Type
deriving (Show)
-- Should only ever have expressions of type 'Value' or 'Bit'.
data EnumElem = EnumElem Name (Maybe Expression)
deriving (Show)
-- |Declarations may contain expressions from this small language
data Expression = Value Int -- ^A literal value
| Bit Int -- ^A log-base-2 literal value
| FieldRef String -- ^A reference to a field in the same declaration
| Op Binop Expression Expression -- ^A binary opeation
deriving (Show)
-- |Supported Binary operations.
data Binop = Add
| Sub
| Mult
| Div
| And
| RShift
deriving (Show)