Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: tools/gn/value.h

Issue 223783005: Add support for reading .gypi files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/template.cc ('k') | tools/gn/value.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/value.h
diff --git a/tools/gn/value.h b/tools/gn/value.h
index ee201c45e7b6a8065f3d014724eade3f79eccb8b..e6a98132972d2619a0c9e39e0192d1511566b788 100644
--- a/tools/gn/value.h
+++ b/tools/gn/value.h
@@ -5,8 +5,11 @@
#ifndef TOOLS_GN_VALUE_H_
#define TOOLS_GN_VALUE_H_
+#include <map>
+
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
#include "tools/gn/err.h"
@@ -22,7 +25,7 @@ class Value {
INTEGER,
STRING,
LIST,
- SCOPE
+ SCOPE,
};
Value();
@@ -31,10 +34,18 @@ class Value {
Value(const ParseNode* origin, int64 int_val);
Value(const ParseNode* origin, std::string str_val);
Value(const ParseNode* origin, const char* str_val);
- Value(const ParseNode* origin, Scope* scope); // Non-owning ptr.
- // (must outlive Value.)
+ // Values "shouldn't" have null scopes when type == Scope, so be sure to
+ // always set one. However, this is not asserted since there are some
+ // use-cases for creating values and immediately setting the scope on it. So
+ // you can pass a null scope here if you promise to set it before any other
+ // code gets it (code will generally assume the scope is not null).
+ Value(const ParseNode* origin, scoped_ptr<Scope> scope);
+
+ Value(const Value& other);
~Value();
+ Value& operator=(const Value& other);
+
Type type() const { return type_; }
// Returns a string describing the given type.
@@ -86,12 +97,13 @@ class Value {
Scope* scope_value() {
DCHECK(type_ == SCOPE);
- return scope_value_;
+ return scope_value_.get();
}
const Scope* scope_value() const {
DCHECK(type_ == SCOPE);
- return scope_value_;
+ return scope_value_.get();
}
+ void SetScopeValue(scoped_ptr<Scope> scope);
// Converts the given value to a string. Returns true if strings should be
// quoted or the ToString of a string should be the string itself.
@@ -106,12 +118,16 @@ class Value {
bool operator!=(const Value& other) const;
private:
+ // This are a lot of objects associated with every Value that need
+ // initialization and tear down every time. It might be more efficient to
+ // create a union of ManualConstructor objects (see SmallMap) and only
+ // use the one we care about.
Type type_;
std::string string_value_;
bool boolean_value_;
int64 int_value_;
std::vector<Value> list_value_;
- Scope* scope_value_; // Non-owning.
+ scoped_ptr<Scope> scope_value_;
const ParseNode* origin_;
};
« no previous file with comments | « tools/gn/template.cc ('k') | tools/gn/value.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698