Author Topic: Not able to generate implementation by using a custom C++ language  (Read 675 times)

MPoudret

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Hello,

I created a custom language based on C++. Implementation Code Templates are copied/pasted from C++ ones.

I also created a MDG technology corresponding to this custom language and I have included the following code options within it:

Code: [Select]
<CodeOptions>
<CodeOption name="DefaultExtension">.h</CodeOption>
<CodeOption name="HasImplementation">true</CodeOption>
<CodeOption name="ImplementationExtension">.cpp</CodeOption>
</CodeOptions>

When generating code using this template, the generated *.cpp files are always empty, except the header part:

Code: [Select]
///////////////////////////////////////////////////////////
//  MyClass.cpp
//  Implementation of the Class MyClass
//  Created on:      20-févr.-2018 17:20:39
//  Original author: Mathieu Poudret
///////////////////////////////////////////////////////////


For instance, the %fileHeaders% macro from my "Import Section Impl" template is empty (It's like if the generated implementation was not able to rely on the generated headers). Same for methods body (bodyLocation = classBody has no effect on the generated *.cpp file), etc. Let me notice that everything's fine if I choose to generate the MyClass code by using the default C++ language. Also, the header files are properly generated by using my custom language.

Do you have some clue about those almost-empty generated *.cpp files?

Regards,
Mathieu

maxh

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
    • SafeCode Consulting
Re: Not able to generate implementation by using a custom C++ language
« Reply #1 on: March 09, 2018, 10:29:02 am »
It's promising that you are seeing the file header comments. This means the impl side is being called.  Keep in mind that the file isn't written until the template recursion is complete, so you are either not recursing beyond the "FileImpl" template, or a called template is terminating prematurely.  The templates can be very touchy, and don't provide much feedback when something goes wrong.  I often insert debug statements along the way to determine where things are going wrong.  Usually I just omitted a % somewhere along the way.

Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 301
  • Karma: +9/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Not able to generate implementation by using a custom C++ language
« Reply #2 on: March 09, 2018, 01:52:12 pm »
Following the debug log tip from above which is the first thing we've to do.

I would like to highlight that everything to do with cpp goes in <<section>>Impl templates.
whats in your 'File Impl'?

Can you try iterating though your Class Imp?

%list="ClassImpl" @separator="\n\n\n"%

and in your Class impl template can you just have your class name printed
//%className%

MPoudret

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Not able to generate implementation by using a custom C++ language
« Reply #3 on: March 13, 2018, 08:16:21 pm »
Many thanks for your help!

Thanks to the support team, I am now able to generate *.cpp files properly. I was investigating my "*impl" templates but my issue came from the "File" (and not "File Impl") template. I was looping over the class template:

Code: [Select]
%list="Class" @separator="\n\n"%
instead of the Namespace template:

Code: [Select]
%list="Namespace" @separator="\n\n"%
I agree that It is sometimes difficult to deal with debugging when using model transformations and code generations templates. I used some debug printing but it did not help this time.

Regards,
Mathieu