| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/value_extractors.h" | 5 #include "tools/gn/value_extractors.h" |
| 6 | 6 |
| 7 #include "tools/gn/build_settings.h" | 7 #include "tools/gn/build_settings.h" |
| 8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
| 9 #include "tools/gn/label.h" | 9 #include "tools/gn/label.h" |
| 10 #include "tools/gn/source_dir.h" | 10 #include "tools/gn/source_dir.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (!v.VerifyTypeIs(Value::STRING, err)) | 94 if (!v.VerifyTypeIs(Value::STRING, err)) |
| 95 return false; | 95 return false; |
| 96 *out = current_dir.ResolveRelativeDir(v.string_value(), | 96 *out = current_dir.ResolveRelativeDir(v.string_value(), |
| 97 build_settings->root_path_utf8()); | 97 build_settings->root_path_utf8()); |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 const BuildSettings* build_settings; | 100 const BuildSettings* build_settings; |
| 101 const SourceDir& current_dir; | 101 const SourceDir& current_dir; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // Fills the label part of a LabelPtrPair, leaving the pointer null. | 104 // Fills in a label. |
| 105 template<typename T> struct LabelResolver { | 105 template<typename T> struct LabelResolver { |
| 106 LabelResolver(const SourceDir& current_dir_in, | 106 LabelResolver(const SourceDir& current_dir_in, |
| 107 const Label& current_toolchain_in) | 107 const Label& current_toolchain_in) |
| 108 : current_dir(current_dir_in), | 108 : current_dir(current_dir_in), |
| 109 current_toolchain(current_toolchain_in) {} | 109 current_toolchain(current_toolchain_in) {} |
| 110 bool operator()(const Value& v, Label* out, Err* err) const { |
| 111 if (!v.VerifyTypeIs(Value::STRING, err)) |
| 112 return false; |
| 113 *out = Label::Resolve(current_dir, current_toolchain, v, err); |
| 114 return !err->has_error(); |
| 115 } |
| 116 const SourceDir& current_dir; |
| 117 const Label& current_toolchain; |
| 118 }; |
| 119 |
| 120 // Fills the label part of a LabelPtrPair, leaving the pointer null. |
| 121 template<typename T> struct LabelPtrResolver { |
| 122 LabelPtrResolver(const SourceDir& current_dir_in, |
| 123 const Label& current_toolchain_in) |
| 124 : current_dir(current_dir_in), |
| 125 current_toolchain(current_toolchain_in) {} |
| 110 bool operator()(const Value& v, LabelPtrPair<T>* out, Err* err) const { | 126 bool operator()(const Value& v, LabelPtrPair<T>* out, Err* err) const { |
| 111 if (!v.VerifyTypeIs(Value::STRING, err)) | 127 if (!v.VerifyTypeIs(Value::STRING, err)) |
| 112 return false; | 128 return false; |
| 113 out->label = Label::Resolve(current_dir, current_toolchain, v, err); | 129 out->label = Label::Resolve(current_dir, current_toolchain, v, err); |
| 114 out->origin = v.origin(); | 130 out->origin = v.origin(); |
| 115 return !err->has_error(); | 131 return !err->has_error(); |
| 116 } | 132 } |
| 117 const SourceDir& current_dir; | 133 const SourceDir& current_dir; |
| 118 const Label& current_toolchain; | 134 const Label& current_toolchain; |
| 119 }; | 135 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return ListValueExtractor(value, dest, err, | 168 return ListValueExtractor(value, dest, err, |
| 153 RelativeDirConverter(build_settings, current_dir)); | 169 RelativeDirConverter(build_settings, current_dir)); |
| 154 } | 170 } |
| 155 | 171 |
| 156 bool ExtractListOfLabels(const Value& value, | 172 bool ExtractListOfLabels(const Value& value, |
| 157 const SourceDir& current_dir, | 173 const SourceDir& current_dir, |
| 158 const Label& current_toolchain, | 174 const Label& current_toolchain, |
| 159 LabelTargetVector* dest, | 175 LabelTargetVector* dest, |
| 160 Err* err) { | 176 Err* err) { |
| 161 return ListValueExtractor(value, dest, err, | 177 return ListValueExtractor(value, dest, err, |
| 162 LabelResolver<Target>(current_dir, | 178 LabelPtrResolver<Target>(current_dir, |
| 163 current_toolchain)); | 179 current_toolchain)); |
| 164 } | 180 } |
| 165 | 181 |
| 166 bool ExtractListOfUniqueLabels(const Value& value, | 182 bool ExtractListOfUniqueLabels(const Value& value, |
| 167 const SourceDir& current_dir, | 183 const SourceDir& current_dir, |
| 168 const Label& current_toolchain, | 184 const Label& current_toolchain, |
| 169 UniqueVector<LabelConfigPair>* dest, | 185 UniqueVector<Label>* dest, |
| 170 Err* err) { | 186 Err* err) { |
| 171 return ListValueUniqueExtractor(value, dest, err, | 187 return ListValueUniqueExtractor(value, dest, err, |
| 172 LabelResolver<Config>(current_dir, | 188 LabelResolver<Config>(current_dir, |
| 173 current_toolchain)); | 189 current_toolchain)); |
| 174 } | 190 } |
| 175 | 191 |
| 176 bool ExtractListOfUniqueLabels(const Value& value, | 192 bool ExtractListOfUniqueLabels(const Value& value, |
| 177 const SourceDir& current_dir, | 193 const SourceDir& current_dir, |
| 178 const Label& current_toolchain, | 194 const Label& current_toolchain, |
| 195 UniqueVector<LabelConfigPair>* dest, |
| 196 Err* err) { |
| 197 return ListValueUniqueExtractor(value, dest, err, |
| 198 LabelPtrResolver<Config>(current_dir, |
| 199 current_toolchain)); |
| 200 } |
| 201 |
| 202 bool ExtractListOfUniqueLabels(const Value& value, |
| 203 const SourceDir& current_dir, |
| 204 const Label& current_toolchain, |
| 179 UniqueVector<LabelTargetPair>* dest, | 205 UniqueVector<LabelTargetPair>* dest, |
| 180 Err* err) { | 206 Err* err) { |
| 181 return ListValueUniqueExtractor(value, dest, err, | 207 return ListValueUniqueExtractor(value, dest, err, |
| 182 LabelResolver<Target>(current_dir, | 208 LabelPtrResolver<Target>(current_dir, |
| 183 current_toolchain)); | 209 current_toolchain)); |
| 184 } | 210 } |
| 185 | 211 |
| 186 bool ExtractRelativeFile(const BuildSettings* build_settings, | 212 bool ExtractRelativeFile(const BuildSettings* build_settings, |
| 187 const Value& value, | 213 const Value& value, |
| 188 const SourceDir& current_dir, | 214 const SourceDir& current_dir, |
| 189 SourceFile* file, | 215 SourceFile* file, |
| 190 Err* err) { | 216 Err* err) { |
| 191 RelativeFileConverter converter(build_settings, current_dir); | 217 RelativeFileConverter converter(build_settings, current_dir); |
| 192 return converter(value, file, err); | 218 return converter(value, file, err); |
| 193 } | 219 } |
| OLD | NEW |