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_VALUE_H_ | 5 #ifndef TOOLS_GN_VALUE_H_ |
6 #define TOOLS_GN_VALUE_H_ | 6 #define TOOLS_GN_VALUE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
8 #include <map> | 9 #include <map> |
9 | 10 |
10 #include "base/basictypes.h" | |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_piece.h" | |
14 #include "tools/gn/err.h" | 14 #include "tools/gn/err.h" |
15 | 15 |
16 class ParseNode; | 16 class ParseNode; |
17 class Scope; | 17 class Scope; |
18 | 18 |
19 // Represents a variable value in the interpreter. | 19 // Represents a variable value in the interpreter. |
20 class Value { | 20 class Value { |
21 public: | 21 public: |
22 enum Type { | 22 enum Type { |
23 NONE = 0, | 23 NONE = 0, |
24 BOOLEAN, | 24 BOOLEAN, |
25 INTEGER, | 25 INTEGER, |
26 STRING, | 26 STRING, |
27 LIST, | 27 LIST, |
28 SCOPE, | 28 SCOPE, |
29 }; | 29 }; |
30 | 30 |
31 Value(); | 31 Value(); |
32 Value(const ParseNode* origin, Type t); | 32 Value(const ParseNode* origin, Type t); |
33 Value(const ParseNode* origin, bool bool_val); | 33 Value(const ParseNode* origin, bool bool_val); |
34 Value(const ParseNode* origin, int64 int_val); | 34 Value(const ParseNode* origin, int64_t int_val); |
35 Value(const ParseNode* origin, std::string str_val); | 35 Value(const ParseNode* origin, std::string str_val); |
36 Value(const ParseNode* origin, const char* str_val); | 36 Value(const ParseNode* origin, const char* str_val); |
37 // Values "shouldn't" have null scopes when type == Scope, so be sure to | 37 // Values "shouldn't" have null scopes when type == Scope, so be sure to |
38 // always set one. However, this is not asserted since there are some | 38 // always set one. However, this is not asserted since there are some |
39 // use-cases for creating values and immediately setting the scope on it. So | 39 // use-cases for creating values and immediately setting the scope on it. So |
40 // you can pass a null scope here if you promise to set it before any other | 40 // you can pass a null scope here if you promise to set it before any other |
41 // code gets it (code will generally assume the scope is not null). | 41 // code gets it (code will generally assume the scope is not null). |
42 Value(const ParseNode* origin, scoped_ptr<Scope> scope); | 42 Value(const ParseNode* origin, scoped_ptr<Scope> scope); |
43 | 43 |
44 Value(const Value& other); | 44 Value(const Value& other); |
(...skipping 12 matching lines...) Expand all Loading... |
57 | 57 |
58 bool& boolean_value() { | 58 bool& boolean_value() { |
59 DCHECK(type_ == BOOLEAN); | 59 DCHECK(type_ == BOOLEAN); |
60 return boolean_value_; | 60 return boolean_value_; |
61 } | 61 } |
62 const bool& boolean_value() const { | 62 const bool& boolean_value() const { |
63 DCHECK(type_ == BOOLEAN); | 63 DCHECK(type_ == BOOLEAN); |
64 return boolean_value_; | 64 return boolean_value_; |
65 } | 65 } |
66 | 66 |
67 int64& int_value() { | 67 int64_t& int_value() { |
68 DCHECK(type_ == INTEGER); | 68 DCHECK(type_ == INTEGER); |
69 return int_value_; | 69 return int_value_; |
70 } | 70 } |
71 const int64& int_value() const { | 71 const int64_t& int_value() const { |
72 DCHECK(type_ == INTEGER); | 72 DCHECK(type_ == INTEGER); |
73 return int_value_; | 73 return int_value_; |
74 } | 74 } |
75 | 75 |
76 std::string& string_value() { | 76 std::string& string_value() { |
77 DCHECK(type_ == STRING); | 77 DCHECK(type_ == STRING); |
78 return string_value_; | 78 return string_value_; |
79 } | 79 } |
80 const std::string& string_value() const { | 80 const std::string& string_value() const { |
81 DCHECK(type_ == STRING); | 81 DCHECK(type_ == STRING); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 bool operator!=(const Value& other) const; | 115 bool operator!=(const Value& other) const; |
116 | 116 |
117 private: | 117 private: |
118 // This are a lot of objects associated with every Value that need | 118 // This are a lot of objects associated with every Value that need |
119 // initialization and tear down every time. It might be more efficient to | 119 // initialization and tear down every time. It might be more efficient to |
120 // create a union of ManualConstructor objects (see SmallMap) and only | 120 // create a union of ManualConstructor objects (see SmallMap) and only |
121 // use the one we care about. | 121 // use the one we care about. |
122 Type type_; | 122 Type type_; |
123 std::string string_value_; | 123 std::string string_value_; |
124 bool boolean_value_; | 124 bool boolean_value_; |
125 int64 int_value_; | 125 int64_t int_value_; |
126 std::vector<Value> list_value_; | 126 std::vector<Value> list_value_; |
127 scoped_ptr<Scope> scope_value_; | 127 scoped_ptr<Scope> scope_value_; |
128 | 128 |
129 const ParseNode* origin_; | 129 const ParseNode* origin_; |
130 }; | 130 }; |
131 | 131 |
132 #endif // TOOLS_GN_VALUE_H_ | 132 #endif // TOOLS_GN_VALUE_H_ |
OLD | NEW |