Automatically reorganize C ++ classes into separate files

I inherited a rather large project with tens of thousands of lines, but previous developers packed them into only 6 files (OMG!) ...

So, for readability, I would like to automatically break all classes into my own cpp / h files.

Is there any tool capable of this?

+4
source share
3 answers

What you need to reorganize your C ++ code database is a tool that can parse C ++ by saving header files, but following #includes and processing them. You must build an “a-depends-on-b” mapping for each pair of dependent elements, and then you must group them. Finally, you should be able to restore the source code according to clustering.

And you want to do this on a complete code base, not just with one compilation unit.

This is a pretty complicated search tool: -} I don’t think you will find it off the shelf.

Our DMS software reengineering toolkit has most of this. This is a general system for analyzing and transforming programs, has a complete C ++ interface and has a managed preprocessor, so it can expand / not expand #includes as necessary. It can capture a-depends-on-b relationships (we did it on a C-system of 26 million lines of code), and it has a proven ability to symbolically symbolize preprocessor conditions; it is possible to capture "a-depends-on-b if".

With this information, you need clustering. I think that for this you need some general clustering algorithm, and some user-defined ones are introduced to override it ("I insist, leave this #include file alone, and these two unbound unrelated things go together"). Then part of the ransformation DMS program can be used to mechanically separate code and include files in grouped dependent declarations.

DMS is a sophisticated tool; after all, it has to deal with such unpleasant things like C ++. Setting it up to perform the above tasks is not trivial, but I think it is within reach.

However, none of this will help you with your immediate problem of acquiring a tool that will help you solve your problem today.

+1
source

I am sure that there is no tool that will automatically complete this task. This is still an active area of ​​research. For example, see “ “ Towards Automating Class Separation Using Clustering Between Dimensions . ”I know several Java tools that provide some help ( JDeodorant , ext-c ), but they are not fully automatic. I don’t know any tools on C ++.

0
source

You do not say which editor or platform you are using, and therefore it is not clear why large files are a problem.

I assume this is your solution:

  • Get the best editor that can handle large files.

A good editor should be able to find a class by name, have a class browser that allows you to go to the definition of any class, member, function or any other definition, find the use of any character from the right side, click or shortcut keys and, as a rule, simplify the search so easy that file size will be out of date.

On the other hand, perhaps you have a good editor, and you just need to learn how to do it in it.

-4
source

All Articles