Let users call constructors that take arguments when allocating with the trick memory manager.
Make this available in both C++ and Python
New Things
Variadic template function (tmm_alloc_args) that wraps a memory allocation and subsequent placement new call .
From a users perspective:
Foo* foo = tmm_alloc_args<Foo>()
The allocation functions takes the template parameters <typename T, typename ...Args> where Args is a parameter pack. We can use this to wrap any constructor call, as long as we can a string representation of the type T to pass to the trick memory manager.
The struct TrickTypeToString let's us get a string representation of the type through template specialization. ICG will generate specializations for all types it knows about (except anything in Trick, std, or er7 namespaces).
ICG Parses Constructors
I've added FunctionVisitor and FunctionDescription classes (modeled after FieldVisitor and FieldDescription). The visitor handles pulling some information out of clang::Decl::CXXConstructor and the description holds it. This info is used by ICG to generate two files: trick_type_to_string_ext.hh and constructors.json. As mentioned above, the TrickTypeToString structures are used to convert types to strings. The constructor information in constructors.json is used by convert_swig to generated addition functions in swig interface files.
If the constructor takes arguments, it'll have an array of type/name pairs.
SWIG Interface files
convert_swig has been updated with a new function process_constructor_json that uses the json data written by ICG to add some functionality. Functions are added to the class using swigs %extend functionality. One alloc function is generated for every constructor overload that exists.
This is an example of the %extend functionality from test/SIM_tmm_alloc_args.
SWIG will make those functions available in python for us, at this point a user can allocate using tmm_alloc_args from python.
var = trick.AllocTestWithArguments.alloc(1, 5.0)
To make it even more seamless I've modified the one of the __init__ overrides in swig_class_typedef.i to call alloc using python's unpacking operator(*). So now you can allocate using trick.AllocTestWithArguments(1, 5.0).
I've also added flags to ICG and convert swig so that all of the above features have to be explicitly enabled via:
coverage: 55.891% (-0.005%) from 55.896%
when pulling 19b06f10deebcf07558e79040c5fb170133a9a68 on M-Herr:master
into 1bdabadcbea6c18ea1117386954975856d1803da on nasa:master.
Goals
New Things
From a users perspective:
Foo* foo = tmm_alloc_args<Foo>()
The allocation functions takes the template parameters
<typename T, typename ...Args>
where Args is a parameter pack. We can use this to wrap any constructor call, as long as we can a string representation of the typeT
to pass to the trick memory manager.The struct
TrickTypeToString
let's us get a string representation of the type through template specialization. ICG will generate specializations for all types it knows about (except anything in Trick, std, or er7 namespaces).clang::Decl::CXXConstructor
and the description holds it. This info is used by ICG to generate two files:trick_type_to_string_ext.hh
andconstructors.json
. As mentioned above, the TrickTypeToStringIf the constructor takes arguments, it'll have an array of type/name pairs.
process_constructor_json
that uses the json data written by ICG to add some functionality. Functions are added to the class using swigs %extend functionality. Onealloc
function is generated for every constructor overload that exists.This is an example of the %extend functionality from test/SIM_tmm_alloc_args.
SWIG will make those functions available in python for us, at this point a user can allocate using tmm_alloc_args from python.
var = trick.AllocTestWithArguments.alloc(1, 5.0)
To make it even more seamless I've modified the one of the
__init__
overrides inswig_class_typedef.i
to call alloc using python's unpacking operator(*). So now you can allocate usingtrick.AllocTestWithArguments(1, 5.0)
.I've also added flags to ICG and convert swig so that all of the above features have to be explicitly enabled via:
This is still a work in progress, but if anyone spots any issues please let me know.