Author Topic: C++ code generation, attribute initialization  (Read 3440 times)

DrStuckforhelp

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
C++ code generation, attribute initialization
« on: May 12, 2012, 01:09:17 am »
I'm using EA 7.5.850 to import my C++ source code into UML.  This is my first EA project, and, esp. compared to Rational Rose, a really nice tool.  But it seems to have some C++ code gen problems.

1) How do I get EA to forward and reverse sync myAttribute:
    class fooA
    {
      fooA (int param) {}
    };
    class fooB
    {
      static const fooA myAttribute(1234);
    };
EA only seems to be able to handle attribute initialization using the "=" operator, which has a different behavior than the initializer form shown above.  I need the initializer form so I can use a static const myAttribute object before my RTOS starts up; the assignment operator requires heap and a working RTOS.  When you try to reverse sync this, EA turns myAttribute into a method.  The parser seems to be confusing this kind of C++ attribute initialization, with a method declaration.


2) In addition, how can I get the implementation of the attribute initialization, into my .cpp file, instead of the .h file.  I need this syntax:
foo.h
    class fooB
    {
        static const fooA myAttribute;
    };
foo.cpp
    const fooA fooB::myAttribute(1234);

I am able to forward sync this syntax by adding the following line to the CodeBodyImpl C++ CodeTemplate:
  %list="Attribute" @separator="\n" @indent=""%
but I cannot see a way to get it back in during the reverse sync.  EA documentation (Help / Synchronize Code) seems to indicate that it does not sync with, or even provide, an AttributeDeclarationImpl which is, ideally, where I would expect to make my modifications.

Has anybody ever sync'd an Attribute with this form?
« Last Edit: May 15, 2012, 09:02:06 pm by DrStuckforhelp »

DrStuckforhelp

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: C++ code generation, attribute initialization
« Reply #1 on: May 16, 2012, 08:42:08 pm »
Update.
The help desk, although very responsive and very cooperative, gave a disappointing reply:  [size=12]"While EA understands the syntax for static const members, it doesn't use them for reverse engineering (or generate them as you have seen)."
[/size]
[/i]
They also gave me a MDGTechnologies fix.xml file that makes the parser ignore an Attribute declaration that looks like a Method, and said  [size=12]"We will include this fix in a future build of EA."[/size]

I've decided to split all of my source code files into two parts. A part that the model generates, and a part that includes all of my special macros, conditional compiles, special Attribute definitions etc.  This de-couples the needs of my compilers from the needs of the CASE tool.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: C++ code generation, attribute initialization
« Reply #2 on: May 17, 2012, 08:10:41 am »
Okay, so given that you only have a problem with reverse engineering not setting that default, something that is only relevant to the syntax in the second part of your question... Why the need to split your files?

  • If you are always forward synchronizing, EA won't touch the initialization of your statics. Only problem here is that EA won't update them with new values.
  • If you are always overriding the file your updated templates will do what you want.
  • The only remaining issue that I see you have is that EA doesn't allow you to get the default value into the model, that won't be helped by splitting your files.
So what is the benefit?

DrStuckforhelp

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: C++ code generation, attribute initialization
« Reply #3 on: May 21, 2012, 10:38:28 pm »
I am using, and want, both, forward(overwrite) and reverse(sync) directions, so your first two suggestions will not work.  Forward(sync) is not used; the source code files produced by EA are intermediate/artifact items that are discarded after a build is completed.
For the third comment, you are correct, EA will not get Attributes from a .cpp file.  I have to manually sync these.  That really sucks, but what else can I do?  However, the split files are not for getting the model to work, but to get my compilers to work.  Let's call the part the has all the special stuff my Master file.  It concatenates the model file to itself using an #include statement.
  I have to wrap the model files with the Master files to handle the complexities of compiling and linking a class library that will support a range of real-time OS's, compilers and linkers.  These complexities have syntax that EA does not forward/reverse-sync.

Where am I supposed to put these kinds of things (they can be unique for each/every model Element):
  •  #if LANG == LANG_MSL

    #pragma srcrelincludes on
    #include "../language/MSL/lang.h"
  #else
    #include <msl_utility>
  #endif
  extern "C" void EnableInterrupts ();
  #define MIDID(c1, c2, c3, c4) (ModuleId)( \
    (((uint32)ModuleId_Cat1_ ##c1) << 24) | \
    (((uint32)ModuleId_Cat2_ ##c2) << 16) | \
    (((uint32)ModuleId_Cat3_ ##c3) <<  8) | \
    (((uint32)ModuleId_Cat4_ ##c4) <<  0) )
  T class::var[] = { 1,2,3 };
[/font]
[/list]
EA strips these out but does not put them back in.  So how do they get back in, to my project, not to my model?

Forward sync was the first thing I tried, but there were several problems with forward sync.  I can't remember what they all were.  One of them had to do with the difference between the code produced by forward sync and forward overwrite.  For instance, I have modified the AttributeDeclaration C++ template to do the initializer with this:
        %if attInitial != "" and attStatic == "T" and attConst != "T"%
         /* = %attInitial% */
        %else%
        %attInitial ? " = " value%
        %endIf%

If I
1) Add an new attribute to a class, in the .h file:
       static int junk [] = {1,2,3};
2) Do a reverse sync
then,

3) A forward sync, produces this:
       static int junk [] = {1,2,3};

4) A forward overwrite, produces this:
        static int junk[] /* = {1,2,3} */;

It seems as if my template customization is being ignored for a sync.  I thought that was the way it was supposed to work.  Perhaps not.
« Last Edit: May 22, 2012, 03:35:23 am by DrStuckforhelp »