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
 Refactor -> Create implementation placement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tjcbs
Tomato Guru

104 Posts

Posted - Oct 18 2014 :  9:03:44 PM  Show Profile  Reply with Quote
Create Implementation should place the implementation consistently with the header file.

So,

void A();
void New(); <-- Create Implementation
void B();

In this case, the implementation of New() should be placed between A() and B() in the c/cpp file, not at the end.

Edit: This does seem to at least come close, some of the time. However, it fails more often than not. Feel free to move to support, and let me know if you need a test case.

Edited by - tjcbs on Oct 18 2014 9:20:36 PM

BOP
New Member

Australia
6 Posts

Posted - Oct 19 2014 :  8:29:45 PM  Show Profile  Reply with Quote
Maybe it needs a switch.

The way I operate I find that the way the implementation is currently stuck to
the end of the source file to actually be a >> feature.

This new code, other more recent code, and any other dubious code, which are the most likely
to need attention over the next few days can be quickly located in the future without even knowing,
or having forgotten, what they are all named. It keeps a timeline of these additions.

Having the most recent code so easily locatable without having to use bookmarks, which are
continually being cleared and redone, or having to use some "find" function or other marker is very handy.

Then when the code is old and tested I can cut and paste the block so that it sits next to
some more related code if needs be.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 20 2014 :  6:29:18 PM  Show Profile  Reply with Quote
We are looking to change this, so that Create Implementation and Move Implementation try and keep the same ordering in the cpp file as is in the header file:

case=12454

This is relatively easy if you get to assume that the two files are currently in the same order, but often the aren't.

BOP, you have a good point, and I have put a note onto the case about being able to turn this off. Note that the moved code is selected in the cpp file, so you can easily cut it and move it to the location you prefer.

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 21 2014 :  03:14:45 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline
This is relatively easy if you get to assume that the two files are currently in the same order, but often the aren't.



I had actually thought of that. One solution, in terms of the example I posted, is to simply ignore B() and insert New() after A(). This produces behavior that is correct if the two files are in the same order, and reasonable if they aren't.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 21 2014 :  2:53:26 PM  Show Profile  Reply with Quote
This is where the rules outlined in the case start, but this assumes that A() already has an implementation. This has been discussed before on the forum, and we have a plan, but its just one of many features that we are looking to add to VA. We are hoping to look at this fairly soon though, since this is a popular request.

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 22 2014 :  6:40:01 PM  Show Profile  Reply with Quote
You can still proceed upwards in the .h file until you find a function with an implementation. Just saying... :)
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 23 2014 :  12:34:02 AM  Show Profile  Reply with Quote
Looking up and down for a reference point is the basic plan. This is a popular idea, its just a matter of prioritising it along with everything else people are interested in

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 23 2014 :  03:27:14 AM  Show Profile  Reply with Quote
I understand that this is just one of many features. A very nice bonus addition to this feature would be to automatically prepend "inline" to non-template functions implemented in a header file. I always forget to do this.

Edited by - tjcbs on Oct 23 2014 03:40:47 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 24 2014 :  12:33:15 AM  Show Profile  Reply with Quote
Are these implementations in the header file already present, or are you adding / moving them via VA somehow?

If they are already present have you considered a regular expression find to search for any that are missing the inline keyboard? Depending on your formatting, searching for something before { that does not contain inline may well work.

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 24 2014 :  02:06:00 AM  Show Profile  Reply with Quote
I'm talking about functions created with this feature, not those already implemented. Currently, this feature creates a function in a header without "inline". Since it is auto-generated, I don't think about it, recompile the whole project (or at least big chunks of it, since a header changed), and get a bunch of duplicate link errors, then have to fix it and recompile again. It would be very nice if this feature added "inline" for non-templpated header functions, since it is always required.

To be totally clear, I am talking about declaring a function in a .h file, and then implementing it (with VA create implementation) at the bottom of that file. I always do this so that the interface stays clean and readable.

Edited by - tjcbs on Oct 24 2014 02:11:40 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 27 2014 :  5:00:55 PM  Show Profile  Reply with Quote
So you are working in a header file with no matching cpp file, so alt-o does nothing? I had been assuming you had a matching cpp file, since that is the situation that normally comes up when talking about Create Implementation.

In this case have you marked the declarations with inline?

There is a difference between not having created the cpp file yet, and not intending to create the cpp file, so I am wary about making assumptions just because there is currently no matching cpp file.

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 27 2014 :  6:50:38 PM  Show Profile  Reply with Quote
yes, alt-o does nothing. I have not marked the declarations with inline, since it is not necessary and clutters the interface with an implementation detail. But even if I do, Create Implementation does not preserve it.

In my opinion it is not common to Create Implementation without a cpp file, if the intention is to later create a cpp file. Whereas it is very common to have functionality implemented in a .h file. Furthermore, even if the function is later moved to a cpp file, the "inline" wouldn't hurt anything. By contrast, the implementations VA is creating now in the .h, without "inline", are illegal.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 27 2014 :  9:24:31 PM  Show Profile  Reply with Quote
Since when are implementations in a header file without "inline" illegal? As I understand it inline is a request to the compiler, nothing more. The compiler will inline, or not inline the function based on its settings, and the conclusions its optimiser reaches about what to do. This page agrees, so I remember correctly:

http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 28 2014 :  01:25:31 AM  Show Profile  Reply with Quote
If you define the function inside of a class, it is "inline" implicitly. But if you define it outside, it is not "inline" implicitly, and *has* to be declared "inline". Otherwise, you get multiple definition errors. Try it!

Similarly, every c-style function defined in a header *must* be "inline"d, or you get the same error.

(of course, the .h file has to be included by more than one .cpp file)

Edited by - tjcbs on Oct 28 2014 2:05:31 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 30 2014 :  8:30:50 PM  Show Profile  Reply with Quote
Ah, this explains why this is important. I suspect I knew that at some point, but I had forgotten that fact, thank you for reminding me. I have put in a feature request for this, since this does make sense:

case=86018

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

kiro
New Member

2 Posts

Posted - Nov 06 2014 :  07:52:04 AM  Show Profile  Reply with Quote
I just want to "upvote" the request, as I would love to have that feature too...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Nov 07 2014 :  1:00:34 PM  Show Profile  Reply with Quote
I have put a note onto the case about your interest in this, thank you, it is good to know which features people are most interested in.

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

Mordachai
Tomato Guru

USA
224 Posts

Posted - Nov 21 2014 :  2:35:26 PM  Show Profile  Reply with Quote
+1 from me as well - and I'd prefer it to work both ways.

Commonly: I have to add a function, I create it to support another in the implementation file, then use "create declaration" -- but then I am sad when the declaration is stuffed onto the end of the class definition, instead of immediately before/after the function I've added this to support.

e.g.

class A
{
void MyCurrentMethod();
void Junk();
void UnrelatedJunk();
}

---
.cpp file:

void A::MyCurrentMethod()
{ ... }

void A::AnotherSupportMethod()
{ ... }

Now right click on AnotherSupportMethod and "create declaration" and I end up with:

class A
{
void MyCurrentMethod();
void Junk();
void UnrelatedJunk();
void AnotherSupportMethod();
}

But would prefer:

class A
{
void MyCurrentMethod();
void AnotherSupportMethod(); // <- same relative spot as in .cpp (or at least in same context as in .cpp - immediately following MyCurrentMethod()...
void Junk();
void UnrelatedJunk();
}

Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Nov 21 2014 :  4:23:49 PM  Show Profile  Reply with Quote
That makes perfect sense, and I have put a note on the case about this. Surprisingly I am not seeing a note about this yet, so you may be the first person to point this out

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

sean
Whole Tomato Software

USA
2817 Posts

Posted - Feb 13 2015 :  8:13:59 PM  Show Profile  Reply with Quote
case=12454 is implemented in build 2059

If you do not like or want the new behavior, change reg value named FindSimilarLocation
it defaults to enabled/01
set to 00 to restore old behavior
Go to Top of Page

tjcbs
Tomato Guru

104 Posts

Posted - Sep 17 2015 :  9:33:35 PM  Show Profile  Reply with Quote
quote:
Originally posted by sean

case=12454 is implemented in build 2059

If you do not like or want the new behavior, change reg value named FindSimilarLocation
it defaults to enabled/01
set to 00 to restore old behavior




This implementation seems fragile.

It was working for a while. Now, it has gone back to dumping the implementation at the end of the cpp file. Or, the beginning of the .h file, for header only classes.

VS2013, VA 10.9.2068.0

FindSimilarLocation is 01, FWIW.

Edited by - tjcbs on Sep 17 2015 9:35:58 PM
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Sep 19 2015 :  1:15:43 PM  Show Profile  Reply with Quote
Now we have a new "Code Generation" section of VA options dialog. If you fire up the dialog and go to that section, is it enabled?

VA Options -> Code Generation -> Maintain order in header and source files for generated C/C++ implementation

quote:
It was working for a while.

Was it working in the same files in which it's broken now?
Is it now broken in every single file or just in certain ones?
Go to Top of Page

tjcbs
Tomato Guru

104 Posts

Posted - Sep 22 2015 :  01:25:32 AM  Show Profile  Reply with Quote
Hmm... It seems like it is still working in class cpp/h files. However, it is not working with c-style function declarations, nor is it working with header only classes. Was it my imagination that it was ever working with these cases?
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Sep 25 2015 :  8:12:20 PM  Show Profile  Reply with Quote
Let's focus on c-style function declarations, first. Can you post an example case where it fails? I put this simplified sample in a header file:

void Test1();
void Test2();
void Test3();

I triggered Created Implementation on Test1 first, and then Test3 and finally Test2. The order was kept in the cpp file. I know it's an oversimplified example, but my point was that it should work, but it certainly does not in your case. I suspect that you have a scenario when it fails, i.e. it's context dependent. The easiest would be if you could send in a header and cpp file pair where you can reproduce this problem. We would keep the files private. But I know it's not often possible, but it's worth asking.

You can send in files via the following form:
http://www.wholetomato.com/support/contact.asp

It's possible that you're using keywords which makes it fail. I tried "external" and it works for me. Do you have any special keyword or a macro in your function declarations?
Go to Top of Page

tjcbs
Tomato Guru

104 Posts

Posted - Oct 01 2015 :  11:13:15 PM  Show Profile  Reply with Quote
I tried the test you described, and it worked correctly. However, inserting a new function into an existing header failed. I will send you a test case. No special keywords are being used.

Note, I am still using 10.9.2068.0
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Oct 02 2015 :  04:00:24 AM  Show Profile  Reply with Quote
Thank you for taking the time to create the test files, I was able to reproduce the problem:

case=92499

This surely helps.
Go to Top of Page

tjcbs
Tomato Guru

104 Posts

Posted - Oct 26 2015 :  12:18:14 AM  Show Profile  Reply with Quote
Another issue: if creating a template member function, VA always puts the implementation in the .h file, even if the class is implemented in a .cpp file.

VA should test whether or not a .cpp file exists, not whether the class is a template.

Edited by - tjcbs on Oct 26 2015 12:19:07 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 26 2015 :  3:14:48 PM  Show Profile  Reply with Quote
As I understand it, for a template class, the function implementation has to be included in the file that uses the method. This is why VA places the implementations into the .h file, since this is the file that you normally include.

I know it is valid to include a .cpp file, but I have virtually never seen this done.

Are you including your .cpp files, or are you using some other method to get your template code to compile?

Are you aware that after triggering "Create Method Implementations..." on the template class to generate the implementations, you can then trigger "Move Method Implementations to Source File..." on the template class name? This will give you a dialog listing the implementations that can be moved, with all of them selected by default.

This does require a second step, but its a fast second step to move all of the implementations to the cpp file.

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

tjcbs
Tomato Guru

104 Posts

Posted - Oct 27 2015 :  05:43:43 AM  Show Profile  Reply with Quote
You can explicitly instantiate templates. This is useful for template classes you really don't want implemented in the .h file, that are templated over a known range of values. In my particular case:

template class particleSystem_<true>;
template class particleSystem_<false>;


But no, I didn't know about Move Method Implementation to Source File, that makes it a lot better, thanks.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19015 Posts

Posted - Oct 27 2015 :  7:33:39 PM  Show Profile  Reply with Quote
Interesting, I know some things about templates, but there is always more to learn. Most cases where people talk about templates keep the implementations in the header file, but obviously not everyone

I am glad that Move Method Implementation is helping, this is a fairly recent addition. It does look helpful, and its ideal in this situation.

zen is the art of being at one with the two'ness
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