2014-07-26 18:37:20 +02:00
|
|
|
<%
|
|
|
|
import re
|
|
|
|
def deduce_normalized_python_class_name(s) :
|
|
|
|
return ''.join([x.capitalize() for x in s.split('_')])
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
def decay(s) :
|
|
|
|
for tok in ['const', '&&', '&'] :
|
|
|
|
s = re.sub(tok,'',s)
|
|
|
|
return s.strip()
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
# compute used_module_list
|
|
|
|
recognized_namespace_for_using = {
|
|
|
|
'triqs::gfs::' : 'gf',
|
|
|
|
'triqs::params::' : 'parameters',
|
|
|
|
'triqs::utility::many_body_operator' : 'operators2',
|
|
|
|
}
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
used_module_list = []
|
|
|
|
def analyse(t) :
|
|
|
|
#global used_module_list
|
|
|
|
for ns, mod in recognized_namespace_for_using.items() :
|
|
|
|
if decay(t.canonical_name).startswith(ns) :
|
|
|
|
used_module_list.append(mod)
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
for c in classes :
|
|
|
|
for m in c.constructors :
|
|
|
|
for t,n,d in m.params : analyse(t)
|
|
|
|
for m in c.methods :
|
|
|
|
for t,n,d in m.params : analyse(t)
|
|
|
|
analyse(m.rtype)
|
2014-07-26 21:51:40 +02:00
|
|
|
for p in c.proplist :
|
|
|
|
analyse(p.getter.rtype)
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
for f in functions :
|
|
|
|
for t,n,d in f.params : analyse(t)
|
|
|
|
analyse(f.rtype)
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
used_module_list = set(used_module_list) # makes unique
|
|
|
|
|
|
|
|
def cls(t) :
|
|
|
|
tname = decay(t.name)
|
|
|
|
if 'gf' in used_module_list: tname = re.sub('triqs::gfs::','',tname)
|
|
|
|
if 'parameters' in used_module_list: tname = re.sub('triqs::params::','',tname)
|
|
|
|
return tname
|
|
|
|
|
|
|
|
def make_signature(m) :
|
|
|
|
assert not m.template_list, "template functions can not be wrapped to Python"
|
|
|
|
s = "({args})"
|
|
|
|
if not m.is_constructor :
|
|
|
|
s = cls(m.rtype) + " {name} " + s
|
|
|
|
s = s.format(args = ', '.join( ["%s %s"%(cls(t),n) + (" = %s"%d if d else "") for t,n,d in m.params]), **m.__dict__)
|
|
|
|
return s.strip()
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
%>
|
2014-07-26 18:37:20 +02:00
|
|
|
##
|
|
|
|
##
|
2014-07-26 21:51:40 +02:00
|
|
|
# Generated automatically using libclang using the command :
|
|
|
|
# ${shell_command}
|
2014-07-26 18:37:20 +02:00
|
|
|
from wrap_generator import *
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
# The module
|
|
|
|
module = module_(full_name = "${modulename}", doc = " ")
|
|
|
|
|
|
|
|
# All the triqs C++/Python modules
|
|
|
|
%for mod in used_module_list :
|
|
|
|
module.use_module('${mod}')
|
|
|
|
%endfor
|
|
|
|
|
|
|
|
# Add here all includes beyond what is automatically included by the triqs modules
|
|
|
|
module.add_include("${args.filename}")
|
|
|
|
|
|
|
|
# Add here anything to add in the C++ code at the start, e.g. namespace using
|
|
|
|
module.add_preamble("""
|
|
|
|
// using namespace XXX;
|
|
|
|
""")
|
2014-07-26 21:51:40 +02:00
|
|
|
|
2014-07-26 18:37:20 +02:00
|
|
|
##
|
|
|
|
%for c in classes :
|
|
|
|
# The class ${c.name}
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
g = class_(
|
|
|
|
py_type = "${deduce_normalized_python_class_name(c.name)}", # name of the python class
|
|
|
|
c_type = "${c.name}", # name of the C++ class
|
|
|
|
#
|
2014-07-26 18:37:20 +02:00
|
|
|
#Hereafter several options to be selected by hand. Cf doc
|
Draft libclang based python wrapper desc generator
- Given a C++ file, e.g. a class,
it calls libclang to parse the C++, and retrieve from
its AST the necessary info to write a xxx_desc.py file.
- THIS IS WORK IN PROGRESS. There are several corner cases for which we
may want (or not) the script to do better.
- It is not designed to be used automatically, but to to 90 % of the
boring typesetting work...
- The preamble still needs manual choices
- The properties, methods, functions are automatically declared in
the _desc file, in the simplest possible way.
- An option --properties, -p : to transform some simple methods or
get_x, set_x into python properties, not methods.
Cf doc.
- requires clang (tested on 3.4).
- the script is configured by cmake and installed in
INSTALLATION_DIRECTORY/bin, with some other files.
It can only be used for applications, after the lib has been installed.
It is cmake configured, to include automatically the various include
paths configure in the triqs installation, including the triqs install dir
in order to simplify invocation.
- TODO : improve, and test more in real cases.
2014-07-06 23:08:33 +02:00
|
|
|
#has_iterator = True,
|
|
|
|
#boost_serializable= True,
|
|
|
|
#is_printable= True,
|
|
|
|
#arithmetic = ("algebra","double")
|
|
|
|
)
|
|
|
|
|
|
|
|
%for m in c.members :
|
|
|
|
g.add_member(c_name = "${m.name}",
|
|
|
|
c_type = "${m.ctype}",
|
|
|
|
read_only= False,
|
|
|
|
doc = """${m.doc} """)
|
|
|
|
|
|
|
|
%endfor
|
|
|
|
##
|
|
|
|
%for m in [m for m in c.constructors if not m.is_template]:
|
|
|
|
g.add_constructor("${make_signature(m)}",
|
|
|
|
doc = """${m.doc} """)
|
|
|
|
|
|
|
|
%endfor
|
|
|
|
##
|
|
|
|
##
|
|
|
|
%for m in [m for m in c.methods]:
|
|
|
|
g.add_method("${make_signature(m)}",
|
|
|
|
%if m.is_static :
|
|
|
|
is_static = True,
|
|
|
|
%endif
|
|
|
|
doc = """${m.doc} """)
|
|
|
|
|
|
|
|
%endfor
|
|
|
|
##
|
|
|
|
%for p in [p for p in c.proplist]:
|
|
|
|
g.add_property(name = "${p.name}",
|
|
|
|
getter = cfunction("${make_signature(p.getter)}"),
|
|
|
|
%if p.setter :
|
|
|
|
setter = cfunction("${make_signature(p.setter)}"),
|
|
|
|
%endif
|
|
|
|
doc = """${p.doc} """)
|
|
|
|
|
|
|
|
%endfor
|
|
|
|
##
|
|
|
|
module.add_class(g)
|
|
|
|
|
|
|
|
%endfor
|
|
|
|
##
|
|
|
|
%for f in functions :
|
|
|
|
module.add_function ("${make_signature(f)}", doc = "${f.doc}")
|
|
|
|
|
|
|
|
%endfor
|
|
|
|
##
|
|
|
|
module.generate_code()
|
|
|
|
|