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

Side by Side Diff: tools/gn/substitution_list.cc

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang warning 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "tools/gn/substitution_list.h"
6
7 #include <string.h>
8
9 #include "tools/gn/value.h"
10
11 SubstitutionList::SubstitutionList() {
12 }
13
14 SubstitutionList::~SubstitutionList() {
15 }
16
17 bool SubstitutionList::Parse(const Value& value, Err* err) {
18 if (!value.VerifyTypeIs(Value::LIST, err))
19 return false;
20
21 const std::vector<Value>& input_list = value.list_value();
22 list_.resize(input_list.size());
23 for (size_t i = 0; i < input_list.size(); i++) {
24 if (!list_[i].Parse(input_list[i], err))
25 return false;
26 }
27
28 FillRequiredTypes();
29 return true;
30 }
31
32 bool SubstitutionList::Parse(const std::vector<std::string>& values,
33 const ParseNode* origin,
34 Err* err) {
35 list_.resize(values.size());
36 for (size_t i = 0; i < values.size(); i++) {
37 if (!list_[i].Parse(values[i], origin, err))
38 return false;
39 }
40
41 FillRequiredTypes();
42 return true;
43 }
44
45 SubstitutionList SubstitutionList::MakeForTest(
46 const char* a,
47 const char* b,
48 const char* c) {
49 std::vector<std::string> input_strings;
50 input_strings.push_back(a);
51 if (b)
52 input_strings.push_back(b);
53 if (c)
54 input_strings.push_back(c);
55
56 Err err;
57 SubstitutionList result;
58 result.Parse(input_strings, NULL, &err);
59 return result;
60 }
61
62 void SubstitutionList::FillRequiredTypes() {
63 bool required_type_bits[SUBSTITUTION_NUM_TYPES];
64 memset(&required_type_bits, 0, SUBSTITUTION_NUM_TYPES);
65 for (size_t i = 0; i < list_.size(); i++)
66 list_[i].FillRequiredTypes(required_type_bits);
67
68 for (size_t i = SUBSTITUTION_FIRST_PATTERN; i < SUBSTITUTION_NUM_TYPES; i++) {
69 if (required_type_bits[i])
70 required_types_.push_back(static_cast<SubstitutionType>(i));
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698