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/java | |
parent | 42062ff986a344f3f33a4465e106fede10aeaa6a (diff) | |
download | lasso-5224c7cf675d6c8b2df9b3f4b43f8cd8d4eb8184.tar.gz lasso-5224c7cf675d6c8b2df9b3f4b43f8cd8d4eb8184.tar.xz lasso-5224c7cf675d6c8b2df9b3f4b43f8cd8d4eb8184.zip |
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/java')
-rw-r--r-- | bindings/java/lang.py | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/bindings/java/lang.py b/bindings/java/lang.py index c854ff85..21fb5bd5 100644 --- a/bindings/java/lang.py +++ b/bindings/java/lang.py @@ -24,7 +24,7 @@ import sys import re import textwrap -import utils +from utils import * lasso_package_name = 'com.entrouvert.lasso' lasso_java_path = 'com/entrouvert/lasso/' @@ -39,15 +39,25 @@ def with_return_owner(d): def generate_arg_list(self,args): def arg_to_decl(arg): type, name, option = arg - return self.JNI_arg_type(type) + ' ' + utils.format_as_camelcase(name) - return ', '.join([ arg_to_decl(x) for x in args ]) + return self.JNI_arg_type(type) + ' ' + format_as_camelcase(name) + return ', '.join([ arg_to_decl(x) for x in args if not is_out(x)]) def generate_arg_list2(args): def arg_to_decl(arg): type, name, option = arg - return utils.format_as_camelcase(name) + if is_out(arg): + return 'output' + return format_as_camelcase(name) return ', '.join([ arg_to_decl(x) for x in args ]) +def generate_arg_list3(self,args): + def arg_to_decl(arg): + type, name, option = arg + if is_out(arg): + return 'Object[] output' + return self.JNI_arg_type(type) + ' ' + format_as_camelcase(name) + return ', '.join([ arg_to_decl(x) for x in args]) + def convert_class_name(lasso_name): return lasso_name[5:] @@ -85,8 +95,8 @@ def error_to_exception(error_name): super = 'Lasso' else: super, name = re.match('LASSO(_.*)_ERROR(_.*)', error_name).groups() - super = utils.format_as_camelcase(super.lower()) - name = utils.format_as_camelcase(name.lower()) + super = format_as_camelcase(super.lower()) + name = format_as_camelcase(name.lower()) return (super+name+'Exception',super+'Exception') def wrapper_decl(name, jnitype, fd): @@ -274,17 +284,17 @@ protected static native void destroy(long cptr); else: jtype = self.JNI_return_type(m.return_type) name = self.JNI_function_name(m) - print >> fd, ' public static native %s %s(%s);' % (jtype,name, generate_arg_list(self,m.args)) + print >> fd, ' public static native %s %s(%s);' % (jtype,name, generate_arg_list3(self,m.args)) def JNI_member_function_prefix(self,c,m): klassname = c.name[5:] - mname = utils.format_as_camelcase(m[1]) + mname = format_as_camelcase(m[1]) return '%s_%s' % (klassname,mname) def generate_JNI_member(self, c, fd): for m in c.members: prefix = self.JNI_member_function_prefix(c,m) - mname = utils.format_as_camelcase(m[1]) + mname = format_as_camelcase(m[1]) mtype = m[0] jtype = self.JNI_member_type(m) @@ -691,7 +701,7 @@ protected static native void destroy(long cptr); continue name, = re.match('LASSO_ERROR(.*)',orig).groups() name = name.lower() - name = utils.format_underscore_as_camelcase(name) + name = format_underscore_as_camelcase(name) name = 'Lasso%sException' % name self.generate_exception_class(name, 'LassoException', 0, orig) self.generate_exception_switch_case(efd, name, orig) @@ -726,7 +736,7 @@ protected static native void destroy(long cptr); if m.rename: return m.rename else: - name = utils.format_as_camelcase(m.name[6:]) + name = format_as_camelcase(m.name[6:]) name = name[prefix:] return name[0].lower() + name[1:] for c in self.binding_data.structs: @@ -776,7 +786,7 @@ protected static native void destroy(long cptr); for m in c.members: type, name, options = m prefix = self.JNI_member_function_prefix(c,m) - jname = utils.format_as_camelcase('_'+name) + jname = format_as_camelcase('_'+name) jtype = self.JNI_member_type(m) if type == 'GList*' or type == 'const GList*': print >> fd, ' public void set%s(List list) {' % jname @@ -859,8 +869,10 @@ protected static native void destroy(long cptr); else: print >> fd, ' /**\n' print >> fd, ' *' - for name, desc in doc.parameters: - print >> fd, normalize(desc, ' * @param %s ' % utils.format_as_camelcase(name)) + for p in doc.parameters: + name = p[0] + desc = p[1] + print >> fd, normalize(desc, ' * @param %s ' % format_as_camelcase(name)) if doc.return_value: print >> fd, normalize(doc.return_value, ' * @return ') if m.errors: @@ -868,7 +880,22 @@ protected static native void destroy(long cptr); err = error_to_exception(err)[0] print >> fd, normalize(err,' * @throws ') print >> fd, ' **/' - if m.return_type == 'GList*' or m.return_type == 'const GList*': + outarg = None + for a in args: + if is_out(a): + # only one output arg supported + assert not outarg + outarg = a + if outarg: + assert is_int(make_arg(m.return_type), self.binding_data) + new_return_type = self.JNI_return_type(var_type(outarg)) + print >> fd, ' public %s %s(%s) {' % (new_return_type, mname, generate_arg_list(self, args[1:])) + print >> fd, ' Object[] output = new Object[1];' + print >> fd, ' LassoException.throwError(LassoJNI.%s(this, %s));' % (jni_name, generate_arg_list2(args[1:])) + print >> fd, ' return (%s)output[0];' % new_return_type + print >> fd, ' }' + + elif m.return_type == 'GList*' or m.return_type == 'const GList*': print >> fd, ' public List %s(%s) {' % (mname,generate_arg_list(self,args[1:])) arglist = generate_arg_list2(args[1:]) if arglist: |