1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
module Wayland.CodeGen.Types
( ProtocolT(..)
, Protocol
, TypedProtocol
, TypedInterfaceDesc
, InterfaceDesc(..)
, EnumDesc(..)
, EntryDesc(..)
, MessageDesc(..)
, MessageType(..)
, ArgumentDesc(..)
, ArgumentType(..)
, ArgumentName(..)
, EnumName(..)
, Description(..)
, TypeInfo(..)
, emptyTypeInfo
, isTypeFree
) where
import qualified Data.Map as M
data ProtocolT i
= Protocol { protName :: !String
, protCopyright :: !(Maybe String)
, protDescription :: !(Maybe Description)
, protInterfaces :: ![i]
}
deriving Show
type Protocol = ProtocolT InterfaceDesc
-- Protocol with type names resolved (avoiding possible name clashes within an interface).
type TypedProtocol = ProtocolT TypedInterfaceDesc
type TypedInterfaceDesc = (InterfaceDesc, TypeInfo)
data InterfaceDesc
= InterfaceDesc { ifName :: !String
, ifVersion :: !Int
, ifDescription :: !(Maybe Description)
, ifEnums :: ![EnumDesc]
, ifRequests :: ![MessageDesc]
, ifEvents :: ![MessageDesc]
}
deriving Show
data EnumDesc
= EnumDesc { enumName :: !String
, enumDescription :: !(Maybe Description)
, enumSince :: !Int
, enumBitfield :: !Bool
, enumEntries :: ![EntryDesc]
}
deriving Show
data EntryDesc
= EntryDesc { entryName :: !String
, entryValue :: !Int
, entryDescription :: !(Maybe Description)
, entrySince :: !Int
, entryDeprecatedSince :: !(Maybe Int)
}
deriving Show
data MessageDesc
= MessageDesc { msgName :: !String
, msgOpCode :: !Int
, msgDescription :: !(Maybe Description)
, msgType :: !MessageType
, msgSince :: !Int
, msgDeprecatedSince :: !(Maybe Int)
, msgArguments :: ![ArgumentDesc]
}
deriving Show
data MessageType
= MessageNormal
| MessageDestructor
deriving (Show, Eq)
data ArgumentDesc
= ArgumentDesc { argName :: !String
, argType :: !ArgumentType
, argDescription :: !(Maybe Description)
, argInterface :: !(Maybe String)
, argEnum :: !(Maybe String)
, argAllowNull :: !Bool
}
deriving Show
data ArgumentType
= ArgumentInt
| ArgumentUInt
| ArgumentFixed
| ArgumentString
| ArgumentArray
| ArgumentFD
| ArgumentNewID
| ArgumentObject
deriving (Show, Eq)
data Description
= Description { descSummary :: !String
, descBody :: !String
}
deriving Show
data ArgumentName
= ArgumentNameNone
| ArgumentNameSingle ArgumentDesc
| ArgumentNameRecord [ArgumentDesc] String
deriving Show
data EnumName
= EnumName EnumDesc String
deriving Show
data TypeInfo
= TypeInfo { typeRequestArgs :: !(M.Map String ArgumentName)
, typeEventArgs :: !(M.Map String ArgumentName)
, typeEnums :: !(M.Map String EnumName)
}
deriving Show
emptyTypeInfo :: TypeInfo
emptyTypeInfo = TypeInfo { typeRequestArgs = M.empty
, typeEventArgs = M.empty
, typeEnums = M.empty
}
isTypeFree :: String -> TypeInfo -> Bool
isTypeFree name types = not $ any (argMatches name) (typeRequestArgs types)
|| any (argMatches name) (typeEventArgs types)
|| any (enumMatches name) (typeEnums types)
where argMatches n (ArgumentNameRecord _ n') = n == n'
argMatches _ _ = False
enumMatches n (EnumName _ n') = n == n'
|