Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 17 | #include "ResourceValues.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 18 | |
| 19 | #include <algorithm> |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 20 | #include <cinttypes> |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 21 | #include <limits> |
| 22 | #include <set> |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 23 | #include <sstream> |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 24 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 25 | #include "android-base/stringprintf.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 26 | #include "androidfw/ResourceTypes.h" |
| 27 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 28 | #include "Resource.h" |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 29 | #include "ResourceUtils.h" |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 30 | #include "ValueVisitor.h" |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 31 | #include "util/Util.h" |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 32 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 33 | using ::aapt::text::Printer; |
| 34 | using ::android::StringPiece; |
| 35 | using ::android::base::StringPrintf; |
| 36 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 37 | namespace aapt { |
| 38 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 39 | void Value::PrettyPrint(Printer* printer) const { |
| 40 | std::ostringstream str_stream; |
| 41 | Print(&str_stream); |
| 42 | printer->Print(str_stream.str()); |
| 43 | } |
| 44 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 45 | std::ostream& operator<<(std::ostream& out, const Value& value) { |
| 46 | value.Print(&out); |
| 47 | return out; |
| 48 | } |
| 49 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 50 | template <typename Derived> |
Adam Lesinski | d3ffa844 | 2017-09-28 13:34:35 -0700 | [diff] [blame] | 51 | void BaseValue<Derived>::Accept(ValueVisitor* visitor) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 52 | visitor->Visit(static_cast<Derived*>(this)); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | template <typename Derived> |
Adam Lesinski | d3ffa844 | 2017-09-28 13:34:35 -0700 | [diff] [blame] | 56 | void BaseValue<Derived>::Accept(ConstValueVisitor* visitor) const { |
| 57 | visitor->Visit(static_cast<const Derived*>(this)); |
| 58 | } |
| 59 | |
| 60 | template <typename Derived> |
| 61 | void BaseItem<Derived>::Accept(ValueVisitor* visitor) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 62 | visitor->Visit(static_cast<Derived*>(this)); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Adam Lesinski | d3ffa844 | 2017-09-28 13:34:35 -0700 | [diff] [blame] | 65 | template <typename Derived> |
| 66 | void BaseItem<Derived>::Accept(ConstValueVisitor* visitor) const { |
| 67 | visitor->Visit(static_cast<const Derived*>(this)); |
| 68 | } |
| 69 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 70 | RawString::RawString(const StringPool::Ref& ref) : value(ref) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 71 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 72 | bool RawString::Equals(const Value* value) const { |
| 73 | const RawString* other = ValueCast<RawString>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 74 | if (!other) { |
| 75 | return false; |
| 76 | } |
| 77 | return *this->value == *other->value; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 80 | RawString* RawString::Clone(StringPool* new_pool) const { |
Adam Lesinski | 8a0b238 | 2017-10-18 15:07:33 -0700 | [diff] [blame] | 81 | RawString* rs = new RawString(new_pool->MakeRef(value)); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 82 | rs->comment_ = comment_; |
| 83 | rs->source_ = source_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 84 | return rs; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 87 | bool RawString::Flatten(android::Res_value* out_value) const { |
| 88 | out_value->dataType = android::Res_value::TYPE_STRING; |
| 89 | out_value->data = util::HostToDevice32(static_cast<uint32_t>(value.index())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 90 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 93 | void RawString::Print(std::ostream* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 94 | *out << "(raw string) " << *value; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 97 | Reference::Reference() : reference_type(Type::kResource) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 98 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 99 | Reference::Reference(const ResourceNameRef& n, Type t) |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 100 | : name(n.ToResourceName()), reference_type(t) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 101 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 102 | Reference::Reference(const ResourceId& i, Type type) |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 103 | : id(i), reference_type(type) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 104 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 105 | Reference::Reference(const ResourceNameRef& n, const ResourceId& i) |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 106 | : name(n.ToResourceName()), id(i), reference_type(Type::kResource) {} |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 107 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 108 | bool Reference::Equals(const Value* value) const { |
| 109 | const Reference* other = ValueCast<Reference>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 110 | if (!other) { |
| 111 | return false; |
| 112 | } |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 113 | return reference_type == other->reference_type && |
| 114 | private_reference == other->private_reference && id == other->id && |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 115 | name == other->name; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 118 | bool Reference::Flatten(android::Res_value* out_value) const { |
Adam Lesinski | b5dc4bd | 2017-02-22 19:29:29 -0800 | [diff] [blame] | 119 | const ResourceId resid = id.value_or_default(ResourceId(0)); |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 120 | const bool dynamic = resid.is_valid_dynamic() && resid.package_id() != kFrameworkPackageId && |
Adam Lesinski | 490595a | 2017-11-07 17:08:07 -0800 | [diff] [blame] | 121 | resid.package_id() < kAppPackageId; |
Adam Lesinski | b5dc4bd | 2017-02-22 19:29:29 -0800 | [diff] [blame] | 122 | |
| 123 | if (reference_type == Reference::Type::kResource) { |
| 124 | if (dynamic) { |
| 125 | out_value->dataType = android::Res_value::TYPE_DYNAMIC_REFERENCE; |
| 126 | } else { |
| 127 | out_value->dataType = android::Res_value::TYPE_REFERENCE; |
| 128 | } |
| 129 | } else { |
| 130 | if (dynamic) { |
| 131 | out_value->dataType = android::Res_value::TYPE_DYNAMIC_ATTRIBUTE; |
| 132 | } else { |
| 133 | out_value->dataType = android::Res_value::TYPE_ATTRIBUTE; |
| 134 | } |
| 135 | } |
| 136 | out_value->data = util::HostToDevice32(resid.id); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 137 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 140 | Reference* Reference::Clone(StringPool* /*new_pool*/) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 141 | return new Reference(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 144 | void Reference::Print(std::ostream* out) const { |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 145 | if (reference_type == Type::kResource) { |
| 146 | *out << "(reference) @"; |
| 147 | if (!name && !id) { |
| 148 | *out << "null"; |
| 149 | return; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 150 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 151 | } else { |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 152 | *out << "(attr-reference) ?"; |
| 153 | } |
| 154 | |
| 155 | if (private_reference) { |
| 156 | *out << "*"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 157 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 158 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 159 | if (name) { |
| 160 | *out << name.value(); |
| 161 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 162 | |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 163 | if (id && id.value().is_valid_dynamic()) { |
| 164 | if (name) { |
| 165 | *out << " "; |
| 166 | } |
| 167 | *out << id.value(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 168 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 171 | static void PrettyPrintReferenceImpl(const Reference& ref, bool print_package, Printer* printer) { |
| 172 | switch (ref.reference_type) { |
| 173 | case Reference::Type::kResource: |
| 174 | printer->Print("@"); |
| 175 | break; |
| 176 | |
| 177 | case Reference::Type::kAttribute: |
| 178 | printer->Print("?"); |
| 179 | break; |
| 180 | } |
| 181 | |
| 182 | if (!ref.name && !ref.id) { |
| 183 | printer->Print("null"); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | if (ref.private_reference) { |
| 188 | printer->Print("*"); |
| 189 | } |
| 190 | |
| 191 | if (ref.name) { |
| 192 | const ResourceName& name = ref.name.value(); |
| 193 | if (print_package) { |
| 194 | printer->Print(name.to_string()); |
| 195 | } else { |
| 196 | printer->Print(to_string(name.type)); |
| 197 | printer->Print("/"); |
| 198 | printer->Print(name.entry); |
| 199 | } |
| 200 | } else if (ref.id && ref.id.value().is_valid_dynamic()) { |
| 201 | printer->Print(ref.id.value().to_string()); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void Reference::PrettyPrint(Printer* printer) const { |
| 206 | PrettyPrintReferenceImpl(*this, true /*print_package*/, printer); |
| 207 | } |
| 208 | |
| 209 | void Reference::PrettyPrint(const StringPiece& package, Printer* printer) const { |
| 210 | const bool print_package = name ? package != name.value().package : true; |
| 211 | PrettyPrintReferenceImpl(*this, print_package, printer); |
| 212 | } |
| 213 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 214 | bool Id::Equals(const Value* value) const { |
| 215 | return ValueCast<Id>(value) != nullptr; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 218 | bool Id::Flatten(android::Res_value* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 219 | out->dataType = android::Res_value::TYPE_INT_BOOLEAN; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 220 | out->data = util::HostToDevice32(0); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 221 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 224 | Id* Id::Clone(StringPool* /*new_pool*/) const { |
| 225 | return new Id(*this); |
| 226 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 227 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 228 | void Id::Print(std::ostream* out) const { |
| 229 | *out << "(id)"; |
| 230 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 231 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 232 | String::String(const StringPool::Ref& ref) : value(ref) { |
| 233 | } |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 234 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 235 | bool String::Equals(const Value* value) const { |
| 236 | const String* other = ValueCast<String>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 237 | if (!other) { |
| 238 | return false; |
| 239 | } |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 240 | |
| 241 | if (this->value != other->value) { |
| 242 | return false; |
| 243 | } |
| 244 | |
| 245 | if (untranslatable_sections.size() != other->untranslatable_sections.size()) { |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | auto other_iter = other->untranslatable_sections.begin(); |
| 250 | for (const UntranslatableSection& this_section : untranslatable_sections) { |
| 251 | if (this_section != *other_iter) { |
| 252 | return false; |
| 253 | } |
| 254 | ++other_iter; |
| 255 | } |
| 256 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 259 | bool String::Flatten(android::Res_value* out_value) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 260 | // Verify that our StringPool index is within encode-able limits. |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 261 | if (value.index() > std::numeric_limits<uint32_t>::max()) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 262 | return false; |
| 263 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 264 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 265 | out_value->dataType = android::Res_value::TYPE_STRING; |
| 266 | out_value->data = util::HostToDevice32(static_cast<uint32_t>(value.index())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 267 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 270 | String* String::Clone(StringPool* new_pool) const { |
Adam Lesinski | 8a0b238 | 2017-10-18 15:07:33 -0700 | [diff] [blame] | 271 | String* str = new String(new_pool->MakeRef(value)); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 272 | str->comment_ = comment_; |
| 273 | str->source_ = source_; |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 274 | str->untranslatable_sections = untranslatable_sections; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 275 | return str; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 278 | void String::Print(std::ostream* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 279 | *out << "(string) \"" << *value << "\""; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 282 | void String::PrettyPrint(Printer* printer) const { |
| 283 | printer->Print("\""); |
| 284 | printer->Print(*value); |
| 285 | printer->Print("\""); |
| 286 | } |
| 287 | |
| 288 | StyledString::StyledString(const StringPool::StyleRef& ref) : value(ref) { |
| 289 | } |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 290 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 291 | bool StyledString::Equals(const Value* value) const { |
| 292 | const StyledString* other = ValueCast<StyledString>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 293 | if (!other) { |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 294 | return false; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 297 | if (this->value != other->value) { |
| 298 | return false; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 299 | } |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 300 | |
| 301 | if (untranslatable_sections.size() != other->untranslatable_sections.size()) { |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | auto other_iter = other->untranslatable_sections.begin(); |
| 306 | for (const UntranslatableSection& this_section : untranslatable_sections) { |
| 307 | if (this_section != *other_iter) { |
| 308 | return false; |
| 309 | } |
| 310 | ++other_iter; |
| 311 | } |
| 312 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 315 | bool StyledString::Flatten(android::Res_value* out_value) const { |
| 316 | if (value.index() > std::numeric_limits<uint32_t>::max()) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 317 | return false; |
| 318 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 319 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 320 | out_value->dataType = android::Res_value::TYPE_STRING; |
| 321 | out_value->data = util::HostToDevice32(static_cast<uint32_t>(value.index())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 322 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 325 | StyledString* StyledString::Clone(StringPool* new_pool) const { |
| 326 | StyledString* str = new StyledString(new_pool->MakeRef(value)); |
| 327 | str->comment_ = comment_; |
| 328 | str->source_ = source_; |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 329 | str->untranslatable_sections = untranslatable_sections; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 330 | return str; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 333 | void StyledString::Print(std::ostream* out) const { |
Adam Lesinski | 060b53d | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 334 | *out << "(styled string) \"" << value->value << "\""; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 335 | for (const StringPool::Span& span : value->spans) { |
Adam Lesinski | 060b53d | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 336 | *out << " " << *span.name << ":" << span.first_char << "," << span.last_char; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 337 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 340 | FileReference::FileReference(const StringPool::Ref& _path) : path(_path) { |
| 341 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 342 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 343 | bool FileReference::Equals(const Value* value) const { |
| 344 | const FileReference* other = ValueCast<FileReference>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 345 | if (!other) { |
| 346 | return false; |
| 347 | } |
Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 348 | return path == other->path; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 351 | bool FileReference::Flatten(android::Res_value* out_value) const { |
| 352 | if (path.index() > std::numeric_limits<uint32_t>::max()) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 353 | return false; |
| 354 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 355 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 356 | out_value->dataType = android::Res_value::TYPE_STRING; |
| 357 | out_value->data = util::HostToDevice32(static_cast<uint32_t>(path.index())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 358 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 361 | FileReference* FileReference::Clone(StringPool* new_pool) const { |
Adam Lesinski | 8a0b238 | 2017-10-18 15:07:33 -0700 | [diff] [blame] | 362 | FileReference* fr = new FileReference(new_pool->MakeRef(path)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 363 | fr->file = file; |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 364 | fr->type = type; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 365 | fr->comment_ = comment_; |
| 366 | fr->source_ = source_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 367 | return fr; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 370 | void FileReference::Print(std::ostream* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 371 | *out << "(file) " << *path; |
Adam Lesinski | a65bbdf | 2018-02-15 12:39:44 -0800 | [diff] [blame^] | 372 | switch (type) { |
| 373 | case ResourceFile::Type::kBinaryXml: |
| 374 | *out << " type=XML"; |
| 375 | break; |
| 376 | case ResourceFile::Type::kProtoXml: |
| 377 | *out << " type=protoXML"; |
| 378 | break; |
| 379 | case ResourceFile::Type::kPng: |
| 380 | *out << " type=PNG"; |
| 381 | break; |
| 382 | default: |
| 383 | break; |
| 384 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 387 | BinaryPrimitive::BinaryPrimitive(const android::Res_value& val) : value(val) { |
| 388 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 389 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 390 | BinaryPrimitive::BinaryPrimitive(uint8_t dataType, uint32_t data) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 391 | value.dataType = dataType; |
| 392 | value.data = data; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 395 | bool BinaryPrimitive::Equals(const Value* value) const { |
| 396 | const BinaryPrimitive* other = ValueCast<BinaryPrimitive>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 397 | if (!other) { |
| 398 | return false; |
| 399 | } |
| 400 | return this->value.dataType == other->value.dataType && |
| 401 | this->value.data == other->value.data; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 404 | bool BinaryPrimitive::Flatten(::android::Res_value* out_value) const { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 405 | out_value->dataType = value.dataType; |
| 406 | out_value->data = util::HostToDevice32(value.data); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 407 | return true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 410 | BinaryPrimitive* BinaryPrimitive::Clone(StringPool* /*new_pool*/) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 411 | return new BinaryPrimitive(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 414 | void BinaryPrimitive::Print(std::ostream* out) const { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 415 | *out << StringPrintf("(primitive) type=0x%02x data=0x%08x", value.dataType, value.data); |
| 416 | } |
| 417 | |
| 418 | static std::string ComplexToString(uint32_t complex_value, bool fraction) { |
| 419 | using ::android::Res_value; |
| 420 | |
| 421 | constexpr std::array<int, 4> kRadixShifts = {{23, 16, 8, 0}}; |
| 422 | |
| 423 | // Determine the radix that was used. |
| 424 | const uint32_t radix = |
| 425 | (complex_value >> Res_value::COMPLEX_RADIX_SHIFT) & Res_value::COMPLEX_RADIX_MASK; |
| 426 | const uint64_t mantissa = uint64_t{(complex_value >> Res_value::COMPLEX_MANTISSA_SHIFT) & |
| 427 | Res_value::COMPLEX_MANTISSA_MASK} |
| 428 | << kRadixShifts[radix]; |
| 429 | const float value = mantissa * (1.0f / (1 << 23)); |
| 430 | |
| 431 | std::string str = StringPrintf("%f", value); |
| 432 | |
| 433 | const int unit_type = |
| 434 | (complex_value >> Res_value::COMPLEX_UNIT_SHIFT) & Res_value::COMPLEX_UNIT_MASK; |
| 435 | if (fraction) { |
| 436 | switch (unit_type) { |
| 437 | case Res_value::COMPLEX_UNIT_FRACTION: |
| 438 | str += "%"; |
| 439 | break; |
| 440 | case Res_value::COMPLEX_UNIT_FRACTION_PARENT: |
| 441 | str += "%p"; |
| 442 | break; |
| 443 | default: |
| 444 | str += "???"; |
| 445 | break; |
| 446 | } |
| 447 | } else { |
| 448 | switch (unit_type) { |
| 449 | case Res_value::COMPLEX_UNIT_PX: |
| 450 | str += "px"; |
| 451 | break; |
| 452 | case Res_value::COMPLEX_UNIT_DIP: |
| 453 | str += "dp"; |
| 454 | break; |
| 455 | case Res_value::COMPLEX_UNIT_SP: |
| 456 | str += "sp"; |
| 457 | break; |
| 458 | case Res_value::COMPLEX_UNIT_PT: |
| 459 | str += "pt"; |
| 460 | break; |
| 461 | case Res_value::COMPLEX_UNIT_IN: |
| 462 | str += "in"; |
| 463 | break; |
| 464 | case Res_value::COMPLEX_UNIT_MM: |
| 465 | str += "mm"; |
| 466 | break; |
| 467 | default: |
| 468 | str += "???"; |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | return str; |
| 473 | } |
| 474 | |
| 475 | void BinaryPrimitive::PrettyPrint(Printer* printer) const { |
| 476 | using ::android::Res_value; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 477 | switch (value.dataType) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 478 | case Res_value::TYPE_NULL: |
| 479 | if (value.data == Res_value::DATA_NULL_EMPTY) { |
| 480 | printer->Print("@empty"); |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 481 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 482 | printer->Print("@null"); |
Adam Lesinski | bab4ef5 | 2017-06-01 15:22:57 -0700 | [diff] [blame] | 483 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 484 | break; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 485 | |
| 486 | case Res_value::TYPE_INT_DEC: |
| 487 | printer->Print(StringPrintf("%" PRIi32, static_cast<int32_t>(value.data))); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 488 | break; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 489 | |
| 490 | case Res_value::TYPE_INT_HEX: |
| 491 | printer->Print(StringPrintf("0x%08x", value.data)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 492 | break; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 493 | |
| 494 | case Res_value::TYPE_INT_BOOLEAN: |
| 495 | printer->Print(value.data != 0 ? "true" : "false"); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 496 | break; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 497 | |
| 498 | case Res_value::TYPE_INT_COLOR_ARGB8: |
| 499 | case Res_value::TYPE_INT_COLOR_RGB8: |
| 500 | case Res_value::TYPE_INT_COLOR_ARGB4: |
| 501 | case Res_value::TYPE_INT_COLOR_RGB4: |
| 502 | printer->Print(StringPrintf("#%08x", value.data)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 503 | break; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 504 | |
| 505 | case Res_value::TYPE_FLOAT: |
| 506 | printer->Print(StringPrintf("%g", *reinterpret_cast<const float*>(&value.data))); |
| 507 | break; |
| 508 | |
| 509 | case Res_value::TYPE_DIMENSION: |
| 510 | printer->Print(ComplexToString(value.data, false /*fraction*/)); |
| 511 | break; |
| 512 | |
| 513 | case Res_value::TYPE_FRACTION: |
| 514 | printer->Print(ComplexToString(value.data, true /*fraction*/)); |
| 515 | break; |
| 516 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 517 | default: |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 518 | printer->Print(StringPrintf("(unknown 0x%02x) 0x%08x", value.dataType, value.data)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 519 | break; |
| 520 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Adam Lesinski | 73bff1e | 2017-12-08 16:06:10 -0800 | [diff] [blame] | 523 | Attribute::Attribute(uint32_t t) |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 524 | : type_mask(t), |
| 525 | min_int(std::numeric_limits<int32_t>::min()), |
| 526 | max_int(std::numeric_limits<int32_t>::max()) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 529 | std::ostream& operator<<(std::ostream& out, const Attribute::Symbol& s) { |
| 530 | if (s.symbol.name) { |
| 531 | out << s.symbol.name.value().entry; |
| 532 | } else { |
| 533 | out << "???"; |
| 534 | } |
| 535 | return out << "=" << s.value; |
| 536 | } |
| 537 | |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 538 | template <typename T> |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 539 | constexpr T* add_pointer(T& val) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 540 | return &val; |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 543 | bool Attribute::Equals(const Value* value) const { |
| 544 | const Attribute* other = ValueCast<Attribute>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 545 | if (!other) { |
| 546 | return false; |
| 547 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 548 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 549 | if (symbols.size() != other->symbols.size()) { |
| 550 | return false; |
| 551 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 552 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 553 | if (type_mask != other->type_mask || min_int != other->min_int || max_int != other->max_int) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 554 | return false; |
| 555 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 556 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 557 | std::vector<const Symbol*> sorted_a; |
| 558 | std::transform(symbols.begin(), symbols.end(), std::back_inserter(sorted_a), |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 559 | add_pointer<const Symbol>); |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 560 | std::sort(sorted_a.begin(), sorted_a.end(), [](const Symbol* a, const Symbol* b) -> bool { |
| 561 | return a->symbol.name < b->symbol.name; |
| 562 | }); |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 563 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 564 | std::vector<const Symbol*> sorted_b; |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 565 | std::transform(other->symbols.begin(), other->symbols.end(), std::back_inserter(sorted_b), |
| 566 | add_pointer<const Symbol>); |
| 567 | std::sort(sorted_b.begin(), sorted_b.end(), [](const Symbol* a, const Symbol* b) -> bool { |
| 568 | return a->symbol.name < b->symbol.name; |
| 569 | }); |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 570 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 571 | return std::equal(sorted_a.begin(), sorted_a.end(), sorted_b.begin(), |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 572 | [](const Symbol* a, const Symbol* b) -> bool { |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 573 | return a->symbol.Equals(&b->symbol) && a->value == b->value; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 574 | }); |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Adam Lesinski | 73bff1e | 2017-12-08 16:06:10 -0800 | [diff] [blame] | 577 | bool Attribute::IsCompatibleWith(const Attribute& attr) const { |
| 578 | // If the high bits are set on any of these attribute type masks, then they are incompatible. |
| 579 | // We don't check that flags and enums are identical. |
| 580 | if ((type_mask & ~android::ResTable_map::TYPE_ANY) != 0 || |
| 581 | (attr.type_mask & ~android::ResTable_map::TYPE_ANY) != 0) { |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | // Every attribute accepts a reference. |
| 586 | uint32_t this_type_mask = type_mask | android::ResTable_map::TYPE_REFERENCE; |
| 587 | uint32_t that_type_mask = attr.type_mask | android::ResTable_map::TYPE_REFERENCE; |
| 588 | return this_type_mask == that_type_mask; |
| 589 | } |
| 590 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 591 | Attribute* Attribute::Clone(StringPool* /*new_pool*/) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 592 | return new Attribute(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 595 | std::string Attribute::MaskString() const { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 596 | if (type_mask == android::ResTable_map::TYPE_ANY) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 597 | return "any"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 598 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 599 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 600 | std::ostringstream out; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 601 | bool set = false; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 602 | if ((type_mask & android::ResTable_map::TYPE_REFERENCE) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 603 | if (!set) { |
| 604 | set = true; |
| 605 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 606 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 607 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 608 | out << "reference"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 609 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 610 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 611 | if ((type_mask & android::ResTable_map::TYPE_STRING) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 612 | if (!set) { |
| 613 | set = true; |
| 614 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 615 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 616 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 617 | out << "string"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 618 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 619 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 620 | if ((type_mask & android::ResTable_map::TYPE_INTEGER) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 621 | if (!set) { |
| 622 | set = true; |
| 623 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 624 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 625 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 626 | out << "integer"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 627 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 628 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 629 | if ((type_mask & android::ResTable_map::TYPE_BOOLEAN) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 630 | if (!set) { |
| 631 | set = true; |
| 632 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 633 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 634 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 635 | out << "boolean"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 636 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 637 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 638 | if ((type_mask & android::ResTable_map::TYPE_COLOR) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 639 | if (!set) { |
| 640 | set = true; |
| 641 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 642 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 643 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 644 | out << "color"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 645 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 646 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 647 | if ((type_mask & android::ResTable_map::TYPE_FLOAT) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 648 | if (!set) { |
| 649 | set = true; |
| 650 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 651 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 652 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 653 | out << "float"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 654 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 655 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 656 | if ((type_mask & android::ResTable_map::TYPE_DIMENSION) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 657 | if (!set) { |
| 658 | set = true; |
| 659 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 660 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 661 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 662 | out << "dimension"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 663 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 664 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 665 | if ((type_mask & android::ResTable_map::TYPE_FRACTION) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 666 | if (!set) { |
| 667 | set = true; |
| 668 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 669 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 670 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 671 | out << "fraction"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 672 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 673 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 674 | if ((type_mask & android::ResTable_map::TYPE_ENUM) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 675 | if (!set) { |
| 676 | set = true; |
| 677 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 678 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 679 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 680 | out << "enum"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 681 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 682 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 683 | if ((type_mask & android::ResTable_map::TYPE_FLAGS) != 0) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 684 | if (!set) { |
| 685 | set = true; |
| 686 | } else { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 687 | out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 688 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 689 | out << "flags"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 690 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 691 | return out.str(); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 694 | void Attribute::Print(std::ostream* out) const { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 695 | *out << "(attr) " << MaskString(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 696 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 697 | if (!symbols.empty()) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 698 | *out << " [" << util::Joiner(symbols, ", ") << "]"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 699 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 700 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 701 | if (min_int != std::numeric_limits<int32_t>::min()) { |
| 702 | *out << " min=" << min_int; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 703 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 704 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 705 | if (max_int != std::numeric_limits<int32_t>::max()) { |
| 706 | *out << " max=" << max_int; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 707 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 708 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 709 | if (IsWeak()) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 710 | *out << " [weak]"; |
| 711 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 714 | static void BuildAttributeMismatchMessage(const Attribute& attr, const Item& value, |
| 715 | DiagMessage* out_msg) { |
| 716 | *out_msg << "expected"; |
| 717 | if (attr.type_mask & android::ResTable_map::TYPE_BOOLEAN) { |
| 718 | *out_msg << " boolean"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 719 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 720 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 721 | if (attr.type_mask & android::ResTable_map::TYPE_COLOR) { |
| 722 | *out_msg << " color"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 723 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 724 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 725 | if (attr.type_mask & android::ResTable_map::TYPE_DIMENSION) { |
| 726 | *out_msg << " dimension"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 727 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 728 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 729 | if (attr.type_mask & android::ResTable_map::TYPE_ENUM) { |
| 730 | *out_msg << " enum"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 731 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 732 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 733 | if (attr.type_mask & android::ResTable_map::TYPE_FLAGS) { |
| 734 | *out_msg << " flags"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 735 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 736 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 737 | if (attr.type_mask & android::ResTable_map::TYPE_FLOAT) { |
| 738 | *out_msg << " float"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 739 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 740 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 741 | if (attr.type_mask & android::ResTable_map::TYPE_FRACTION) { |
| 742 | *out_msg << " fraction"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 743 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 744 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 745 | if (attr.type_mask & android::ResTable_map::TYPE_INTEGER) { |
| 746 | *out_msg << " integer"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 747 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 748 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 749 | if (attr.type_mask & android::ResTable_map::TYPE_REFERENCE) { |
| 750 | *out_msg << " reference"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 751 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 752 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 753 | if (attr.type_mask & android::ResTable_map::TYPE_STRING) { |
| 754 | *out_msg << " string"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 755 | } |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 756 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 757 | *out_msg << " but got " << value; |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 760 | bool Attribute::Matches(const Item& item, DiagMessage* out_msg) const { |
| 761 | constexpr const uint32_t TYPE_ENUM = android::ResTable_map::TYPE_ENUM; |
| 762 | constexpr const uint32_t TYPE_FLAGS = android::ResTable_map::TYPE_FLAGS; |
| 763 | constexpr const uint32_t TYPE_INTEGER = android::ResTable_map::TYPE_INTEGER; |
| 764 | constexpr const uint32_t TYPE_REFERENCE = android::ResTable_map::TYPE_REFERENCE; |
| 765 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 766 | android::Res_value val = {}; |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 767 | item.Flatten(&val); |
| 768 | |
| 769 | const uint32_t flattened_data = util::DeviceToHost32(val.data); |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 770 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 771 | // Always allow references. |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 772 | const uint32_t actual_type = ResourceUtils::AndroidTypeToAttributeTypeMask(val.dataType); |
| 773 | |
| 774 | // Only one type must match between the actual and expected. |
| 775 | if ((actual_type & (type_mask | TYPE_REFERENCE)) == 0) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 776 | if (out_msg) { |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 777 | BuildAttributeMismatchMessage(*this, item, out_msg); |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 778 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 779 | return false; |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 780 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 781 | |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 782 | // Enums and flags are encoded as integers, so check them first before doing any range checks. |
| 783 | if ((type_mask & TYPE_ENUM) != 0 && (actual_type & TYPE_ENUM) != 0) { |
| 784 | for (const Symbol& s : symbols) { |
| 785 | if (flattened_data == s.value) { |
| 786 | return true; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | // If the attribute accepts integers, we can't fail here. |
| 791 | if ((type_mask & TYPE_INTEGER) == 0) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 792 | if (out_msg) { |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 793 | *out_msg << item << " is not a valid enum"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 794 | } |
| 795 | return false; |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | if ((type_mask & TYPE_FLAGS) != 0 && (actual_type & TYPE_FLAGS) != 0) { |
| 800 | uint32_t mask = 0u; |
| 801 | for (const Symbol& s : symbols) { |
| 802 | mask |= s.value; |
| 803 | } |
| 804 | |
| 805 | // Check if the flattened data is covered by the flag bit mask. |
| 806 | // If the attribute accepts integers, we can't fail here. |
| 807 | if ((mask & flattened_data) == flattened_data) { |
| 808 | return true; |
| 809 | } else if ((type_mask & TYPE_INTEGER) == 0) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 810 | if (out_msg) { |
Adam Lesinski | 3124e7c | 2017-06-13 16:03:55 -0700 | [diff] [blame] | 811 | *out_msg << item << " is not a valid flag"; |
| 812 | } |
| 813 | return false; |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | // Finally check the integer range of the value. |
| 818 | if ((type_mask & TYPE_INTEGER) != 0 && (actual_type & TYPE_INTEGER) != 0) { |
| 819 | if (static_cast<int32_t>(flattened_data) < min_int) { |
| 820 | if (out_msg) { |
| 821 | *out_msg << item << " is less than minimum integer " << min_int; |
| 822 | } |
| 823 | return false; |
| 824 | } else if (static_cast<int32_t>(flattened_data) > max_int) { |
| 825 | if (out_msg) { |
| 826 | *out_msg << item << " is greater than maximum integer " << max_int; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 827 | } |
| 828 | return false; |
| 829 | } |
| 830 | } |
| 831 | return true; |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 834 | std::ostream& operator<<(std::ostream& out, const Style::Entry& entry) { |
| 835 | if (entry.key.name) { |
| 836 | out << entry.key.name.value(); |
| 837 | } else if (entry.key.id) { |
| 838 | out << entry.key.id.value(); |
| 839 | } else { |
| 840 | out << "???"; |
| 841 | } |
| 842 | out << " = " << entry.value; |
| 843 | return out; |
| 844 | } |
| 845 | |
| 846 | template <typename T> |
| 847 | std::vector<T*> ToPointerVec(std::vector<T>& src) { |
| 848 | std::vector<T*> dst; |
| 849 | dst.reserve(src.size()); |
| 850 | for (T& in : src) { |
| 851 | dst.push_back(&in); |
| 852 | } |
| 853 | return dst; |
| 854 | } |
| 855 | |
| 856 | template <typename T> |
| 857 | std::vector<const T*> ToPointerVec(const std::vector<T>& src) { |
| 858 | std::vector<const T*> dst; |
| 859 | dst.reserve(src.size()); |
| 860 | for (const T& in : src) { |
| 861 | dst.push_back(&in); |
| 862 | } |
| 863 | return dst; |
| 864 | } |
| 865 | |
| 866 | static bool KeyNameComparator(const Style::Entry* a, const Style::Entry* b) { |
| 867 | return a->key.name < b->key.name; |
| 868 | } |
| 869 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 870 | bool Style::Equals(const Value* value) const { |
| 871 | const Style* other = ValueCast<Style>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 872 | if (!other) { |
| 873 | return false; |
| 874 | } |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 875 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 876 | if (bool(parent) != bool(other->parent) || |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 877 | (parent && other->parent && !parent.value().Equals(&other->parent.value()))) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 878 | return false; |
| 879 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 880 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 881 | if (entries.size() != other->entries.size()) { |
| 882 | return false; |
| 883 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 884 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 885 | std::vector<const Entry*> sorted_a = ToPointerVec(entries); |
| 886 | std::sort(sorted_a.begin(), sorted_a.end(), KeyNameComparator); |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 887 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 888 | std::vector<const Entry*> sorted_b = ToPointerVec(other->entries); |
| 889 | std::sort(sorted_b.begin(), sorted_b.end(), KeyNameComparator); |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 890 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 891 | return std::equal(sorted_a.begin(), sorted_a.end(), sorted_b.begin(), |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 892 | [](const Entry* a, const Entry* b) -> bool { |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 893 | return a->key.Equals(&b->key) && a->value->Equals(b->value.get()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 894 | }); |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 897 | Style* Style::Clone(StringPool* new_pool) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 898 | Style* style = new Style(); |
| 899 | style->parent = parent; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 900 | style->parent_inferred = parent_inferred; |
| 901 | style->comment_ = comment_; |
| 902 | style->source_ = source_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 903 | for (auto& entry : entries) { |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 904 | style->entries.push_back(Entry{entry.key, std::unique_ptr<Item>(entry.value->Clone(new_pool))}); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 905 | } |
| 906 | return style; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 907 | } |
| 908 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 909 | void Style::Print(std::ostream* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 910 | *out << "(style) "; |
| 911 | if (parent && parent.value().name) { |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 912 | const Reference& parent_ref = parent.value(); |
| 913 | if (parent_ref.private_reference) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 914 | *out << "*"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 915 | } |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 916 | *out << parent_ref.name.value(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 917 | } |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 918 | *out << " [" << util::Joiner(entries, ", ") << "]"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 919 | } |
| 920 | |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 921 | Style::Entry CloneEntry(const Style::Entry& entry, StringPool* pool) { |
| 922 | Style::Entry cloned_entry{entry.key}; |
| 923 | if (entry.value != nullptr) { |
| 924 | cloned_entry.value.reset(entry.value->Clone(pool)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 925 | } |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 926 | return cloned_entry; |
| 927 | } |
| 928 | |
| 929 | void Style::MergeWith(Style* other, StringPool* pool) { |
| 930 | if (other->parent) { |
| 931 | parent = other->parent; |
| 932 | } |
| 933 | |
| 934 | // We can't assume that the entries are sorted alphabetically since they're supposed to be |
| 935 | // sorted by Resource Id. Not all Resource Ids may be set though, so we can't sort and merge |
| 936 | // them keying off that. |
| 937 | // |
| 938 | // Instead, sort the entries of each Style by their name in a separate structure. Then merge |
| 939 | // those. |
| 940 | |
| 941 | std::vector<Entry*> this_sorted = ToPointerVec(entries); |
| 942 | std::sort(this_sorted.begin(), this_sorted.end(), KeyNameComparator); |
| 943 | |
| 944 | std::vector<Entry*> other_sorted = ToPointerVec(other->entries); |
| 945 | std::sort(other_sorted.begin(), other_sorted.end(), KeyNameComparator); |
| 946 | |
| 947 | auto this_iter = this_sorted.begin(); |
| 948 | const auto this_end = this_sorted.end(); |
| 949 | |
| 950 | auto other_iter = other_sorted.begin(); |
| 951 | const auto other_end = other_sorted.end(); |
| 952 | |
| 953 | std::vector<Entry> merged_entries; |
| 954 | while (this_iter != this_end) { |
| 955 | if (other_iter != other_end) { |
| 956 | if ((*this_iter)->key.name < (*other_iter)->key.name) { |
| 957 | merged_entries.push_back(std::move(**this_iter)); |
| 958 | ++this_iter; |
| 959 | } else { |
| 960 | // The other overrides. |
| 961 | merged_entries.push_back(CloneEntry(**other_iter, pool)); |
| 962 | if ((*this_iter)->key.name == (*other_iter)->key.name) { |
| 963 | ++this_iter; |
| 964 | } |
| 965 | ++other_iter; |
| 966 | } |
| 967 | } else { |
| 968 | merged_entries.push_back(std::move(**this_iter)); |
| 969 | ++this_iter; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | while (other_iter != other_end) { |
| 974 | merged_entries.push_back(CloneEntry(**other_iter, pool)); |
| 975 | ++other_iter; |
| 976 | } |
| 977 | |
| 978 | entries = std::move(merged_entries); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 979 | } |
| 980 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 981 | bool Array::Equals(const Value* value) const { |
| 982 | const Array* other = ValueCast<Array>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 983 | if (!other) { |
| 984 | return false; |
| 985 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 986 | |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 987 | if (elements.size() != other->elements.size()) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 988 | return false; |
| 989 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 990 | |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 991 | return std::equal(elements.begin(), elements.end(), other->elements.begin(), |
| 992 | [](const std::unique_ptr<Item>& a, const std::unique_ptr<Item>& b) -> bool { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 993 | return a->Equals(b.get()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 994 | }); |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 997 | Array* Array::Clone(StringPool* new_pool) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 998 | Array* array = new Array(); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 999 | array->comment_ = comment_; |
| 1000 | array->source_ = source_; |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 1001 | for (auto& item : elements) { |
| 1002 | array->elements.emplace_back(std::unique_ptr<Item>(item->Clone(new_pool))); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1003 | } |
| 1004 | return array; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1007 | void Array::Print(std::ostream* out) const { |
Adam Lesinski | 4ffea04 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 1008 | *out << "(array) [" << util::Joiner(elements, ", ") << "]"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1011 | bool Plural::Equals(const Value* value) const { |
| 1012 | const Plural* other = ValueCast<Plural>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1013 | if (!other) { |
| 1014 | return false; |
| 1015 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1016 | |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 1017 | auto one_iter = values.begin(); |
| 1018 | auto one_end_iter = values.end(); |
| 1019 | auto two_iter = other->values.begin(); |
| 1020 | for (; one_iter != one_end_iter; ++one_iter, ++two_iter) { |
| 1021 | const std::unique_ptr<Item>& a = *one_iter; |
| 1022 | const std::unique_ptr<Item>& b = *two_iter; |
| 1023 | if (a != nullptr && b != nullptr) { |
| 1024 | if (!a->Equals(b.get())) { |
| 1025 | return false; |
| 1026 | } |
| 1027 | } else if (a != b) { |
| 1028 | return false; |
| 1029 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1030 | } |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 1031 | return true; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1034 | Plural* Plural::Clone(StringPool* new_pool) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1035 | Plural* p = new Plural(); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1036 | p->comment_ = comment_; |
| 1037 | p->source_ = source_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1038 | const size_t count = values.size(); |
| 1039 | for (size_t i = 0; i < count; i++) { |
| 1040 | if (values[i]) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1041 | p->values[i] = std::unique_ptr<Item>(values[i]->Clone(new_pool)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1042 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1043 | } |
| 1044 | return p; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1045 | } |
| 1046 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1047 | void Plural::Print(std::ostream* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1048 | *out << "(plural)"; |
| 1049 | if (values[Zero]) { |
| 1050 | *out << " zero=" << *values[Zero]; |
| 1051 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1052 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1053 | if (values[One]) { |
| 1054 | *out << " one=" << *values[One]; |
| 1055 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1056 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1057 | if (values[Two]) { |
| 1058 | *out << " two=" << *values[Two]; |
| 1059 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1060 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1061 | if (values[Few]) { |
| 1062 | *out << " few=" << *values[Few]; |
| 1063 | } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1064 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1065 | if (values[Many]) { |
| 1066 | *out << " many=" << *values[Many]; |
| 1067 | } |
Adam Lesinski | 8f7c550 | 2017-03-02 17:45:01 -0800 | [diff] [blame] | 1068 | |
| 1069 | if (values[Other]) { |
| 1070 | *out << " other=" << *values[Other]; |
| 1071 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1074 | bool Styleable::Equals(const Value* value) const { |
| 1075 | const Styleable* other = ValueCast<Styleable>(value); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1076 | if (!other) { |
| 1077 | return false; |
| 1078 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 1079 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1080 | if (entries.size() != other->entries.size()) { |
| 1081 | return false; |
| 1082 | } |
Adam Lesinski | 5e8fa3a | 2016-06-27 16:21:42 -0700 | [diff] [blame] | 1083 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1084 | return std::equal(entries.begin(), entries.end(), other->entries.begin(), |
| 1085 | [](const Reference& a, const Reference& b) -> bool { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1086 | return a.Equals(&b); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1087 | }); |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1090 | Styleable* Styleable::Clone(StringPool* /*new_pool*/) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1091 | return new Styleable(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1092 | } |
| 1093 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1094 | void Styleable::Print(std::ostream* out) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1095 | *out << "(styleable) " |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1096 | << " [" << util::Joiner(entries, ", ") << "]"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1097 | } |
| 1098 | |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 1099 | bool operator<(const Reference& a, const Reference& b) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1100 | int cmp = a.name.value_or_default({}).compare(b.name.value_or_default({})); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1101 | if (cmp != 0) return cmp < 0; |
| 1102 | return a.id < b.id; |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | bool operator==(const Reference& a, const Reference& b) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1106 | return a.name == b.name && a.id == b.id; |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | bool operator!=(const Reference& a, const Reference& b) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1110 | return a.name != b.name || a.id != b.id; |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 1113 | struct NameOnlyComparator { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1114 | bool operator()(const Reference& a, const Reference& b) const { |
| 1115 | return a.name < b.name; |
| 1116 | } |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 1117 | }; |
| 1118 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 1119 | void Styleable::MergeWith(Styleable* other) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1120 | // Compare only names, because some References may already have their IDs |
Adam Lesinski | 5924d8c | 2017-05-30 15:15:58 -0700 | [diff] [blame] | 1121 | // assigned (framework IDs that don't change). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1122 | std::set<Reference, NameOnlyComparator> references; |
| 1123 | references.insert(entries.begin(), entries.end()); |
| 1124 | references.insert(other->entries.begin(), other->entries.end()); |
| 1125 | entries.clear(); |
| 1126 | entries.reserve(references.size()); |
| 1127 | entries.insert(entries.end(), references.begin(), references.end()); |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 1130 | } // namespace aapt |