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
 Technical Support
 Problems with Extract Method from C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

brainbug
New Member

3 Posts

Posted - Nov 21 2008 :  04:21:24 AM  Show Profile  Reply with Quote
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

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 22 2008 :  10:56:14 AM  Show Profile  Reply with Quote
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.

Edited by - accord on Nov 22 2008 11:01:08 AM
Go to Top of Page

brainbug
New Member

3 Posts

Posted - Nov 24 2008 :  05:18:00 AM  Show Profile  Reply with Quote
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
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 26 2008 :  03:46:34 AM  Show Profile  Reply with Quote
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
Go to Top of Page

brainbug
New Member

3 Posts

Posted - Nov 26 2008 :  03:53:41 AM  Show Profile  Reply with Quote
1.
No there are no underlines in the source file.

2.
No I extracted f2(&ms);
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 28 2008 :  04:02:56 AM  Show Profile  Reply with Quote
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.
Go to Top of Page

support
Whole Tomato Software

5566 Posts

Posted - Jan 27 2009 :  9:23:19 PM  Show Profile  Reply with Quote
case=1156 is fixed in build 1715

Whole Tomato Software, Inc.
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