summaryrefslogtreecommitdiff
path: root/tools/aapt2/link/XmlReferenceLinker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/link/XmlReferenceLinker.cpp')
-rw-r--r--tools/aapt2/link/XmlReferenceLinker.cpp46
1 files changed, 8 insertions, 38 deletions
diff --git a/tools/aapt2/link/XmlReferenceLinker.cpp b/tools/aapt2/link/XmlReferenceLinker.cpp
index c3c16b92f712..aaa085e2eb15 100644
--- a/tools/aapt2/link/XmlReferenceLinker.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker.cpp
@@ -33,49 +33,18 @@ namespace aapt {
namespace {
-// Visits all references (including parents of styles, references in styles, arrays, etc) and
-// links their symbolic name to their Resource ID, performing mangling and package aliasing
-// as needed.
-class ReferenceVisitor : public DescendingValueVisitor {
- public:
- using DescendingValueVisitor::Visit;
-
- ReferenceVisitor(const CallSite& callsite, IAaptContext* context, SymbolTable* symbols,
- xml::IPackageDeclStack* decls)
- : callsite_(callsite), context_(context), symbols_(symbols), decls_(decls), error_(false) {}
-
- void Visit(Reference* ref) override {
- if (!ReferenceLinker::LinkReference(callsite_, ref, context_, symbols_, decls_)) {
- error_ = true;
- }
- }
-
- bool HasError() const {
- return error_;
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ReferenceVisitor);
-
- const CallSite& callsite_;
- IAaptContext* context_;
- SymbolTable* symbols_;
- xml::IPackageDeclStack* decls_;
- bool error_;
-};
-
// Visits each xml Element and compiles the attributes within.
class XmlVisitor : public xml::PackageAwareVisitor {
public:
using xml::PackageAwareVisitor::Visit;
- XmlVisitor(const Source& source, const CallSite& callsite, IAaptContext* context,
- SymbolTable* symbols)
+ XmlVisitor(const Source& source, StringPool* pool, const CallSite& callsite,
+ IAaptContext* context, ResourceTable* table, SymbolTable* symbols)
: source_(source),
callsite_(callsite),
context_(context),
symbols_(symbols),
- reference_visitor_(callsite, context, symbols, this) {
+ reference_transformer_(callsite, context, symbols, pool, table, this) {
}
void Visit(xml::Element* el) override {
@@ -127,7 +96,7 @@ class XmlVisitor : public xml::PackageAwareVisitor {
if (attr.compiled_value) {
// With a compiledValue, we must resolve the reference and assign it an ID.
attr.compiled_value->SetSource(source);
- attr.compiled_value->Accept(&reference_visitor_);
+ attr.compiled_value = attr.compiled_value->Transform(reference_transformer_);
} else if ((attribute->type_mask & android::ResTable_map::TYPE_STRING) == 0) {
// We won't be able to encode this as a string.
DiagMessage msg(source);
@@ -143,7 +112,7 @@ class XmlVisitor : public xml::PackageAwareVisitor {
}
bool HasError() {
- return error_ || reference_visitor_.HasError();
+ return error_ || reference_transformer_.HasError();
}
private:
@@ -154,7 +123,7 @@ class XmlVisitor : public xml::PackageAwareVisitor {
IAaptContext* context_;
SymbolTable* symbols_;
- ReferenceVisitor reference_visitor_;
+ ReferenceLinkerTransformer reference_transformer_;
bool error_ = false;
};
@@ -173,7 +142,8 @@ bool XmlReferenceLinker::Consume(IAaptContext* context, xml::XmlResource* resour
callsite.package = context->GetCompilationPackage();
}
- XmlVisitor visitor(resource->file.source, callsite, context, context->GetExternalSymbols());
+ XmlVisitor visitor(resource->file.source, &resource->string_pool, callsite, context, table_,
+ context->GetExternalSymbols());
if (resource->root) {
resource->root->Accept(&visitor);
return !visitor.HasError();