Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there C++ refactoring patterns implemented as a set of Clang tools?

Tags:

c++

clang

So I found that nice video on Clang tooling... And could not help but wonder: is there any sample codebase/compiled tooling suite for full project beautification and cleanup (alike C# resharper)? Code formating on project scale such as: extra space at line end, unification of member/class naming, ways of how {}brackets are placed after if etc?

like image 975
myWallJSON Avatar asked Feb 24 '13 20:02

myWallJSON


1 Answers

Clang's libtooling is fairly new so there's not too much based on it currently.

Also in my experience it's a pain to link against (there's no clang version of llvm-config and in the tutorials the devs seem to think people will build their tools inside of the full clang repo rather than as nice separate projects. The Ubuntu builds of clang only include libtooling as a static .a, no .so. Official LLVM nightly builds for Ubuntu don't seem to include the static libclangTooling.a at all.

There is include-what-you-use which is designed to remove unused header files.

There is clReflect which generates reflection bindings. (Not sure if this actually uses libtooling or just libclang, but its the same kind of thing.)

There is also refactorial that supports some other operations.

There are some tools included as part of clang. Most notably A c++11 migration tool. There is also a tool for modules (A feature being worked on for a future version of C++).

This stuff should be very useful and powerful once it takes off.

Personally I'm trying (unsuccessfully currently) to build a simple CLI re-factoring tool, cppmv which is designed to just let you rename classes, functions, variables, move them around namespaces and such while keeping their uses syncd but I don't have anything useful at this stage. Other tools could be cppls (to list namespaces, classes functions and so on). Maybe cppcp, if you want to copy something for some reason (you could have a 'template' class for example) but it seems less useful.

I was also looking at making a FUSE userspace filesystem that would let you mount and browse your project so you can use traditional 'mv' and 'cp' commands, but that was more of an excuse to learn FUSE rather than because it would be useful to do things that way. Although it might be possible to edit source code of specific classes and functions in their own separate individual 'files', although that wouldn't be useful for many things like IDEs since you would loose information about headers and such.

It would also be nice to have a live, 'see as you edit', ASTMatcher based tool, or some simple re-factoring scripting language bindings.

EDIT: There is now also clang-format for code style formatting and (as of 3.4) a clang-format.py script for Vim integration. clang-apply-replacements "that finds files containing serialized Replacements and applies those changes after deduplication and detecting conflicts."

It might be worth looking at this video where some of this stuff is demoed.

like image 65
David C. Bishop Avatar answered Nov 15 '22 18:11

David C. Bishop