]> git.tdb.fi Git - builder.git/blob - source/analyzer.h
Inline simple constructors
[builder.git] / source / analyzer.h
1 #ifndef ANALYZER_H_
2 #define ANALYZER_H_
3
4 #include <map>
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         using TableRow = std::vector<std::string>;
28
29         Builder &builder;
30         Mode mode = DEPS;
31         std::vector<TableRow> table;
32         unsigned max_depth = 0;
33         bool full_paths = false;
34         std::map<const Target *, std::set<Target *> > rdepends;
35
36 public:
37         Analyzer(Builder &b): builder(b) { }
38
39         void set_mode(Mode m) { mode = m; }
40         void set_max_depth(unsigned m) { max_depth = m; }
41         void set_full_paths(bool f) { full_paths = f; }
42
43         /// Performs the analysis and prints out the resulting dependency tree.
44         void analyze();
45
46 private:
47         /** Adds rows for a target, then recursively adds rows for dependencies as
48         needed. */
49         void build_depend_table(Target &, unsigned);
50
51         /// Prints out the table that resulted from the analysis.
52         void print_table() const;
53
54         static bool target_order(const Target *, const Target *);
55         static bool target_order_full(const Target *, const Target *);
56 };
57
58 #endif