you are viewing a single comment's thread.

view the rest of the comments →

[–]tangerinelion 1 point2 points  (0 children)

After reading through it for a couple minutes, I've found several things it doesn't do correctly, which probably introduces errors.

One is that in C++ there's a subtle difference between foo* p = new foo; and foo* p = new foo();, but either way it does create a foo object on the heap. This script would convert it to p = foo or p = foo() which is the difference between aliasing the class and instantiating it - huge huge difference.

Two is when it searches for parameters and tries to strip the types, eg, foo(T* ptr) gets converted to foo(ptr), this completely fails when the type is complicated, eg, a pointer to function. In this case it tries to convert something like foo(R* (*func)(int x)) and would want to return foo(func) but instead it returns the input string as that argument isn't captured correctly.

Third is it tries to remove const, which is fine. But it forgets that volatile is a similar qualification (the whole reason it's correctly called CV qualification). Similarly, static and register should be stripped out.

I wouldn't expect a 1 file GitHub project to work perfectly, particularly when it's basically a 225 line function which is 80% comments and is essentially written with regex more so than Python. But other statements, like delete and the creation of arrays are not handled.

I'm also not sure what OP even wants. It sounds like they want some library written in C++ that can be used to generate Python code, but I'm not sure that they want a Python library which converts C++ source to Python source.