16f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski/*
26f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * Copyright (C) 2015 The Android Open Source Project
36f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *
46f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
56f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * you may not use this file except in compliance with the License.
66f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * You may obtain a copy of the License at
76f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *
86f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
96f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski *
106f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * Unless required by applicable law or agreed to in writing, software
116f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
126f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * See the License for the specific language governing permissions and
146f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski * limitations under the License.
156f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski */
166f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
176f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include "Resource.h"
186f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include "ResourceTypeExtensions.h"
196f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include "ResourceValues.h"
206f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include "Util.h"
216f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
226f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include <androidfw/ResourceTypes.h>
236f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski#include <limits>
246f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
256f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskinamespace aapt {
266f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
276f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Value::isItem() const {
286f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return false;
296f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
306f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
316f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Value::isWeak() const {
326f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return false;
336f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
346f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
356f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Item::isItem() const {
366f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
376f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
386f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
396f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiRawString::RawString(const StringPool::Ref& ref) : value(ref) {
406f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
416f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
42769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiRawString* RawString::clone(StringPool* newPool) const {
43769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam Lesinski    return new RawString(newPool->makeRef(*value));
446f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
456f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
466f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool RawString::flatten(android::Res_value& outValue) const {
476f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.dataType = ExtendedTypes::TYPE_RAW_STRING;
486f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.data = static_cast<uint32_t>(value.getIndex());
496f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
506f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
516f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
526f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid RawString::print(std::ostream& out) const {
536f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(raw string) " << *value;
546f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
556f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
566f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiReference::Reference() : referenceType(Reference::Type::kResource) {
576f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
586f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
596f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiReference::Reference(const ResourceNameRef& n, Type t) :
606f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        name(n.toResourceName()), referenceType(t) {
616f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
626f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
636f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiReference::Reference(const ResourceId& i, Type type) : id(i), referenceType(type) {
646f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
656f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
666f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Reference::flatten(android::Res_value& outValue) const {
676f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.dataType = (referenceType == Reference::Type::kResource)
686f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        ? android::Res_value::TYPE_REFERENCE
696f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        : android::Res_value::TYPE_ATTRIBUTE;
706f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.data = id.id;
716f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
726f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
736f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
74769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiReference* Reference::clone(StringPool* /*newPool*/) const {
756f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    Reference* ref = new Reference();
766f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    ref->referenceType = referenceType;
776f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    ref->name = name;
786f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    ref->id = id;
796f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return ref;
806f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
816f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
826f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid Reference::print(std::ostream& out) const {
836f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(reference) ";
846f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (referenceType == Reference::Type::kResource) {
856f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "@";
866f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    } else {
876f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "?";
886f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
896f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
906f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (name.isValid()) {
916f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << name;
926f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
936f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
946f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (id.isValid() || Res_INTERNALID(id.id)) {
956f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << " " << id;
966f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
976f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
986f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
996f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Id::isWeak() const {
1006f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
1016f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1026f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1036f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Id::flatten(android::Res_value& out) const {
104330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski    out.dataType = android::Res_value::TYPE_INT_BOOLEAN;
105330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski    out.data = 0;
1066f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
1076f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1086f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
109769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiId* Id::clone(StringPool* /*newPool*/) const {
1106f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return new Id();
1116f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1126f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1136f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid Id::print(std::ostream& out) const {
1146f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(id)";
1156f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1166f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1176f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiString::String(const StringPool::Ref& ref) : value(ref) {
1186f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1196f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1206f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool String::flatten(android::Res_value& outValue) const {
1216f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    // Verify that our StringPool index is within encodeable limits.
1226f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (value.getIndex() > std::numeric_limits<uint32_t>::max()) {
1236f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        return false;
1246f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
1256f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1266f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.dataType = android::Res_value::TYPE_STRING;
1276f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.data = static_cast<uint32_t>(value.getIndex());
1286f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
1296f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1306f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
131769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiString* String::clone(StringPool* newPool) const {
132769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam Lesinski    return new String(newPool->makeRef(*value));
1336f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1346f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1356f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid String::print(std::ostream& out) const {
1366f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(string) \"" << *value << "\"";
1376f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1386f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1396f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiStyledString::StyledString(const StringPool::StyleRef& ref) : value(ref) {
1406f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1416f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1426f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool StyledString::flatten(android::Res_value& outValue) const {
1436f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (value.getIndex() > std::numeric_limits<uint32_t>::max()) {
1446f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        return false;
1456f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
1466f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1476f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.dataType = android::Res_value::TYPE_STRING;
1486f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.data = static_cast<uint32_t>(value.getIndex());
1496f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
1506f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1516f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
152769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiStyledString* StyledString::clone(StringPool* newPool) const {
153769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam Lesinski    return new StyledString(newPool->makeRef(value));
1546f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1556f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1566f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid StyledString::print(std::ostream& out) const {
1576f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(styled string) \"" << *value->str << "\"";
1586f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1596f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1606f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiFileReference::FileReference(const StringPool::Ref& _path) : path(_path) {
1616f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1626f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1636f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool FileReference::flatten(android::Res_value& outValue) const {
1646f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (path.getIndex() > std::numeric_limits<uint32_t>::max()) {
1656f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        return false;
1666f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
1676f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1686f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.dataType = android::Res_value::TYPE_STRING;
1696f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue.data = static_cast<uint32_t>(path.getIndex());
1706f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
1716f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1726f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
173769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiFileReference* FileReference::clone(StringPool* newPool) const {
174769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam Lesinski    return new FileReference(newPool->makeRef(*path));
1756f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1766f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1776f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid FileReference::print(std::ostream& out) const {
1786f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(file) " << *path;
1796f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1806f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1816f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiBinaryPrimitive::BinaryPrimitive(const android::Res_value& val) : value(val) {
1826f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1836f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1846f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool BinaryPrimitive::flatten(android::Res_value& outValue) const {
1856f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    outValue = value;
1866f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return true;
1876f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1886f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
189769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiBinaryPrimitive* BinaryPrimitive::clone(StringPool* /*newPool*/) const {
1906f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return new BinaryPrimitive(value);
1916f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
1926f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
1936f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid BinaryPrimitive::print(std::ostream& out) const {
1946f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    switch (value.dataType) {
1956f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_NULL:
1966f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "(null)";
1976f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            break;
1986f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_DEC:
1996f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "(integer) " << value.data;
2006f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            break;
2016f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_HEX:
2026f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "(integer) " << std::hex << value.data << std::dec;
2036f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            break;
2046f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_BOOLEAN:
2056f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "(boolean) " << (value.data != 0 ? "true" : "false");
2066f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            break;
2076f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_COLOR_ARGB8:
2086f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_COLOR_RGB8:
2096f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_COLOR_ARGB4:
2106f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        case android::Res_value::TYPE_INT_COLOR_RGB4:
2116f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "(color) #" << std::hex << value.data << std::dec;
2126f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            break;
2136f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        default:
2146f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "(unknown 0x" << std::hex << (int) value.dataType << ") 0x"
2156f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski                << std::hex << value.data << std::dec;
2166f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            break;
2176f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2186f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
2196f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2206f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam LesinskiAttribute::Attribute(bool w, uint32_t t) : weak(w), typeMask(t) {
2216f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
2226f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2236f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskibool Attribute::isWeak() const {
2246f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return weak;
2256f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
2266f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
227769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiAttribute* Attribute::clone(StringPool* /*newPool*/) const {
2286f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    Attribute* attr = new Attribute(weak);
2296f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    attr->typeMask = typeMask;
2306f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    std::copy(symbols.begin(), symbols.end(), std::back_inserter(attr->symbols));
2316f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return attr;
2326f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
2336f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
234330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinskivoid Attribute::printMask(std::ostream& out) const {
2356f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (typeMask == android::ResTable_map::TYPE_ANY) {
236330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski        out << "any";
2376f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        return;
2386f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2396f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2406f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    bool set = false;
2416f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_REFERENCE) != 0) {
2426f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2436f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2446f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2456f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
2466f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
2476f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "reference";
2486f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2496f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2506f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_STRING) != 0) {
2516f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2526f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2536f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2546f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
2556f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
2566f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "string";
2576f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2586f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2596f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_INTEGER) != 0) {
2606f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2616f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2626f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2636f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
2646f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
2656f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "integer";
2666f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2676f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2686f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_BOOLEAN) != 0) {
2696f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2706f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2716f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2726f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
2736f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
2746f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "boolean";
2756f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2766f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2776f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_COLOR) != 0) {
2786f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2796f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2806f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2816f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
2826f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
2836f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "color";
2846f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2856f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2866f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_FLOAT) != 0) {
2876f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2886f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2896f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2906f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
2916f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
2926f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "float";
2936f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
2946f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
2956f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_DIMENSION) != 0) {
2966f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
2976f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
2986f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
2996f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
3006f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
3016f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "dimension";
3026f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
3036f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3046f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_FRACTION) != 0) {
3056f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
3066f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
3076f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
3086f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
3096f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
3106f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "fraction";
3116f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
3126f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3136f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_ENUM) != 0) {
3146f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
3156f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
3166f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
3176f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
3186f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
3196f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "enum";
3206f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
3216f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3226f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if ((typeMask & android::ResTable_map::TYPE_FLAGS) != 0) {
3236f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        if (!set) {
3246f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            set = true;
3256f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        } else {
3266f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski            out << "|";
3276f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        }
3286f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << "flags";
3296f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
330330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski}
331330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski
332330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinskivoid Attribute::print(std::ostream& out) const {
333330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski    out << "(attr) ";
334330edcdf1316ed599fe0eb16a64330821fd92f18Adam Lesinski    printMask(out);
3356f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3366f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << " ["
3376f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        << util::joiner(symbols.begin(), symbols.end(), ", ")
3386f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        << "]";
3396f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3406f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (weak) {
3416f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << " [weak]";
3426f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
3436f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
3446f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
345769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiStyle* Style::clone(StringPool* newPool) const {
346bdaa092a193d8ddccbd9ad8434be97878e6ded59Adam Lesinski    Style* style = new Style();
3476f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    style->parent = parent;
348bdaa092a193d8ddccbd9ad8434be97878e6ded59Adam Lesinski    style->parentInferred = parentInferred;
3496f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    for (auto& entry : entries) {
3506f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        style->entries.push_back(Entry{
3516f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski                entry.key,
352769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam Lesinski                std::unique_ptr<Item>(entry.value->clone(newPool))
3536f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        });
3546f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
3556f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return style;
3566f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
3576f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3586f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskivoid Style::print(std::ostream& out) const {
3596f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << "(style) ";
3606f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    if (!parent.name.entry.empty()) {
3616f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        out << parent.name;
3626f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    }
3636f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << " ["
3646f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        << util::joiner(entries.begin(), entries.end(), ", ")
3656f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski        << "]";
3666f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
3676f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
3686f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinskistatic ::std::ostream& operator<<(::std::ostream& out, const Style::Entry& value) {
3696f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    out << value.key.name << " = ";
3706f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    value.value->print(out);
3716f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    return out;
3726f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski}
3736f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski
374769de98f2dd41bfe39a1c9f76aefd1ad58942733Adam LesinskiArray* Array::clone(StringPool* newPool) const {
3756f6ceb7e1456698b1f33e04536bfb3227f9fcfcbAdam Lesinski    Array* array = new Array();
376