4

Possible Duplicate:
C++ code dependency / call-graph “viewer”?

I am working on a huge C++ code base and currently I am stuck with the problem of modularizing my code. I have to divide my code into separate independent modules.

One approach I can think of is to generate the dependency graph and then do a higher level categorization. Other approach is to start with a entry point (some function abc()) and generating a function call tree whose each node will contain the name of the file in which that function resides. Thereafter I can use some script to extract those functions into separate modules.

My question is, is there any tool that can help me do this task? Has anybody faced such a problem earlier. Or can you suggest any approach to achieve the same?

Community
  • 1
  • 1
mukesh
  • 726
  • 1
  • 11
  • 27
  • 2
    Define "huge". Also, is there already some kind of modularization present in the code base? – wolfgang Jun 04 '12 at 11:01
  • @wolfgang : I have more than 1 million lines of code and around 30000 files in my code base .There is currently no modularization as such.. – mukesh Jun 04 '12 at 11:16
  • you can try cppdepend(http://www.cppdepend.com) which shows your dependency graph as modules and you can filter what you want to show in the dependency graph by using the CQLinq. – James from CppDepend Team Jul 10 '17 at 17:52

5 Answers5

6

First level of modularization - and I hope you already have done that - is structuring your code in classes. If your code is merely a collection of functions - i.e., C plus some syntactic suggar - then it's high time to rewrite your code, because no amount of dependency-graph-building will save you from maintenance hell.

If you have classes, modularizing should be a matter of finding classes that closely work together (like Customer, Order and Invoice) and separate them from classes that are only losely coupled with them (like Employer or Facility). Then take it from there.

Modularizing code is something that requires, first and foremost, thought. No automatic procedure is a replacement for that. Actually, from what little you wrote, I would fear that any automated process would make things worse, because apparently there has been too little thought invested in this project already. I.e., you wrote 1 million lines of code without thinking about modularization, and now you want modularization to happen while still not actually thinking about it. You are heading for epic fail.

DevSolar
  • 67,862
  • 21
  • 134
  • 209
  • yes my code is already organized in the form of classes but the problem is my code base is so huge ,its very difficult to find classes that work together. – mukesh Jun 04 '12 at 11:25
  • @ scholar: Then my second paragraph holds true. It should be possible to form "logic groups" of classes. The logic is actually more important than frequency of function calling. If you have a graphics program, you should have input / output filters in one module, transform filters in another, GUI elements in a third and so on. How often they call each other is irrelevant - the *compiler* finds code in other modules easy enough. The idea of modularization is for the *maintainer* of the code finding a certain function easily. No code analysis tool can replace common sense here. – DevSolar Jun 04 '12 at 11:28
4

To get some overview doxygen might help. But you have to play around a little with the doxyfile settings to generate dependency graps and if your Code base is huge you should disable dynamic stuff from the generated methods. Doxygen can create include, inheritance, call and caller graphs using graphviz.

Here are simple examples but it also works for bigger ones. But doxygen will only give you an overview and no refactoring capabilities.

albert
  • 8,285
  • 3
  • 19
  • 32
Totonga
  • 4,236
  • 2
  • 25
  • 31
1

I regularly use "Understand for C/C++" to investigate these kind of dependencies.

If the code base is really huge and you start your modularization from scratch, you might want to look at some other tools, like:

  • Cytoscape (which can take the output of "Understand for C/C++" to visualize the dependencies
  • Lattix
Patrick
  • 23,217
  • 12
  • 67
  • 130
1

It sounds like you are looking for a refactoring tool. Try taking a look at the answers on this question: Is there a working C++ refactoring tool?

Community
  • 1
  • 1
Gustav Bertram
  • 14,591
  • 3
  • 40
  • 65
0

One method will be a bit long but what you can do is to remove a method and compile to find dependencies and than group the decadencies into one component. Although this does not resolve your issue fully but it is an approach to start off with.

Tariq Mehmood
  • 259
  • 1
  • 5
  • 15