Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Problems with Extract Method from C

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
brainbug Posted - Nov 21 2008 : 04:21:24 AM
I use Extract Method from C and face some problems:

1. The function is often placed below the function it was extracted from (seems to occur most often when there are no other functions above:

int f()
{
    return MyMethod();
}

int MyMethod()
{
    return 1*2;
}


which means it will not compile.

2. On bigger projects I have tried this on the behaviour is very strange (I have not been able to reproduce it in any test code):

// Extracting the if statement
int f2()
{
    int a;

    if (a != 0)
    {
        a = 1*2*3;
    }

    return a;
}

// becomes

int f2()
{
    int MyMethod( int a ) 
    {
        if (a != 0)
        {
            a = 1*2*3;
        }	return a;
    }
    
    int a;

    a = MyMethod(a);

    return a;
}


Sometimes it even puts it inside another function earlier in the source file.

3. Function calls within the code extracted will sometimes be extracted as parameters (unable to verify this in test project):

// Extracting the if statement
int f1(int b)
{
    return b*2;
}

int f2()
{
    int a,b;

    if (a != 0)
    {
        a = f1(b);
    }

    return a;
}

// becomes

int f1(int b)
{
    return b*2;
}

int MyMethod(int a, int f1, int b ) 
{
    if (a != 0)
    {
        a = f1(b);
    } return a;
}

int f2()
{
    int a, b;

    if (a != 0)
    {
        a = f1(b);
    }

    return a;
}


/Johannes
6   L A T E S T    R E P L I E S    (Newest First)
support Posted - Jan 27 2009 : 9:23:19 PM
case=1156 is fixed in build 1715
accord Posted - Nov 28 2008 : 04:02:56 AM
point 1: these effects depend on something that I don't know, so we have to figure out what are these. Can you take a screenshot of your function?

point 2 is

case=1152

Extract Method should pass object instances by reference.
brainbug Posted - Nov 26 2008 : 03:53:41 AM
1.
No there are no underlines in the source file.

2.
No I extracted f2(&ms);
accord Posted - Nov 26 2008 : 03:46:34 AM
Point 1 and 2: Do you see underlines in your code if you turn on

VA Options -> Advanced -> Underlines -> Underline mistyped symbols using

after you modify the source?

point 3: you extracted the declaration of "ms" and VAX did it. It is your responsibility to extract the right piece of code. VAX is doing what you say to do
brainbug Posted - Nov 24 2008 : 05:18:00 AM
2.
This is a straight C project so no classes.
The function is in the middle of a source file that contains a lot of functions.

3.
One thing I noticed is that it only occurs for functions defined in the source file.

Another problem I found today is that dereferencing does not work on function locals when using extract method:


int f2(mystruct *ms)
{
...
}

int f()
{
   mystruct ms;

   f2(&ms);
}


becomes



int f2(mystruct *ms)
{
...
}

void MyMethod(mystruct ms)
{
  f2(&ms);
}

int f()
{
   mystruct ms;

   MyMethod(ms);
}


/Johannes
accord Posted - Nov 22 2008 : 10:56:14 AM
1. I am seeing the same effect here if this function is the first function in the file:

case=1156

2. I wasn't able to repro this, so I will need more information.
- Did you use global functions also in your "big" project? (so your function is not inside a class)
- Was your function the last one? If yes: was the last line an empty line in your file?
- Something is different around the function in your "big" project, but what?

3. The same as point 2: there is something around your function, that may confuse the parser, so we have to find what that is.

The best if you can send an example file from the project. I know that usually it isn't possible, but worth to ask.

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