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