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 | |
| 17 | #include "Resource.h" |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 18 | #include "ResourceUtils.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 19 | #include "ResourceValues.h" |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 20 | #include "ValueVisitor.h" |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 21 | #include "io/File.h" |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 22 | #include "util/Util.h" |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 23 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 24 | #include <androidfw/ResourceTypes.h> |
| 25 | #include <limits> |
| 26 | |
| 27 | namespace aapt { |
| 28 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 29 | template <typename Derived> |
| 30 | void BaseValue<Derived>::accept(RawValueVisitor* visitor) { |
| 31 | visitor->visit(static_cast<Derived*>(this)); |
| 32 | } |
| 33 | |
| 34 | template <typename Derived> |
| 35 | void BaseItem<Derived>::accept(RawValueVisitor* visitor) { |
| 36 | visitor->visit(static_cast<Derived*>(this)); |
| 37 | } |
| 38 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 39 | RawString::RawString(const StringPool::Ref& ref) : value(ref) { |
| 40 | } |
| 41 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 42 | bool RawString::equals(const Value* value) const { |
| 43 | const RawString* other = valueCast<RawString>(value); |
| 44 | if (!other) { |
| 45 | return false; |
| 46 | } |
| 47 | return *this->value == *other->value; |
| 48 | } |
| 49 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 50 | RawString* RawString::clone(StringPool* newPool) const { |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 51 | RawString* rs = new RawString(newPool->makeRef(*value)); |
| 52 | rs->mComment = mComment; |
| 53 | rs->mSource = mSource; |
| 54 | return rs; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 57 | bool RawString::flatten(android::Res_value* outValue) const { |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 58 | outValue->dataType = android::Res_value::TYPE_STRING; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 59 | outValue->data = util::hostToDevice32(static_cast<uint32_t>(value.getIndex())); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 63 | void RawString::print(std::ostream* out) const { |
| 64 | *out << "(raw string) " << *value; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | Reference::Reference() : referenceType(Reference::Type::kResource) { |
| 68 | } |
| 69 | |
| 70 | Reference::Reference(const ResourceNameRef& n, Type t) : |
| 71 | name(n.toResourceName()), referenceType(t) { |
| 72 | } |
| 73 | |
| 74 | Reference::Reference(const ResourceId& i, Type type) : id(i), referenceType(type) { |
| 75 | } |
| 76 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 77 | bool Reference::equals(const Value* value) const { |
| 78 | const Reference* other = valueCast<Reference>(value); |
| 79 | if (!other) { |
| 80 | return false; |
| 81 | } |
| 82 | return referenceType == other->referenceType && privateReference == other->privateReference && |
| 83 | id == other->id && name == other->name; |
| 84 | } |
| 85 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 86 | bool Reference::flatten(android::Res_value* outValue) const { |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 87 | outValue->dataType = (referenceType == Reference::Type::kResource) ? |
| 88 | android::Res_value::TYPE_REFERENCE : android::Res_value::TYPE_ATTRIBUTE; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 89 | outValue->data = util::hostToDevice32(id ? id.value().id : 0); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 90 | return true; |
| 91 | } |
| 92 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 93 | Reference* Reference::clone(StringPool* /*newPool*/) const { |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 94 | return new Reference(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 97 | void Reference::print(std::ostream* out) const { |
| 98 | *out << "(reference) "; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 99 | if (referenceType == Reference::Type::kResource) { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 100 | *out << "@"; |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 101 | if (privateReference) { |
| 102 | *out << "*"; |
| 103 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 104 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 105 | *out << "?"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 108 | if (name) { |
| 109 | *out << name.value(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 112 | if (id && !Res_INTERNALID(id.value().id)) { |
| 113 | *out << " " << id.value(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 117 | bool Id::equals(const Value* value) const { |
| 118 | return valueCast<Id>(value) != nullptr; |
| 119 | } |
| 120 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 121 | bool Id::flatten(android::Res_value* out) const { |
| 122 | out->dataType = android::Res_value::TYPE_INT_BOOLEAN; |
| 123 | out->data = util::hostToDevice32(0); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 124 | return true; |
| 125 | } |
| 126 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 127 | Id* Id::clone(StringPool* /*newPool*/) const { |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 128 | return new Id(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 131 | void Id::print(std::ostream* out) const { |
| 132 | *out << "(id)"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 135 | String::String(const StringPool::Ref& ref) : value(ref) { |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 138 | bool String::equals(const Value* value) const { |
| 139 | const String* other = valueCast<String>(value); |
| 140 | if (!other) { |
| 141 | return false; |
| 142 | } |
| 143 | return *this->value == *other->value; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 146 | bool String::flatten(android::Res_value* outValue) const { |
| 147 | // Verify that our StringPool index is within encode-able limits. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 148 | if (value.getIndex() > std::numeric_limits<uint32_t>::max()) { |
| 149 | return false; |
| 150 | } |
| 151 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 152 | outValue->dataType = android::Res_value::TYPE_STRING; |
| 153 | outValue->data = util::hostToDevice32(static_cast<uint32_t>(value.getIndex())); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 154 | return true; |
| 155 | } |
| 156 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 157 | String* String::clone(StringPool* newPool) const { |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 158 | String* str = new String(newPool->makeRef(*value)); |
| 159 | str->mComment = mComment; |
| 160 | str->mSource = mSource; |
| 161 | return str; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 164 | void String::print(std::ostream* out) const { |
| 165 | *out << "(string) \"" << *value << "\""; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 168 | StyledString::StyledString(const StringPool::StyleRef& ref) : value(ref) { |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 171 | bool StyledString::equals(const Value* value) const { |
| 172 | const StyledString* other = valueCast<StyledString>(value); |
| 173 | if (!other) { |
| 174 | return false; |
| 175 | } |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 176 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 177 | if (*this->value->str == *other->value->str) { |
| 178 | const std::vector<StringPool::Span>& spansA = this->value->spans; |
| 179 | const std::vector<StringPool::Span>& spansB = other->value->spans; |
| 180 | return std::equal(spansA.begin(), spansA.end(), spansB.begin(), |
| 181 | [](const StringPool::Span& a, const StringPool::Span& b) -> bool { |
| 182 | return *a.name == *b.name && a.firstChar == b.firstChar && a.lastChar == b.lastChar; |
| 183 | }); |
| 184 | } |
| 185 | return false; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 188 | bool StyledString::flatten(android::Res_value* outValue) const { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 189 | if (value.getIndex() > std::numeric_limits<uint32_t>::max()) { |
| 190 | return false; |
| 191 | } |
| 192 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 193 | outValue->dataType = android::Res_value::TYPE_STRING; |
| 194 | outValue->data = util::hostToDevice32(static_cast<uint32_t>(value.getIndex())); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 195 | return true; |
| 196 | } |
| 197 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 198 | StyledString* StyledString::clone(StringPool* newPool) const { |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 199 | StyledString* str = new StyledString(newPool->makeRef(value)); |
| 200 | str->mComment = mComment; |
| 201 | str->mSource = mSource; |
| 202 | return str; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 205 | void StyledString::print(std::ostream* out) const { |
| 206 | *out << "(styled string) \"" << *value->str << "\""; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 207 | for (const StringPool::Span& span : value->spans) { |
| 208 | *out << " "<< *span.name << ":" << span.firstChar << "," << span.lastChar; |
| 209 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | FileReference::FileReference(const StringPool::Ref& _path) : path(_path) { |
| 213 | } |
| 214 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 215 | bool FileReference::equals(const Value* value) const { |
| 216 | const FileReference* other = valueCast<FileReference>(value); |
| 217 | if (!other) { |
| 218 | return false; |
| 219 | } |
| 220 | return *path == *other->path; |
| 221 | } |
| 222 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 223 | bool FileReference::flatten(android::Res_value* outValue) const { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 224 | if (path.getIndex() > std::numeric_limits<uint32_t>::max()) { |
| 225 | return false; |
| 226 | } |
| 227 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 228 | outValue->dataType = android::Res_value::TYPE_STRING; |
| 229 | outValue->data = util::hostToDevice32(static_cast<uint32_t>(path.getIndex())); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 230 | return true; |
| 231 | } |
| 232 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 233 | FileReference* FileReference::clone(StringPool* newPool) const { |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 234 | FileReference* fr = new FileReference(newPool->makeRef(*path)); |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 235 | fr->file = file; |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 236 | fr->mComment = mComment; |
| 237 | fr->mSource = mSource; |
| 238 | return fr; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 241 | void FileReference::print(std::ostream* out) const { |
| 242 | *out << "(file) " << *path; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | BinaryPrimitive::BinaryPrimitive(const android::Res_value& val) : value(val) { |
| 246 | } |
| 247 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 248 | BinaryPrimitive::BinaryPrimitive(uint8_t dataType, uint32_t data) { |
| 249 | value.dataType = dataType; |
| 250 | value.data = data; |
| 251 | } |
| 252 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 253 | bool BinaryPrimitive::equals(const Value* value) const { |
| 254 | const BinaryPrimitive* other = valueCast<BinaryPrimitive>(value); |
| 255 | if (!other) { |
| 256 | return false; |
| 257 | } |
| 258 | return this->value.dataType == other->value.dataType && this->value.data == other->value.data; |
| 259 | } |
| 260 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 261 | bool BinaryPrimitive::flatten(android::Res_value* outValue) const { |
| 262 | outValue->dataType = value.dataType; |
| 263 | outValue->data = util::hostToDevice32(value.data); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 264 | return true; |
| 265 | } |
| 266 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 267 | BinaryPrimitive* BinaryPrimitive::clone(StringPool* /*newPool*/) const { |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 268 | return new BinaryPrimitive(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 271 | void BinaryPrimitive::print(std::ostream* out) const { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 272 | switch (value.dataType) { |
| 273 | case android::Res_value::TYPE_NULL: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 274 | *out << "(null)"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 275 | break; |
| 276 | case android::Res_value::TYPE_INT_DEC: |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 277 | *out << "(integer) " << static_cast<int32_t>(value.data); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 278 | break; |
| 279 | case android::Res_value::TYPE_INT_HEX: |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 280 | *out << "(integer) 0x" << std::hex << value.data << std::dec; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 281 | break; |
| 282 | case android::Res_value::TYPE_INT_BOOLEAN: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 283 | *out << "(boolean) " << (value.data != 0 ? "true" : "false"); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 284 | break; |
| 285 | case android::Res_value::TYPE_INT_COLOR_ARGB8: |
| 286 | case android::Res_value::TYPE_INT_COLOR_RGB8: |
| 287 | case android::Res_value::TYPE_INT_COLOR_ARGB4: |
| 288 | case android::Res_value::TYPE_INT_COLOR_RGB4: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 289 | *out << "(color) #" << std::hex << value.data << std::dec; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 290 | break; |
| 291 | default: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 292 | *out << "(unknown 0x" << std::hex << (int) value.dataType << ") 0x" |
| 293 | << std::hex << value.data << std::dec; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 298 | Attribute::Attribute(bool w, uint32_t t) : |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 299 | typeMask(t), |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 300 | minInt(std::numeric_limits<int32_t>::min()), |
| 301 | maxInt(std::numeric_limits<int32_t>::max()) { |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 302 | mWeak = w; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 305 | bool Attribute::equals(const Value* value) const { |
| 306 | const Attribute* other = valueCast<Attribute>(value); |
| 307 | if (!other) { |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | return this->typeMask == other->typeMask && this->minInt == other->minInt && |
| 312 | this->maxInt == other->maxInt && |
| 313 | std::equal(this->symbols.begin(), this->symbols.end(), |
| 314 | other->symbols.begin(), |
| 315 | [](const Symbol& a, const Symbol& b) -> bool { |
| 316 | return a.symbol.equals(&b.symbol) && a.value == b.value; |
| 317 | }); |
| 318 | } |
| 319 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 320 | Attribute* Attribute::clone(StringPool* /*newPool*/) const { |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 321 | return new Attribute(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 324 | void Attribute::printMask(std::ostream* out) const { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 325 | if (typeMask == android::ResTable_map::TYPE_ANY) { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 326 | *out << "any"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 327 | return; |
| 328 | } |
| 329 | |
| 330 | bool set = false; |
| 331 | if ((typeMask & android::ResTable_map::TYPE_REFERENCE) != 0) { |
| 332 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 333 | set = true; |
| 334 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 335 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 336 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 337 | *out << "reference"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if ((typeMask & android::ResTable_map::TYPE_STRING) != 0) { |
| 341 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 342 | set = true; |
| 343 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 344 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 345 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 346 | *out << "string"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | if ((typeMask & android::ResTable_map::TYPE_INTEGER) != 0) { |
| 350 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 351 | set = true; |
| 352 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 353 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 354 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 355 | *out << "integer"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | if ((typeMask & android::ResTable_map::TYPE_BOOLEAN) != 0) { |
| 359 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 360 | set = true; |
| 361 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 362 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 363 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 364 | *out << "boolean"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | if ((typeMask & android::ResTable_map::TYPE_COLOR) != 0) { |
| 368 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 369 | set = true; |
| 370 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 371 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 372 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 373 | *out << "color"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | if ((typeMask & android::ResTable_map::TYPE_FLOAT) != 0) { |
| 377 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 378 | set = true; |
| 379 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 380 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 381 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 382 | *out << "float"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | if ((typeMask & android::ResTable_map::TYPE_DIMENSION) != 0) { |
| 386 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 387 | set = true; |
| 388 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 389 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 390 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 391 | *out << "dimension"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | if ((typeMask & android::ResTable_map::TYPE_FRACTION) != 0) { |
| 395 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 396 | set = true; |
| 397 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 398 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 399 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 400 | *out << "fraction"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | if ((typeMask & android::ResTable_map::TYPE_ENUM) != 0) { |
| 404 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 405 | set = true; |
| 406 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 407 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 408 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 409 | *out << "enum"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | if ((typeMask & android::ResTable_map::TYPE_FLAGS) != 0) { |
| 413 | if (!set) { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 414 | set = true; |
| 415 | } else { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 416 | *out << "|"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 417 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 418 | *out << "flags"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 419 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 422 | void Attribute::print(std::ostream* out) const { |
| 423 | *out << "(attr) "; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 424 | printMask(out); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 425 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 426 | if (!symbols.empty()) { |
| 427 | *out << " [" |
| 428 | << util::joiner(symbols.begin(), symbols.end(), ", ") |
| 429 | << "]"; |
| 430 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 431 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 432 | if (minInt != std::numeric_limits<int32_t>::min()) { |
| 433 | *out << " min=" << minInt; |
| 434 | } |
| 435 | |
| 436 | if (maxInt != std::numeric_limits<int32_t>::max()) { |
| 437 | *out << " max=" << maxInt; |
| 438 | } |
| 439 | |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 440 | if (isWeak()) { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 441 | *out << " [weak]"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 445 | static void buildAttributeMismatchMessage(DiagMessage* msg, const Attribute* attr, |
| 446 | const Item* value) { |
| 447 | *msg << "expected"; |
| 448 | if (attr->typeMask & android::ResTable_map::TYPE_BOOLEAN) { |
| 449 | *msg << " boolean"; |
| 450 | } |
| 451 | |
| 452 | if (attr->typeMask & android::ResTable_map::TYPE_COLOR) { |
| 453 | *msg << " color"; |
| 454 | } |
| 455 | |
| 456 | if (attr->typeMask & android::ResTable_map::TYPE_DIMENSION) { |
| 457 | *msg << " dimension"; |
| 458 | } |
| 459 | |
| 460 | if (attr->typeMask & android::ResTable_map::TYPE_ENUM) { |
| 461 | *msg << " enum"; |
| 462 | } |
| 463 | |
| 464 | if (attr->typeMask & android::ResTable_map::TYPE_FLAGS) { |
| 465 | *msg << " flags"; |
| 466 | } |
| 467 | |
| 468 | if (attr->typeMask & android::ResTable_map::TYPE_FLOAT) { |
| 469 | *msg << " float"; |
| 470 | } |
| 471 | |
| 472 | if (attr->typeMask & android::ResTable_map::TYPE_FRACTION) { |
| 473 | *msg << " fraction"; |
| 474 | } |
| 475 | |
| 476 | if (attr->typeMask & android::ResTable_map::TYPE_INTEGER) { |
| 477 | *msg << " integer"; |
| 478 | } |
| 479 | |
| 480 | if (attr->typeMask & android::ResTable_map::TYPE_REFERENCE) { |
| 481 | *msg << " reference"; |
| 482 | } |
| 483 | |
| 484 | if (attr->typeMask & android::ResTable_map::TYPE_STRING) { |
| 485 | *msg << " string"; |
| 486 | } |
| 487 | |
| 488 | *msg << " but got " << *value; |
| 489 | } |
| 490 | |
| 491 | bool Attribute::matches(const Item* item, DiagMessage* outMsg) const { |
| 492 | android::Res_value val = {}; |
| 493 | item->flatten(&val); |
| 494 | |
| 495 | // Always allow references. |
| 496 | const uint32_t mask = typeMask | android::ResTable_map::TYPE_REFERENCE; |
| 497 | if (!(mask & ResourceUtils::androidTypeToAttributeTypeMask(val.dataType))) { |
| 498 | if (outMsg) { |
| 499 | buildAttributeMismatchMessage(outMsg, this, item); |
| 500 | } |
| 501 | return false; |
| 502 | |
| 503 | } else if (ResourceUtils::androidTypeToAttributeTypeMask(val.dataType) & |
| 504 | android::ResTable_map::TYPE_INTEGER) { |
| 505 | if (static_cast<int32_t>(util::deviceToHost32(val.data)) < minInt) { |
| 506 | if (outMsg) { |
| 507 | *outMsg << *item << " is less than minimum integer " << minInt; |
| 508 | } |
| 509 | return false; |
| 510 | } else if (static_cast<int32_t>(util::deviceToHost32(val.data)) > maxInt) { |
| 511 | if (outMsg) { |
| 512 | *outMsg << *item << " is greater than maximum integer " << maxInt; |
| 513 | } |
| 514 | return false; |
| 515 | } |
| 516 | } |
| 517 | return true; |
| 518 | } |
| 519 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 520 | bool Style::equals(const Value* value) const { |
| 521 | const Style* other = valueCast<Style>(value); |
| 522 | if (!other) { |
| 523 | return false; |
| 524 | } |
| 525 | if (bool(parent) != bool(other->parent) || |
| 526 | (parent && other->parent && !parent.value().equals(&other->parent.value()))) { |
| 527 | return false; |
| 528 | } |
| 529 | return std::equal(entries.begin(), entries.end(), other->entries.begin(), |
| 530 | [](const Entry& a, const Entry& b) -> bool { |
| 531 | return a.key.equals(&b.key) && a.value->equals(b.value.get()); |
| 532 | }); |
| 533 | } |
| 534 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 535 | Style* Style::clone(StringPool* newPool) const { |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 536 | Style* style = new Style(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 537 | style->parent = parent; |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 538 | style->parentInferred = parentInferred; |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 539 | style->mComment = mComment; |
| 540 | style->mSource = mSource; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 541 | for (auto& entry : entries) { |
| 542 | style->entries.push_back(Entry{ |
| 543 | entry.key, |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 544 | std::unique_ptr<Item>(entry.value->clone(newPool)) |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 545 | }); |
| 546 | } |
| 547 | return style; |
| 548 | } |
| 549 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 550 | void Style::print(std::ostream* out) const { |
| 551 | *out << "(style) "; |
| 552 | if (parent && parent.value().name) { |
Adam Lesinski | 24b8ff0 | 2015-12-16 14:01:57 -0800 | [diff] [blame] | 553 | if (parent.value().privateReference) { |
| 554 | *out << "*"; |
| 555 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 556 | *out << parent.value().name.value(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 557 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 558 | *out << " [" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 559 | << util::joiner(entries.begin(), entries.end(), ", ") |
| 560 | << "]"; |
| 561 | } |
| 562 | |
| 563 | static ::std::ostream& operator<<(::std::ostream& out, const Style::Entry& value) { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 564 | if (value.key.name) { |
| 565 | out << value.key.name.value(); |
| 566 | } else { |
| 567 | out << "???"; |
| 568 | } |
| 569 | out << " = "; |
| 570 | value.value->print(&out); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 571 | return out; |
| 572 | } |
| 573 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 574 | bool Array::equals(const Value* value) const { |
| 575 | const Array* other = valueCast<Array>(value); |
| 576 | if (!other) { |
| 577 | return false; |
| 578 | } |
| 579 | |
| 580 | return std::equal(items.begin(), items.end(), other->items.begin(), |
| 581 | [](const std::unique_ptr<Item>& a, const std::unique_ptr<Item>& b) -> bool { |
| 582 | return a->equals(b.get()); |
| 583 | }); |
| 584 | } |
| 585 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 586 | Array* Array::clone(StringPool* newPool) const { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 587 | Array* array = new Array(); |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 588 | array->mComment = mComment; |
| 589 | array->mSource = mSource; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 590 | for (auto& item : items) { |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 591 | array->items.emplace_back(std::unique_ptr<Item>(item->clone(newPool))); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 592 | } |
| 593 | return array; |
| 594 | } |
| 595 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 596 | void Array::print(std::ostream* out) const { |
| 597 | *out << "(array) [" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 598 | << util::joiner(items.begin(), items.end(), ", ") |
| 599 | << "]"; |
| 600 | } |
| 601 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 602 | bool Plural::equals(const Value* value) const { |
| 603 | const Plural* other = valueCast<Plural>(value); |
| 604 | if (!other) { |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | return std::equal(values.begin(), values.end(), other->values.begin(), |
| 609 | [](const std::unique_ptr<Item>& a, const std::unique_ptr<Item>& b) -> bool { |
| 610 | if (bool(a) != bool(b)) { |
| 611 | return false; |
| 612 | } |
| 613 | return bool(a) == bool(b) || a->equals(b.get()); |
| 614 | }); |
| 615 | } |
| 616 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 617 | Plural* Plural::clone(StringPool* newPool) const { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 618 | Plural* p = new Plural(); |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 619 | p->mComment = mComment; |
| 620 | p->mSource = mSource; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 621 | const size_t count = values.size(); |
| 622 | for (size_t i = 0; i < count; i++) { |
| 623 | if (values[i]) { |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 624 | p->values[i] = std::unique_ptr<Item>(values[i]->clone(newPool)); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | return p; |
| 628 | } |
| 629 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 630 | void Plural::print(std::ostream* out) const { |
| 631 | *out << "(plural)"; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 632 | if (values[Zero]) { |
| 633 | *out << " zero=" << *values[Zero]; |
| 634 | } |
| 635 | |
| 636 | if (values[One]) { |
| 637 | *out << " one=" << *values[One]; |
| 638 | } |
| 639 | |
| 640 | if (values[Two]) { |
| 641 | *out << " two=" << *values[Two]; |
| 642 | } |
| 643 | |
| 644 | if (values[Few]) { |
| 645 | *out << " few=" << *values[Few]; |
| 646 | } |
| 647 | |
| 648 | if (values[Many]) { |
| 649 | *out << " many=" << *values[Many]; |
| 650 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static ::std::ostream& operator<<(::std::ostream& out, const std::unique_ptr<Item>& item) { |
| 654 | return out << *item; |
| 655 | } |
| 656 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame^] | 657 | bool Styleable::equals(const Value* value) const { |
| 658 | const Styleable* other = valueCast<Styleable>(value); |
| 659 | if (!other) { |
| 660 | return false; |
| 661 | } |
| 662 | return std::equal(entries.begin(), entries.end(), other->entries.begin(), |
| 663 | [](const Reference& a, const Reference& b) -> bool { |
| 664 | return a.equals(&b); |
| 665 | }); |
| 666 | } |
| 667 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 668 | Styleable* Styleable::clone(StringPool* /*newPool*/) const { |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 669 | return new Styleable(*this); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 672 | void Styleable::print(std::ostream* out) const { |
| 673 | *out << "(styleable) " << " [" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 674 | << util::joiner(entries.begin(), entries.end(), ", ") |
| 675 | << "]"; |
| 676 | } |
| 677 | |
| 678 | } // namespace aapt |