Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: bluekylin on July 30, 2005, 06:16:33 am

Title: How about refactor?
Post by: bluekylin on July 30, 2005, 06:16:33 am
Is there a plan to implement refactor? like as the refactor of eclipse
Title: Re: How about refactor?
Post by: Urxae on July 30, 2005, 11:57:00 am
Sounds like a very good idea for a plugin :). Unfortunately as far as I know nobody is working on this :(.
I'd sure like someone to take up the task though, I really love the Java refactorings in Eclipse and would certainly be interested in a plugin for Code::Blocks that implemented something similar for C++.
Unfortunately, the fact that C++ has a preprocessor will probably make refactoring for it more difficult to implement as fully as possible for Java. I think implementing it the same way Eclipse does will be very difficult, as that would entail implementing a dynamic syntax tree of the files being edited (scratch that, of everything that uses anything declared in it even). Which requires a dynamic standards-compliant preprocessor and parser for C++ (one of the more difficult languages to parse fully).
However, a more limited form may be possible by ignoring preprocessing (or at least the more advanced uses of it) and not parsing expressions fully, but just enough to recognize what elements it contains (for instance, operator precedence probably doesn't matter much, but things like function calls are easily recognizable and handy for things like renaming said functions).
Title: Re: How about refactor?
Post by: rickg22 on August 01, 2005, 05:48:16 pm
Sounds like a very good idea for a plugin :). Unfortunately as far as I know nobody is working on this :(

Maybe because of the very few people around, nobody has the slightest idea of what refactoring is? :P
Title: Re: How about refactor?
Post by: David Perfors on August 01, 2005, 05:52:39 pm
No I don't know for sure what is is... ;) And I have used Eclipse for a long time...
Title: Re: How about refactor?
Post by: squizzz on August 01, 2005, 06:00:27 pm
Refactoring is basically process of cleaning up existing source code in order to make it... well... better, more clearly written (easier to mantain, expand, have more potential, etc).

However, I have no idea how plugin could effectively aid this quest. (Did anyone make such a thing ever work?)
Any ideas? :)


Btw: Wikipedia says: Code refactoring (http://en.wikipedia.org/wiki/Refactoring).
Title: Re: How about refactor?
Post by: Urxae on August 01, 2005, 06:26:26 pm
Maybe because of the very few people around, nobody has the slightest idea of what refactoring is? :P

Short version: Refactoring is changing the code without changing the functionality. (Usually done to clean up the code)

Some examples:

There are more possible refactorings. The above-linked wikipedia article has a list of some of them (mostly just their names though).
They're usually well-defined and perfectly doable by a program, provided it has a syntax tree to work on. Not sure how easy this is without actually parsing to full C++ syntax trees.

However, I have no idea how plugin could effectively aid this quest. (Did anyone make such a thing ever work?)
Any ideas? :)

Well, they implemented it for Java programs in Eclipse. Java has a much easier to parse syntax though, and Eclipse maintains an abstract syntax tree on the fly for Java programs. Pretty easy to use, too. Just right-click a relevant piece of code (usually an identifier or selection) -> Refactor (IIRC) -> <name of refactoring>. It pops up a dialog for any specific choices you need to make (new name of field/function, new order of parameters, etc.). Then just click OK and it does it all for you ;).

Unfortunately, for C++ it'll probably be more difficult because of the grammar from hell (to parse).
Title: Re: How about refactor?
Post by: bluekylin on August 02, 2005, 05:57:17 am
Sounds like a very good idea for a plugin :). Unfortunately as far as I know nobody is working on this :(.
I'd sure like someone to take up the task though, I really love the Java refactorings in Eclipse and would certainly be interested in a plugin for Code::Blocks that implemented something similar for C++.
Unfortunately, the fact that C++ has a preprocessor will probably make refactoring for it more difficult to implement as fully as possible for Java. I think implementing it the same way Eclipse does will be very difficult, as that would entail implementing a dynamic syntax tree of the files being edited (scratch that, of everything that uses anything declared in it even). Which requires a dynamic standards-compliant preprocessor and parser for C++ (one of the more difficult languages to parse fully).
However, a more limited form may be possible by ignoring preprocessing (or at least the more advanced uses of it) and not parsing expressions fully, but just enough to recognize what elements it contains (for instance, operator precedence probably doesn't matter much, but things like function calls are easily recognizable and handy for things like renaming said functions).
   Yes, refactor must need the support of compiler. And we know, the refactor need the correct code, at least which can be compiled success :). So we can use the preprocessor and parser of compiler to gather info we need. But, I don't know whether there is such a compiler. how about gcc?
Title: Re: How about refactor?
Post by: Funto on August 02, 2005, 02:43:48 pm
Maybe should we take a look at Bison?
Title: Re: How about refactor?
Post by: bluekylin on August 03, 2005, 06:02:06 am
 Bison? How about boost::spirit?
The macro maybe a nightmare!
Title: Re: How about refactor?
Post by: tuft on September 24, 2005, 08:17:28 pm
How about using code from CPPRefactory, it's open source.
http://sourceforge.net/projects/cpptool