Book a Demo

Author Topic: Advice for code placement in templates  (Read 2897 times)

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Advice for code placement in templates
« on: May 11, 2013, 04:32:54 pm »
The final model translation is to a language specific model to which the code generation templates can be applied. Since the final model is language specific it seems okay to insert code snippets during that translation using code="".

Another approach is to put the code snippets in the code gen template and insert stereotypes and tags into the final model to select the snippets.

I've started using the latter but am uneasy about splitting decision from action. The model transform makes a decision but the action is in the code gen template. It seems like the code gen template should only handle compiler differences, like pragmas, or perhaps coding standard formatting differences that are not already handled by a source formatter.

Does anyone have guidance or experience to share?

Thanks,
Dan

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: Advice for code placement in templates
« Reply #1 on: May 14, 2013, 04:02:00 am »
I discovered that controlling include statement is problematic at the code gen step. If you care about include file order, construct the code in the model transform using the header= attribute. Otherwise, it appears impossible to insert statements between the '#include "ThisClass.h"' and "using ThisClass;" statements.

The target coding standard stipulates the order to be: ThisClass.h, dependency includes, system includes. Most would agree that there should be no include statements after a using statement.