Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Dobrin on February 07, 2014, 12:32:25 am

Title: Code Generation - Preprocessor Directives
Post by: Dobrin 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


Title: Re: Code Generation - Preprocessor Directives
Post by: qwerty 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.
Title: Re: Code Generation - Preprocessor Directives
Post by: Helmut Ortmann 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
Title: Re: Code Generation - Preprocessor Directives
Post by: Geert Bellekens 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
Title: Re: Code Generation - Preprocessor Directives
Post by: Helmut Ortmann 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
Title: Re: Code Generation - Preprocessor Directives
Post by: Geert Bellekens 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
Title: Re: Code Generation - Preprocessor Directives
Post by: qwerty 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.
Title: Re: Code Generation - Preprocessor Directives
Post by: Eve 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.