2008-04-29 14:00:40 +02:00
|
|
|
#! /usr/bin/env python
|
2008-04-29 14:03:01 +02:00
|
|
|
#
|
|
|
|
# Lasso - A free implementation of the Liberty Alliance specifications.
|
2008-09-12 17:06:58 +02:00
|
|
|
#
|
2008-04-29 14:03:01 +02:00
|
|
|
# Copyright (C) 2004-2007 Entr'ouvert
|
|
|
|
# http://lasso.entrouvert.org
|
|
|
|
#
|
|
|
|
# Authors: See AUTHORS file in top-level directory.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2013-11-27 20:04:51 +01:00
|
|
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2008-04-29 14:03:01 +02:00
|
|
|
|
2008-04-29 14:00:40 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
2014-12-01 16:53:07 +01:00
|
|
|
from six import print_
|
2008-04-29 14:02:30 +02:00
|
|
|
import sys
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
from utils import *
|
2008-04-29 14:00:40 +02:00
|
|
|
|
2008-04-29 14:03:01 +02:00
|
|
|
from optparse import OptionParser
|
2008-04-29 14:10:03 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
from lxml import etree as ET
|
|
|
|
except ImportError:
|
|
|
|
try:
|
|
|
|
import cElementTree as ET
|
|
|
|
except ImportError:
|
2008-04-29 23:07:28 +02:00
|
|
|
try:
|
|
|
|
import elementtree.ElementTree as ET
|
|
|
|
except ImportError:
|
|
|
|
import xml.etree.ElementTree as ET
|
2008-04-29 14:01:58 +02:00
|
|
|
|
2008-08-05 16:53:35 +02:00
|
|
|
sys.path.append(os.path.dirname(__file__))
|
|
|
|
|
2010-02-01 02:18:03 +01:00
|
|
|
# monkey patch os.path to include relpath if python version is < 2.6
|
|
|
|
if not hasattr(os.path, "relpath"):
|
|
|
|
def relpath(longPath, basePath):
|
|
|
|
if not longPath.startswith(basePath):
|
|
|
|
raise RuntimeError("Unexpected arguments")
|
|
|
|
if longPath == basePath:
|
|
|
|
return "."
|
|
|
|
i = len(basePath)
|
|
|
|
if not basePath.endswith(os.path.sep):
|
|
|
|
i += len(os.path.sep)
|
|
|
|
return longPath[i:]
|
|
|
|
|
|
|
|
os.path.relpath = relpath
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-29 14:01:30 +02:00
|
|
|
class BindingData:
|
2008-04-29 14:03:17 +02:00
|
|
|
src_dir = os.path.dirname(__file__)
|
|
|
|
|
2008-04-29 14:08:43 +02:00
|
|
|
def __init__(self, options = None):
|
2008-04-29 14:01:42 +02:00
|
|
|
self.headers = []
|
2010-01-26 00:47:56 +01:00
|
|
|
# [(char,string)]
|
|
|
|
# where char is:
|
|
|
|
# - i: integer
|
|
|
|
# - s: string
|
2008-04-29 14:01:14 +02:00
|
|
|
self.constants = []
|
|
|
|
self.structs = []
|
2008-04-29 14:01:22 +02:00
|
|
|
self.struct_dict = {}
|
2008-04-29 14:01:14 +02:00
|
|
|
self.functions = []
|
2008-04-29 14:01:42 +02:00
|
|
|
self.enums = []
|
2008-04-29 14:08:43 +02:00
|
|
|
self.options = options
|
2008-04-29 14:03:17 +02:00
|
|
|
self.overrides = ET.parse(os.path.join(self.src_dir, 'overrides.xml'))
|
2009-08-26 17:15:02 +02:00
|
|
|
self.functions_toskip = dict()
|
2010-01-28 16:31:46 +01:00
|
|
|
self.structs_toskip = dict()
|
2009-08-26 17:15:02 +02:00
|
|
|
|
|
|
|
for func in self.overrides.findall('func'):
|
|
|
|
if func.attrib.get('skip') == 'true':
|
|
|
|
self.functions_toskip[func.attrib.get('name')] = 1
|
2010-01-28 16:31:46 +01:00
|
|
|
for struct in self.overrides.findall('struct'):
|
|
|
|
if struct.attrib.get('skip') == 'true':
|
|
|
|
self.structs_toskip[struct.attrib.get('name')] = 1
|
2008-04-29 14:01:14 +02:00
|
|
|
|
2008-04-29 14:08:43 +02:00
|
|
|
def match_tag_language(self,tag):
|
|
|
|
if self.options and self.options.language:
|
|
|
|
languages = tag.attrib.get('language')
|
|
|
|
if languages:
|
|
|
|
lang_list = languages.split(' ')
|
|
|
|
if self.options.language in lang_list:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
2008-04-29 14:01:14 +02:00
|
|
|
def display_structs(self):
|
|
|
|
for struct in self.structs:
|
2008-04-29 14:01:22 +02:00
|
|
|
struct.display()
|
2008-04-29 14:01:14 +02:00
|
|
|
|
|
|
|
def display_funcs(self):
|
|
|
|
for func in self.functions:
|
2014-12-01 11:46:21 +01:00
|
|
|
print(func.return_type, func.name)
|
2008-04-29 14:01:14 +02:00
|
|
|
for a in func.args:
|
2014-12-01 11:46:21 +01:00
|
|
|
print(' ', a)
|
2008-04-29 14:01:14 +02:00
|
|
|
|
2008-04-29 14:01:18 +02:00
|
|
|
def order_class_hierarchy(self):
|
|
|
|
new_order = []
|
|
|
|
while self.structs:
|
|
|
|
for c in self.structs:
|
|
|
|
if c.parent == 'GObject' or c.parent in [x.name for x in new_order]:
|
|
|
|
self.structs.remove(c)
|
|
|
|
new_order.append(c)
|
|
|
|
break
|
|
|
|
self.structs = new_order
|
2008-04-29 14:01:14 +02:00
|
|
|
|
2008-04-29 14:01:22 +02:00
|
|
|
def create_struct_dict(self):
|
|
|
|
for c in self.structs:
|
|
|
|
self.struct_dict[c.name] = c
|
|
|
|
|
|
|
|
def attach_methods(self):
|
|
|
|
self.create_struct_dict()
|
|
|
|
for f in self.functions[:]:
|
|
|
|
if len(f.args) == 0:
|
|
|
|
continue
|
2008-04-29 14:06:30 +02:00
|
|
|
if f.name.endswith('_new') or '_new_' in f.name:
|
2008-04-29 14:01:22 +02:00
|
|
|
# constructor for another class
|
|
|
|
continue
|
|
|
|
arg_type = f.args[0][0]
|
|
|
|
if arg_type[-1] == '*':
|
|
|
|
arg_type = arg_type[:-1]
|
2008-08-05 16:53:29 +02:00
|
|
|
arg_type = arg_type.replace('const ','')
|
2008-04-29 14:01:22 +02:00
|
|
|
c = self.struct_dict.get(arg_type)
|
|
|
|
if not c:
|
|
|
|
continue
|
|
|
|
c.methods.append(f)
|
2008-04-29 14:08:27 +02:00
|
|
|
if f.docstring and f.docstring.parameters:
|
2008-04-29 14:06:21 +02:00
|
|
|
# remove first parameter, which is self/this/etc.
|
|
|
|
f.docstring.parameters = f.docstring.parameters[1:]
|
2008-04-29 14:08:27 +02:00
|
|
|
|
2008-04-29 14:01:22 +02:00
|
|
|
self.functions.remove(f)
|
|
|
|
|
2008-04-29 14:06:30 +02:00
|
|
|
def look_for_docstrings(self, srcdir, exception_doc):
|
|
|
|
def getfunc(name):
|
|
|
|
funcs = [f for f in self.functions if f.name == name]
|
|
|
|
if not funcs:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return funcs[0]
|
2009-03-27 16:04:46 +01:00
|
|
|
regex = re.compile(r'\/\*\*\s(.*?)\*\/', re.DOTALL)
|
2008-04-29 14:03:01 +02:00
|
|
|
for base, dirnames, filenames in os.walk(srcdir):
|
2011-10-18 17:35:55 +02:00
|
|
|
bname = os.path.basename(base)
|
|
|
|
if bname == '.svn':
|
2008-04-29 14:02:56 +02:00
|
|
|
# ignore svn directories
|
|
|
|
continue
|
|
|
|
if not 'Makefile.am' in filenames:
|
|
|
|
# not a source dir
|
|
|
|
continue
|
|
|
|
makefile_am = open(os.path.join(base, 'Makefile.am')).read()
|
|
|
|
filenames = [x for x in filenames if x.endswith('.c') if x in makefile_am]
|
|
|
|
for filename in filenames:
|
|
|
|
s = open(os.path.join(base, filename)).read()
|
|
|
|
docstrings = regex.findall(s)
|
|
|
|
for d in docstrings:
|
|
|
|
docstring = '\n'.join([x[3:] for x in d.splitlines()])
|
|
|
|
function_name = docstring.splitlines(1)[0].strip().strip(':')
|
2008-04-29 14:06:30 +02:00
|
|
|
func = getfunc(function_name)
|
2008-04-29 14:02:56 +02:00
|
|
|
if not func:
|
|
|
|
continue
|
2010-01-04 10:16:00 +01:00
|
|
|
func.docstring = DocString(func, docstring, self)
|
2008-04-29 14:06:30 +02:00
|
|
|
if exception_doc:
|
|
|
|
lines = os.popen('perl ../utility-scripts/error-analyzer.pl %s' % srcdir, 'r').readlines()
|
|
|
|
for line in lines:
|
|
|
|
elts = re.split(r' +',line.strip())
|
|
|
|
func = getfunc(elts[0])
|
|
|
|
if func:
|
|
|
|
func.errors = elts[1:]
|
2008-04-29 14:02:56 +02:00
|
|
|
|
2008-04-29 14:00:58 +02:00
|
|
|
|
|
|
|
class Struct:
|
|
|
|
def __init__(self, name):
|
2008-04-29 14:01:18 +02:00
|
|
|
self.name = name[1:] # skip leading _
|
2008-04-29 14:01:02 +02:00
|
|
|
self.parent = None
|
|
|
|
self.members = []
|
2008-04-29 14:01:22 +02:00
|
|
|
self.methods = []
|
2008-04-29 14:00:58 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
2008-04-29 14:01:02 +02:00
|
|
|
return '<Struct name:%s, childof:%s>' % (self.name, self.parent)
|
2008-04-29 14:00:58 +02:00
|
|
|
|
2008-04-29 14:01:22 +02:00
|
|
|
def display(self):
|
2014-12-01 11:46:21 +01:00
|
|
|
print(self.__repr__())
|
2008-04-29 14:01:22 +02:00
|
|
|
for m in self.members:
|
2014-12-01 11:46:21 +01:00
|
|
|
print(' ', m)
|
2008-04-29 14:01:22 +02:00
|
|
|
for m in self.methods:
|
2014-12-01 11:46:21 +01:00
|
|
|
print(' ', m)
|
2008-04-29 14:01:22 +02:00
|
|
|
|
2010-02-04 23:24:06 +01:00
|
|
|
def getMember(self, name):
|
|
|
|
l = [m for m in self.members if arg_name(m) == name]
|
|
|
|
if l:
|
|
|
|
return l[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getMethod(self, name):
|
|
|
|
l = [m for m in self.methods if m.name == name]
|
|
|
|
if l:
|
|
|
|
return l[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2009-08-26 17:15:02 +02:00
|
|
|
toskip = None
|
|
|
|
|
2008-04-29 14:00:40 +02:00
|
|
|
|
2008-04-29 14:01:10 +02:00
|
|
|
class Function:
|
|
|
|
return_type = None
|
2008-04-29 14:08:31 +02:00
|
|
|
return_type_qualifier = None
|
2010-01-28 16:31:46 +01:00
|
|
|
return_arg = None
|
2008-04-29 14:01:10 +02:00
|
|
|
name = None
|
2008-04-29 14:04:24 +02:00
|
|
|
rename = None
|
2008-04-29 14:01:10 +02:00
|
|
|
args = None
|
2008-04-29 14:02:56 +02:00
|
|
|
docstring = None
|
2008-04-29 14:05:51 +02:00
|
|
|
return_owner = True
|
2008-04-29 14:06:17 +02:00
|
|
|
skip = False
|
2008-04-29 14:06:30 +02:00
|
|
|
errors = None
|
2008-09-12 17:06:58 +02:00
|
|
|
|
2008-04-29 14:01:22 +02:00
|
|
|
def __repr__(self):
|
2008-04-29 14:07:15 +02:00
|
|
|
return '<Function return_type:%s name:%s args:%r>' % (
|
2010-01-28 16:31:46 +01:00
|
|
|
self.return_arg, self.name, self.args)
|
2008-04-29 14:01:10 +02:00
|
|
|
|
2008-04-29 14:01:58 +02:00
|
|
|
def apply_overrides(self):
|
|
|
|
for func in binding.overrides.findall('func'):
|
2008-04-29 14:08:43 +02:00
|
|
|
if not binding.match_tag_language(func):
|
|
|
|
continue
|
2008-04-29 14:01:58 +02:00
|
|
|
if func.attrib.get('name') != self.name:
|
|
|
|
continue
|
|
|
|
for param in func.findall('param'):
|
|
|
|
try:
|
|
|
|
arg = [x for x in self.args if x[1] == param.attrib.get('name')][0]
|
|
|
|
except IndexError:
|
2014-12-01 16:53:07 +01:00
|
|
|
print_('W: no such param (%s) in function (%s)' % (
|
2014-12-01 11:46:21 +01:00
|
|
|
param.attrib.get('name'), self.name), file=sys.stderr)
|
2008-04-29 14:01:58 +02:00
|
|
|
continue
|
|
|
|
if param.attrib.get('optional') == 'true':
|
|
|
|
arg[2]['optional'] = True
|
2008-04-29 14:02:30 +02:00
|
|
|
if param.attrib.get('default'):
|
|
|
|
arg[2]['default'] = param.attrib.get('default')
|
2008-04-29 14:08:35 +02:00
|
|
|
if param.attrib.get('type'):
|
|
|
|
arg[0] = param.attrib.get('type')
|
2008-04-29 14:08:43 +02:00
|
|
|
if param.attrib.get('elem_type'):
|
2010-01-04 10:16:00 +01:00
|
|
|
arg[2]['element-type'] = param.attrib.get('elem_type')
|
2008-04-29 14:04:24 +02:00
|
|
|
if func.attrib.get('rename'):
|
|
|
|
self.rename = func.attrib.get('rename')
|
2008-04-29 14:05:51 +02:00
|
|
|
if func.attrib.get('return_owner'):
|
|
|
|
self.return_owner = (func.attrib.get('return_owner') != 'false')
|
2008-04-29 14:06:30 +02:00
|
|
|
if func.attrib.get('return_type'):
|
|
|
|
self.return_type = func.attrib.get('return_type')
|
2008-04-29 14:09:47 +02:00
|
|
|
if func.attrib.get('skip'):
|
|
|
|
skip = func.attrib.get('skip')
|
|
|
|
if skip == 'true':
|
|
|
|
self.skip = True
|
|
|
|
elif skip == 'unless-id-wsf' and not binding.options.idwsf:
|
|
|
|
self.skip = True
|
|
|
|
elif binding.options.language in skip.split(','):
|
|
|
|
self.skip = True
|
2008-04-29 14:08:31 +02:00
|
|
|
if func.attrib.get('return_type_qualifier'):
|
|
|
|
self.return_type_qualifier = func.attrib.get('return_type_qualifier')
|
2008-04-29 14:08:27 +02:00
|
|
|
for param in binding.overrides.findall('arg'):
|
2008-04-29 14:08:43 +02:00
|
|
|
if not binding.match_tag_language(param):
|
|
|
|
continue
|
2008-04-29 14:08:27 +02:00
|
|
|
arg_name = param.attrib.get('name')
|
2008-04-29 14:08:43 +02:00
|
|
|
arg_sub = param.attrib.get('rename')
|
2008-04-29 14:08:27 +02:00
|
|
|
if arg_name and arg_sub:
|
|
|
|
args = [ x for x in self.args if x[1] == arg_name]
|
|
|
|
for arg in args:
|
2010-01-04 10:16:00 +01:00
|
|
|
arg[2]['original-name'] = arg[1]
|
2008-04-29 14:08:27 +02:00
|
|
|
arg[1] = arg_sub
|
2008-04-29 14:01:58 +02:00
|
|
|
|
2008-04-29 14:01:14 +02:00
|
|
|
|
2008-04-29 14:06:21 +02:00
|
|
|
class DocString:
|
|
|
|
orig_docstring = None
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
parameters = None
|
2008-04-29 14:06:21 +02:00
|
|
|
return_value = None
|
|
|
|
description = None
|
|
|
|
|
2010-01-04 10:16:00 +01:00
|
|
|
def __init__(self, function, docstring, binding_data):
|
|
|
|
self.binding_data = binding_data
|
2008-04-29 14:06:21 +02:00
|
|
|
self.orig_docstring = docstring
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
self.parameters = []
|
|
|
|
self.params = {}
|
2008-04-29 14:06:21 +02:00
|
|
|
lines = docstring.splitlines()
|
|
|
|
# ignore the first line, it has the symbol name
|
|
|
|
lines = lines[1:]
|
|
|
|
|
|
|
|
# look for parameters
|
|
|
|
while lines[0].strip():
|
|
|
|
if not self.parameters and not lines[0].startswith('@'):
|
|
|
|
# function without parameters
|
|
|
|
break
|
|
|
|
if not self.parameters:
|
|
|
|
self.parameters = []
|
|
|
|
|
|
|
|
if lines[0][0] == '@':
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
|
|
|
|
splits = lines[0][1:].split(':', 2)
|
|
|
|
param_name = splits[0]
|
|
|
|
if len(splits) > 2:
|
|
|
|
param_options = splits[1]
|
|
|
|
param_desc = splits[2]
|
|
|
|
self.parameters.append([param_name, param_desc, param_options])
|
|
|
|
self.params[param_name] = { 'desc': param_desc, 'options': param_options }
|
|
|
|
for a in function.args:
|
2010-01-04 10:16:00 +01:00
|
|
|
if a[1] == param_name or a[2].get('original-name') == param_name:
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
arg = a
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise Exception('should not happen ' + param_name + ' ' + lines[0] + repr(function))
|
2010-01-04 10:13:43 +01:00
|
|
|
self.annotation2arg(arg, param_options)
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
else:
|
|
|
|
param_desc = splits[1]
|
|
|
|
self.parameters.append([param_name, param_desc])
|
|
|
|
self.params[param_name] = { 'desc': param_desc }
|
2008-04-29 14:06:21 +02:00
|
|
|
else:
|
|
|
|
# continuation of previous description
|
|
|
|
self.parameters[-1][1] = self.parameters[-1][1] + ' ' + lines[0].strip()
|
|
|
|
|
|
|
|
lines = lines[1:]
|
|
|
|
|
|
|
|
# blank line then description, till the end or the return value
|
|
|
|
lines = lines[1:]
|
|
|
|
self.description = ''
|
|
|
|
while not lines[0].startswith('Return value'):
|
|
|
|
self.description += lines[0] + '\n'
|
|
|
|
if len(lines) == 1:
|
|
|
|
self.description = self.description.strip()
|
|
|
|
return
|
|
|
|
lines = lines[1:]
|
|
|
|
self.description = self.description.strip()
|
|
|
|
|
|
|
|
# return value
|
2010-01-04 10:13:43 +01:00
|
|
|
if lines[0].startswith('Return value') or lines[0].startswith('Returns'):
|
2008-04-29 14:06:21 +02:00
|
|
|
lines[0] = lines[0].split(':', 1)[1]
|
2010-01-04 10:13:43 +01:00
|
|
|
accu = ''
|
2008-04-29 14:06:21 +02:00
|
|
|
while lines[0].strip():
|
2010-01-04 10:13:43 +01:00
|
|
|
accu = accu + ' ' + lines[0].strip()
|
2008-04-29 14:06:21 +02:00
|
|
|
if len(lines) == 1:
|
|
|
|
break
|
|
|
|
lines = lines[1:]
|
2010-01-04 10:13:43 +01:00
|
|
|
# find GObject-introspection annotations
|
|
|
|
if re.match(r'\s*\(', accu):
|
|
|
|
annotation, accu = accu.split(':', 1)
|
|
|
|
self.annotation2arg(function.return_arg, annotation)
|
|
|
|
self.return_value = accu.strip() # remove leading space
|
|
|
|
def annotation2arg(self, arg, annotation):
|
|
|
|
'''Convert GObject-introspection annotations to arg options'''
|
|
|
|
|
|
|
|
if 'allow-none' in annotation:
|
|
|
|
arg[2]['optional'] = True
|
2010-01-29 01:43:51 +01:00
|
|
|
if re.search(r'\(\s*out\s*\)', annotation):
|
2010-01-04 10:13:43 +01:00
|
|
|
arg[2]['out'] = True
|
2010-01-29 01:43:51 +01:00
|
|
|
if re.search(r'\(\s*in\s*\)', annotation):
|
2010-01-04 10:13:43 +01:00
|
|
|
arg[2]['in'] = True
|
2010-01-29 01:43:51 +01:00
|
|
|
m = re.search(r'\(\s*default\s*([^ )]*)\s*\)', annotation)
|
|
|
|
if m:
|
|
|
|
prefix = ''
|
|
|
|
if is_boolean(arg):
|
|
|
|
prefix = 'b:'
|
|
|
|
elif is_int(arg, self.binding_data):
|
|
|
|
prefix = 'c:'
|
|
|
|
else:
|
|
|
|
raise Exception('should not happen: could not found type for default: ' + annotation)
|
|
|
|
arg[2]['default'] = prefix + m.group(1)
|
|
|
|
arg[2]['optional'] = True
|
2017-09-11 12:07:48 +02:00
|
|
|
m = re.search(r'\(\s*element-type\s+([\w*]+)(?:\s+([\w*]+))?', annotation)
|
2010-01-04 10:13:43 +01:00
|
|
|
if m:
|
|
|
|
if len(m.groups()) > 2:
|
|
|
|
arg[2]['key-type'] = \
|
|
|
|
convert_type_from_gobject_annotation(m.group(1))
|
|
|
|
arg[2]['value-type'] = \
|
|
|
|
convert_type_from_gobject_annotation(m.group(2))
|
|
|
|
else:
|
|
|
|
arg[2]['element-type'] = \
|
|
|
|
convert_type_from_gobject_annotation(m.group(1))
|
2010-01-29 01:43:51 +01:00
|
|
|
m = re.search(r'\(\s*transfer\s+(\w+)', annotation)
|
2010-01-04 10:13:43 +01:00
|
|
|
if m:
|
|
|
|
arg[2]['transfer'] = m.group(1)
|
2008-04-29 14:06:21 +02:00
|
|
|
|
2008-04-29 14:01:10 +02:00
|
|
|
def normalise_var(type, name):
|
|
|
|
if name[0] == '*':
|
|
|
|
type += '*'
|
|
|
|
name = name[1:]
|
|
|
|
return type, name
|
|
|
|
|
2010-01-14 17:18:42 +01:00
|
|
|
exclude_private = True
|
2008-04-29 14:01:14 +02:00
|
|
|
|
|
|
|
def parse_header(header_file):
|
|
|
|
global binding
|
|
|
|
|
2008-04-29 14:01:22 +02:00
|
|
|
struct_names = {}
|
2008-04-29 14:00:40 +02:00
|
|
|
in_comment = False
|
2008-04-29 14:00:50 +02:00
|
|
|
in_enum = False
|
2008-04-29 14:00:58 +02:00
|
|
|
in_struct = None
|
2008-04-29 14:01:02 +02:00
|
|
|
in_struct_private = False
|
2008-04-29 14:01:50 +02:00
|
|
|
in_ifdef_zero = False
|
2008-04-29 14:00:40 +02:00
|
|
|
|
2014-12-01 11:46:21 +01:00
|
|
|
lines = open(header_file).readlines()
|
2008-04-29 14:01:06 +02:00
|
|
|
i = 0
|
|
|
|
while i < len(lines):
|
|
|
|
line = lines[i]
|
2008-04-29 14:01:10 +02:00
|
|
|
while line.endswith('\\\n'):
|
2008-04-29 14:01:06 +02:00
|
|
|
i += 1
|
2008-04-29 14:01:10 +02:00
|
|
|
line = line[:-2] + ' ' + lines[i].lstrip()
|
2008-04-29 14:01:06 +02:00
|
|
|
|
2008-04-29 14:00:40 +02:00
|
|
|
if in_comment:
|
|
|
|
if '*/' in line:
|
|
|
|
in_comment = False
|
2008-04-29 14:01:06 +02:00
|
|
|
elif '/*' in line and not '*/' in line:
|
2008-04-29 14:00:50 +02:00
|
|
|
in_comment = True
|
2008-04-29 14:01:50 +02:00
|
|
|
elif in_ifdef_zero:
|
|
|
|
# minimal support for code sections commented with #if 0
|
|
|
|
if line.startswith('#endif'):
|
|
|
|
in_ifdef_zero = False
|
|
|
|
elif line.startswith('#if 0'):
|
|
|
|
in_ifdef_zero = True
|
2008-04-29 14:01:06 +02:00
|
|
|
elif in_enum:
|
2008-04-29 14:00:50 +02:00
|
|
|
if line.startswith('}'):
|
|
|
|
in_enum = False
|
2008-04-29 14:01:42 +02:00
|
|
|
enum_name = line[2:].strip().strip(';')
|
|
|
|
binding.enums.append(enum_name)
|
2008-04-29 14:00:50 +02:00
|
|
|
else:
|
|
|
|
m = re.match('\s*([a-zA-Z0-9_]+)', line)
|
|
|
|
if m:
|
2008-04-29 14:02:06 +02:00
|
|
|
binding.constants.append(('i', m.group(1)))
|
2008-04-29 14:01:06 +02:00
|
|
|
elif line.startswith('#define'):
|
2010-02-17 11:14:45 +01:00
|
|
|
m = re.match(r'#define\s+([a-zA-Z0-9_]+)\s+([-\w"]+)', line)
|
2008-04-29 14:01:06 +02:00
|
|
|
if m:
|
2010-02-04 23:24:06 +01:00
|
|
|
constant_name = m.group(1)
|
|
|
|
if constant_name[0] != '_':
|
2008-04-29 14:01:06 +02:00
|
|
|
# ignore private constants
|
2008-04-29 14:02:06 +02:00
|
|
|
if '"' in line:
|
|
|
|
constant_type = 's'
|
2010-02-17 11:14:45 +01:00
|
|
|
elif m.group(2).startswith('LASSO_'):
|
|
|
|
l = [ c for c in binding.constants if m.group(2) == c[1] ]
|
|
|
|
if l:
|
|
|
|
contant_type = l[0][0]
|
|
|
|
else:
|
|
|
|
raise Exception()
|
2008-04-29 14:02:06 +02:00
|
|
|
else:
|
|
|
|
constant_type = 'i'
|
2010-02-04 23:24:06 +01:00
|
|
|
constant = (constant_type, constant_name)
|
|
|
|
binding.constants.append(constant)
|
2008-04-29 14:01:06 +02:00
|
|
|
elif line.startswith('typedef enum {'):
|
2008-04-29 14:00:50 +02:00
|
|
|
in_enum = True
|
2008-04-29 14:01:06 +02:00
|
|
|
elif line.startswith('typedef struct'):
|
2008-04-29 14:00:58 +02:00
|
|
|
m = re.match('typedef struct ([a-zA-Z0-9_]+)', line)
|
2008-04-29 14:01:06 +02:00
|
|
|
if m:
|
|
|
|
struct_name = m.group(1)
|
|
|
|
if not (struct_name.endswith('Class') or struct_name.endswith('Private')):
|
2008-04-29 14:01:22 +02:00
|
|
|
struct_names[struct_name] = True
|
2008-04-29 14:01:06 +02:00
|
|
|
elif line.startswith('struct _'):
|
2008-04-29 14:00:58 +02:00
|
|
|
m = re.match('struct ([a-zA-Z0-9_]+)', line)
|
|
|
|
struct_name = m.group(1)
|
2008-04-29 14:01:22 +02:00
|
|
|
if struct_name in struct_names:
|
2008-04-29 14:01:06 +02:00
|
|
|
in_struct = Struct(struct_name)
|
|
|
|
in_struct_private = False
|
|
|
|
elif in_struct:
|
2008-04-29 14:00:58 +02:00
|
|
|
if line.startswith('}'):
|
2010-01-28 16:31:46 +01:00
|
|
|
if not in_struct.name in binding.structs_toskip:
|
|
|
|
binding.structs.append(in_struct)
|
|
|
|
else:
|
2014-12-01 16:53:07 +01:00
|
|
|
print_('W: skipping structure %s due to overrides.xml' % in_struct.name, file=sys.stderr)
|
2008-04-29 14:00:58 +02:00
|
|
|
in_struct = None
|
2008-04-29 14:01:06 +02:00
|
|
|
elif '/*< public >*/' in line:
|
2008-04-29 14:01:02 +02:00
|
|
|
in_struct_private = False
|
2008-04-29 14:01:06 +02:00
|
|
|
elif '/*< private >*/' in line:
|
2008-04-29 14:01:02 +02:00
|
|
|
in_struct_private = True
|
2010-01-14 17:18:42 +01:00
|
|
|
elif in_struct_private and exclude_private:
|
2008-04-29 14:01:06 +02:00
|
|
|
pass
|
2010-01-14 17:18:42 +01:00
|
|
|
elif 'DEPRECATED' in line and exclude_private:
|
2009-03-27 16:06:24 +01:00
|
|
|
pass
|
2008-04-29 14:01:06 +02:00
|
|
|
else:
|
2008-08-05 16:53:07 +02:00
|
|
|
# TODO: Add parsing of OFTYPE
|
2011-12-16 10:02:14 +01:00
|
|
|
# Transform struct to typedef
|
|
|
|
# example: "struct _LassoAssertion" -> "LassoAssertion"
|
|
|
|
line = re.sub('\s+struct _', ' ', line)
|
2008-04-29 14:01:06 +02:00
|
|
|
member_match = re.match('\s+(\w+)\s+(\*?\w+)', line)
|
|
|
|
if member_match:
|
2010-01-28 16:31:46 +01:00
|
|
|
member_type, member_name = normalise_var(member_match.group(1), member_match.group(2))
|
|
|
|
field = (member_type, member_name, {})
|
|
|
|
if member_type == 'void*':
|
2014-12-01 16:53:07 +01:00
|
|
|
print_('W: skipping field %s.%s' % (in_struct.name, member_name), file=sys.stderr)
|
2008-04-29 14:01:06 +02:00
|
|
|
else:
|
2010-01-28 16:31:46 +01:00
|
|
|
if is_glist(field) or is_hashtable(field):
|
|
|
|
found = re.search(r' of ([^*]*)', line)
|
|
|
|
if found:
|
|
|
|
field[2]['element-type'] = clean_type(found.group(1))
|
|
|
|
if member_name == 'parent':
|
|
|
|
in_struct.parent = member_type
|
|
|
|
else:
|
2015-05-27 17:09:33 +02:00
|
|
|
in_struct.members.append(field)
|
2008-04-29 14:01:10 +02:00
|
|
|
elif line.startswith('LASSO_EXPORT '):
|
|
|
|
while not line.strip().endswith(';'):
|
|
|
|
i += 1
|
2010-01-04 10:16:00 +01:00
|
|
|
line = line[:-1] + ' ' + lines[i].lstrip()
|
2008-04-29 14:01:10 +02:00
|
|
|
|
2010-01-04 10:13:43 +01:00
|
|
|
# parse the type, then the name, then argument list
|
2010-01-04 10:16:00 +01:00
|
|
|
m = re.match(r'LASSO_EXPORT\s+([^(]*(?:\s|\*))(\w+)\s*\(\s*(.*?)\s*\)\s*;', line)
|
2010-01-14 17:18:42 +01:00
|
|
|
if m and (not exclude_private or not m.group(2).endswith('_get_type')):
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
return_type, function_name, args = m.groups()
|
2008-08-05 16:52:52 +02:00
|
|
|
return_type = return_type.strip()
|
2008-04-29 14:01:10 +02:00
|
|
|
f = Function()
|
2008-04-29 14:01:30 +02:00
|
|
|
if function_name[0] == '*':
|
|
|
|
return_type += '*'
|
|
|
|
function_name = function_name[1:]
|
2009-08-26 17:15:02 +02:00
|
|
|
if binding.functions_toskip.get(function_name) != 1:
|
2010-01-29 01:43:51 +01:00
|
|
|
if re.search(r'\<const\>', return_type):
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
f.return_owner = False
|
|
|
|
# clean the type
|
|
|
|
return_type = clean_type(return_type)
|
2009-08-26 17:15:02 +02:00
|
|
|
if return_type != 'void':
|
|
|
|
f.return_type = return_type
|
2010-01-04 10:13:43 +01:00
|
|
|
f.return_arg = (return_type, None, {})
|
2010-01-14 17:18:42 +01:00
|
|
|
if function_name.endswith('_destroy') and exclude_private:
|
2009-08-26 17:15:02 +02:00
|
|
|
# skip the _destroy functions, they are just wrapper over
|
|
|
|
# g_object_unref
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
f.name = function_name
|
|
|
|
f.args = []
|
|
|
|
for arg in [x.strip() for x in args.split(',')]:
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
arg = clean_type(arg)
|
2009-08-26 17:15:02 +02:00
|
|
|
if arg == 'void' or arg == '':
|
|
|
|
continue
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
m = re.match(r'(.*(?:\s|\*))(\w+)', arg)
|
2009-08-26 17:15:02 +02:00
|
|
|
if m:
|
2010-01-04 10:13:41 +01:00
|
|
|
type, name = m.groups()
|
|
|
|
type = clean_type(type)
|
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.
2010-01-04 10:13:36 +01:00
|
|
|
f.args.append(list((type, name, {})))
|
2009-08-26 17:15:02 +02:00
|
|
|
else:
|
2014-12-01 16:53:07 +01:00
|
|
|
print_('failed to process:', arg, 'in line:', line, file=sys.stderr)
|
2010-01-04 10:13:41 +01:00
|
|
|
f.skip = True
|
2009-08-26 17:15:02 +02:00
|
|
|
f.apply_overrides()
|
|
|
|
if not f.skip:
|
|
|
|
binding.functions.append(f)
|
2010-01-28 16:31:46 +01:00
|
|
|
else:
|
2014-12-01 16:53:07 +01:00
|
|
|
print_('W: skipping function', f, file=sys.stderr)
|
2008-04-29 14:01:06 +02:00
|
|
|
|
|
|
|
i += 1
|
2008-04-29 14:01:02 +02:00
|
|
|
|
2008-04-29 14:00:40 +02:00
|
|
|
|
2008-04-29 14:09:47 +02:00
|
|
|
def parse_headers(srcdir):
|
2010-01-29 17:42:37 +01:00
|
|
|
wsf_prefixes = ['disco_', 'dst_', 'is_', 'profile_service_', 'discovery_',
|
2010-09-29 15:56:59 +02:00
|
|
|
'wsf_', 'interaction_', 'utility_', 'sa_', 'authentication_',
|
2010-09-30 11:21:09 +02:00
|
|
|
'wsse_', 'sec_', 'idwsf2_', 'wsf2_', 'wsa_', 'wsu', 'soap_binding']
|
2010-01-29 17:42:37 +01:00
|
|
|
|
|
|
|
srcdir = os.path.abspath(srcdir)
|
|
|
|
parentdir = os.path.dirname(srcdir)
|
2008-04-29 14:03:05 +02:00
|
|
|
|
2010-02-04 23:24:06 +01:00
|
|
|
exclusion = ('xml_idff.h', 'xml_idwsf.h', 'xml_saml2.h', \
|
|
|
|
'xml_idwsf2.h', 'xml_soap11.h',
|
2010-03-27 17:51:16 +01:00
|
|
|
'lasso_config.h', 'saml2_xsd.h' )
|
2010-02-04 23:24:06 +01:00
|
|
|
if not binding.options.idwsf:
|
2010-02-05 01:44:52 +01:00
|
|
|
exclusion += ( 'idwsf_strings.h', )
|
2008-04-29 14:03:01 +02:00
|
|
|
for base, dirnames, filenames in os.walk(srcdir):
|
2011-10-18 17:35:55 +02:00
|
|
|
bname = os.path.basename(base)
|
|
|
|
if bname == '.svn':
|
2008-04-29 14:01:14 +02:00
|
|
|
# ignore svn directories
|
2008-04-29 14:00:40 +02:00
|
|
|
continue
|
2008-04-29 14:01:14 +02:00
|
|
|
if not 'Makefile.am' in filenames:
|
|
|
|
# not a source dir
|
|
|
|
continue
|
2011-11-08 01:10:22 +01:00
|
|
|
if not binding.options.idwsf and (bname == 'id-wsf' or \
|
|
|
|
bname == 'id-wsf-2.0' or bname == 'ws'):
|
2008-04-29 14:03:05 +02:00
|
|
|
# ignore ID-WSF
|
|
|
|
continue
|
2008-04-29 14:01:14 +02:00
|
|
|
makefile_am = open(os.path.join(base, 'Makefile.am')).read()
|
|
|
|
filenames = [x for x in filenames if x.endswith('.h') if x in makefile_am]
|
|
|
|
for filename in filenames:
|
2010-01-29 17:42:37 +01:00
|
|
|
if filename in exclusion:
|
2008-04-29 14:01:14 +02:00
|
|
|
continue
|
2010-01-29 17:42:37 +01:00
|
|
|
if 'private' in filename:
|
2008-04-29 14:03:05 +02:00
|
|
|
continue
|
2010-01-29 17:42:37 +01:00
|
|
|
if not binding.options.idwsf:
|
|
|
|
if True in (filename.startswith(wsf_prefix) for wsf_prefix in wsf_prefixes):
|
|
|
|
continue
|
|
|
|
header_path = os.path.join(base, filename)
|
|
|
|
header_relpath = os.path.relpath(header_path, parentdir)
|
|
|
|
|
|
|
|
binding.headers.append(header_relpath)
|
|
|
|
parse_header(header_path)
|
2008-04-29 14:04:28 +02:00
|
|
|
binding.constants.append(('b', 'LASSO_WSF_ENABLED'))
|
2008-04-29 14:00:40 +02:00
|
|
|
|
2008-04-29 14:03:01 +02:00
|
|
|
def main():
|
|
|
|
global binding
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-l', '--language', dest = 'language')
|
|
|
|
parser.add_option('-s', '--src-dir', dest = 'srcdir', default = '../lasso/')
|
2008-04-29 14:03:05 +02:00
|
|
|
parser.add_option('--enable-id-wsf', dest = 'idwsf', action = 'store_true')
|
2008-04-29 14:06:30 +02:00
|
|
|
parser.add_option('--enable-exception-docs', dest= 'exception_doc', action = 'store_true')
|
2008-04-29 14:03:01 +02:00
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
if not options.language:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2008-04-29 14:08:43 +02:00
|
|
|
binding = BindingData(options)
|
2008-04-29 14:09:47 +02:00
|
|
|
parse_headers(options.srcdir)
|
2008-04-29 14:06:42 +02:00
|
|
|
binding.look_for_docstrings(options.srcdir, options.exception_doc)
|
2008-04-29 14:03:01 +02:00
|
|
|
binding.order_class_hierarchy()
|
|
|
|
binding.attach_methods()
|
|
|
|
|
|
|
|
if options.language == 'python':
|
2008-08-05 16:52:52 +02:00
|
|
|
from python import lang
|
2008-04-29 14:03:01 +02:00
|
|
|
|
2008-08-05 16:52:52 +02:00
|
|
|
python_binding = lang.Binding(binding)
|
2008-04-29 14:03:01 +02:00
|
|
|
python_binding.generate()
|
2008-04-29 14:03:09 +02:00
|
|
|
elif options.language == 'php5':
|
2008-08-05 16:52:52 +02:00
|
|
|
from php5 import lang
|
2008-04-29 14:03:09 +02:00
|
|
|
|
2008-08-05 16:52:52 +02:00
|
|
|
php5_binding = lang.Binding(binding)
|
2008-04-29 14:03:09 +02:00
|
|
|
php5_binding.generate()
|
2008-04-29 14:06:30 +02:00
|
|
|
elif options.language == 'java':
|
2008-08-05 16:52:52 +02:00
|
|
|
from java import lang
|
2008-04-29 14:06:30 +02:00
|
|
|
|
2008-08-05 16:52:52 +02:00
|
|
|
java_binding = lang.Binding(binding)
|
2010-01-26 00:47:56 +01:00
|
|
|
java_binding.generate()
|
2008-04-29 14:07:06 +02:00
|
|
|
elif options.language == 'java-list':
|
2008-08-05 16:52:52 +02:00
|
|
|
from java import lang
|
2008-04-29 14:07:06 +02:00
|
|
|
|
2008-08-05 16:52:52 +02:00
|
|
|
java_binding = lang.Binding(binding)
|
2010-01-26 00:47:56 +01:00
|
|
|
java_binding.print_list_of_files()
|
|
|
|
elif options.language == 'perl':
|
|
|
|
from perl import lang
|
|
|
|
perl_binding = lang.Binding(binding)
|
|
|
|
perl_binding.generate()
|
2008-04-29 14:01:10 +02:00
|
|
|
|
2008-04-29 14:03:01 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|