summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUli Schlachter <psychon@znc.in>2019-11-02 14:50:04 +0100
committerUli Schlachter <psychon@znc.in>2019-12-28 08:32:05 +0000
commite79f6b01e04f704c9f158e074ec2654407eae8e4 (patch)
tree5dada2b64decdc7af6060ee3b9817b469d7c6539
parent3cc42f6d233aba508c932a7d1d5578799e9236fa (diff)
downloadxcb-proto-e79f6b01e04f704c9f158e074ec2654407eae8e4.tar.gz
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>
-rw-r--r--xcbgen/state.py6
-rw-r--r--xcbgen/xtypes.py35
2 files changed, 22 insertions, 19 deletions
diff --git a/xcbgen/state.py b/xcbgen/state.py
index a8346bb..0dbecdc 100644
--- a/xcbgen/state.py
+++ b/xcbgen/state.py
@@ -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):
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 8a9d130..3afc812 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -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