From efcdb95fa7cf2da7d599e0bcda250514ac5ee048 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 14 Apr 2021 17:31:37 -0700 Subject: Aapt2 ValueTransformer For future macro support, aapt2 must be able to convert Reference values into other Value types. Currently a DescendingValueVisitor is used to visit all of the References in a ResourceTable or a compiled XML file to set their resource ids during the link phase. This was fine since we were only mutating the resource id of the visited Reference. A macro may reference a String, BinaryPrimitive, or any other Item type. During the link phase, we will need to transform references to macros into the values of the macros. The only parameter in the methods of the ValueVisitor interface is a raw pointer to the type being visited. The visitor interface does not support reassigning the visited type to a different type. ValueTransformer is a new interface for consuming a Value type and transforming it into a compatible Value type. This change refactors Value::Clone to use this interface. Bug: 175616308 Test: aapt2_tests Change-Id: Ic1b9d718b932c208764114cd9c74d880e189ccb0 --- tools/aapt2/split/TableSplitter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/aapt2/split') diff --git a/tools/aapt2/split/TableSplitter.cpp b/tools/aapt2/split/TableSplitter.cpp index 2f319b11e3b2..116b2ab9aa98 100644 --- a/tools/aapt2/split/TableSplitter.cpp +++ b/tools/aapt2/split/TableSplitter.cpp @@ -229,6 +229,7 @@ void TableSplitter::SplitTable(ResourceTable* original_table) { for (size_t idx = 0; idx < split_count; idx++) { const SplitConstraints& split_constraint = split_constraints_[idx]; ResourceTable* split_table = splits_[idx].get(); + CloningValueTransformer cloner(&split_table->string_pool); // Select the values we want from this entry for this split. SplitValueSelector selector(split_constraint); @@ -254,8 +255,7 @@ void TableSplitter::SplitTable(ResourceTable* original_table) { for (ResourceConfigValue* config_value : selected_values) { ResourceConfigValue* new_config_value = split_entry->FindOrCreateValue(config_value->config, config_value->product); - new_config_value->value = std::unique_ptr( - config_value->value->Clone(&split_table->string_pool)); + new_config_value->value = config_value->value->Transform(cloner); } } } -- cgit v1.2.3-59-g8ed1b