]> git.tdb.fi Git - builder.git/blob - source/analyzer.h
Comments and member ordering
[builder.git] / source / analyzer.h
1 #ifndef ANALYZER_H_
2 #define ANALYZER_H_
3
4 #include <list>
5 #include <set>
6 #include <string>
7 #include <vector>
8
9 class Builder;
10 class Target;
11
12 /**
13 Performs various kinds of dependency analysis on the build tree.
14 */
15 class Analyzer
16 {
17 public:
18         enum Mode
19         {
20                 DEPS,     //< Skip over "trivial" targets such as InstalledFile
21                 ALLDEPS,  //< Print out absolutely every target
22                 REBUILD,  //< Print targets that are going to be rebuilt
23                 RDEPS     //< Print targets that depend on the given targets
24         };
25
26 private:
27         typedef std::vector<std::string> TableRow;
28         typedef std::list<TableRow> Table;
29
30         Builder &builder;
31         Mode mode;
32         Table table;
33         unsigned max_depth;
34         bool full_paths;
35         std::map<const Target *, std::set<Target *> > rdepends;
36
37 public:
38         Analyzer(Builder &);
39
40         void set_mode(Mode m) { mode = m; }
41         void set_max_depth(unsigned m) { max_depth = m; }
42         void set_full_paths(bool f) { full_paths = f; }
43
44         /// Performs the analysis and prints out the resulting dependency tree.
45         void analyze();
46
47 private:
48         /** Adds rows for a target, then recursively adds rows for dependencies as
49         needed. */
50         void build_depend_table(Target &, unsigned);
51
52         /// Prints out the table that resulted from the analysis.
53         void print_table() const;
54
55         static bool target_order(const Target *, const Target *);
56         static bool target_order_full(const Target *, const Target *);
57 };
58
59 #endif