Book a Demo

Author Topic: code generation for #define ?  (Read 4164 times)

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
code generation for #define ?
« on: November 04, 2008, 09:05:44 am »
Hi all,

(EA 7.1 Build 833)

I am doing code generation with C and I am wondering how to get EA to generate the statement "#define MYCONSTANT 100".

The help for "Object Oriented Programming In C" states that the tagged value "define" applies to "Attributes" and Corresponds to "#define statement".

I tried adding an attribute MYCONSTANT to the class and adding a tagged value called "define" to that attribute, but it had no effect. Your suggestions would be very welcome.

Thanks,

Owen


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: code generation for #define ?
« Reply #1 on: November 05, 2008, 08:18:06 am »
Apparently you're close.

Set the value of the tag named define to "true".

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: code generation for #define ?
« Reply #2 on: November 06, 2008, 08:08:48 am »
Thanks that works! more or less

Now I have
Code: [Select]
typedef struct myRecord
{
  #define MYCONSTANT 100
  int myArray[MYCONSTANT ];
} myRecord;
but I would prefer to have
Code: [Select]
#define MYCONSTANT 100
typedef struct myRecord
{
  int myArray[MYCONSTANT ];
} myRecord;

Can this be done by adjusting the metadata of the attribute MYCONSTANT ?   Or was it a mistake to make MYCONSTANT an attribute of the myRecord class?

Thanks and regards,

Owen

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: code generation for #define ?
« Reply #3 on: November 06, 2008, 08:31:21 am »
Yeah, you'll need to move it out of myRecord.  Which will probably mean defining an extra class that represents the file itself.

OwenInCanada

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
  • have the right tool for the job
    • View Profile
Re: code generation for #define ?
« Reply #4 on: November 07, 2008, 08:16:25 am »
Thank you for the suggestions. Now I have moved my defines to a separate class, however they are still generated within a code block. Is it possible to get the defines to appear outside a code block?

Code: [Select]
/**
 * Collect several defines in one place.
 */
typedef struct ApiDataTypeDefines
{
      #define ECG_DMA_BUFSIZE 12
      #define ECG_FLASH_NUMBUFFERS 10

} ApiDataTypeDefines;

This example was generated using stereotype <<dataType>> applied to a block object in a SysML diagram.  I have tried many different stereotypes, and also setting each attribute as static, and the result is consistently as above.

Regards,

Owen