mirror of
https://gitlab.freedesktop.org/xorg/proto/xcbproto.git
synced 2026-05-08 21:48:05 +02:00
Allow access to the original type in the XML
xcbgen 'helpfully' transforms things to C types already so that libxcb does not have to do so. Thus, even though the XML says that a field has type CARD8, xcbgen will claim uint8_t. This might be a bit weird, but is so far totally fine. However, the type mapping that xcbgen uses is not injective. All of CARD8, BYTE and BOOL get turned into uint8_t and the original type is lost. This is totally fine for libxcb, but programming languages other than C do have built in boolean types. My personal problem is with Rust, where providing a boolean for an integer argument causes a compiler error. This results in (relatively) ugly "0 / 1" instead of "false / true". This commit adds a new xml_type member to SimpleType. This type contains the original string that appeared in the XML file. Since libxcb creates instances of SimpleType itself and to avoid breaking the API, the new argument to SimpleType.__init__ defaults to None. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
3cc42f6d23
commit
e79f6b01e0
2 changed files with 22 additions and 19 deletions
|
|
@ -100,12 +100,12 @@ class Module(object):
|
|||
self.add_type('INT16', '', ('int16_t',), tint16)
|
||||
self.add_type('INT32', '', ('int32_t',), tint32)
|
||||
self.add_type('INT64', '', ('int64_t',), tint64)
|
||||
self.add_type('BYTE', '', ('uint8_t',), tcard8)
|
||||
self.add_type('BOOL', '', ('uint8_t',), tcard8)
|
||||
self.add_type('BYTE', '', ('uint8_t',), tbyte)
|
||||
self.add_type('BOOL', '', ('uint8_t',), tbool)
|
||||
self.add_type('char', '', ('char',), tchar)
|
||||
self.add_type('float', '', ('float',), tfloat)
|
||||
self.add_type('double', '', ('double',), tdouble)
|
||||
self.add_type('void', '', ('void',), tcard8)
|
||||
self.add_type('void', '', ('void',), tvoid)
|
||||
|
||||
# This goes out and parses the rest of the XML
|
||||
def register(self):
|
||||
|
|
|
|||
|
|
@ -192,12 +192,12 @@ class SimpleType(PrimitiveType):
|
|||
Any type which is typedef'ed to cardinal will be one of these.
|
||||
|
||||
Public fields added:
|
||||
none
|
||||
xml_type is the original string describing the type in the XML
|
||||
'''
|
||||
def __init__(self, name, size):
|
||||
def __init__(self, name, size, xml_type=None):
|
||||
PrimitiveType.__init__(self, name, size)
|
||||
self.is_simple = True
|
||||
|
||||
self.xml_type = xml_type
|
||||
|
||||
def resolve(self, module):
|
||||
self.resolved = True
|
||||
|
|
@ -206,24 +206,27 @@ class SimpleType(PrimitiveType):
|
|||
|
||||
|
||||
# Cardinal datatype globals. See module __init__ method.
|
||||
tcard8 = SimpleType(('uint8_t',), 1)
|
||||
tcard16 = SimpleType(('uint16_t',), 2)
|
||||
tcard32 = SimpleType(('uint32_t',), 4)
|
||||
tcard64 = SimpleType(('uint64_t',), 8)
|
||||
tint8 = SimpleType(('int8_t',), 1)
|
||||
tint16 = SimpleType(('int16_t',), 2)
|
||||
tint32 = SimpleType(('int32_t',), 4)
|
||||
tint64 = SimpleType(('int64_t',), 8)
|
||||
tchar = SimpleType(('char',), 1)
|
||||
tfloat = SimpleType(('float',), 4)
|
||||
tdouble = SimpleType(('double',), 8)
|
||||
tcard8 = SimpleType(('uint8_t',), 1, 'CARD8')
|
||||
tcard16 = SimpleType(('uint16_t',), 2, 'CARD16')
|
||||
tcard32 = SimpleType(('uint32_t',), 4, 'CARD32')
|
||||
tcard64 = SimpleType(('uint64_t',), 8, 'CARD64')
|
||||
tint8 = SimpleType(('int8_t',), 1, 'INT8')
|
||||
tint16 = SimpleType(('int16_t',), 2, 'INT16')
|
||||
tint32 = SimpleType(('int32_t',), 4, 'INT32')
|
||||
tint64 = SimpleType(('int64_t',), 8, 'INT64')
|
||||
tchar = SimpleType(('char',), 1, 'char')
|
||||
tfloat = SimpleType(('float',), 4, 'float')
|
||||
tdouble = SimpleType(('double',), 8, 'double')
|
||||
tbyte = SimpleType(('uint8_t',), 1, 'BYTE')
|
||||
tbool = SimpleType(('uint8_t',), 1, 'BOOL')
|
||||
tvoid = SimpleType(('uint8_t',), 1, 'void')
|
||||
|
||||
class FileDescriptor(SimpleType):
|
||||
'''
|
||||
Derived class which represents a file descriptor.
|
||||
'''
|
||||
def __init__(self):
|
||||
SimpleType.__init__(self, ('int'), 4)
|
||||
SimpleType.__init__(self, ('int'), 4, 'fd')
|
||||
self.is_fd = True
|
||||
|
||||
def fixed_size(self):
|
||||
|
|
@ -240,7 +243,7 @@ class Enum(SimpleType):
|
|||
bits contains a list of (name, bitnum) tuples. items only appear if specified as a bit. bitnum is a number.
|
||||
'''
|
||||
def __init__(self, name, elt):
|
||||
SimpleType.__init__(self, name, 4)
|
||||
SimpleType.__init__(self, name, 4, 'enum')
|
||||
self.values = []
|
||||
self.bits = []
|
||||
self.doc = None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue