Book a Demo

Author Topic: C++ generate source parameter as reference  (Read 5905 times)

Richard Fasang

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
C++ generate source parameter as reference
« on: May 26, 2010, 07:00:17 pm »
Hello,

with EA8.0.856 I have tried to generate C++ code (Ansi).

1. I have tried design class with operation using parameter passed as reference "+ Abstract Pure readConfiguration ([inout] Fixed poReadConfigurationService: IINIFileService): void"

2. I have set also in C++ to use pointer as default for references (Tools | Options | Source Code Engineering | C++ dialog)

3. I have set also to highlight reference with '*' as described in help topic "Operation Parameters by Reference"

Highlight in EA works well and I see '*' in graphic class representation.
Generate of C++ but generates method without '*' which I expects to be there because of points 1 and 2. Here is result of code generation:

virtual void readConfiguration(const IINIFileService poReadConfigurationService) =0;

What's wrong?

Regards,
Richard Fasang

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8098
  • Karma: +118/-20
    • View Profile
Re: C++ generate source parameter as reference
« Reply #1 on: May 27, 2010, 08:11:14 am »
C++ code generation does not use parameter kind.

The only supported way of specifying a parameter is passed by reference is to add the reference character explicitly.

Richard Fasang

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: C++ generate source parameter as reference
« Reply #2 on: May 28, 2010, 03:27:03 pm »
Thank You very much for answer,

I used also suggested way in past but it has following disadvantage:

When I change name of class (e.g. when making refactoring) EA changes all places where original class was used *except* parameters (I think EA assumes 'INIFileService*' has nothing to do with 'INIFileService')

Is it possible to solve that issue somehow?

Regards,
Richard Fasang

WorkerBee

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: C++ generate source parameter as reference
« Reply #3 on: May 28, 2010, 10:16:49 pm »
We are facing the same problem for some years now.
I have tried modifying the code generation templates, but even if code generation works properly then, the next bigger problem which arises then is reverse engineering.
Solution 1: modify template to generate the * or & character if [inout/out] is specified.
Solution 2: specify method/parameter signature something like
func(MyClass &param1)
...
Code generation is no problem then, but pressing F7 will screw up your definition and you end up in func(MyClass& param1), so the classifier info gets lost.
Even worse, pressing F11 after the first generation you will be asked to reassign/delete etc the already existing method. Very annoying.
This seems to be due to a mismatch between code generation and reverse engineering.

What you can do is to omit the reference whilst in the design phase of your project. Then renaming of a class used as parameter or return value (here the same problem occurs) is no problem, EA traces it an renames the referencing places accordingly.
Then, right before code generation you apply the */& characters to your parameter and or return value classifiers.
Of course, just a workaround, but in the coding phase you rarely change class names, if ever.

Uncle G.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8098
  • Karma: +118/-20
    • View Profile
Re: C++ generate source parameter as reference
« Reply #4 on: May 31, 2010, 09:24:21 am »
Quote
This seems to be due to a mismatch between code generation and reverse engineering.
Exactly, there is a mismatch between your templates and the way EA interprets the code being generated.  Precisely why I didn't recommend changing templates as an option.

Richard Fasang

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: C++ generate source parameter as reference
« Reply #5 on: May 31, 2010, 02:52:26 pm »
Quote
Exactly, there is a mismatch between your templates and the way EA interprets the code being generated.  Precisely why I didn't recommend changing templates as an option.

thnx, I will study templates to change generation for C++.

Let me but ask one question: Is there reason why for C++ is [in/out] not taken into account? I think (but I am just a BFU) [in/out] are references therefore it shouldbe easy to generate source with specified reference character e.g. '*'.

Regards,
Richard Fasang

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8098
  • Karma: +118/-20
    • View Profile
Re: C++ generate source parameter as reference
« Reply #6 on: June 01, 2010, 08:24:08 am »
One reason, is that in order for generation to use in/out we would need to reverse engineer pointers or references as either as in/out.  Which would then create problems with generation in systems where a mixture of references and pointers are used.

The other thing is that it doesn't actually solve the problem with needing to append to append a reference character to the type because you could have pointer to a pointer, you could have parameters passed by reference that you explicitly want to declare as in only etc.

Richard Fasang

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: C++ generate source parameter as reference
« Reply #7 on: June 01, 2010, 02:04:27 pm »
Quote
One reason, is that in order for generation to use in/out we would need to reverse engineer pointers or references as either as in/out.  Which would then create problems with generation in systems where a mixture of references and pointers are used.

The other thing is that it doesn't actually solve the problem with needing to append to append a reference character to the type because you could have pointer to a pointer, you could have parameters passed by reference that you explicitly want to declare as in only etc.

Yes, it looks like serious problem. I think that it is better to use explicit '*' in parameter specification. It is not problem at all, but anoying is that EA will not trace change of parameter type name.

Is it possible to change EA in way, that you are able to trace that stuff even if parameter type will have additional '*'? E.g. If I use class 'IINIFileService' and change parameter type to 'IINIFileService *' (space delimited), will be possible to trace change IINIFileService class name?

Regards,
Richard Fasang