]> git.tdb.fi Git - builder.git/blob - source/analyzer.h
Replace per-file copyright notices with a single file
[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 Install and Compile
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         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         /**
44         Performs the analysis and prints out the resulting dependency tree.
45         */
46         void analyze();
47
48 private:
49         /**
50         Adds rows to the table for the given target and its dependencies.
51         */
52         void build_depend_table(Target &, unsigned);
53
54         /**
55         Prints out the table that resulted from the analysis.
56         */
57         void print_table() const;
58
59         static bool target_order(const Target *, const Target *);
60         static bool target_order_full(const Target *, const Target *);
61 };
62
63 #endif