From 73bff1e8519bb73f17a801f45977d41b69b5b0d0 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 8 Dec 2017 16:06:10 -0800 Subject: AAPT2: Allow compatible duplicate Attributes If a resource XML file defines two compatible Attributes, they should be merged without throwing an error. Ex: In this case, string|reference and string are the same, so these should merge correctly. Bug: 65699599 Test: make aapt2_tests Test: make AaptBasicTest Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95 --- tools/aapt2/ResourceValues.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'tools/aapt2/ResourceValues.cpp') diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp index a782cd3672d1..77cee0683f3e 100644 --- a/tools/aapt2/ResourceValues.cpp +++ b/tools/aapt2/ResourceValues.cpp @@ -507,17 +507,10 @@ void BinaryPrimitive::PrettyPrint(Printer* printer) const { } } -Attribute::Attribute() - : type_mask(0u), - min_int(std::numeric_limits::min()), - max_int(std::numeric_limits::max()) { -} - -Attribute::Attribute(bool w, uint32_t t) +Attribute::Attribute(uint32_t t) : type_mask(t), min_int(std::numeric_limits::min()), max_int(std::numeric_limits::max()) { - weak_ = w; } std::ostream& operator<<(std::ostream& out, const Attribute::Symbol& s) { @@ -568,6 +561,20 @@ bool Attribute::Equals(const Value* value) const { }); } +bool Attribute::IsCompatibleWith(const Attribute& attr) const { + // If the high bits are set on any of these attribute type masks, then they are incompatible. + // We don't check that flags and enums are identical. + if ((type_mask & ~android::ResTable_map::TYPE_ANY) != 0 || + (attr.type_mask & ~android::ResTable_map::TYPE_ANY) != 0) { + return false; + } + + // Every attribute accepts a reference. + uint32_t this_type_mask = type_mask | android::ResTable_map::TYPE_REFERENCE; + uint32_t that_type_mask = attr.type_mask | android::ResTable_map::TYPE_REFERENCE; + return this_type_mask == that_type_mask; +} + Attribute* Attribute::Clone(StringPool* /*new_pool*/) const { return new Attribute(*this); } -- cgit v1.2.3