diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-01-04 09:13:36 +0000 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-01-04 09:13:36 +0000 |
| commit | 5224c7cf675d6c8b2df9b3f4b43f8cd8d4eb8184 (patch) | |
| tree | fc571c8d011bd0b73d932601e0b026f338e5d675 /bindings/utils.py | |
| parent | 42062ff986a344f3f33a4465e106fede10aeaa6a (diff) | |
Bindings: make the binding infrastructure understand GObject-introspections annotations
* bindings/bindings.py
* bindings/utils.py:
add convenience function to treat arguments tuple:
(type,name,{annotations}).
introduce new argument options, fix that arguments are 3-tuple of the
form (type,name,annotations), where annotations is a dictionary.
Key of this dictionnary can be:
- optional, wheter the argument is necessary, it means it has a
default value.
- out, means that the pointer is a pointer of pointer, for bindings
that can return exceptions, it will be returned instead of the
integer error code, the only way to access error codes will be
exceptions.
- element-type, contained type of a list or an array,
- key-type, value-type, type of respectively the key and value of a
GHashTable.
- transfer, wheter a the callee(for arguments)/caller(for return
values) owns the values passed, it can be none,container(if the
callee/caller only owns the container not the contained value) or
full.
doc.parameters is now a 3-tuple of (attribute-name,
attribute-description, attribute-annotations) where
attribute-annotations is a string of the form '(option1)(option2
option-arguments) etc.'.
- add predicates for xml, list and time_t values. improve predicates
for cstring and const modifier.
* bindings/overrides.xml:
'out' arguments are not well supported for java, so skip functions
using them.
* bindings/java/lang.py bindings/php5/php_code.py
bindings/php5/wrapper_source.py bindings/python/lang.py:
- update language specifig binding generators for handling new
annotations.
- improve python method declaration, handle optional arguments with
default values, factorize this chode in two methods,
get_python_arg_decl and defval_to_python_value.
* bindings/python/tests/Makefile.am
bindings/python/tests/idwsf1_tests.py
bindings/python/tests/idwsf2_tests.py:
make test work with out of source build dir.
Diffstat (limited to 'bindings/utils.py')
| -rw-r--r-- | bindings/utils.py | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/bindings/utils.py b/bindings/utils.py index a2370b9c..e1248d92 100644 --- a/bindings/utils.py +++ b/bindings/utils.py @@ -22,6 +22,18 @@ import re import string +_mapping_convert_type_from_gobject_annotation = { + 'utf8': 'char8' +} + +def convert_type_from_gobject_annotation(type): + return _mapping_convert_type_from_gobject_annotation.get(type, type) + +def clean_type(type): + type = type.strip() + type = re.sub('\s+', ' ', type) + return re.sub('\s*\*\s*', '*', type) + def format_as_camelcase(var): '''Format an identifier name into CamelCase''' if '_' in var: @@ -100,3 +112,102 @@ def group(list): +def _test_arg(arg, what): + return bool(arg[2].get(what)) + +def is_optional(arg): + return _test_arg(arg, 'optional') + +def element_type(arg): + return arg[2].get('element-type') + +def key_type(arg): + return arg[2].get('key-type') + +def value_type(arg): + return arg[2].get('value-type') + +def is_out(arg): + return _test_arg(arg, 'out') or arg_type(arg).endswith('**') + +def is_glist(arg): + return re.match('GList\>', var_type(arg)) + +def is_hashtable(arg): + return re.match('GHashTable\>', var_type(arg)) + +def var_type(arg): + '''Return the type of variable to store content''' + if is_out(arg): + return arg[0][:-1] + else: + return arg[0] + +def unref_type(arg): + return (var_type(arg), arg[1], arg[2]) + +def ref_name(arg): + if is_out(arg): + return '&%s' % arg[1] + else: + return arg[1] + +def arg_type(arg): + return arg[0] + +def arg_name(arg): + return arg[1] + +def unconstify(type): + return re.sub(r'\bconst\b\s*', '', type).strip() + +def make_arg(type): + return (type,'',{}) + +def arg_default(arg): + return arg[2].get('default') + +def remove_modifiers(type): + type = re.sub(r'\s*\bunsigned\b\s*', ' ', type).strip() + type = re.sub(r'\s*\bconst\b\s*', ' ', type).strip() + type = re.sub(r'\s*\bsigned\b\s*', ' ', type).strip() + type = re.sub(r'\s*\bvolatile\b\s*', ' ', type).strip() + return clean_type(type) + +def is_const(arg): + return bool(re.search(r'\bconst\b', arg_type(arg))) + +def is_cstring(arg): + return unconstify(arg_type(arg)) in ('char*','gchar*','guchar*') + +def is_xml_node(arg): + return unconstify(arg_type(arg)).startswith('xmlNode') + +def is_boolean(arg): + return arg_type(arg) in ('gboolean','bool') + +def is_pointer(arg): + return arg_type(arg).endswith('*') + +def is_list(arg): + return unconstify(arg_type(arg)).startswith('GList') + +def is_int(arg, binding_data): + return arg_type(arg) in [ 'int', 'gint', 'long', 'glong'] + binding_data.enums + +def is_time_t_pointer(arg): + return re.match(r'\btime_t*', unconstify(arg_type(arg))) + +def is_transfer_full(arg): + transfer = arg[2].get('transfer') + if transfer: + return transfer == 'full' + else: + return is_out(arg) or is_object(arg) + +_not_objects = ( 'GHashTable', 'GList', 'GType' ) + +def is_object(arg): + + t = unconstify(arg_type(arg)) + return t[0] in string.uppercase and not [ x for x in _not_objects if x in t ] |
