{-# LANGUAGE
RecordWildCards
#-}-- |-- 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.--moduleData.XCB.Types(XHeader,XDecl,StructElem,XidUnionElem,XReply,GenXHeader(..),GenXDecl(..),GenStructElem(..),GenXReply,GenXidUnionElem(..),EnumElem(..),Expression(..),Binop(..),Type(..),EnumVals,MaskVals,Name,Ref,MaskName,ListName,MaskPadding)whereimportControl.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.dataGenXHeadertyp=XHeader{xheader_header::Name-- ^Name of module. Used in the other modules as a reference.,xheader_xname::MaybeName-- ^Name used to indentify extensions between the X client and server.,xheader_name::MaybeName-- ^InterCaps name.,xheader_multiword::MaybeBool,xheader_major_version::MaybeInt,xheader_minor_version::MaybeInt,xheader_decls::[GenXDecltyp]-- ^Declarations contained in this module.}deriving(Show)instanceFunctorGenXHeaderwherefmap=mapTypesmapTypes::(a->b)->GenXHeadera->GenXHeaderbmapTypesfXHeader{..}=XHeaderxheader_headerxheader_xnamexheader_namexheader_multiwordxheader_major_versionxheader_minor_version(map(mapDeclsf)xheader_decls)typeXHeader=GenXHeaderTypetypeXDecl=GenXDeclTypetypeStructElem=GenStructElemTypetypeXidUnionElem=GenXidUnionElemTypetypeXReply=GenXReplyType-- |The different types of declarations which can be made in one of the-- XML files.dataGenXDecltyp=XStructName[GenStructElemtyp]|XTypeDefNametyp|XEventNameInt[GenStructElemtyp](MaybeBool)-- ^ The boolean indicates if the event includes a sequence number.|XRequestNameInt[GenStructElemtyp](Maybe(GenXReplytyp))|XidTypeName|XidUnionName[GenXidUnionElemtyp]|XEnumName[EnumElem]|XUnionName[GenStructElemtyp]|XImportName|XErrorNameInt[GenStructElemtyp]deriving(Show)instanceFunctorGenXDeclwherefmap=mapDeclsmapDecls::(a->b)->GenXDecla->GenXDeclbmapDeclsf=gowherego(XStructnameelems)=XStructname(map(mapSElemf)elems)go(XTypeDefnamet)=XTypeDefname(ft)go(XEventnamenelemsseqNum)=XEventnamen(map(mapSElemf)elems)seqNumgo(XRequestnamenelemsrep)=XRequestnamen(map(mapSElemf)elems)(mapReplyfrep)go(XidTypename)=XidTypenamego(XEnumnameelems)=XEnumnameelemsgo(XUnionnameelems)=XUnionname(map(mapSElemf)elems)go(XidUnionnameelems)=XidUnionname(map(mapUnionsf)elems)go(XImportname)=XImportnamego(XErrornamenelems)=XErrornamen(map(mapSElemf)elems)mapReply::Functorf=>(typ->typ')->f[GenStructElemtyp]->f[GenStructElemtyp']mapReplyf=fmap(map(mapSElemf))dataGenStructElemtyp=PadInt|ListNametyp(MaybeExpression)(Maybe(EnumValstyp))|SFieldNametyp(Maybe(EnumValstyp))(Maybe(MaskValstyp))|ExprFieldNametypExpression|ValueParamtypName(MaybeMaskPadding)ListNamederiving(Show)instanceFunctorGenStructElemwherefmap=mapSElemmapSElem::(typ->typ')->GenStructElemtyp->GenStructElemtyp'mapSElemf=gowherego(Padn)=Padngo(Listnametypexprenum)=Listname(ftyp)expr(liftMfenum)go(SFieldnametypenummask)=SFieldname(ftyp)(liftMfenum)(liftMfmask)go(ExprFieldnametypexpr)=ExprFieldname(ftyp)exprgo(ValueParamtypnamepadlname)=ValueParam(ftyp)namepadlnametypeEnumValstyp=typtypeMaskValstyp=typtypeName=StringtypeGenXReplytyp=[GenStructElemtyp]typeRef=StringtypeMaskName=NametypeListName=NametypeMaskPadding=Int-- |Types may include a reference to the containing module.dataType=UnQualTypeName|QualTypeNameNamederivingShowdataGenXidUnionElemtyp=XidUnionElemtypderiving(Show)instanceFunctorGenXidUnionElemwherefmap=mapUnionsmapUnions::(typ->typ')->GenXidUnionElemtyp->GenXidUnionElemtyp'mapUnionsf(XidUnionElemt)=XidUnionElem(ft)-- Should only ever have expressions of type 'Value' or 'Bit'.dataEnumElem=EnumElemName(MaybeExpression)deriving(Show)-- |Declarations may contain expressions from this small languagedataExpression=ValueInt-- ^A literal value|BitInt-- ^A log-base-2 literal value|FieldRefName-- ^A reference to a field in the same declaration|OpBinopExpressionExpression-- ^A binary opeationderiving(Show)-- |Supported Binary operations.dataBinop=Add|Sub|Mult|Div|And|RShiftderiving(Show)