]> git.tdb.fi Git - builder.git/blob - source/analyzer.h
Remove most container typedefs and refactor others
[builder.git] / source / analyzer.h
1 #ifndef ANALYZER_H_
2 #define ANALYZER_H_
3
4 #include <list>
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <vector>
9
10 class Builder;
11 class Target;
12
13 /**
14 Performs various kinds of dependency analysis on the build tree.
15 */
16 class Analyzer
17 {
18 public:
19         enum Mode
20         {
21                 DEPS,     //< Skip over "trivial" targets such as InstalledFile
22                 ALLDEPS,  //< Print out absolutely every target
23                 REBUILD,  //< Print targets that are going to be rebuilt
24                 RDEPS     //< Print targets that depend on the given targets
25         };
26
27 private:
28         using TableRow = std::vector<std::string>;
29
30         Builder &builder;
31         Mode mode;
32         std::list<TableRow> 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