Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 'Extract Method' fails to detect needed parameters

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
nodet Posted - Mar 08 2007 : 08:52:22 AM
Hi,

I am using build 1548 of Visual Assist X. I noticed a problem when extracting some code that uses pointers to members: the method that is created misses some parameters... Consider the following code:

class Elem;
class K {
  int getNumberOfElements() const;
  Elem* getElement(int) const;  
  void method();
};

void K::method() {
  int (K:: *getNb)() const;
  getNb = &K::getNumberOfElements;
  Elem* (K:: * get)(int) const;
  get = &K::getElement;

  for (int i = 0; i < (this->*getNb)(); ++i) {
    Elem* elem = (this->*get)(i);
    // Do something with elem
  }
}

Select the whole 'for' loop (the blue lines), and choose 'Extract Method'. You get the following incorrect code:

class Elem;
class K {
  int getNumberOfElements() const;
  Elem* getElement(int) const;  
  void method();

  void MyMethod() {
    for (int i = 0; i < (this->*getNb)(); ++i) {
      Elem* elem = (this->*get)(i);
      // Do something with elem
    }
  }
};

void K::method() {
  int (K:: *getNb)() const;
  getNb = &K::getNumberOfElements;
  Elem* (K:: * get)(int) const;
  get = &K::getElement;

  MyMethod();
}

instead of

class Elem;
class K {
  int getNumberOfElements() const;
  Elem* getElement(int) const;  
  void method();

  void MyMethod(int (K:: *getNb)() const, Elem* (K:: * get)(int) const) {
    for (int i = 0; i < (this->*getNb)(); ++i) {
      Elem* elem = (this->*get)(i);
      // Do something with elem
    }
  }
};

void K::method() {
  int (K:: *getNb)() const;
  getNb = &K::getNumberOfElements;
  Elem* (K:: * get)(int) const;
  get = &K::getElement;

  MyMethod(getNb, get);
}

Not a big deal (I don't write such code every day...), but I thought you'd like to know...
Thanks.
3   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Mar 09 2007 : 12:41:44 PM
Apologies, my mistake. The compilation errors were unresolved externals, I should have checked the nature of the errors more carefully. Once I added dummy implementations in the class K the errors went away.

I have put in a bug report for VA not understanding the function pointer variables, since this is a problem, and I suspect is the real cause of the bug with Extract Method:

case=5433
nodet Posted - Mar 08 2007 : 4:31:46 PM
I don't understand! The code does compile for me:

W:\\MSVC8\\TestScheduler>type testVAX.cpp
//
// Test Visual Assist 'ExtractMethod'
//

class Elem;
class K {
  int getNumberOfElements() const;
  Elem* getElement(int) const;
  void method();

};

void K::method() {
  int (K:: *getNb)() const;
  getNb = &K::getNumberOfElements;
  Elem* (K:: * get)(int) const;
  get = &K::getElement;

  for (int i = 0; i < (this->*getNb)(); ++i) {
    Elem* elem = (this->*get)(i);
    // Do something with elem
  }
}

W:\\MSVC8\\TestScheduler>cl /c testVAX.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

testVAX.cpp

W:\\MSVC8\\TestScheduler>

I checked that it also compiles with MSVC 7 (13.10.3077) and gcc 3.4.4.

Of course, this code looks rather bizarre, but this is a trimmed down version of a more complicated code, where the method that I extract is called several times with different sets of parameters.
feline Posted - Mar 08 2007 : 11:41:14 AM
I suspect you have missed a bit when you constructed this example. In the K::method function the first line is:

	int (K:: *getNb)() const;


where VA is underlining "getNb" as a mistyped symbol, which is reasonable, since this code does not compile, I just checked in VS2005. Since VA does not understand "getNb" it makes sense that Extract Method is going to have problems with this code as well.

"getNb" seems to be a function pointer, but why are you trying to create a function pointer variable as a class member inside a member function? I am feeling a bit confused by this

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000