README.cppclean 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. Goal:
  2. -----
  3. CppClean attempts to find problems in C++ source that slow development
  4. in large code bases, for example various forms of unused code.
  5. Unused code can be unused functions, methods, data members, types, etc
  6. to unnecessary #include directives. Unnecessary #includes can cause
  7. considerable extra compiles increasing the edit-compile-run cycle.
  8. The project home page is: http://code.google.com/p/cppclean/
  9. Features:
  10. ---------
  11. * Find and print C++ language constructs: classes, methods, functions, etc.
  12. * Find classes with virtual methods, no virtual destructor, and no bases
  13. * Find global/static data that are potential problems when using threads
  14. * Unnecessary forward class declarations
  15. * Unnecessary function declarations
  16. * Undeclared function definitions
  17. * (planned) Find unnecessary header files #included
  18. - No direct reference to anything in the header
  19. - Header is unnecessary if classes were forward declared instead
  20. * (planned) Source files that reference headers not directly #included,
  21. ie, files that rely on a transitive #include from another header
  22. * (planned) Unused members (private, protected, & public) methods and data
  23. * (planned) Store AST in a SQL database so relationships can be queried
  24. AST is Abstract Syntax Tree, a representation of parsed source code.
  25. http://en.wikipedia.org/wiki/Abstract_syntax_tree
  26. System Requirements:
  27. --------------------
  28. * Python 2.4 or later (2.3 probably works too)
  29. * Works on Windows (untested), Mac OS X, and Unix
  30. How to Run:
  31. -----------
  32. For all examples, it is assumed that cppclean resides in a directory called
  33. /cppclean.
  34. To print warnings for classes with virtual methods, no virtual destructor and
  35. no base classes:
  36. /cppclean/run.sh nonvirtual_dtors.py file1.h file2.h file3.cc ...
  37. To print all the functions defined in header file(s):
  38. /cppclean/run.sh functions.py file1.h file2.h ...
  39. All the commands take multiple files on the command line. Other programs
  40. include: find_warnings, headers, methods, and types. Some other programs
  41. are available, but used primarily for debugging.
  42. run.sh is a simple wrapper that sets PYTHONPATH to /cppclean and then
  43. runs the program in /cppclean/cpp/PROGRAM.py. There is currently
  44. no equivalent for Windows. Contributions for a run.bat file
  45. would be greatly appreciated.
  46. How to Configure:
  47. -----------------
  48. You can add a siteheaders.py file in /cppclean/cpp to configure where
  49. to look for other headers (typically -I options passed to a compiler).
  50. Currently two values are supported: _TRANSITIVE and GetIncludeDirs.
  51. _TRANSITIVE should be set to a boolean value (True or False) indicating
  52. whether to transitively process all header files. The default is False.
  53. GetIncludeDirs is a function that takes a single argument and returns
  54. a sequence of directories to include. This can be a generator or
  55. return a static list.
  56. def GetIncludeDirs(filename):
  57. return ['/some/path/with/other/headers']
  58. # Here is a more complicated example.
  59. def GetIncludeDirs(filename):
  60. yield '/path1'
  61. yield os.path.join('/path2', os.path.dirname(filename))
  62. yield '/path3'
  63. How to Test:
  64. ------------
  65. For all examples, it is assumed that cppclean resides in a directory called
  66. /cppclean. The tests require
  67. cd /cppclean
  68. make test
  69. # To generate expected results after a change:
  70. make expected
  71. Current Status:
  72. ---------------
  73. The parser works pretty well for header files, parsing about 99% of Google's
  74. header files. Anything which inspects structure of C++ source files should
  75. work reasonably well. Function bodies are not transformed to an AST,
  76. but left as tokens. Much work is still needed on finding unused header files
  77. and storing an AST in a database.
  78. Non-goals:
  79. ----------
  80. * Parsing all valid C++ source
  81. * Handling invalid C++ source gracefully
  82. * Compiling to machine code (or anything beyond an AST)
  83. Contact:
  84. --------
  85. If you used cppclean, I would love to hear about your experiences
  86. cppclean@googlegroups.com. Even if you don't use cppclean, I'd like to
  87. hear from you. :-) (You can contact me directly at: nnorwitz@gmail.com)