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

Unified Diff: tools/gn/substitution_list.cc

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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/substitution_list.h ('k') | tools/gn/substitution_pattern.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/substitution_list.cc
diff --git a/tools/gn/substitution_list.cc b/tools/gn/substitution_list.cc
new file mode 100644
index 0000000000000000000000000000000000000000..26b3909e7980b28a164488c911cc1551fa49d6d6
--- /dev/null
+++ b/tools/gn/substitution_list.cc
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/gn/substitution_list.h"
+
+#include <string.h>
+
+#include "tools/gn/value.h"
+
+SubstitutionList::SubstitutionList() {
+}
+
+SubstitutionList::~SubstitutionList() {
+}
+
+bool SubstitutionList::Parse(const Value& value, Err* err) {
+ if (!value.VerifyTypeIs(Value::LIST, err))
+ return false;
+
+ const std::vector<Value>& input_list = value.list_value();
+ list_.resize(input_list.size());
+ for (size_t i = 0; i < input_list.size(); i++) {
+ if (!list_[i].Parse(input_list[i], err))
+ return false;
+ }
+
+ FillRequiredTypes();
+ return true;
+}
+
+bool SubstitutionList::Parse(const std::vector<std::string>& values,
+ const ParseNode* origin,
+ Err* err) {
+ list_.resize(values.size());
+ for (size_t i = 0; i < values.size(); i++) {
+ if (!list_[i].Parse(values[i], origin, err))
+ return false;
+ }
+
+ FillRequiredTypes();
+ return true;
+}
+
+SubstitutionList SubstitutionList::MakeForTest(
+ const char* a,
+ const char* b,
+ const char* c) {
+ std::vector<std::string> input_strings;
+ input_strings.push_back(a);
+ if (b)
+ input_strings.push_back(b);
+ if (c)
+ input_strings.push_back(c);
+
+ Err err;
+ SubstitutionList result;
+ result.Parse(input_strings, NULL, &err);
+ return result;
+}
+
+void SubstitutionList::FillRequiredTypes() {
+ bool required_type_bits[SUBSTITUTION_NUM_TYPES];
+ memset(&required_type_bits, 0, SUBSTITUTION_NUM_TYPES);
+ for (size_t i = 0; i < list_.size(); i++)
+ list_[i].FillRequiredTypes(required_type_bits);
+
+ for (size_t i = SUBSTITUTION_FIRST_PATTERN; i < SUBSTITUTION_NUM_TYPES; i++) {
+ if (required_type_bits[i])
+ required_types_.push_back(static_cast<SubstitutionType>(i));
+ }
+}
« no previous file with comments | « tools/gn/substitution_list.h ('k') | tools/gn/substitution_pattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698