Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] toggle function refactoring

Hi Mr. Kesselhaus (is that your real name?), hi all,

> I'm doing embedded SW development for automotive since a decade now, but 
> I don't just close my eyes. That's why I'm looking with envy on the 
> language and tooling support for languages like Java, which C never 
> really got yet, like the easy setup of JUnit tests or like the reverse 
> engineering capabilities for Visualization and Analysis or even UML 
> model/diagram generation from code.
> 
> Even with all the mentioned frustration, I'm still a very happy user of 
> CDT, since it offers me lots of visualization and analysis, other IDEs 
> do not provide at all. I have 3rd-party code, that is very configurable 
> by compiler switches (defines), and CDT helps me a lot to distinct 
> between active and inactive code.


If you appreciate CDT that much and want some specific implementations of refactorings (even for C) and are not able to do it yourself, you might be able to spend money or pursue your employer/customer to spend money and having us implement it for you. We are a university institute and have to make money to finance our assistants and developing tools for customers is one possible revenue stream.

My personal interest is solely in C++ (I won't comment my reasons to not start a language war but I taught and programmed in C heavily a quarter of a century ago - I am getting old :-) and therefore my students that have developed the initial version of toggle function definition implemented it for C++ only (there are internal differences in the representation of C and C++ even for identical code that make the effort supporting both languages in an initial implementation a lot of effort).



> Not sure, what you fixed, and when it will be available.
> Now I tried with the following in the C source file:
> static inline int RangeCompare(float value, float lowLimit, float highLimit)
> {
>   return (value > highLimit) - (value < lowLimit);
> }
> 
> I get then once in the header:
> inline static int RangeCompare(float value, float lowLimit, float highLimit)
> {
>   return (value > highLimit) - (value < lowLimit);
> }
> 
> but currently there is no way back, Selecting the function in the header 
> and using "Toggle Function Definition" gives me
> !ENTRY org.eclipse.cdt.ui 4 0 2013-08-11 21:46:27.876
> !MESSAGE One-definition-rule broken

Did you try loading your C source code as C++ into Eclipse CDT and then try the refactoring? 

I am not sure my students who made the initial implementation actually thought about static inline functions. In C++ you have actually up to 3 position combinations for the function declaration and definition (for member functions) and 2 for non-member functions. I believe the combination of inline with static never was tested.


On 12.08.2013, at 15:29, cdt-dev-request@xxxxxxxxxxx wrote:

> * if you change the signature of the function implementation, update the 
> prototype and vice versa (e.g. add/remove arguments, change return type)

That is what my invention "toggle function definition" actually solves for those cases it is working. 

> * change signature by adding/ removing arguments, or changing their 
> types and type qualifiers
>        uint8 <-> uint8*                type to pointer to type
>        uint8 <-> uint16,               type to other type
>        const vs non-const  (const uint8* p <-> uint8* const p <-> const 
> uint8* const p)
>        combine/extract function arguments to/from a struct or pointer 
> to struct

Those are interesting ideas, however, I rarely see benefit of having them for C++ where other mechanisms (like references) make the use of pointers for "out" parameters less attractive (even though google proposes them for C++ in their style guide). If you want those (for C) we are able to implement them, when somebody covers our to-be-financed hours. I put my own (free:-) time into the C++ part of CDT.

The const-introduction "changes" are implemented by our Linticator product, when PC-lint suggest using const, as a quick-fix (CTRL-1).

Regards
Peter.

-- 
Prof. Peter Sommerlad

Institut für Software: Bessere Software - Einfach, Schneller!
HSR Hochschule für Technik Rapperswil
Oberseestr 10, Postfach 1475, CH-8640 Rapperswil

http://ifs.hsr.ch http://cute-test.com http://linticator.com http://includator.com
tel:+41 55 222 49 84 == mobile:+41 79 432 23 32
fax:+41 55 222 46 29 == mailto:peter.sommerlad@xxxxxx







Back to the top