Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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
-
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.
-
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
-
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
-
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
-
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
-
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.
-
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:
$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.