OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_GN_CONFIG_H_ | 5 #ifndef TOOLS_GN_CONFIG_H_ |
6 #define TOOLS_GN_CONFIG_H_ | 6 #define TOOLS_GN_CONFIG_H_ |
7 | 7 |
8 #include "base/logging.h" | |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "tools/gn/config_values.h" | 10 #include "tools/gn/config_values.h" |
10 #include "tools/gn/item.h" | 11 #include "tools/gn/item.h" |
12 #include "tools/gn/label_ptr.h" | |
13 #include "tools/gn/unique_vector.h" | |
11 | 14 |
12 // Represents a named config in the dependency graph. | 15 // Represents a named config in the dependency graph. |
16 // | |
17 // A config can contain other configs. We track both the data assigned directly | |
Dirk Pranke
2015/09/15 21:31:31
"contain" seems like a confusing way to describe t
| |
18 // on the config, this list of sub-configs, and (when the config is resolved) | |
19 // the resulting values of everything merged together. This prevents us from | |
20 // having to do a complicated recursive walk of configs to compute a target's | |
21 // flags. | |
Dirk Pranke
2015/09/15 21:31:31
I don't think I understand this sentence; aren't y
| |
13 class Config : public Item { | 22 class Config : public Item { |
14 public: | 23 public: |
15 Config(const Settings* settings, const Label& label); | 24 Config(const Settings* settings, const Label& label); |
16 ~Config() override; | 25 ~Config() override; |
17 | 26 |
27 // Item implementation. | |
18 Config* AsConfig() override; | 28 Config* AsConfig() override; |
19 const Config* AsConfig() const override; | 29 const Config* AsConfig() const override; |
30 bool OnResolved(Err* err) override; | |
20 | 31 |
21 ConfigValues& config_values() { return config_values_; } | 32 // The values set directly on this config. This will not contain datra from |
Dirk Pranke
2015/09/15 21:31:31
typo: "data"
| |
22 const ConfigValues& config_values() const { return config_values_; } | 33 // sub-configs. |
34 ConfigValues& own_values() { return own_values_; } | |
35 const ConfigValues& own_values() const { return own_values_; } | |
36 | |
37 // The values that represent this config and all sub-configs combined into | |
38 // one. This is only valid after the config is resolved (when we know the | |
39 // contents of the sub-configs). | |
40 const ConfigValues& resolved_values() const { | |
41 DCHECK(resolved_); | |
42 if (configs_.empty()) // No sub configs, just use the regular values. | |
43 return own_values_; | |
44 return composite_values_; | |
45 } | |
46 | |
47 // List of sub-configs. | |
48 const UniqueVector<LabelConfigPair>& configs() const { return configs_; } | |
49 UniqueVector<LabelConfigPair>& configs() { return configs_; } | |
23 | 50 |
24 private: | 51 private: |
25 ConfigValues config_values_; | 52 ConfigValues own_values_; |
53 | |
54 // Contains the own_values combined with sub-configs. Most configs don't have | |
55 // sub-configs. So as an optimization, this is not populated if there are no | |
56 // items in configs_. The resolved_values() getter handles this. | |
57 bool resolved_; | |
58 ConfigValues composite_values_; | |
59 | |
60 UniqueVector<LabelConfigPair> configs_; | |
26 | 61 |
27 DISALLOW_COPY_AND_ASSIGN(Config); | 62 DISALLOW_COPY_AND_ASSIGN(Config); |
28 }; | 63 }; |
29 | 64 |
30 #endif // TOOLS_GN_CONFIG_H_ | 65 #endif // TOOLS_GN_CONFIG_H_ |
OLD | NEW |