Home | History | Annotate | Download | only in gn
      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   SubstitutionBits bits;
     29   FillRequiredTypes(&bits);
     30   bits.FillVector(&required_types_);
     31   return true;
     32 }
     33 
     34 bool SubstitutionList::Parse(const std::vector<std::string>& values,
     35                              const ParseNode* origin,
     36                              Err* err) {
     37   list_.resize(values.size());
     38   for (size_t i = 0; i < values.size(); i++) {
     39     if (!list_[i].Parse(values[i], origin, err))
     40       return false;
     41   }
     42 
     43   SubstitutionBits bits;
     44   FillRequiredTypes(&bits);
     45   bits.FillVector(&required_types_);
     46   return true;
     47 }
     48 
     49 SubstitutionList SubstitutionList::MakeForTest(
     50     const char* a,
     51     const char* b,
     52     const char* c) {
     53   std::vector<std::string> input_strings;
     54   input_strings.push_back(a);
     55   if (b)
     56     input_strings.push_back(b);
     57   if (c)
     58     input_strings.push_back(c);
     59 
     60   Err err;
     61   SubstitutionList result;
     62   result.Parse(input_strings, NULL, &err);
     63   return result;
     64 }
     65 
     66 void SubstitutionList::FillRequiredTypes(SubstitutionBits* bits) const {
     67   for (size_t i = 0; i < list_.size(); i++)
     68     list_[i].FillRequiredTypes(bits);
     69 }
     70