Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Macro Expansion
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pat
New Member

8 Posts

Posted - Feb 12 2007 :  07:56:48 AM  Show Profile  Reply with Quote
What I'm really missing is a automatic macro expansion. I suggest a menu item in the refactoring popup when hovering on preprocessor macro names. If you hover the macro name at definition the expansion could be solution wide, so that all usages of this macro will be expanded. If one hovers the macro name at usage this single macro usage should be expanded.

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 12 2007 :  08:11:31 AM  Show Profile  Reply with Quote
I am very warey of this, since what happens when the macro creates a class, complete with variables and access functions, and calls on 6 other macro's to do the job?

I have seen code like this. Some macro's are very simple. Some macro's are very long, complex pieces of code.

Plus VA does not automatically know which macro to use, consider the code:

#ifdef DEBUG
#define FELINE_MACRO // form 1
#else
#define FELINE_MACRO // form 2
#endif


For now have you considered using VA's rename refactoring?

zen is the art of being at one with the two'ness
Go to Top of Page

pat
New Member

8 Posts

Posted - Feb 12 2007 :  08:47:58 AM  Show Profile  Reply with Quote
Hm I can't see any problems with huge macros. And macros that are used in a macro that is about to expand shouldn't be expanded. One may expand them manually if liked.

Expansion of macros that are defined inside of preprocessor conditions should bring up a warning. Maybe this is really a case to avoid - so you're right at this point.

But nevertheless I would benefit by such a feature. Example: When I debug a program the VC debugger gives me no chance to debug the code inside a macro. So if I have complex macro code that needs to be debugged, I have to expand the macro by myself. Ok, this is no real issue. But an automatic expansion may have the following advantages:

1) The expansion of macro parameters would be much easier:

#define QUBIC(x) ((x)*(x)*(x))

printf( "%d", QUBIC(2) );         // using the macro
printf( "%d", ((2)*(2)*(2)) );    // expanded

2) Multi line macros can be formatted after expansion:

#define MY_CLASS(x) \  class x : base \  { \    int i; \\ 
  }

MY_CLASS(A);                        // using the macro

class A : base   {     int i;   };  // after expansion into a single line

class A : base 
  { 
    int i; 
  };                                // after expansion multi lined

class A : base 
{ 
  int i; 
};                                  // after formatting (ALT+F8)

3) It could be reversable with using special comments to surround the expanded code. Like this:

#define MY_MACRO "This is my macro string"

printf(MY_MACRO);  // with macro
printf(/*#MY_MACRO*/"This is my macro string"/*MY_MACRO#*/  // reversable expanded

Because this doesn't really look great (maybe it's acceptable with multiline macros), the reversable behaviour should be optional.

Edited by - pat on Feb 20 2007 05:39:08 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 12 2007 :  09:21:08 AM  Show Profile  Reply with Quote
Have a look at the macro here:

http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=4947#18888

I have seen MUCH more complex macro's being used in some people's code.

Personally I would view your situation as a good reason for not using macro's to begin with. How many different macro's are you looking at in your code? After you have expanded all of them then this feature in VA will be of no further use, so it seems like quite a lot of work for limited return.

The idea of reversing this, I am not keen on this at all, since it is opening a major can of worms.

zen is the art of being at one with the two'ness
Go to Top of Page

pat
New Member

8 Posts

Posted - Feb 12 2007 :  09:44:02 AM  Show Profile  Reply with Quote
Hm I'm a professional C++ programmer since over 14 years and I know very well about macros and the problems they may cause. But it's a C++ feature that can be used in a proper way. And in most of my projects I had contact with macros. Currently I'm working on a large library, with many classes that have similiar properties which I'm using macros for their definition. I avoid macros if I can, but in this case I need them.

Macro expansion is a thing I'm dreaming of for a long time, because I can remember many times I wished me this feature in VC. So it's not like I just want to expand some macros in a current project and hope that you would do the work for me ;). I would also be able to write some scripts by my self in this case. (_o_)

I really think this is an interesting feature for your VAssist refactoring module. May be there are other forum members, who think the same... we'll see - here in this thread.

Thank you for your fast responses feline.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 12 2007 :  1:32:20 PM  Show Profile  Reply with Quote
One big concern is the question of how this scales. I was discussing a test file, representative of real world code, with a user a little while ago. This file starts with 1,300 lines of macro's! Macro's are using macro's, and there are a lot of conditional macro's in there.

This is an extreme case, there is no doubt about it, but we do need to stop and consider the extreme cases, since this is where the trouble really starts. You have already said that you use macro's when they are the best solution, e.g. to create a class, this is a bit more complex than the simple one line test case

Problems with the debugger are one reason why I am very wary of macro's, plus the fact that they tend to make the code very hard to follow. Personally I would look to templates before macro's.

Another aspect to all of this is how far should VA try and go when evaluating macro's? What about FALSE, TRUE, etc?

zen is the art of being at one with the two'ness
Go to Top of Page

pat
New Member

8 Posts

Posted - Feb 12 2007 :  1:59:19 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

Personally I would look to templates before macro's.



I love templates but in some cases macros are irreplaceable!

quote:

Another aspect to all of this is how far should VA try and go when evaluating macro's? What about FALSE, TRUE, etc?



Again: VA should just expand ONE macro at once. I think there is no problem with TRUE/FALSE or stuff like that.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 12 2007 :  2:28:06 PM  Show Profile  Reply with Quote
*ah* I managed to read your original statement back to front *oops*

zen is the art of being at one with the two'ness
Go to Top of Page

KirillMueller
Ketchup Master

72 Posts

Posted - Feb 16 2007 :  4:47:20 PM  Show Profile  Reply with Quote
I'd like to second pat's suggestion. Especially the simple variant of replacing one single invocation of a macro with its expanded textual equivalent, not touching any nested macros, is a feature I miss sometimes. If a macro is defined more than once (p.ex. a debug/release version), a menu could be offered. Replacing all invocations of a macro would be of limited use to me, although this would fit well into the collection of refactoring commands.
Go to Top of Page

pat
New Member

8 Posts

Posted - Feb 16 2007 :  7:13:05 PM  Show Profile  Reply with Quote
Thank your Kirill, I was beginning to worry about my programming style and that I'm the only one using macros somethimes ;)
Go to Top of Page

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - Feb 19 2007 :  07:38:59 AM  Show Profile  Reply with Quote
Well, even if you avoid macros like the plague, you rarely get to choose when it comes to legacy code that uses them. And yes, in such a case I would welcome a function that would replace one - or even better, all - instances of a specific macro call.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 19 2007 :  2:17:25 PM  Show Profile  Reply with Quote
With three people all seeing a use for this I have put in a feature request for expanding macro's:

case=5160

I still think that expanding and then "contracting" the macro is just asking for trouble though, so I have not mentioned this on the feature request.

zen is the art of being at one with the two'ness
Go to Top of Page

schoenherr
Tomato Guru

Germany
160 Posts

Posted - Feb 20 2007 :  12:36:50 AM  Show Profile  Reply with Quote
this suggestion sounds good to me, esspecially if you encounter a problem in a large macro i can expand it, rebuild my app and debug it properly.
Go to Top of Page

KirillMueller
Ketchup Master

72 Posts

Posted - Feb 22 2007 :  08:37:07 AM  Show Profile  Reply with Quote
Fine, thanks Contracting is calling for trouble, that's right. One can undo changes using the editor or a revision control system if needed.
Go to Top of Page

pat
New Member

8 Posts

Posted - Feb 22 2007 :  09:05:28 AM  Show Profile  Reply with Quote
Undo or RCS is ok for reversing changes.
Go to Top of Page

rryk
Senior Member

Germany
48 Posts

Posted - Mar 06 2011 :  7:39:29 PM  Show Profile  Reply with Quote
In the project that I work with I have many nested macros which create tons of code (several methods). Eclipse is able to expand them to the actual code, which is very helpful sometimes. Visual Assist is already invaluable for me, but it can become even better with macro expansion feature.

Please do not advice me to get rid of macros, since I do not control part of the code which contains macros, but I build on top of the system and often have to deal with them. Original developer claims that it is very difficult (or even impossible) to do certain things in C++ without macros (do not ask me which ones - I don't know).

Any feedback from the developer? Is this feature planned in future versions? How soon should we expect it? Should we expect it at all?
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Mar 07 2011 :  3:59:56 PM  Show Profile  Reply with Quote
This is still in our list of enhancements to make to VA, but currently there has not been any progress on this.

Are you aware that VA shows you the macro definition in the Definition field when the caret is inside the macro name? I know this is not the same, but hopefully it will be of some help.

zen is the art of being at one with the two'ness
Go to Top of Page

rryk
Senior Member

Germany
48 Posts

Posted - May 24 2011 :  9:04:57 PM  Show Profile  Reply with Quote
Having a simple definition of the macro in the Definition Window is not enough. Please let me illustrate the need for a complete macro expansion by showing some files from the project that I work with. Please download the archive here: http://dl.dropbox.com/u/16259710/macros.zip. Open MFFloat.hpp and try to resolve
RTSG_DECLARE_MFIELD_SHARED_PRIMITIVE_TYPE((MFFloat, std::vector<float>)
to the actual code. All files that contain nested macro definitions are also in archive. You will soon find out that it takes ages to do that manually. Eclipse can do this work for me even showing step-by-step how macros were expanded. Here are some screenshots:

http://i53.tinypic.com/5xsp7d.jpg
http://i51.tinypic.com/zwzz81.jpg
http://i54.tinypic.com/33cvxmp.jpg

In many other things Eclipse is much less convenient than Visual Studio with Visual Assist X. My hope is to have the best of two worlds.

P.S. It is possible to generate macro expansions using Visual Studio itself as described in here: http://fneep.fiffa.net/?p=66. This is, however, not very convenient as one has to run build and it does not generate step-by-step expansion as Eclipse does.

Edited by - rryk on May 24 2011 9:41:15 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - May 25 2011 :  1:22:17 PM  Show Profile  Reply with Quote
Am I reading your screen shots correctly? It actually takes 78 steps to fully expand this macro?

This is some rather complex macro code, I certainly see that.

zen is the art of being at one with the two'ness
Go to Top of Page

eplawless
New Member

Canada
5 Posts

Posted - May 28 2011 :  11:55:15 AM  Show Profile  Reply with Quote
This would be a great feature to add. I'm one of two VA X users in an office of about 15 programmers; the remainder are in various stages of being convinced that they'd want to use your software. Availability of macro expansion is one of the two questions that have come up repeatedly. It's possible that we'll pick up some additional licenses when this is implemented.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - May 30 2011 :  11:33:02 AM  Show Profile  Reply with Quote
I have put in a feature request for some form of dialog to expand / explore complex macro's to see what our developers make of it:

case=57776

Some of these examples, you don't just want to expand the macro in place inside the code, which is what the original feature request was for.

zen is the art of being at one with the two'ness
Go to Top of Page

rryk
Senior Member

Germany
48 Posts

Posted - Jul 24 2011 :  10:31:52 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

Am I reading your screen shots correctly? It actually takes 78 steps to fully expand this macro?


Yes. It is highly complex macro system.

quote:
I have put in a feature request for some form of dialog to expand / explore complex macro's to see what our developers make of it:

case=57776


Can we vote for feature requests, e.g. like in Google Code?
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Jul 25 2011 :  11:25:31 AM  Show Profile  Reply with Quote
We don't currently have a voting system, partly due to the number of bugs and feature request. Once you get past 20 or 30 a simple multiple choice vote gets very unwieldy.

We do keep a close eye on the forum, since this gives us some indication of how many users a given problem or feature request is effecting, and use this to help inform our decisions about what to fix or change next.

zen is the art of being at one with the two'ness
Go to Top of Page

abraxas
Junior Member

11 Posts

Posted - Aug 02 2011 :  04:21:00 AM  Show Profile  Reply with Quote
+1 for case 57776 ;)

I wouldn't want macros to be expanded in place inside the code, but it would definitely help to see for a specific use of a macro what will be made out of it. Especially when trying to decipher some third party or legacy code.

Actually this is the single most missed feature of VA X I can think of. Similar to eplawless' situation, I am the only VA X user in our company right now, but I am rather sure that the macro expansion feature alone would convince some of the other developers to go VA X.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Aug 03 2011 :  10:27:26 AM  Show Profile  Reply with Quote
Are you aware that you can use Alt-g on the macro to go to the macro declaration? Also VA will try and show you the macro definition in its definition field, normally shown at the top of the editor, when the caret is inside the macro.

None of this is the same as macro expansion, but hopefully it will help a bit.

zen is the art of being at one with the two'ness
Go to Top of Page

samaursa
Senior Member

Canada
47 Posts

Posted - Aug 03 2011 :  10:41:54 AM  Show Profile  Reply with Quote
I for one would buy/upgrade my license if VA included proper macro expansion similar to eclipse.
Go to Top of Page

abraxas
Junior Member

11 Posts

Posted - Aug 03 2011 :  11:18:39 AM  Show Profile  Reply with Quote
Yes, I am aware of the possibility to go to the macro definition and also that I will see the macro defintion on mouse over and it already is quite a help. Thanks for pointing out the definition field, it does help as well especially for classes that are defined through a macro.

I still think, to actually be able to see the expanded macro with the parameters I put into it, would make it a lot easier to follow what is going on inside the macro for a specific call.
Go to Top of Page

SBone
New Member

USA
4 Posts

Posted - Jan 31 2013 :  2:38:15 PM  Show Profile  Reply with Quote
Since you are taking votes, I am also interested VERY MUCH in this feature. I'd be able to sell VAX to everyone else on my team, no problem. Several of them have switched to Eclipse just to get some bit of this functionality.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000