Book a Demo

Author Topic: how to export/transform  C++ signatures to Python  (Read 3798 times)

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
how to export/transform  C++ signatures to Python
« on: August 29, 2012, 05:31:07 am »
Hi all,

I have successfully imported a C++ project and I have a collection of classes in EA.

Is there a way to export the signatures as Python. I am really not concerned how much information is lost.

When I select a class and do generate code, with the language adjusted from c++ to Python, I get an error, as EA tries to read the associated c++ .h file as Python. How to make use of the platform independent information in my existing classes?

Many thanks for suggestions/pointers/recipes.

Regards,

Owen

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: how to export/transform  C++ signatures to Pyt
« Reply #1 on: August 29, 2012, 09:31:24 am »
Create a transformation that sets that language to Python and removes the types.

Try it and make a modification for anything that produces bad python.

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: how to export/transform  C++ signatures to Pyt
« Reply #2 on: August 30, 2012, 12:33:31 am »
Just by changing the language to Python in new transformation, as you suggested, the result was fairly good.
Code: [Select]
 %TRANSFORM_CURRENT("language","stereotype")%
  language=%qt%Python%qt%
Three more changes would be nice:
1. From foo.h (c++), the emitted constructor in foo.py is foo.foo, whereas in Python, I would like to make it be foo.__init__.
2. All operation signatures such as foo:method(arg0,arg1) from c++, should have a "self" parameter in Python: foo.method( self, arg0, arg1 ).
3. A destructor should not be emitted in Python, but I presently have foo.~foo(), which is a Python syntax error.

I am reading Chapter 12 MDA Transforms, but I'm a bit lost.
May I ask, what are the attributes/keywords/macro_variables associated with the features that I've listed, and where?

Thanks
Owen

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: how to export/transform  C++ signatures to Pyt
« Reply #3 on: August 30, 2012, 08:39:12 am »
1,2. Modify the operation template.
%if className==opName%
  name="__init__"
%else%
  name=%qt%%opName%%qt%
%endIf%
Parameter
{
  name="self"
  type="something"
}
3. At the top of the operation template.
$destructor = %dl% + %className%
%if opName == $destructor%
%endTemplate%

All the keywords are listed in the code template syntax. The items that EA looks for when reading back your generated intermediate code are somewhere in the transformation section.