blob: dbd0a0ca1799fb3e54670acfe309790bfe3aa3c6 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Adam Lesinskicacb28f2016-10-19 12:18:14 -070017#include "ResourceTable.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080018
Adam Lesinskicacb28f2016-10-19 12:18:14 -070019#include <algorithm>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020#include <memory>
21#include <string>
22#include <tuple>
23
Adam Lesinski66ea8402017-06-28 11:44:11 -070024#include "android-base/logging.h"
Adam Lesinski71be7052017-12-12 16:48:07 -080025#include "android-base/stringprintf.h"
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020026#include "androidfw/ConfigDescription.h"
Adam Lesinski66ea8402017-06-28 11:44:11 -070027#include "androidfw/ResourceTypes.h"
28
Ryan Mitchell83a37ad2018-08-06 16:32:24 -070029#include "Debug.h"
Adam Lesinski66ea8402017-06-28 11:44:11 -070030#include "NameMangler.h"
31#include "ResourceValues.h"
32#include "ValueVisitor.h"
33#include "text/Unicode.h"
34#include "util/Util.h"
35
36using ::aapt::text::IsValidResourceEntryName;
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020037using ::android::ConfigDescription;
Adam Lesinski66ea8402017-06-28 11:44:11 -070038using ::android::StringPiece;
Adam Lesinski71be7052017-12-12 16:48:07 -080039using ::android::base::StringPrintf;
Adam Lesinskid5083f62017-01-16 15:07:21 -080040
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080041namespace aapt {
42
Ryan Mitchell54237ff2018-12-13 15:44:29 -080043const char* Overlayable::kActorScheme = "overlay";
44
Ryan Mitchell83a37ad2018-08-06 16:32:24 -070045static bool less_than_type_and_id(const std::unique_ptr<ResourceTableType>& lhs,
46 const std::pair<ResourceType, Maybe<uint8_t>>& rhs) {
47 return lhs->type < rhs.first || (lhs->type == rhs.first && rhs.second && lhs->id < rhs.second);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080048}
49
Adam Lesinski1ab598f2015-08-14 14:26:04 -070050template <typename T>
Adam Lesinskib1afa072017-03-29 13:52:38 -070051static bool less_than_struct_with_name(const std::unique_ptr<T>& lhs, const StringPiece& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070052 return lhs->name.compare(0, lhs->name.size(), rhs.data(), rhs.size()) < 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080053}
54
David Chaloupkae3c1a4a2018-01-18 13:44:36 +000055template <typename T>
56static bool less_than_struct_with_name_and_id(const std::unique_ptr<T>& lhs,
Ryan Mitchell8d4ee972018-08-27 11:24:04 -070057 const std::pair<StringPiece, Maybe<uint16_t>>& rhs) {
David Chaloupkae3c1a4a2018-01-18 13:44:36 +000058 int name_cmp = lhs->name.compare(0, lhs->name.size(), rhs.first.data(), rhs.first.size());
Ryan Mitchell83a37ad2018-08-06 16:32:24 -070059 return name_cmp < 0 || (name_cmp == 0 && rhs.second && lhs->id < rhs.second);
David Chaloupkae3c1a4a2018-01-18 13:44:36 +000060}
61
Adam Lesinski71be7052017-12-12 16:48:07 -080062ResourceTablePackage* ResourceTable::FindPackage(const StringPiece& name) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070063 const auto last = packages.end();
Adam Lesinskib1afa072017-03-29 13:52:38 -070064 auto iter = std::lower_bound(packages.begin(), last, name,
65 less_than_struct_with_name<ResourceTablePackage>);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066 if (iter != last && name == (*iter)->name) {
67 return iter->get();
68 }
69 return nullptr;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080070}
71
Adam Lesinski71be7052017-12-12 16:48:07 -080072ResourceTablePackage* ResourceTable::FindPackageById(uint8_t id) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070073 for (auto& package : packages) {
74 if (package->id && package->id.value() == id) {
75 return package.get();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080076 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -070077 }
78 return nullptr;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080079}
80
Adam Lesinskib1afa072017-03-29 13:52:38 -070081ResourceTablePackage* ResourceTable::CreatePackage(const StringPiece& name, Maybe<uint8_t> id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070082 ResourceTablePackage* package = FindOrCreatePackage(name);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070083 if (id && !package->id) {
84 package->id = id;
Adam Lesinski9ba47d82015-10-13 11:37:10 -070085 return package;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070086 }
87
88 if (id && package->id && package->id.value() != id.value()) {
89 return nullptr;
90 }
91 return package;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080092}
93
David Chaloupkae3c1a4a2018-01-18 13:44:36 +000094ResourceTablePackage* ResourceTable::CreatePackageAllowingDuplicateNames(const StringPiece& name,
95 const Maybe<uint8_t> id) {
96 const auto last = packages.end();
97 auto iter = std::lower_bound(packages.begin(), last, std::make_pair(name, id),
98 less_than_struct_with_name_and_id<ResourceTablePackage>);
99
100 if (iter != last && name == (*iter)->name && id == (*iter)->id) {
101 return iter->get();
102 }
103
104 std::unique_ptr<ResourceTablePackage> new_package = util::make_unique<ResourceTablePackage>();
105 new_package->name = name.to_string();
106 new_package->id = id;
107 return packages.emplace(iter, std::move(new_package))->get();
108}
109
Adam Lesinskib1afa072017-03-29 13:52:38 -0700110ResourceTablePackage* ResourceTable::FindOrCreatePackage(const StringPiece& name) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700111 const auto last = packages.end();
Adam Lesinskib1afa072017-03-29 13:52:38 -0700112 auto iter = std::lower_bound(packages.begin(), last, name,
113 less_than_struct_with_name<ResourceTablePackage>);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700114 if (iter != last && name == (*iter)->name) {
115 return iter->get();
116 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800117
Adam Lesinskib1afa072017-03-29 13:52:38 -0700118 std::unique_ptr<ResourceTablePackage> new_package = util::make_unique<ResourceTablePackage>();
Adam Lesinskid5083f62017-01-16 15:07:21 -0800119 new_package->name = name.to_string();
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700120 return packages.emplace(iter, std::move(new_package))->get();
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700121}
122
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700123ResourceTableType* ResourceTablePackage::FindType(ResourceType type, const Maybe<uint8_t> id) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700124 const auto last = types.end();
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700125 auto iter = std::lower_bound(types.begin(), last, std::make_pair(type, id),
126 less_than_type_and_id);
127 if (iter != last && (*iter)->type == type && (!id || id == (*iter)->id)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700128 return iter->get();
129 }
130 return nullptr;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700131}
132
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700133ResourceTableType* ResourceTablePackage::FindOrCreateType(ResourceType type,
134 const Maybe<uint8_t> id) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700135 const auto last = types.end();
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700136 auto iter = std::lower_bound(types.begin(), last, std::make_pair(type, id),
137 less_than_type_and_id);
138 if (iter != last && (*iter)->type == type && (!id || id == (*iter)->id)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700139 return iter->get();
140 }
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700141
142 auto new_type = new ResourceTableType(type);
143 new_type->id = id;
144 return types.emplace(iter, std::move(new_type))->get();
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700145}
146
Ryan Mitchell8d4ee972018-08-27 11:24:04 -0700147ResourceEntry* ResourceTableType::FindEntry(const StringPiece& name, const Maybe<uint16_t> id) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700148 const auto last = entries.end();
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700149 auto iter = std::lower_bound(entries.begin(), last, std::make_pair(name, id),
150 less_than_struct_with_name_and_id<ResourceEntry>);
151 if (iter != last && name == (*iter)->name && (!id || id == (*iter)->id)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700152 return iter->get();
153 }
154 return nullptr;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700155}
156
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700157ResourceEntry* ResourceTableType::FindOrCreateEntry(const StringPiece& name,
Ryan Mitchell8d4ee972018-08-27 11:24:04 -0700158 const Maybe<uint16_t > id) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700159 auto last = entries.end();
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700160 auto iter = std::lower_bound(entries.begin(), last, std::make_pair(name, id),
161 less_than_struct_with_name_and_id<ResourceEntry>);
162 if (iter != last && name == (*iter)->name && (!id || id == (*iter)->id)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700163 return iter->get();
164 }
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700165
166 auto new_entry = new ResourceEntry(name);
167 new_entry->id = id;
168 return entries.emplace(iter, std::move(new_entry))->get();
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700169}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800170
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700171ResourceConfigValue* ResourceEntry::FindValue(const ConfigDescription& config) {
172 return FindValue(config, StringPiece());
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800173}
174
175struct ConfigKey {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700176 const ConfigDescription* config;
177 const StringPiece& product;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800178};
179
Adam Lesinski34a16872018-02-23 16:18:10 -0800180bool lt_config_key_ref(const std::unique_ptr<ResourceConfigValue>& lhs, const ConfigKey& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700181 int cmp = lhs->config.compare(*rhs.config);
182 if (cmp == 0) {
183 cmp = StringPiece(lhs->product).compare(rhs.product);
184 }
185 return cmp < 0;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800186}
187
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700188ResourceConfigValue* ResourceEntry::FindValue(const ConfigDescription& config,
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800189 const StringPiece& product) {
Adam Lesinski34a16872018-02-23 16:18:10 -0800190 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
191 lt_config_key_ref);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700192 if (iter != values.end()) {
193 ResourceConfigValue* value = iter->get();
194 if (value->config == config && StringPiece(value->product) == product) {
195 return value;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800196 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700197 }
198 return nullptr;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800199}
200
Adam Lesinskib1afa072017-03-29 13:52:38 -0700201ResourceConfigValue* ResourceEntry::FindOrCreateValue(const ConfigDescription& config,
202 const StringPiece& product) {
Adam Lesinski34a16872018-02-23 16:18:10 -0800203 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
204 lt_config_key_ref);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700205 if (iter != values.end()) {
206 ResourceConfigValue* value = iter->get();
207 if (value->config == config && StringPiece(value->product) == product) {
208 return value;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800209 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700210 }
211 ResourceConfigValue* newValue =
Adam Lesinskib1afa072017-03-29 13:52:38 -0700212 values.insert(iter, util::make_unique<ResourceConfigValue>(config, product))->get();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700213 return newValue;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800214}
215
Adam Lesinskib1afa072017-03-29 13:52:38 -0700216std::vector<ResourceConfigValue*> ResourceEntry::FindAllValues(const ConfigDescription& config) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700217 std::vector<ResourceConfigValue*> results;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800218
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700219 auto iter = values.begin();
220 for (; iter != values.end(); ++iter) {
221 ResourceConfigValue* value = iter->get();
222 if (value->config == config) {
223 results.push_back(value);
224 ++iter;
225 break;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800226 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700227 }
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800228
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700229 for (; iter != values.end(); ++iter) {
230 ResourceConfigValue* value = iter->get();
231 if (value->config == config) {
232 results.push_back(value);
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800233 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700234 }
235 return results;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800236}
237
Adam Lesinski34a16872018-02-23 16:18:10 -0800238bool ResourceEntry::HasDefaultValue() const {
239 const ConfigDescription& default_config = ConfigDescription::DefaultConfig();
240
241 // The default config should be at the top of the list, since the list is sorted.
242 for (auto& config_value : values) {
243 if (config_value->config == default_config) {
244 return true;
Adam Lesinski458b8772016-04-25 14:20:21 -0700245 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700246 }
Adam Lesinski34a16872018-02-23 16:18:10 -0800247 return false;
Adam Lesinski458b8772016-04-25 14:20:21 -0700248}
249
Adam Lesinski71be7052017-12-12 16:48:07 -0800250// The default handler for collisions.
251//
252// Typically, a weak value will be overridden by a strong value. An existing weak
253// value will not be overridden by an incoming weak value.
254//
255// There are some exceptions:
256//
257// Attributes: There are two types of Attribute values: USE and DECL.
258//
259// USE is anywhere an Attribute is declared without a format, and in a place that would
260// be legal to declare if the Attribute already existed. This is typically in a
261// <declare-styleable> tag. Attributes defined in a <declare-styleable> are also weak.
262//
263// DECL is an absolute declaration of an Attribute and specifies an explicit format.
264//
265// A DECL will override a USE without error. Two DECLs must match in their format for there to be
266// no error.
Adam Lesinskib1afa072017-03-29 13:52:38 -0700267ResourceTable::CollisionResult ResourceTable::ResolveValueCollision(Value* existing,
268 Value* incoming) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700269 Attribute* existing_attr = ValueCast<Attribute>(existing);
270 Attribute* incoming_attr = ValueCast<Attribute>(incoming);
271 if (!incoming_attr) {
272 if (incoming->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700273 // We're trying to add a weak resource but a resource
274 // already exists. Keep the existing.
275 return CollisionResult::kKeepOriginal;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700276 } else if (existing->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700277 // Override the weak resource with the new strong resource.
278 return CollisionResult::kTakeNew;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800279 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700280 // The existing and incoming values are strong, this is an error
281 // if the values are not both attributes.
Adam Lesinski5c3464c2016-08-24 16:03:48 -0700282 return CollisionResult::kConflict;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700283 }
284
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700285 if (!existing_attr) {
286 if (existing->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700287 // The existing value is not an attribute and it is weak,
288 // so take the incoming attribute value.
289 return CollisionResult::kTakeNew;
290 }
291 // The existing value is not an attribute and it is strong,
292 // so the incoming attribute value is an error.
293 return CollisionResult::kConflict;
294 }
295
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700296 CHECK(incoming_attr != nullptr && existing_attr != nullptr);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700297
298 //
299 // Attribute specific handling. At this point we know both
300 // values are attributes. Since we can declare and define
301 // attributes all-over, we do special handling to see
302 // which definition sticks.
303 //
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800304 if (existing_attr->IsCompatibleWith(*incoming_attr)) {
305 // The two attributes are both DECLs, but they are plain attributes with compatible formats.
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700306 // Keep the strongest one.
Adam Lesinskib1afa072017-03-29 13:52:38 -0700307 return existing_attr->IsWeak() ? CollisionResult::kTakeNew : CollisionResult::kKeepOriginal;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700308 }
309
Adam Lesinskib1afa072017-03-29 13:52:38 -0700310 if (existing_attr->IsWeak() && existing_attr->type_mask == android::ResTable_map::TYPE_ANY) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700311 // Any incoming attribute is better than this.
312 return CollisionResult::kTakeNew;
313 }
314
Adam Lesinskib1afa072017-03-29 13:52:38 -0700315 if (incoming_attr->IsWeak() && incoming_attr->type_mask == android::ResTable_map::TYPE_ANY) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700316 // The incoming attribute may be a USE instead of a DECL.
317 // Keep the existing attribute.
318 return CollisionResult::kKeepOriginal;
319 }
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700320
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700321 return CollisionResult::kConflict;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800322}
323
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700324ResourceTable::CollisionResult ResourceTable::IgnoreCollision(Value* /** existing **/,
325 Value* /** incoming **/) {
326 return CollisionResult::kKeepBoth;
327}
328
Adam Lesinski71be7052017-12-12 16:48:07 -0800329static StringPiece ResourceNameValidator(const StringPiece& name) {
Adam Lesinski66ea8402017-06-28 11:44:11 -0700330 if (!IsValidResourceEntryName(name)) {
331 return name;
Adam Lesinskib1afa072017-03-29 13:52:38 -0700332 }
333 return {};
334}
335
Adam Lesinski71be7052017-12-12 16:48:07 -0800336static StringPiece SkipNameValidator(const StringPiece& /*name*/) {
Adam Lesinskib1afa072017-03-29 13:52:38 -0700337 return {};
338}
Adam Lesinski330edcd2015-05-04 17:40:56 -0700339
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700340bool ResourceTable::AddResource(const ResourceNameRef& name,
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800341 const ConfigDescription& config,
342 const StringPiece& product,
343 std::unique_ptr<Value> value,
Adam Lesinskie78fd612015-10-22 12:48:43 -0700344 IDiagnostics* diag) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700345 return AddResourceImpl(name, ResourceId{}, config, product, std::move(value),
346 (validate_resources_ ? ResourceNameValidator : SkipNameValidator),
347 (validate_resources_ ? ResolveValueCollision : IgnoreCollision), diag);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700348}
349
Adam Lesinski71be7052017-12-12 16:48:07 -0800350bool ResourceTable::AddResourceWithId(const ResourceNameRef& name, const ResourceId& res_id,
351 const ConfigDescription& config, const StringPiece& product,
352 std::unique_ptr<Value> value, IDiagnostics* diag) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700353 return AddResourceImpl(name, res_id, config, product, std::move(value),
354 (validate_resources_ ? ResourceNameValidator : SkipNameValidator),
355 (validate_resources_ ? ResolveValueCollision : IgnoreCollision), diag);
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800356}
357
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700358bool ResourceTable::AddFileReference(const ResourceNameRef& name,
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800359 const ConfigDescription& config,
360 const Source& source,
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700361 const StringPiece& path,
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700362 IDiagnostics* diag) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700363 return AddFileReferenceImpl(name, config, source, path, nullptr,
364 (validate_resources_ ? ResourceNameValidator : SkipNameValidator),
365 diag);
Adam Lesinskifb48d292015-11-07 15:52:13 -0800366}
367
Adam Lesinski71be7052017-12-12 16:48:07 -0800368bool ResourceTable::AddFileReferenceMangled(const ResourceNameRef& name,
369 const ConfigDescription& config, const Source& source,
370 const StringPiece& path, io::IFile* file,
371 IDiagnostics* diag) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700372 return AddFileReferenceImpl(name, config, source, path, file,
373 (validate_resources_ ? ResourceNameValidator : SkipNameValidator),
374 diag);
Adam Lesinski355f2852016-02-13 20:26:45 -0800375}
376
Adam Lesinskib1afa072017-03-29 13:52:38 -0700377bool ResourceTable::AddFileReferenceImpl(const ResourceNameRef& name,
378 const ConfigDescription& config, const Source& source,
379 const StringPiece& path, io::IFile* file,
380 NameValidator name_validator, IDiagnostics* diag) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700381 std::unique_ptr<FileReference> fileRef =
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700382 util::make_unique<FileReference>(string_pool.MakeRef(path));
383 fileRef->SetSource(source);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700384 fileRef->file = file;
Adam Lesinskib1afa072017-03-29 13:52:38 -0700385 return AddResourceImpl(name, ResourceId{}, config, StringPiece{}, std::move(fileRef),
386 name_validator, ResolveValueCollision, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700387}
388
Adam Lesinski71be7052017-12-12 16:48:07 -0800389bool ResourceTable::AddResourceMangled(const ResourceNameRef& name, const ConfigDescription& config,
390 const StringPiece& product, std::unique_ptr<Value> value,
391 IDiagnostics* diag) {
392 return AddResourceImpl(name, ResourceId{}, config, product, std::move(value), SkipNameValidator,
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700393 (validate_resources_ ? ResolveValueCollision : IgnoreCollision), diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700394}
395
Adam Lesinski71be7052017-12-12 16:48:07 -0800396bool ResourceTable::AddResourceWithIdMangled(const ResourceNameRef& name, const ResourceId& id,
397 const ConfigDescription& config,
398 const StringPiece& product,
399 std::unique_ptr<Value> value, IDiagnostics* diag) {
400 return AddResourceImpl(name, id, config, product, std::move(value), SkipNameValidator,
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700401 (validate_resources_ ? ResolveValueCollision : IgnoreCollision), diag);
Adam Lesinski9e10ac72015-10-16 14:37:48 -0700402}
403
Adam Lesinski71be7052017-12-12 16:48:07 -0800404bool ResourceTable::ValidateName(NameValidator name_validator, const ResourceNameRef& name,
405 const Source& source, IDiagnostics* diag) {
406 const StringPiece bad_char = name_validator(name.entry);
407 if (!bad_char.empty()) {
408 diag->Error(DiagMessage(source) << "resource '" << name << "' has invalid entry name '"
409 << name.entry << "'. Invalid character '" << bad_char << "'");
410 return false;
411 }
412 return true;
413}
414
Adam Lesinskib1afa072017-03-29 13:52:38 -0700415bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceId& res_id,
416 const ConfigDescription& config, const StringPiece& product,
417 std::unique_ptr<Value> value, NameValidator name_validator,
Adam Lesinski71be7052017-12-12 16:48:07 -0800418 const CollisionResolverFunc& conflict_resolver,
Adam Lesinskib1afa072017-03-29 13:52:38 -0700419 IDiagnostics* diag) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700420 CHECK(value != nullptr);
421 CHECK(diag != nullptr);
Adam Lesinskie78fd612015-10-22 12:48:43 -0700422
Adam Lesinski71be7052017-12-12 16:48:07 -0800423 const Source& source = value->GetSource();
424 if (!ValidateName(name_validator, name, source, diag)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700425 return false;
426 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800427
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700428 // Check for package names appearing twice with two different package ids
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700429 ResourceTablePackage* package = FindOrCreatePackage(name.package);
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800430 if (res_id.is_valid_dynamic() && package->id && package->id.value() != res_id.package_id()) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700431 diag->Error(DiagMessage(source)
432 << "trying to add resource '" << name << "' with ID " << res_id
433 << " but package '" << package->name << "' already has ID "
434 << StringPrintf("%02x", package->id.value()));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700435 return false;
436 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800437
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700438 // Whether or not to error on duplicate resources
439 bool check_id = validate_resources_ && res_id.is_valid_dynamic();
440 // Whether or not to create a duplicate resource if the id does not match
441 bool use_id = !validate_resources_ && res_id.is_valid_dynamic();
442
443 ResourceTableType* type = package->FindOrCreateType(name.type, use_id ? res_id.type_id()
444 : Maybe<uint8_t>());
445
446 // Check for types appearing twice with two different type ids
447 if (check_id && type->id && type->id.value() != res_id.type_id()) {
Adam Lesinski71be7052017-12-12 16:48:07 -0800448 diag->Error(DiagMessage(source)
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700449 << "trying to add resource '" << name << "' with ID " << res_id
450 << " but type '" << type->type << "' already has ID "
451 << StringPrintf("%02x", type->id.value()));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700452 return false;
453 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800454
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700455 ResourceEntry* entry = type->FindOrCreateEntry(name.entry, use_id ? res_id.entry_id()
Ryan Mitchell8d4ee972018-08-27 11:24:04 -0700456 : Maybe<uint16_t>());
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700457
458 // Check for entries appearing twice with two different entry ids
459 if (check_id && entry->id && entry->id.value() != res_id.entry_id()) {
Adam Lesinski71be7052017-12-12 16:48:07 -0800460 diag->Error(DiagMessage(source)
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700461 << "trying to add resource '" << name << "' with ID " << res_id
462 << " but resource already has ID "
463 << ResourceId(package->id.value(), type->id.value(), entry->id.value()));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700464 return false;
465 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700466
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700467 ResourceConfigValue* config_value = entry->FindOrCreateValue(config, product);
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700468 if (!config_value->value) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700469 // Resource does not exist, add it now.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700470 config_value->value = std::move(value);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700471 } else {
Adam Lesinski71be7052017-12-12 16:48:07 -0800472 switch (conflict_resolver(config_value->value.get(), value.get())) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700473 case CollisionResult::kKeepBoth:
474 // Insert the value ignoring for duplicate configurations
475 entry->values.push_back(util::make_unique<ResourceConfigValue>(config, product));
476 entry->values.back()->value = std::move(value);
477 break;
478
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700479 case CollisionResult::kTakeNew:
480 // Take the incoming value.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700481 config_value->value = std::move(value);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700482 break;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800483
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700484 case CollisionResult::kConflict:
Adam Lesinski71be7052017-12-12 16:48:07 -0800485 diag->Error(DiagMessage(source) << "duplicate value for resource '" << name << "' "
486 << "with config '" << config << "'");
487 diag->Error(DiagMessage(source) << "resource previously defined here");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700488 return false;
Adam Lesinski5c3464c2016-08-24 16:03:48 -0700489
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700490 case CollisionResult::kKeepOriginal:
491 break;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800492 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700493 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800494
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800495 if (res_id.is_valid_dynamic()) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700496 package->id = res_id.package_id();
497 type->id = res_id.type_id();
498 entry->id = res_id.entry_id();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700499 }
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700500
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700501 return true;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800502}
503
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700504bool ResourceTable::GetValidateResources() {
505 return validate_resources_;
506}
507
Adam Lesinski71be7052017-12-12 16:48:07 -0800508bool ResourceTable::SetVisibility(const ResourceNameRef& name, const Visibility& visibility,
509 IDiagnostics* diag) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700510 return SetVisibilityImpl(name, visibility, {}, ResourceNameValidator, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700511}
512
Adam Lesinski71be7052017-12-12 16:48:07 -0800513bool ResourceTable::SetVisibilityMangled(const ResourceNameRef& name, const Visibility& visibility,
514 IDiagnostics* diag) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700515 return SetVisibilityImpl(name, visibility, {}, SkipNameValidator, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700516}
517
Adam Lesinski71be7052017-12-12 16:48:07 -0800518bool ResourceTable::SetVisibilityWithId(const ResourceNameRef& name, const Visibility& visibility,
519 const ResourceId& res_id, IDiagnostics* diag) {
520 return SetVisibilityImpl(name, visibility, res_id, ResourceNameValidator, diag);
521}
522
523bool ResourceTable::SetVisibilityWithIdMangled(const ResourceNameRef& name,
524 const Visibility& visibility,
525 const ResourceId& res_id, IDiagnostics* diag) {
526 return SetVisibilityImpl(name, visibility, res_id, SkipNameValidator, diag);
527}
528
529bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibility& visibility,
530 const ResourceId& res_id, NameValidator name_validator,
531 IDiagnostics* diag) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700532 CHECK(diag != nullptr);
Adam Lesinskie78fd612015-10-22 12:48:43 -0700533
Adam Lesinski71be7052017-12-12 16:48:07 -0800534 const Source& source = visibility.source;
535 if (!ValidateName(name_validator, name, source, diag)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700536 return false;
537 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800538
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700539 // Check for package names appearing twice with two different package ids
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700540 ResourceTablePackage* package = FindOrCreatePackage(name.package);
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800541 if (res_id.is_valid_dynamic() && package->id && package->id.value() != res_id.package_id()) {
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700542 diag->Error(DiagMessage(source)
543 << "trying to add resource '" << name << "' with ID " << res_id
544 << " but package '" << package->name << "' already has ID "
545 << StringPrintf("%02x", package->id.value()));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700546 return false;
547 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800548
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700549 // Whether or not to error on duplicate resources
550 bool check_id = validate_resources_ && res_id.is_valid_dynamic();
551 // Whether or not to create a duplicate resource if the id does not match
552 bool use_id = !validate_resources_ && res_id.is_valid_dynamic();
553
554 ResourceTableType* type = package->FindOrCreateType(name.type, use_id ? res_id.type_id()
555 : Maybe<uint8_t>());
556
557 // Check for types appearing twice with two different type ids
558 if (check_id && type->id && type->id.value() != res_id.type_id()) {
Adam Lesinski71be7052017-12-12 16:48:07 -0800559 diag->Error(DiagMessage(source)
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700560 << "trying to add resource '" << name << "' with ID " << res_id
561 << " but type '" << type->type << "' already has ID "
562 << StringPrintf("%02x", type->id.value()));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700563 return false;
564 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700565
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700566 ResourceEntry* entry = type->FindOrCreateEntry(name.entry, use_id ? res_id.entry_id()
Ryan Mitchell8d4ee972018-08-27 11:24:04 -0700567 : Maybe<uint16_t>());
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700568
569 // Check for entries appearing twice with two different entry ids
570 if (check_id && entry->id && entry->id.value() != res_id.entry_id()) {
Adam Lesinski71be7052017-12-12 16:48:07 -0800571 diag->Error(DiagMessage(source)
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700572 << "trying to add resource '" << name << "' with ID " << res_id
573 << " but resource already has ID "
574 << ResourceId(package->id.value(), type->id.value(), entry->id.value()));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700575 return false;
576 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800577
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800578 if (res_id.is_valid_dynamic()) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700579 package->id = res_id.package_id();
580 type->id = res_id.type_id();
581 entry->id = res_id.entry_id();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700582 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800583
Adam Lesinski71be7052017-12-12 16:48:07 -0800584 // Only mark the type visibility level as public, it doesn't care about being private.
585 if (visibility.level == Visibility::Level::kPublic) {
586 type->visibility_level = Visibility::Level::kPublic;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700587 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800588
Adam Lesinski71be7052017-12-12 16:48:07 -0800589 if (visibility.level == Visibility::Level::kUndefined &&
590 entry->visibility.level != Visibility::Level::kUndefined) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700591 // We can't undefine a symbol (remove its visibility). Ignore.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800592 return true;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700593 }
594
Adam Lesinski71be7052017-12-12 16:48:07 -0800595 if (visibility.level < entry->visibility.level) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700596 // We can't downgrade public to private. Ignore.
597 return true;
598 }
599
Adam Lesinski4488f1c2017-05-26 17:33:38 -0700600 // This symbol definition takes precedence, replace.
Adam Lesinski71be7052017-12-12 16:48:07 -0800601 entry->visibility = visibility;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700602 return true;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800603}
604
Adam Lesinski71be7052017-12-12 16:48:07 -0800605bool ResourceTable::SetAllowNew(const ResourceNameRef& name, const AllowNew& allow_new,
606 IDiagnostics* diag) {
607 return SetAllowNewImpl(name, allow_new, ResourceNameValidator, diag);
608}
609
610bool ResourceTable::SetAllowNewMangled(const ResourceNameRef& name, const AllowNew& allow_new,
611 IDiagnostics* diag) {
612 return SetAllowNewImpl(name, allow_new, SkipNameValidator, diag);
613}
614
615bool ResourceTable::SetAllowNewImpl(const ResourceNameRef& name, const AllowNew& allow_new,
616 NameValidator name_validator, IDiagnostics* diag) {
617 CHECK(diag != nullptr);
618
619 if (!ValidateName(name_validator, name, allow_new.source, diag)) {
620 return false;
621 }
622
623 ResourceTablePackage* package = FindOrCreatePackage(name.package);
624 ResourceTableType* type = package->FindOrCreateType(name.type);
625 ResourceEntry* entry = type->FindOrCreateEntry(name.entry);
626 entry->allow_new = allow_new;
627 return true;
628}
629
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800630bool ResourceTable::SetOverlayable(const ResourceNameRef& name, const OverlayableItem& overlayable,
Adam Lesinski71be7052017-12-12 16:48:07 -0800631 IDiagnostics* diag) {
Ryan Mitchell1bb1fe02018-11-16 11:21:41 -0800632 return SetOverlayableImpl(name, overlayable, ResourceNameValidator, diag);
Adam Lesinski71be7052017-12-12 16:48:07 -0800633}
634
Ryan Mitchell1bb1fe02018-11-16 11:21:41 -0800635bool ResourceTable::SetOverlayableMangled(const ResourceNameRef& name,
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800636 const OverlayableItem& overlayable, IDiagnostics* diag) {
Ryan Mitchell1bb1fe02018-11-16 11:21:41 -0800637 return SetOverlayableImpl(name, overlayable, SkipNameValidator, diag);
Adam Lesinski71be7052017-12-12 16:48:07 -0800638}
639
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800640bool ResourceTable::SetOverlayableImpl(const ResourceNameRef& name,
641 const OverlayableItem& overlayable,
Ryan Mitchell1bb1fe02018-11-16 11:21:41 -0800642 NameValidator name_validator, IDiagnostics *diag) {
Adam Lesinski71be7052017-12-12 16:48:07 -0800643 CHECK(diag != nullptr);
644
645 if (!ValidateName(name_validator, name, overlayable.source, diag)) {
646 return false;
647 }
648
649 ResourceTablePackage* package = FindOrCreatePackage(name.package);
650 ResourceTableType* type = package->FindOrCreateType(name.type);
651 ResourceEntry* entry = type->FindOrCreateEntry(name.entry);
Ryan Mitchelle4e989c2018-10-29 02:21:50 -0700652
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800653 if (entry->overlayable_item) {
Ryan Mitchell1bb1fe02018-11-16 11:21:41 -0800654 diag->Error(DiagMessage(overlayable.source)
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800655 << "duplicate overlayable declaration for resource '" << name << "'");
656 diag->Error(DiagMessage(entry->overlayable_item.value().source)
657 << "previous declaration here");
Ryan Mitchell1bb1fe02018-11-16 11:21:41 -0800658 return false;
Adam Lesinski71be7052017-12-12 16:48:07 -0800659 }
Ryan Mitchelle4e989c2018-10-29 02:21:50 -0700660
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800661 entry->overlayable_item = overlayable;
Adam Lesinski71be7052017-12-12 16:48:07 -0800662 return true;
663}
664
665Maybe<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNameRef& name) const {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700666 ResourceTablePackage* package = FindPackage(name.package);
Adam Lesinski71be7052017-12-12 16:48:07 -0800667 if (package == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700668 return {};
669 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800670
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700671 ResourceTableType* type = package->FindType(name.type);
Adam Lesinski71be7052017-12-12 16:48:07 -0800672 if (type == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700673 return {};
674 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800675
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700676 ResourceEntry* entry = type->FindEntry(name.entry);
Adam Lesinski71be7052017-12-12 16:48:07 -0800677 if (entry == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700678 return {};
679 }
680 return SearchResult{package, type, entry};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800681}
682
Shane Farmer0a5b2012017-06-22 12:24:12 -0700683std::unique_ptr<ResourceTable> ResourceTable::Clone() const {
684 std::unique_ptr<ResourceTable> new_table = util::make_unique<ResourceTable>();
685 for (const auto& pkg : packages) {
686 ResourceTablePackage* new_pkg = new_table->CreatePackage(pkg->name, pkg->id);
687 for (const auto& type : pkg->types) {
688 ResourceTableType* new_type = new_pkg->FindOrCreateType(type->type);
Adam Lesinski71be7052017-12-12 16:48:07 -0800689 new_type->id = type->id;
690 new_type->visibility_level = type->visibility_level;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700691
692 for (const auto& entry : type->entries) {
693 ResourceEntry* new_entry = new_type->FindOrCreateEntry(entry->name);
Adam Lesinski71be7052017-12-12 16:48:07 -0800694 new_entry->id = entry->id;
695 new_entry->visibility = entry->visibility;
696 new_entry->allow_new = entry->allow_new;
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800697 new_entry->overlayable_item = entry->overlayable_item;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700698
699 for (const auto& config_value : entry->values) {
700 ResourceConfigValue* new_value =
701 new_entry->FindOrCreateValue(config_value->config, config_value->product);
Adam Lesinski71be7052017-12-12 16:48:07 -0800702 new_value->value.reset(config_value->value->Clone(&new_table->string_pool));
Shane Farmer0a5b2012017-06-22 12:24:12 -0700703 }
704 }
705 }
706 }
707 return new_table;
708}
709
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700710} // namespace aapt