Book a Demo

Author Topic: Code import - macro substitution  (Read 3452 times)

minty

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Code import - macro substitution
« on: April 24, 2009, 07:58:23 am »
When importing C++ code our large legacy code base uses MACROs to transform

MY_METHOD(FunctionName)(int arg1, float arg2);

into

virtual MyResultType FunctionName (int arg1, float arg2);


Can I call a custom text substitution script on the fly by hooking into the import process for each file, or any other suggestions?

My thought was to pre-process each imported header file with a reasonably simple search/replace script to achieve this text substitution.

I don't think the standard EA macro import capabilities support even such modest macro substitutions - currently by defining MY_METHOD() in EA's macro list we simply have these methods ignored in our generated classes.


I'm not trying to round trip but I do want all methods and comments imported if possible.

One alternative is to pre-process the whole project standalone prior to import; that's messier and requires a partially pre-processed equivalent of the source tree for EA to operate on.

Other things I've tried - a full blow pre-process stage with a tool such as 'mcpp'. Its output is more controllable than gcc but still does too much to the file as I only want to selectively pre-process a few simple things.

gcc as just a pre-processor strips any comments and mangles whitespace making it even less friendly as a starting point than mcpp.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code import - macro substitution
« Reply #1 on: April 27, 2009, 02:55:15 pm »
Contact Sparx Support directly with concrete examples of the macros you want expanded.

We can help you.

minty

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Code import - macro substitution
« Reply #2 on: April 28, 2009, 07:57:45 am »
Thanks for the positive response.

The example given above, expanding MY_METHOD(FunctionName)(...) to virtual MyErrorCodeType FunctionName(...) *is* a concrete example with names changed to protect the guilty who littered the legacy codebase with Macros :)

I'll put together a couple more examples of different variants and problems not solved by substitution with blanks and get back to you via support.

Will I be able to share any solution in the forums?

Personally I like to browse for solutions to problems I didn't know I had so that the poor overworked, under-appreciated tech support staff only get hit with the really difficult questions :)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code import - macro substitution
« Reply #3 on: April 28, 2009, 08:03:47 am »
The solution I can give you is an MDG technology file that adds support for your macros to our code parser.  It will be specific to your situation, although I have written similar scripts before.

The reason why we are doing it this way is that for various reasons we are unable to support users modifying the import (in this way or any other way).