Book a Demo

Author Topic: SOLVED: Includes in generated C code  (Read 3229 times)

ThomasW

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
SOLVED: Includes in generated C code
« on: November 17, 2011, 03:27:13 am »
Hey everyone,

I'm currently working with EA, generating C code from my class diagrams (interfaces and function bodies).

Currently I'm facing a problem with the includes, maybe someone can give me a hint.

Here is description of my problem:
Interface A has a "use" dependency to Interface B.
Class C, which is a struct is part of Interface B.

If I generate code for Interface A, I will not get an #include statement for the inclusion of interface B.
This is because the dependency "use" will not lead to an include automatically.
I solved that issue following the steps described here:
http://blog.sparxsystems.de/2010/01/genegieren-von-include-using-import-etc-aus-dependencies-bei-der-codegenerierung/
(Sorry, text is in german but the screenshots of the code templates are easy to understand).

Now I've got an #include statement and everything is fine....
But if I add an operation to Interface A which has a parameter or return type that is defined in Interface B (e.g. Class C (struct)) EA adds an include statement for that purpose.
Now I've got duplicated includes and I have no idea how this can be solved.
The idea I had was to check for duplicates but I was not able to get it to work.

Any idea?  :-[
Thanks in advance.

Thomas
« Last Edit: November 18, 2011, 08:58:26 pm by thomas.wendel »

ThomasW

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Includes in generated C code
« Reply #1 on: November 18, 2011, 08:58:05 pm »
Ok, semms like I've solved the problem on my own.
Time to say thank you: Thanks Thomas!
Oh, no problem, you're welcome! ;-)

Ok, just if anyone has the same problem:
The code generation template modification, mentioned above can be adapted to avoid multiple includes.
Here's the code for template Import Section:
OLD
Code: [Select]
$imports += %list="Import" @separator="\n" importFromDependency=="T"%
%REMOVE_DUPLICATES($imports, "\n")%
%fileImports%
NEW
Code: [Select]
$imports+=%fileImports%
$imports += %list="Import" @separator="\n" importFromDependency=="T"%
%REMOVE_DUPLICATES($imports, "\n")%