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.
5 #include "tools/gn/substitution_list.h"
9 #include "tools/gn/value.h"
11 SubstitutionList::SubstitutionList() {
14 SubstitutionList::~SubstitutionList() {
17 bool SubstitutionList::Parse(const Value
& value
, Err
* err
) {
18 if (!value
.VerifyTypeIs(Value::LIST
, err
))
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
))
28 SubstitutionBits bits
;
29 FillRequiredTypes(&bits
);
30 bits
.FillVector(&required_types_
);
34 bool SubstitutionList::Parse(const std::vector
<std::string
>& values
,
35 const ParseNode
* origin
,
37 list_
.resize(values
.size());
38 for (size_t i
= 0; i
< values
.size(); i
++) {
39 if (!list_
[i
].Parse(values
[i
], origin
, err
))
43 SubstitutionBits bits
;
44 FillRequiredTypes(&bits
);
45 bits
.FillVector(&required_types_
);
49 SubstitutionList
SubstitutionList::MakeForTest(
53 std::vector
<std::string
> input_strings
;
54 input_strings
.push_back(a
);
56 input_strings
.push_back(b
);
58 input_strings
.push_back(c
);
61 SubstitutionList result
;
62 result
.Parse(input_strings
, nullptr, &err
);
66 void SubstitutionList::FillRequiredTypes(SubstitutionBits
* bits
) const {
67 for (const auto& item
: list_
)
68 item
.FillRequiredTypes(bits
);