Code::Blocks Forums
Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: bluekylin on July 30, 2005, 06:16:33 am
-
Is there a plan to implement refactor? like as the refactor of eclipse
-
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).
-
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
-
No I don't know for sure what is is... ;) And I have used Eclipse for a long time...
-
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).
-
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:
- Moving a method or field to a base class from a derived class
- Putting some code in a separate function
- Replacing all calls to a function by inlined versions of that function (reverse of above)
- Renaming something. A class, variable, function, typedef, whatever.
- Encapsulating a field: make a public field private and add accessors (GetXXX/SetXXX).
- Reorder the parameters of a function, both in declaration/definition and in all calls.
- Add a parameter to a function, and automatically update all calls to it by putting in some default value for it.
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).
-
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?
-
Maybe should we take a look at Bison?
-
Bison? How about boost::spirit?
The macro maybe a nightmare!
-
How about using code from CPPRefactory, it's open source.
http://sourceforge.net/projects/cpptool