Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pfernique committed Feb 13, 2018
1 parent 1be69f4 commit ca775e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bin/conda/python-autowig/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package:
name: python-autowig
version: "1.0.0"
version: "1.0.1"

source:
path: ../../..
Expand Down
26 changes: 16 additions & 10 deletions src/py/autowig/asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,13 @@ def overloads(self):
else:
raise NotImplementedError('For parent class \'' + parent.__class__.__name__ + '\'')

@property
def prototype(self):
return self.return_type.desugared_type.globalname + ' ' + self.localname + '(' + \
', '.join(parameter.qualified_type.desugared_type.globalname for parameter in self.parameters) + ')'
def prototype(self, desugared):
if desugared:
return str(self.return_type.desugared_type) + ' ' + self.localname + '(' + \
', '.join(str(parameter.qualified_type.desugared_type) for parameter in self.parameters) + ')'
else:
return str(self.return_type) + ' ' + self.localname + '(' + \
', '.join(str(parameter.qualified_type) for parameter in self.parameters) + ')'

class MethodProxy(FunctionProxy):
"""
Expand Down Expand Up @@ -1076,11 +1079,14 @@ def overrides(self):
if len(methods) > 0:
return methods

@property
def prototype(self):
return 'static ' * self.is_static + self.return_type.desugared_type.globalname + ' ' + self.localname + '(' + \
', '.join(parameter.qualified_type.desugared_type.globalname for parameter in self.parameters) + ')' + ' const' * self.is_const + ' volatile' * self.is_volatile

def prototype(self, desugared):
if desugared:
return 'static ' * self.is_static + str(self.return_type.desugared_type) + ' ' + self.localname + '(' + \
', '.join(str(parameter.qualified_type.desugared_type) for parameter in self.parameters) + ')' + ' const' * self.is_const + ' volatile' * self.is_volatile
else:
return 'static ' * self.is_static + str(self.return_type) + ' ' + self.localname + '(' + \
', '.join(str(parameter.qualified_type) for parameter in self.parameters) + ')' + ' const' * self.is_const + ' volatile' * self.is_volatile

class ConstructorProxy(DeclarationProxy):
"""
"""
Expand Down Expand Up @@ -1784,4 +1790,4 @@ def __getitem__(self, node):
raise KeyError('\'' + node + '\' parameter')

__all__ += [subclass.__name__.rsplit('.', 1).pop() for subclass in subclasses(NodeProxy)]
__all__ += [subclass.__name__.rsplit('.', 1).pop() for subclass in subclasses(EdgeProxy)]
__all__ += [subclass.__name__.rsplit('.', 1).pop() for subclass in subclasses(EdgeProxy)]
14 changes: 7 additions & 7 deletions src/py/autowig/boost_python_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class Wrap_${cls.hash} : public ${cls.globalname.replace('struct ', '', 1).repla
<% prototypes = set() %>
% for mtd in cls.methods(access=access, inherited=True):
% if mtd.access == access:
%if mtd.prototype not in prototypes and mtd.is_virtual and mtd.is_pure:
%if mtd.prototype(desugared=True) not in prototypes and mtd.is_virtual and mtd.is_pure:
virtual ${mtd.return_type.globalname} ${mtd.localname}(${', '.join(parameter.qualified_type.globalname + ' param_' + str(parameter.index) for parameter in mtd.parameters)}) \
% if mtd.is_const:
const
Expand All @@ -471,7 +471,7 @@ class Wrap_${cls.hash} : public ${cls.globalname.replace('struct ', '', 1).repla
% endif
% endif
<% prototypes.add(mtd.prototype) %>\
<% prototypes.add(mtd.prototype(desugared=True)) %>\
% endif
% endfor
Expand Down Expand Up @@ -955,7 +955,7 @@ def edit(self, row):
if not parsed:
parsed = parse.parse(' class_{hash}.def(boost::python::init< >({documentation}));', line)
if parsed:
return "for constructor in asg['" + node.globalname + "'].constructors(access='public'):\n\tif constructor.prototype == '" + node.localname + "(" + parsed.named.get("parameters","") + ")" + "':\n\t\tconstructor.boost_python_export = False\n\t\tbreak\n"
return "for constructor in asg['" + node.globalname + "'].constructors(access='public'):\n\tif constructor.prototype(desugared=False) == '" + node.localname + "(" + parsed.named.get("parameters","") + ")" + "':\n\t\tconstructor.boost_python_export = False\n\t\tbreak\n"
else:
parsed = parse.parse(' class_{hash}.def{what}({python}, {cpp}, {documentation});', line)
if not parsed:
Expand All @@ -972,7 +972,7 @@ def edit(self, row):
parsed = parse.parse(' {return_type} (::{scope}::*'+ pointer + ')(){cv}= {globalname};', lines[row])
if parsed:
localname = parsed["globalname"].split('::')[-1]
return "for method in asg['" + node.globalname + "'].methods(access='public'):\n\tif method.prototype == '" + parsed["return_type"].lstrip() + " " + localname + "(" + parsed.named.get("parameters","") + ")" + parsed["cv"].rstrip() + "':\n\t\tmethod.boost_python_export = False\n\t\tbreak\n"
return "for method in asg['" + node.globalname + "'].methods(access='public'):\n\tif method.prototype(desugared=False) == '" + parsed["return_type"].lstrip() + " " + localname + "(" + parsed.named.get("parameters","") + ")" + parsed["cv"].rstrip() + "':\n\t\tmethod.boost_python_export = False\n\t\tbreak\n"
else:
row = row + 1
while row < len(lines) and parsed is None:
Expand All @@ -982,7 +982,7 @@ def edit(self, row):
row = row + 1
if parsed:
localname = parsed["globalname"].split('::')[-1]
return "for method in asg['" + node.globalname + "'].methods(access='public'):\n\tif method.prototype == 'static " + parsed["return_type"].lstrip() + " " + localname + "(" + parsed.named.get("parameters","") + ")" + parsed["cv"].rstrip() + "':\n\t\tmethod.boost_python_export = False\n\t\tbreak\n"
return "for method in asg['" + node.globalname + "'].methods(access='public'):\n\tif method.prototype(desugared=False) == 'static " + parsed["return_type"].lstrip() + " " + localname + "(" + parsed.named.get("parameters","") + ")" + parsed["cv"].rstrip() + "':\n\t\tmethod.boost_python_export = False\n\t\tbreak\n"
else:
return ""
elif parsed['cpp'].startswith('function_pointer_'):
Expand All @@ -998,7 +998,7 @@ def edit(self, row):
parsed = parse.parse(' {return_type} ({pointer})(){cv}= {globalname};', line)
if parsed:
localname = parsed["globalname"].split('::')[-1]
return "for method in asg['" + node.globalname + "'].methods(access='public') + asg['" + node.globalname + "'].functions():\n\tif method.prototype == '" + parsed["return_type"].lstrip() + " " + localname + "(" + parsed.named.get("parameters","") + ")" + parsed["cv"].rstrip() + "':\n\t\tmethod.boost_python_export = False\n\t\tbreak\n"
return "for method in asg['" + node.globalname + "'].methods(access='public') + asg['" + node.globalname + "'].functions():\n\tif method.prototype(desugared=False) == '" + parsed["return_type"].lstrip() + " " + localname + "(" + parsed.named.get("parameters","") + ")" + parsed["cv"].rstrip() + "':\n\t\tmethod.boost_python_export = False\n\t\tbreak\n"
else:
return ""

Expand Down Expand Up @@ -1519,4 +1519,4 @@ def boost_python_internal_generator(asg, pattern=None, *args, **kwargs):
"""
return boost_python_generator(asg,
[node for node in asg.declarations(pattern=pattern) if not getattr(node.header, 'is_external_dependency', True)],
*args, **kwargs)
*args, **kwargs)
45 changes: 3 additions & 42 deletions src/py/autowig/libclang_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def libclang_parser(asg, filepaths, flags, silent=False, **kwargs):
with open(filehandler.name, 'r') as filehandler:
_asg = filehandler.read()
for fct in asg.functions():
_asg.replace(fct._node, fct.globalname + '::' + str(uuid.uuid5(uuid.NAMESPACE_X500, fct.prototype)))
_asg.replace(fct._node, fct.globalname + '::' + str(uuid.uuid5(uuid.NAMESPACE_X500, fct.prototype(True))))
for cls in asg.classes():
for ctr in cls.constructors():
_asg.replace(ctr._node, ctr.globalname + '::' + str(uuid.uuid5(uuid.NAMESPACE_X500, ctr.prototype)))
_asg.replace(ctr._node, ctr.globalname + '::' + str(uuid.uuid5(uuid.NAMESPACE_X500, ctr.prototype(True))))
with open(filehandler.name, 'w') as filehandler:
filehandler.write(_asg)
with open(filehandler.name, 'r') as filehandler:
Expand Down Expand Up @@ -614,43 +614,4 @@ def read_cursor(asg, cursor, scope):
return []
else:
warnings.warn('Undefined behaviour for \'' + str(cursor.kind) + '\' cursor')
return []

#def read_cursor(asg, cursor):
# asg._node += 1
# node = asg._node
# asg._nodes[node] = cursor
# asg._children[node] = []
# for child in cursor.get_children():
# asg._children[node].append(asg._libclang_read_cursor(child))
# return node
#
#AbstractSyntaxTree._libclang_read_cursor = _libclang_read_cursor
#del _libclang_read_cursor
#
#def create(cls, tu):
# asg = AbstractSyntaxTree()
# asg.node = 0
# node = asg.node
# asg._nodes[node] = tu.cursor
# asg._children[node] = []
# asg.node += 1
# for child in tu.cursor.get_children():
# asg._children[node].append(asg._libclang_read_cursor(child))
# del asg.node
# return asg
#
#AbstractSyntaxTree.create = classmethod(create)
#del create
#
#def _libclang_read_cursor(asg, cursor):
# node = asg._node
# asg._nodes[node] = cursor
# asg._children[node] = []
# asg._node += 1
# for child in cursor.get_children():
# asg._children[node].append(asg._libclang_read_cursor(child))
# return node
#
#AbstractSyntaxTree._libclang_read_cursor = _libclang_read_cursor
#del _libclang_read_cursor
return []

0 comments on commit ca775e9

Please sign in to comment.