Book a Demo

Author Topic: Code Generation - Preprocessor Directives  (Read 5618 times)

Dobrin

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Code Generation - Preprocessor Directives
« on: February 07, 2014, 12:32:25 am »
Hello all,

Does anyone know how can i generate C code that contains preprocessor directives using EA? Or maybe point me in a direction where I can find some information?

For example I would like to generate this portion of code:

#ifdef MY_DEF
     void my_function_1 (int a, int b);
#else
     void my_function_2(void);
#endif


Thank you in advance for your answer.
Dobrin



qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Code Generation - Preprocessor Directives
« Reply #1 on: February 07, 2014, 01:31:31 am »
You can modify the code generation macros for your needs. Cumbersome since you don't have a good guide to explain Sparx' proprietary macro language.

q.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Code Generation - Preprocessor Directives
« Reply #2 on: February 07, 2014, 01:37:20 am »
Hello,

you can adapt forward generation.

Be aware:
This has no effect on synchronization. Code and model may differ because you write compiler directives in Code and forget to change your model accordingly.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code Generation - Preprocessor Directives
« Reply #3 on: February 07, 2014, 05:56:43 pm »
Apparently since v11 (which is now in beta stage) you can also adapt the macro's for reverse engineering.
This should then support full roundtrip engineering for whatever language or dialect you use.

Geert

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Code Generation - Preprocessor Directives
« Reply #4 on: February 07, 2014, 06:39:48 pm »
Hi Geert,

thanks for the information.

Could you give a link to the information about how to adapt the macro for reverse engineering.

It would close a gap.

Thanks,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code Generation - Preprocessor Directives
« Reply #5 on: February 07, 2014, 07:15:00 pm »
Quote
Hi Geert,

thanks for the information.

Could you give a link to the information about how to adapt the macro for reverse engineering.

It would close a gap.

Thanks,

Helmut
I would, if I knew where to find it  :D

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Code Generation - Preprocessor Directives
« Reply #6 on: February 07, 2014, 10:26:32 pm »
I guess they just opened access to the BNF-based syntax description for RE which you can also use since V10. There's only that one guy from Sweden here on the forum that actively posts on that topic.

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation - Preprocessor Directives
« Reply #7 on: February 10, 2014, 09:17:07 am »
Nothing new in version 11 here.

See the help at http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/grammar_editor_for_imported_co.html

Customization of existing languages is not supported.

But I feel that you may have been led off track. You can generate what you want by customizing the templates. EA won't import anything into your model different because of the conditional, and you won't be able to change the value to move a function into a different block. But other synchronization would still work.

As an example of what you could do if you know in advance what the conditionals you will use are:

Code: [Select]
$myDefFeatures += %list="Operation" @separator="\n" @indent="\t" opStereotype=="mydef"%
%if $myDefFeatures != ""%
#ifdef MY_DEF
$myDefFeatures
#endIf
%endIf%

Note: I recommend avoiding functions that you want imported being in else preprocessor sections. EA doesn't import from that section because it's common for code to simply not parse if both sections are included.