Skip to content

@Govelius /I give up
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
D bindings for xcb
--- src/c_client.py 2010-08-13 12:43:31.000000000 +0100
+++ src/d_client.py 2011-08-08 12:58:04.426679530 +0100
@@ -13,9 +13,11 @@
_extension_special_cases = ['XPrint', 'XCMisc', 'BigRequests']
-_cplusplus_annoyances = {'class' : '_class',
- 'new' : '_new',
- 'delete': '_delete'}
+_d_annoyances = {'class' : '_class',
+ 'new' : '_new',
+ 'delete' : '_delete',
+ 'version' : '_version',
+ 'immutable': '_immutable'}
_hlines = []
_hlevel = 0
@@ -23,6 +25,12 @@
_clevel = 0
_ns = None
+def _d(fmt, *args):
+ '''
+ Writes the given line to the header file ( to workaround DMD flaws ).
+ '''
+ _hlines[_hlevel].append(fmt % args)
+
def _h(fmt, *args):
'''
Writes the given line to the header file.
@@ -77,10 +85,10 @@
def _cpp(str):
'''
- Checks for certain C++ reserved words and fixes them.
+ Checks for certain D reserved words and fixes them.
'''
- if str in _cplusplus_annoyances:
- return _cplusplus_annoyances[str]
+ if str in _d_annoyances:
+ return _d_annoyances[str]
else:
return str
@@ -142,21 +150,21 @@
_c_setlevel(0)
_hc('/*')
- _hc(' * This file generated automatically from %s by c_client.py.', _ns.file)
+ _hc(' * This file generated automatically from %s by d_client.py.', _ns.file)
_hc(' * Edit at your peril.')
_hc(' */')
_hc('')
- _h('/**')
- _h(' * @defgroup XCB_%s_API XCB %s API', _ns.ext_name, _ns.ext_name)
- _h(' * @brief %s XCB Protocol Implementation.', _ns.ext_name)
- _h(' * @{')
- _h(' **/')
+# _h('/**')
+# _h(' * @defgroup XCB_%s_API XCB %s API', _ns.ext_name, _ns.ext_name)
+# _h(' * @brief %s XCB Protocol Implementation.', _ns.ext_name)
+# _h(' * @{')
+# _h(' **/')
+# _h('#ifndef __%s_H', _ns.header.upper())
+ _h('module shd.c.xcb.%s;', _ns.header.lower())
_h('')
- _h('#ifndef __%s_H', _ns.header.upper())
- _h('#define __%s_H', _ns.header.upper())
+ _h('import shd.c.xcb.xcb;')
_h('')
- _h('#include "xcb.h"')
_c('#include <string.h>')
_c('#include <assert.h>')
@@ -165,19 +173,19 @@
if _ns.is_ext:
for (n, h) in self.imports:
- _hc('#include "%s.h"', h)
+ _hc('import shd.c.xcb.%s;', h)
- _h('')
- _h('#ifdef __cplusplus')
- _h('extern "C" {')
- _h('#endif')
+# _h('')
+# _h('#ifdef __cplusplus')
+# _h('extern "C" {')
+# _h('#endif')
if _ns.is_ext:
_h('')
- _h('#define XCB_%s_MAJOR_VERSION %s', _ns.ext_name.upper(), _ns.major_version)
- _h('#define XCB_%s_MINOR_VERSION %s', _ns.ext_name.upper(), _ns.minor_version)
- _h(' ') #XXX
- _h('extern xcb_extension_t %s;', _ns.c_ext_global_name)
+ _h('enum XCB_%s_MAJOR_VERSION = %s;', _ns.ext_name.upper(), _ns.major_version)
+ _h('enum XCB_%s_MINOR_VERSION = %s;', _ns.ext_name.upper(), _ns.minor_version)
+ _h('') #XXX
+ _h('extern(C) extern xcb_extension_t %s;', _ns.c_ext_global_name)
_c('')
_c('xcb_extension_t %s = { "%s", 0 };', _ns.c_ext_global_name, _ns.ext_xname)
@@ -191,33 +199,33 @@
_c_setlevel(2)
_hc('')
- _h('')
- _h('#ifdef __cplusplus')
- _h('}')
- _h('#endif')
-
- _h('')
- _h('#endif')
- _h('')
- _h('/**')
- _h(' * @}')
- _h(' */')
+# _h('')
+# _h('#ifdef __cplusplus')
+# _h('}')
+# _h('#endif')
+
+# _h('')
+# _h('#endif')
+# _h('')
+# _h('/**')
+# _h(' * @}')
+# _h(' */')
# Write header file
- hfile = open('%s.h' % _ns.header, 'w')
+ hfile = open('%s.d' % _ns.header, 'w')
for list in _hlines:
for line in list:
hfile.write(line)
hfile.write('\n')
hfile.close()
- # Write source file
- cfile = open('%s.c' % _ns.header, 'w')
- for list in _clines:
- for line in list:
- cfile.write(line)
- cfile.write('\n')
- cfile.close()
+# # Write source file
+# cfile = open('%s.c' % _ns.header, 'w')
+# for list in _clines:
+# for line in list:
+# cfile.write(line)
+# cfile.write('\n')
+# cfile.close()
def build_collision_table():
global namecount
@@ -238,17 +246,18 @@
_h_setlevel(0)
_h('')
- _h('typedef enum %s {', tname)
+ _h('enum /* %s */', tname)
+ _h('{')
count = len(self.values)
for (enam, eval) in self.values:
count = count - 1
- equals = ' = ' if eval != '' else ''
+ equals = '\t= ' if eval != '' else ''
comma = ',' if count > 0 else ''
- _h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
+ _h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
- _h('} %s;', tname)
+ _h('}')
def _c_type_setup(self, name, postfix):
'''
@@ -260,7 +269,7 @@
'''
# Do all the various names in advance
self.c_type = _t(name + postfix)
- self.c_wiretype = 'char' if self.c_type == 'void' else self.c_type
+ self.c_wiretype = 'char' if self.c_type == 'void' else self.c_type # Shahid TODO
self.c_iterator_type = _t(name + ('iterator',))
self.c_next_name = _n(name + ('next',))
@@ -337,11 +346,12 @@
_h('/**')
_h(' * @brief %s', self.c_iterator_type)
_h(' **/')
- _h('typedef struct %s {', self.c_iterator_type)
- _h(' %s *data; /**< */', self.c_type)
- _h(' int%s rem; /**< */', ' ' * (len(self.c_type) - 2))
- _h(' int%s index; /**< */', ' ' * (len(self.c_type) - 2))
- _h('} %s;', self.c_iterator_type)
+ _h('struct %s', self.c_iterator_type)
+ _h('{')
+ _h(' %s* data; /**< */', self.c_type)
+ _h(' int%s rem; /**< */', ' ' * (len(self.c_type) - 2))
+ _h(' int%s index; /**< */', ' ' * (len(self.c_type) - 2))
+ _h('}')
_h_setlevel(1)
_c_setlevel(1)
@@ -359,14 +369,15 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** void %s', self.c_next_name)
- _hc(' ** ')
- _hc(' ** @param %s *i', self.c_iterator_type)
+ _hc(' **')
+ _hc(' ** @param %s* i', self.c_iterator_type)
_hc(' ** @returns void')
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _h('extern(C)')
_hc('void')
- _h('%s (%s *i /**< */);', self.c_next_name, self.c_iterator_type)
+ _h('%s( %s* i /**< */);', self.c_next_name, self.c_iterator_type)
_c('%s (%s *i /**< */)', self.c_next_name, self.c_iterator_type)
_c('{')
@@ -398,14 +409,34 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** xcb_generic_iterator_t %s', self.c_end_name)
- _hc(' ** ')
+ _hc(' **')
_hc(' ** @param %s i', self.c_iterator_type)
_hc(' ** @returns xcb_generic_iterator_t')
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _d('@disable')
+ _h('extern(C)')
_hc('xcb_generic_iterator_t')
- _h('%s (%s i /**< */);', self.c_end_name, self.c_iterator_type)
+ _h('%s( %s i /**< */);', self.c_end_name, self.c_iterator_type)
+ _d('/* DMD sucks */')
+ _d('xcb_generic_iterator_t')
+ _d('%s_D( %s i /**< */);', self.c_end_name, self.c_iterator_type)
+ _d('{')
+ _d(' asm {')
+ _d('')
+ _d(' naked;')
+ _d(' push RDI;')
+ _d(' mov RDI, RSI;')
+ _d(' call %s;', self.c_end_name)
+ _d(' pop RSI;')
+ _d(' mov [RSI ], RAX;')
+ _d(' mov [RSI+8], RDX;')
+ _d(' mov RAX, RSI;')
+ _d(' ret;')
+ _d(' }')
+ _d('}')
+
_c('%s (%s i /**< */)', self.c_end_name, self.c_iterator_type)
_c('{')
_c(' xcb_generic_iterator_t ret;')
@@ -467,15 +498,16 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** %s %s', field.c_field_type, field.c_accessor_name)
- _hc(' ** ')
- _hc(' ** @param const %s *R', self.c_type)
+ _hc(' **')
+ _hc(' ** @param const %s* R', self.c_type)
_hc(' ** @returns %s', field.c_field_type)
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _h('extern(C)')
_hc('%s', field.c_field_type)
- _h('%s (const %s *R /**< */);', field.c_accessor_name, self.c_type)
- _c('%s (const %s *R /**< */)', field.c_accessor_name, self.c_type)
+ _h('%s( const %s* R /**< */);', field.c_accessor_name, self.c_type)
+ _c('%s (const %s* R /**< */)', field.c_accessor_name, self.c_type)
_c('{')
_c(' xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
_c(' return * (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
@@ -486,14 +518,15 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** %s * %s', field.c_field_type, field.c_accessor_name)
- _hc(' ** ')
- _hc(' ** @param const %s *R', self.c_type)
- _hc(' ** @returns %s *', field.c_field_type)
+ _hc(' **')
+ _hc(' ** @param const %s* R', self.c_type)
+ _hc(' ** @returns %s*', field.c_field_type)
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
- _hc('%s *', field.c_field_type)
- _h('%s (const %s *R /**< */);', field.c_accessor_name, self.c_type)
+ _hc('')
+ _h('extern(C)')
+ _hc('%s*', field.c_field_type)
+ _h('%s( const %s* R /**< */);', field.c_accessor_name, self.c_type)
_c('%s (const %s *R /**< */)', field.c_accessor_name, self.c_type)
_c('{')
_c(' xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
@@ -516,14 +549,15 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** %s * %s', field.c_field_type, field.c_accessor_name)
- _hc(' ** ')
- _hc(' ** @param const %s *R', self.c_type)
- _hc(' ** @returns %s *', field.c_field_type)
+ _hc(' **')
+ _hc(' ** @param const %s* R', self.c_type)
+ _hc(' ** @returns %s*', field.c_field_type)
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
- _hc('%s *', field.c_field_type)
- _h('%s (const %s *R /**< */);', field.c_accessor_name, self.c_type)
+ _hc('')
+ _h('extern(C)')
+ _hc('%s*', field.c_field_type)
+ _h('%s( const %s* R /**< */);', field.c_accessor_name, self.c_type)
_c('%s (const %s *R /**< */)', field.c_accessor_name, self.c_type)
_c('{')
@@ -540,14 +574,15 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** int %s', field.c_length_name)
- _hc(' ** ')
- _hc(' ** @param const %s *R', self.c_type)
+ _hc(' **')
+ _hc(' ** @param const %s* R', self.c_type)
_hc(' ** @returns int')
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _h('extern(C)')
_hc('int')
- _h('%s (const %s *R /**< */);', field.c_length_name, self.c_type)
+ _h('%s( const %s* R /**< */);', field.c_length_name, self.c_type)
_c('%s (const %s *R /**< */)', field.c_length_name, self.c_type)
_c('{')
_c(' return %s;', _c_accessor_get_expr(field.type.expr, 'R'))
@@ -559,14 +594,33 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** xcb_generic_iterator_t %s', field.c_end_name)
- _hc(' ** ')
- _hc(' ** @param const %s *R', self.c_type)
+ _hc(' **')
+ _hc(' ** @param const %s* R', self.c_type)
_hc(' ** @returns xcb_generic_iterator_t')
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _d('@disable')
+ _h('extern(C)')
_hc('xcb_generic_iterator_t')
- _h('%s (const %s *R /**< */);', field.c_end_name, self.c_type)
+ _h('%s( const %s* R /**< */);', field.c_end_name, self.c_type)
+ _d('/* DMD sucks */')
+ _d('xcb_generic_iterator_t')
+ _d('%s_D( const %s* R /**< */);', field.c_end_name, self.c_type)
+ _d('{')
+ _d(' asm {')
+ _d('')
+ _d(' naked;')
+ _d(' push RDI;')
+ _d(' mov RDI, RSI;')
+ _d(' call %s;', field.c_end_name)
+ _d(' pop RSI;')
+ _d(' mov [RSI ], RAX;')
+ _d(' mov [RSI+8], RDX;')
+ _d(' mov RAX, RSI;')
+ _d(' ret;')
+ _d(' }')
+ _d('}')
_c('%s (const %s *R /**< */)', field.c_end_name, self.c_type)
_c('{')
_c(' xcb_generic_iterator_t i;')
@@ -588,14 +642,33 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** %s %s', field.c_iterator_type, field.c_iterator_name)
- _hc(' ** ')
- _hc(' ** @param const %s *R', self.c_type)
+ _hc(' **')
+ _hc(' ** @param const %s* R', self.c_type)
_hc(' ** @returns %s', field.c_iterator_type)
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _d('@disable')
+ _h('extern(C)')
_hc('%s', field.c_iterator_type)
- _h('%s (const %s *R /**< */);', field.c_iterator_name, self.c_type)
+ _h('%s( const %s* R /**< */);', field.c_iterator_name, self.c_type)
+ _d('/* DMD sucks */')
+ _d('%s', field.c_iterator_type)
+ _d('%s_D( const %s* R /**< */)', field.c_iterator_name, self.c_type)
+ _d('{')
+ _d(' asm {')
+ _d('')
+ _d(' naked;')
+ _d(' push RDI;')
+ _d(' mov RDI, RSI;')
+ _d(' call %s;', field.c_iterator_name)
+ _d(' pop RSI;')
+ _d(' mov [RSI ], RAX;')
+ _d(' mov [RSI+8], RDX;')
+ _d(' mov RAX, RSI;')
+ _d(' ret;')
+ _d(' }')
+ _d('}')
_c('%s (const %s *R /**< */)', field.c_iterator_name, self.c_type)
_c('{')
_c(' %s i;', field.c_iterator_type)
@@ -624,7 +697,7 @@
def c_simple(self, name):
'''
Exported function that handles cardinal type declarations.
- These are types which are typedef'd to one of the CARDx's, char, float, etc.
+ These are types which are alias'd to one of the CARDx's, char, float, etc.
'''
_c_type_setup(self, name, ())
@@ -633,7 +706,7 @@
_h_setlevel(0)
my_name = _t(name)
_h('')
- _h('typedef %s %s;', _t(self.name), my_name)
+ _h('alias %s %s;', _t(self.name), my_name)
# Iterator
_c_iterator(self, name)
@@ -648,7 +721,8 @@
_h('/**')
_h(' * @brief %s', self.c_type)
_h(' **/')
- _h('typedef %s %s {', self.c_container, self.c_type)
+ _h('%s %s', self.c_container, self.c_type)
+ _h('{')
struct_fields = []
maxtypelen = 0
@@ -666,14 +740,14 @@
struct_fields.append(field)
for field in struct_fields:
- if len(field.c_field_type) > maxtypelen:
- maxtypelen = len(field.c_field_type)
+ if len(field.c_field_type)+len(field.c_subscript) > maxtypelen:
+ maxtypelen = len(field.c_field_type)+len(field.c_subscript)
for field in struct_fields:
- spacing = ' ' * (maxtypelen - len(field.c_field_type))
- _h(' %s%s %s%s; /**< */', field.c_field_type, spacing, field.c_field_name, field.c_subscript)
+ spacing = ' ' * (maxtypelen - len(field.c_field_type)-len(field.c_subscript))
+ _h(' %s%s%s %s; /**< */', field.c_field_type, field.c_subscript, spacing, field.c_field_name)
- _h('} %s;', self.c_type)
+ _h('}')
def c_struct(self, name):
'''
@@ -756,7 +830,7 @@
_h(' * @return A cookie')
_h(' *')
_h(' * Delivers a request to the X server.')
- _h(' * ')
+ _h(' *')
if checked:
_h(' * This form can be used only if the request will not cause')
_h(' * a reply to be generated. Any returned error will be')
@@ -771,26 +845,27 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** %s %s', cookie_type, func_name)
- _hc(' ** ')
+ _hc(' **')
spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
- _hc(' ** @param xcb_connection_t%s *c', spacing)
+ _hc(' ** @param xcb_connection_t*%s c', spacing)
for field in param_fields:
spacing = ' ' * (maxtypelen - len(field.c_field_const_type))
- _hc(' ** @param %s%s %s%s', field.c_field_const_type, spacing, field.c_pointer, field.c_field_name)
+ _hc(' ** @param %s%s%s %s', field.c_field_const_type, field.c_pointer, spacing, field.c_field_name)
_hc(' ** @returns %s', cookie_type)
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
+ _hc('')
+ _h('extern(C)')
_hc('%s', cookie_type)
spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
comma = ',' if len(param_fields) else ');'
- _h('%s (xcb_connection_t%s *c /**< */%s', func_name, spacing, comma)
+ _h('%s( xcb_connection_t*%s c /**< */%s', func_name, spacing, comma)
comma = ',' if len(param_fields) else ')'
- _c('%s (xcb_connection_t%s *c /**< */%s', func_name, spacing, comma)
+ _c('%s( xcb_connection_t*%s c /**< */%s', func_name, spacing, comma)
func_spacing = ' ' * (len(func_name) + 2)
count = len(param_fields)
@@ -798,9 +873,9 @@
count = count - 1
spacing = ' ' * (maxtypelen - len(field.c_field_const_type))
comma = ',' if count else ');'
- _h('%s%s%s %s%s /**< */%s', func_spacing, field.c_field_const_type, spacing, field.c_pointer, field.c_field_name, comma)
+ _h('%s%s%s%s %s /**< */%s', func_spacing, field.c_field_const_type, field.c_pointer, spacing, field.c_field_name, comma)
comma = ',' if count else ')'
- _c('%s%s%s %s%s /**< */%s', func_spacing, field.c_field_const_type, spacing, field.c_pointer, field.c_field_name, comma)
+ _c('%s%s%s%s %s /**< */%s', func_spacing, field.c_field_const_type, field.c_pointer, spacing, field.c_field_name, comma)
count = 2
for field in param_fields:
@@ -874,7 +949,7 @@
_h(' * @param e The xcb_generic_error_t supplied')
_h(' *')
_h(' * Returns the reply of the request asked by')
- _h(' * ')
+ _h(' *')
_h(' * The parameter @p e supplied to this function must be NULL if')
_h(' * %s(). is used.', self.c_unchecked_name)
_h(' * Otherwise, it stores the error if any.')
@@ -886,19 +961,20 @@
_hc('/*****************************************************************************')
_hc(' **')
_hc(' ** %s * %s', self.c_reply_type, self.c_reply_name)
- _hc(' ** ')
- _hc(' ** @param xcb_connection_t%s *c', spacing1)
+ _hc(' **')
+ _hc(' ** @param xcb_connection_t*%s c', spacing1)
_hc(' ** @param %s cookie', self.c_cookie_type)
- _hc(' ** @param xcb_generic_error_t%s **e', spacing2)
- _hc(' ** @returns %s *', self.c_reply_type)
+ _hc(' ** @param xcb_generic_error_t**%s e', spacing2)
+ _hc(' ** @returns %s*', self.c_reply_type)
_hc(' **')
_hc(' *****************************************************************************/')
- _hc(' ')
- _hc('%s *', self.c_reply_type)
- _hc('%s (xcb_connection_t%s *c /**< */,', self.c_reply_name, spacing1)
+ _hc('')
+ _h('extern(C)')
+ _hc('%s*', self.c_reply_type)
+ _hc('%s( xcb_connection_t*%s c /**< */,', self.c_reply_name, spacing1)
_hc('%s%s cookie /**< */,', spacing3, self.c_cookie_type)
- _h('%sxcb_generic_error_t%s **e /**< */);', spacing3, spacing2)
- _c('%sxcb_generic_error_t%s **e /**< */)', spacing3, spacing2)
+ _h('%sxcb_generic_error_t**%s e /**< */);', spacing3, spacing2)
+ _c('%sxcb_generic_error_t**%s e /**< */)', spacing3, spacing2)
_c('{')
_c(' return (%s *) xcb_wait_for_reply(c, cookie.sequence, e);', self.c_reply_type)
_c('}')
@@ -910,7 +986,7 @@
_h_setlevel(0)
_h('')
_h('/** Opcode for %s. */', _n(name))
- _h('#define %s %s', _n(name).upper(), opcode)
+ _h('enum %s = %s;', _n(name).upper(), opcode)
def _c_cookie(self, name):
'''
@@ -921,9 +997,10 @@
_h('/**')
_h(' * @brief %s', self.c_cookie_type)
_h(' **/')
- _h('typedef struct %s {', self.c_cookie_type)
- _h(' unsigned int sequence; /**< */')
- _h('} %s;', self.c_cookie_type)
+ _h('struct %s', self.c_cookie_type)
+ _h('{')
+ _h(' uint sequence; /**< */')
+ _h('}')
def c_request(self, name):
'''
@@ -971,7 +1048,7 @@
else:
# Typedef
_h('')
- _h('typedef %s %s;', _t(self.name + ('event',)), _t(name + ('event',)))
+ _h('alias %s %s;', _t(self.name + ('event',)), _t(name + ('event',)))
def c_error(self, name):
'''
@@ -988,7 +1065,7 @@
else:
# Typedef
_h('')
- _h('typedef %s %s;', _t(self.name + ('error',)), _t(name + ('error',)))
+ _h('alias %s %s;', _t(self.name + ('error',)), _t(name + ('error',)))
# Main routine starts here
@@ -1012,7 +1089,7 @@
opts, args = getopt.getopt(sys.argv[1:], 'p:')
except getopt.GetoptError, err:
print str(err)
- print 'Usage: c_client.py [-p path] file.xml'
+ print 'Usage: d_client.py [-p path] file.xml'
sys.exit(1)
for (opt, arg) in opts:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.