AAPT2: Rename to match new style
Use Google3 naming style to match new
projects' and open source google projects' style.
Preferred to do this in a massive CL so as to avoid
style inconsistencies that plague legacy code bases.
This is a relatively NEW code base, may as well keep
it up to date.
Test: name/style refactor - existing tests pass
Change-Id: Ie80ecb78d46ec53efdfca2336bb57d96cbb7fb87
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.cpp b/tools/aapt2/unflatten/BinaryResourceParser.cpp
index 546b607..aeabcff 100644
--- a/tools/aapt2/unflatten/BinaryResourceParser.cpp
+++ b/tools/aapt2/unflatten/BinaryResourceParser.cpp
@@ -15,6 +15,16 @@
*/
#include "unflatten/BinaryResourceParser.h"
+
+#include <algorithm>
+#include <map>
+#include <string>
+
+#include "android-base/logging.h"
+#include "android-base/macros.h"
+#include "androidfw/ResourceTypes.h"
+#include "androidfw/TypeWrappers.h"
+
#include "ResourceTable.h"
#include "ResourceUtils.h"
#include "ResourceValues.h"
@@ -23,13 +33,6 @@
#include "unflatten/ResChunkPullParser.h"
#include "util/Util.h"
-#include <android-base/macros.h>
-#include <androidfw/ResourceTypes.h>
-#include <androidfw/TypeWrappers.h>
-#include <algorithm>
-#include <map>
-#include <string>
-
namespace aapt {
using namespace android;
@@ -41,29 +44,31 @@
* given a mapping from resource ID to resource name.
*/
class ReferenceIdToNameVisitor : public ValueVisitor {
- private:
- const std::map<ResourceId, ResourceName>* mMapping;
-
public:
- using ValueVisitor::visit;
+ using ValueVisitor::Visit;
explicit ReferenceIdToNameVisitor(
const std::map<ResourceId, ResourceName>* mapping)
- : mMapping(mapping) {
- assert(mMapping);
+ : mapping_(mapping) {
+ CHECK(mapping_ != nullptr);
}
- void visit(Reference* reference) override {
- if (!reference->id || !reference->id.value().isValid()) {
+ void Visit(Reference* reference) override {
+ if (!reference->id || !reference->id.value().is_valid()) {
return;
}
ResourceId id = reference->id.value();
- auto cacheIter = mMapping->find(id);
- if (cacheIter != mMapping->end()) {
- reference->name = cacheIter->second;
+ auto cache_iter = mapping_->find(id);
+ if (cache_iter != mapping_->end()) {
+ reference->name = cache_iter->second;
}
}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ReferenceIdToNameVisitor);
+
+ const std::map<ResourceId, ResourceName>* mapping_;
};
} // namespace
@@ -72,33 +77,32 @@
ResourceTable* table,
const Source& source,
const void* data, size_t len)
- : mContext(context),
- mTable(table),
- mSource(source),
- mData(data),
- mDataLen(len) {}
+ : context_(context),
+ table_(table),
+ source_(source),
+ data_(data),
+ data_len_(len) {}
-bool BinaryResourceParser::parse() {
- ResChunkPullParser parser(mData, mDataLen);
+bool BinaryResourceParser::Parse() {
+ ResChunkPullParser parser(data_, data_len_);
bool error = false;
- while (ResChunkPullParser::isGoodEvent(parser.next())) {
- if (parser.getChunk()->type != android::RES_TABLE_TYPE) {
- mContext->getDiagnostics()->warn(DiagMessage(mSource)
+ while (ResChunkPullParser::IsGoodEvent(parser.Next())) {
+ if (parser.chunk()->type != android::RES_TABLE_TYPE) {
+ context_->GetDiagnostics()->Warn(DiagMessage(source_)
<< "unknown chunk of type '"
- << (int)parser.getChunk()->type << "'");
+ << (int)parser.chunk()->type << "'");
continue;
}
- if (!parseTable(parser.getChunk())) {
+ if (!ParseTable(parser.chunk())) {
error = true;
}
}
- if (parser.getEvent() == ResChunkPullParser::Event::BadDocument) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
- << "corrupt resource table: "
- << parser.getLastError());
+ if (parser.event() == ResChunkPullParser::Event::kBadDocument) {
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "corrupt resource table: " << parser.error());
return false;
}
return !error;
@@ -108,212 +112,210 @@
* Parses the resource table, which contains all the packages, types, and
* entries.
*/
-bool BinaryResourceParser::parseTable(const ResChunk_header* chunk) {
- const ResTable_header* tableHeader = convertTo<ResTable_header>(chunk);
- if (!tableHeader) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+bool BinaryResourceParser::ParseTable(const ResChunk_header* chunk) {
+ const ResTable_header* table_header = ConvertTo<ResTable_header>(chunk);
+ if (!table_header) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt ResTable_header chunk");
return false;
}
- ResChunkPullParser parser(getChunkData(&tableHeader->header),
- getChunkDataLen(&tableHeader->header));
- while (ResChunkPullParser::isGoodEvent(parser.next())) {
- switch (util::deviceToHost16(parser.getChunk()->type)) {
+ ResChunkPullParser parser(GetChunkData(&table_header->header),
+ GetChunkDataLen(&table_header->header));
+ while (ResChunkPullParser::IsGoodEvent(parser.Next())) {
+ switch (util::DeviceToHost16(parser.chunk()->type)) {
case android::RES_STRING_POOL_TYPE:
- if (mValuePool.getError() == NO_INIT) {
- status_t err = mValuePool.setTo(
- parser.getChunk(), util::deviceToHost32(parser.getChunk()->size));
+ if (value_pool_.getError() == NO_INIT) {
+ status_t err = value_pool_.setTo(
+ parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
if (err != NO_ERROR) {
- mContext->getDiagnostics()->error(
- DiagMessage(mSource) << "corrupt string pool in ResTable: "
- << mValuePool.getError());
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "corrupt string pool in ResTable: "
+ << value_pool_.getError());
return false;
}
// Reserve some space for the strings we are going to add.
- mTable->stringPool.hintWillAdd(mValuePool.size(),
- mValuePool.styleCount());
+ table_->string_pool.HintWillAdd(value_pool_.size(),
+ value_pool_.styleCount());
} else {
- mContext->getDiagnostics()->warn(
- DiagMessage(mSource) << "unexpected string pool in ResTable");
+ context_->GetDiagnostics()->Warn(
+ DiagMessage(source_) << "unexpected string pool in ResTable");
}
break;
case android::RES_TABLE_PACKAGE_TYPE:
- if (!parsePackage(parser.getChunk())) {
+ if (!ParsePackage(parser.chunk())) {
return false;
}
break;
default:
- mContext->getDiagnostics()->warn(
- DiagMessage(mSource)
+ context_->GetDiagnostics()->Warn(
+ DiagMessage(source_)
<< "unexpected chunk type "
- << (int)util::deviceToHost16(parser.getChunk()->type));
+ << (int)util::DeviceToHost16(parser.chunk()->type));
break;
}
}
- if (parser.getEvent() == ResChunkPullParser::Event::BadDocument) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
- << "corrupt resource table: "
- << parser.getLastError());
+ if (parser.event() == ResChunkPullParser::Event::kBadDocument) {
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "corrupt resource table: " << parser.error());
return false;
}
return true;
}
-bool BinaryResourceParser::parsePackage(const ResChunk_header* chunk) {
- const ResTable_package* packageHeader = convertTo<ResTable_package>(chunk);
- if (!packageHeader) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+bool BinaryResourceParser::ParsePackage(const ResChunk_header* chunk) {
+ const ResTable_package* package_header = ConvertTo<ResTable_package>(chunk);
+ if (!package_header) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt ResTable_package chunk");
return false;
}
- uint32_t packageId = util::deviceToHost32(packageHeader->id);
- if (packageId > std::numeric_limits<uint8_t>::max()) {
- mContext->getDiagnostics()->error(
- DiagMessage(mSource) << "package ID is too big (" << packageId << ")");
+ uint32_t package_id = util::DeviceToHost32(package_header->id);
+ if (package_id > std::numeric_limits<uint8_t>::max()) {
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "package ID is too big (" << package_id << ")");
return false;
}
// Extract the package name.
- size_t len = strnlen16((const char16_t*)packageHeader->name,
- arraysize(packageHeader->name));
- std::u16string packageName;
- packageName.resize(len);
+ size_t len = strnlen16((const char16_t*)package_header->name,
+ arraysize(package_header->name));
+ std::u16string package_name;
+ package_name.resize(len);
for (size_t i = 0; i < len; i++) {
- packageName[i] = util::deviceToHost16(packageHeader->name[i]);
+ package_name[i] = util::DeviceToHost16(package_header->name[i]);
}
- ResourceTablePackage* package = mTable->createPackage(
- util::utf16ToUtf8(packageName), static_cast<uint8_t>(packageId));
+ ResourceTablePackage* package = table_->CreatePackage(
+ util::Utf16ToUtf8(package_name), static_cast<uint8_t>(package_id));
if (!package) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
- << "incompatible package '" << packageName
- << "' with ID " << packageId);
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "incompatible package '" << package_name
+ << "' with ID " << package_id);
return false;
}
// There can be multiple packages in a table, so
// clear the type and key pool in case they were set from a previous package.
- mTypePool.uninit();
- mKeyPool.uninit();
+ type_pool_.uninit();
+ key_pool_.uninit();
- ResChunkPullParser parser(getChunkData(&packageHeader->header),
- getChunkDataLen(&packageHeader->header));
- while (ResChunkPullParser::isGoodEvent(parser.next())) {
- switch (util::deviceToHost16(parser.getChunk()->type)) {
+ ResChunkPullParser parser(GetChunkData(&package_header->header),
+ GetChunkDataLen(&package_header->header));
+ while (ResChunkPullParser::IsGoodEvent(parser.Next())) {
+ switch (util::DeviceToHost16(parser.chunk()->type)) {
case android::RES_STRING_POOL_TYPE:
- if (mTypePool.getError() == NO_INIT) {
- status_t err = mTypePool.setTo(
- parser.getChunk(), util::deviceToHost32(parser.getChunk()->size));
+ if (type_pool_.getError() == NO_INIT) {
+ status_t err = type_pool_.setTo(
+ parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
if (err != NO_ERROR) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt type string pool in "
<< "ResTable_package: "
- << mTypePool.getError());
+ << type_pool_.getError());
return false;
}
- } else if (mKeyPool.getError() == NO_INIT) {
- status_t err = mKeyPool.setTo(
- parser.getChunk(), util::deviceToHost32(parser.getChunk()->size));
+ } else if (key_pool_.getError() == NO_INIT) {
+ status_t err = key_pool_.setTo(
+ parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
if (err != NO_ERROR) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt key string pool in "
<< "ResTable_package: "
- << mKeyPool.getError());
+ << key_pool_.getError());
return false;
}
} else {
- mContext->getDiagnostics()->warn(DiagMessage(mSource)
+ context_->GetDiagnostics()->Warn(DiagMessage(source_)
<< "unexpected string pool");
}
break;
case android::RES_TABLE_TYPE_SPEC_TYPE:
- if (!parseTypeSpec(parser.getChunk())) {
+ if (!ParseTypeSpec(parser.chunk())) {
return false;
}
break;
case android::RES_TABLE_TYPE_TYPE:
- if (!parseType(package, parser.getChunk())) {
+ if (!ParseType(package, parser.chunk())) {
return false;
}
break;
default:
- mContext->getDiagnostics()->warn(
- DiagMessage(mSource)
+ context_->GetDiagnostics()->Warn(
+ DiagMessage(source_)
<< "unexpected chunk type "
- << (int)util::deviceToHost16(parser.getChunk()->type));
+ << (int)util::DeviceToHost16(parser.chunk()->type));
break;
}
}
- if (parser.getEvent() == ResChunkPullParser::Event::BadDocument) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
- << "corrupt ResTable_package: "
- << parser.getLastError());
+ if (parser.event() == ResChunkPullParser::Event::kBadDocument) {
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "corrupt ResTable_package: " << parser.error());
return false;
}
// Now go through the table and change local resource ID references to
// symbolic references.
- ReferenceIdToNameVisitor visitor(&mIdIndex);
- visitAllValuesInTable(mTable, &visitor);
+ ReferenceIdToNameVisitor visitor(&id_index_);
+ VisitAllValuesInTable(table_, &visitor);
return true;
}
-bool BinaryResourceParser::parseTypeSpec(const ResChunk_header* chunk) {
- if (mTypePool.getError() != NO_ERROR) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+bool BinaryResourceParser::ParseTypeSpec(const ResChunk_header* chunk) {
+ if (type_pool_.getError() != NO_ERROR) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "missing type string pool");
return false;
}
- const ResTable_typeSpec* typeSpec = convertTo<ResTable_typeSpec>(chunk);
- if (!typeSpec) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ const ResTable_typeSpec* type_spec = ConvertTo<ResTable_typeSpec>(chunk);
+ if (!type_spec) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt ResTable_typeSpec chunk");
return false;
}
- if (typeSpec->id == 0) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ if (type_spec->id == 0) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "ResTable_typeSpec has invalid id: "
- << typeSpec->id);
+ << type_spec->id);
return false;
}
return true;
}
-bool BinaryResourceParser::parseType(const ResourceTablePackage* package,
+bool BinaryResourceParser::ParseType(const ResourceTablePackage* package,
const ResChunk_header* chunk) {
- if (mTypePool.getError() != NO_ERROR) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ if (type_pool_.getError() != NO_ERROR) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "missing type string pool");
return false;
}
- if (mKeyPool.getError() != NO_ERROR) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ if (key_pool_.getError() != NO_ERROR) {
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "missing key string pool");
return false;
}
- const ResTable_type* type = convertTo<ResTable_type>(chunk);
+ const ResTable_type* type = ConvertTo<ResTable_type>(chunk);
if (!type) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt ResTable_type chunk");
return false;
}
if (type->id == 0) {
- mContext->getDiagnostics()->error(DiagMessage(mSource)
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "ResTable_type has invalid id: "
<< (int)type->id);
return false;
@@ -322,12 +324,12 @@
ConfigDescription config;
config.copyFromDtoH(type->config);
- const std::string typeStr = util::getString(mTypePool, type->id - 1);
+ const std::string type_str = util::GetString(type_pool_, type->id - 1);
- const ResourceType* parsedType = parseResourceType(typeStr);
- if (!parsedType) {
- mContext->getDiagnostics()->error(
- DiagMessage(mSource) << "invalid type name '" << typeStr
+ const ResourceType* parsed_type = ParseResourceType(type_str);
+ if (!parsed_type) {
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "invalid type name '" << type_str
<< "' for type with ID " << (int)type->id);
return false;
}
@@ -340,91 +342,90 @@
}
const ResourceName name(
- package->name, *parsedType,
- util::getString(mKeyPool, util::deviceToHost32(entry->key.index)));
+ package->name, *parsed_type,
+ util::GetString(key_pool_, util::DeviceToHost32(entry->key.index)));
- const ResourceId resId(package->id.value(), type->id,
- static_cast<uint16_t>(it.index()));
+ const ResourceId res_id(package->id.value(), type->id,
+ static_cast<uint16_t>(it.index()));
- std::unique_ptr<Value> resourceValue;
+ std::unique_ptr<Value> resource_value;
if (entry->flags & ResTable_entry::FLAG_COMPLEX) {
const ResTable_map_entry* mapEntry =
static_cast<const ResTable_map_entry*>(entry);
// TODO(adamlesinski): Check that the entry count is valid.
- resourceValue = parseMapEntry(name, config, mapEntry);
+ resource_value = ParseMapEntry(name, config, mapEntry);
} else {
const Res_value* value =
(const Res_value*)((const uint8_t*)entry +
- util::deviceToHost32(entry->size));
- resourceValue = parseValue(name, config, value, entry->flags);
+ util::DeviceToHost32(entry->size));
+ resource_value = ParseValue(name, config, value, entry->flags);
}
- if (!resourceValue) {
- mContext->getDiagnostics()->error(
- DiagMessage(mSource) << "failed to parse value for resource " << name
- << " (" << resId << ") with configuration '"
+ if (!resource_value) {
+ context_->GetDiagnostics()->Error(
+ DiagMessage(source_) << "failed to parse value for resource " << name
+ << " (" << res_id << ") with configuration '"
<< config << "'");
return false;
}
- if (!mTable->addResourceAllowMangled(name, config, {},
- std::move(resourceValue),
- mContext->getDiagnostics())) {
+ if (!table_->AddResourceAllowMangled(name, config, {},
+ std::move(resource_value),
+ context_->GetDiagnostics())) {
return false;
}
if ((entry->flags & ResTable_entry::FLAG_PUBLIC) != 0) {
Symbol symbol;
symbol.state = SymbolState::kPublic;
- symbol.source = mSource.withLine(0);
- if (!mTable->setSymbolStateAllowMangled(name, resId, symbol,
- mContext->getDiagnostics())) {
+ symbol.source = source_.WithLine(0);
+ if (!table_->SetSymbolStateAllowMangled(name, res_id, symbol,
+ context_->GetDiagnostics())) {
return false;
}
}
// Add this resource name->id mapping to the index so
// that we can resolve all ID references to name references.
- auto cacheIter = mIdIndex.find(resId);
- if (cacheIter == mIdIndex.end()) {
- mIdIndex.insert({resId, name});
+ auto cache_iter = id_index_.find(res_id);
+ if (cache_iter == id_index_.end()) {
+ id_index_.insert({res_id, name});
}
}
return true;
}
-std::unique_ptr<Item> BinaryResourceParser::parseValue(
+std::unique_ptr<Item> BinaryResourceParser::ParseValue(
const ResourceNameRef& name, const ConfigDescription& config,
const Res_value* value, uint16_t flags) {
if (name.type == ResourceType::kId) {
return util::make_unique<Id>();
}
- const uint32_t data = util::deviceToHost32(value->data);
+ const uint32_t data = util::DeviceToHost32(value->data);
if (value->dataType == Res_value::TYPE_STRING) {
- const std::string str = util::getString(mValuePool, data);
+ const std::string str = util::GetString(value_pool_, data);
- const ResStringPool_span* spans = mValuePool.styleAt(data);
+ const ResStringPool_span* spans = value_pool_.styleAt(data);
// Check if the string has a valid style associated with it.
if (spans != nullptr && spans->name.index != ResStringPool_span::END) {
- StyleString styleStr = {str};
+ StyleString style_str = {str};
while (spans->name.index != ResStringPool_span::END) {
- styleStr.spans.push_back(
- Span{util::getString(mValuePool, spans->name.index),
+ style_str.spans.push_back(
+ Span{util::GetString(value_pool_, spans->name.index),
spans->firstChar, spans->lastChar});
spans++;
}
- return util::make_unique<StyledString>(mTable->stringPool.makeRef(
- styleStr,
+ return util::make_unique<StyledString>(table_->string_pool.MakeRef(
+ style_str,
StringPool::Context(StringPool::Context::kStylePriority, config)));
} else {
- if (name.type != ResourceType::kString &&
- util::stringStartsWith(str, "res/")) {
+ if (name.type != ResourceType::kString && util::StartsWith(str, "res/")) {
// This must be a FileReference.
- return util::make_unique<FileReference>(mTable->stringPool.makeRef(
+ return util::make_unique<FileReference>(table_->string_pool.MakeRef(
str,
StringPool::Context(StringPool::Context::kHighPriority, config)));
}
@@ -432,7 +433,7 @@
// There are no styles associated with this string, so treat it as
// a simple string.
return util::make_unique<String>(
- mTable->stringPool.makeRef(str, StringPool::Context(config)));
+ table_->string_pool.MakeRef(str, StringPool::Context(config)));
}
}
@@ -444,9 +445,9 @@
if (data == 0) {
// A reference of 0, must be the magic @null reference.
- Res_value nullType = {};
- nullType.dataType = Res_value::TYPE_REFERENCE;
- return util::make_unique<BinaryPrimitive>(nullType);
+ Res_value null_type = {};
+ null_type.dataType = Res_value::TYPE_REFERENCE;
+ return util::make_unique<BinaryPrimitive>(null_type);
}
// This is a normal reference.
@@ -457,87 +458,88 @@
return util::make_unique<BinaryPrimitive>(*value);
}
-std::unique_ptr<Value> BinaryResourceParser::parseMapEntry(
+std::unique_ptr<Value> BinaryResourceParser::ParseMapEntry(
const ResourceNameRef& name, const ConfigDescription& config,
const ResTable_map_entry* map) {
switch (name.type) {
case ResourceType::kStyle:
- return parseStyle(name, config, map);
+ return ParseStyle(name, config, map);
case ResourceType::kAttrPrivate:
// fallthrough
case ResourceType::kAttr:
- return parseAttr(name, config, map);
+ return ParseAttr(name, config, map);
case ResourceType::kArray:
- return parseArray(name, config, map);
+ return ParseArray(name, config, map);
case ResourceType::kPlurals:
- return parsePlural(name, config, map);
+ return ParsePlural(name, config, map);
default:
- assert(false && "unknown map type");
+ LOG(FATAL) << "unknown map type";
break;
}
return {};
}
-std::unique_ptr<Style> BinaryResourceParser::parseStyle(
+std::unique_ptr<Style> BinaryResourceParser::ParseStyle(
const ResourceNameRef& name, const ConfigDescription& config,
const ResTable_map_entry* map) {
std::unique_ptr<Style> style = util::make_unique<Style>();
- if (util::deviceToHost32(map->parent.ident) != 0) {
+ if (util::DeviceToHost32(map->parent.ident) != 0) {
// The parent is a regular reference to a resource.
- style->parent = Reference(util::deviceToHost32(map->parent.ident));
+ style->parent = Reference(util::DeviceToHost32(map->parent.ident));
}
- for (const ResTable_map& mapEntry : map) {
- if (Res_INTERNALID(util::deviceToHost32(mapEntry.name.ident))) {
+ for (const ResTable_map& map_entry : map) {
+ if (Res_INTERNALID(util::DeviceToHost32(map_entry.name.ident))) {
continue;
}
- Style::Entry styleEntry;
- styleEntry.key = Reference(util::deviceToHost32(mapEntry.name.ident));
- styleEntry.value = parseValue(name, config, &mapEntry.value, 0);
- if (!styleEntry.value) {
+ Style::Entry style_entry;
+ style_entry.key = Reference(util::DeviceToHost32(map_entry.name.ident));
+ style_entry.value = ParseValue(name, config, &map_entry.value, 0);
+ if (!style_entry.value) {
return {};
}
- style->entries.push_back(std::move(styleEntry));
+ style->entries.push_back(std::move(style_entry));
}
return style;
}
-std::unique_ptr<Attribute> BinaryResourceParser::parseAttr(
+std::unique_ptr<Attribute> BinaryResourceParser::ParseAttr(
const ResourceNameRef& name, const ConfigDescription& config,
const ResTable_map_entry* map) {
- const bool isWeak =
- (util::deviceToHost16(map->flags) & ResTable_entry::FLAG_WEAK) != 0;
- std::unique_ptr<Attribute> attr = util::make_unique<Attribute>(isWeak);
+ const bool is_weak =
+ (util::DeviceToHost16(map->flags) & ResTable_entry::FLAG_WEAK) != 0;
+ std::unique_ptr<Attribute> attr = util::make_unique<Attribute>(is_weak);
// First we must discover what type of attribute this is. Find the type mask.
- auto typeMaskIter =
+ auto type_mask_iter =
std::find_if(begin(map), end(map), [](const ResTable_map& entry) -> bool {
- return util::deviceToHost32(entry.name.ident) ==
+ return util::DeviceToHost32(entry.name.ident) ==
ResTable_map::ATTR_TYPE;
});
- if (typeMaskIter != end(map)) {
- attr->typeMask = util::deviceToHost32(typeMaskIter->value.data);
+ if (type_mask_iter != end(map)) {
+ attr->type_mask = util::DeviceToHost32(type_mask_iter->value.data);
}
- for (const ResTable_map& mapEntry : map) {
- if (Res_INTERNALID(util::deviceToHost32(mapEntry.name.ident))) {
- switch (util::deviceToHost32(mapEntry.name.ident)) {
+ for (const ResTable_map& map_entry : map) {
+ if (Res_INTERNALID(util::DeviceToHost32(map_entry.name.ident))) {
+ switch (util::DeviceToHost32(map_entry.name.ident)) {
case ResTable_map::ATTR_MIN:
- attr->minInt = static_cast<int32_t>(mapEntry.value.data);
+ attr->min_int = static_cast<int32_t>(map_entry.value.data);
break;
case ResTable_map::ATTR_MAX:
- attr->maxInt = static_cast<int32_t>(mapEntry.value.data);
+ attr->max_int = static_cast<int32_t>(map_entry.value.data);
break;
}
continue;
}
- if (attr->typeMask & (ResTable_map::TYPE_ENUM | ResTable_map::TYPE_FLAGS)) {
+ if (attr->type_mask &
+ (ResTable_map::TYPE_ENUM | ResTable_map::TYPE_FLAGS)) {
Attribute::Symbol symbol;
- symbol.value = util::deviceToHost32(mapEntry.value.data);
- symbol.symbol = Reference(util::deviceToHost32(mapEntry.name.ident));
+ symbol.value = util::DeviceToHost32(map_entry.value.data);
+ symbol.symbol = Reference(util::DeviceToHost32(map_entry.name.ident));
attr->symbols.push_back(std::move(symbol));
}
}
@@ -546,27 +548,27 @@
return attr;
}
-std::unique_ptr<Array> BinaryResourceParser::parseArray(
+std::unique_ptr<Array> BinaryResourceParser::ParseArray(
const ResourceNameRef& name, const ConfigDescription& config,
const ResTable_map_entry* map) {
std::unique_ptr<Array> array = util::make_unique<Array>();
- for (const ResTable_map& mapEntry : map) {
- array->items.push_back(parseValue(name, config, &mapEntry.value, 0));
+ for (const ResTable_map& map_entry : map) {
+ array->items.push_back(ParseValue(name, config, &map_entry.value, 0));
}
return array;
}
-std::unique_ptr<Plural> BinaryResourceParser::parsePlural(
+std::unique_ptr<Plural> BinaryResourceParser::ParsePlural(
const ResourceNameRef& name, const ConfigDescription& config,
const ResTable_map_entry* map) {
std::unique_ptr<Plural> plural = util::make_unique<Plural>();
- for (const ResTable_map& mapEntry : map) {
- std::unique_ptr<Item> item = parseValue(name, config, &mapEntry.value, 0);
+ for (const ResTable_map& map_entry : map) {
+ std::unique_ptr<Item> item = ParseValue(name, config, &map_entry.value, 0);
if (!item) {
return {};
}
- switch (util::deviceToHost32(mapEntry.name.ident)) {
+ switch (util::DeviceToHost32(map_entry.name.ident)) {
case ResTable_map::ATTR_ZERO:
plural->values[Plural::Zero] = std::move(item);
break;
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.h b/tools/aapt2/unflatten/BinaryResourceParser.h
index 99f2bd4..dc668fd 100644
--- a/tools/aapt2/unflatten/BinaryResourceParser.h
+++ b/tools/aapt2/unflatten/BinaryResourceParser.h
@@ -17,16 +17,17 @@
#ifndef AAPT_BINARY_RESOURCE_PARSER_H
#define AAPT_BINARY_RESOURCE_PARSER_H
+#include <string>
+
+#include "android-base/macros.h"
+#include "androidfw/ResourceTypes.h"
+
#include "ResourceTable.h"
#include "ResourceValues.h"
#include "Source.h"
-
#include "process/IResourceTableConsumer.h"
#include "util/Util.h"
-#include <androidfw/ResourceTypes.h>
-#include <string>
-
namespace aapt {
struct SymbolTable_entry;
@@ -45,44 +46,44 @@
* add any resources parsed to `table`. `source` is for logging purposes.
*/
BinaryResourceParser(IAaptContext* context, ResourceTable* table,
- const Source& source, const void* data, size_t dataLen);
-
- BinaryResourceParser(const BinaryResourceParser&) = delete; // No copy.
+ const Source& source, const void* data, size_t data_len);
/*
* Parses the binary resource table and returns true if successful.
*/
- bool parse();
+ bool Parse();
private:
- bool parseTable(const android::ResChunk_header* chunk);
- bool parsePackage(const android::ResChunk_header* chunk);
- bool parseTypeSpec(const android::ResChunk_header* chunk);
- bool parseType(const ResourceTablePackage* package,
+ DISALLOW_COPY_AND_ASSIGN(BinaryResourceParser);
+
+ bool ParseTable(const android::ResChunk_header* chunk);
+ bool ParsePackage(const android::ResChunk_header* chunk);
+ bool ParseTypeSpec(const android::ResChunk_header* chunk);
+ bool ParseType(const ResourceTablePackage* package,
const android::ResChunk_header* chunk);
- std::unique_ptr<Item> parseValue(const ResourceNameRef& name,
+ std::unique_ptr<Item> ParseValue(const ResourceNameRef& name,
const ConfigDescription& config,
const android::Res_value* value,
uint16_t flags);
- std::unique_ptr<Value> parseMapEntry(const ResourceNameRef& name,
+ std::unique_ptr<Value> ParseMapEntry(const ResourceNameRef& name,
const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Style> parseStyle(const ResourceNameRef& name,
+ std::unique_ptr<Style> ParseStyle(const ResourceNameRef& name,
const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Attribute> parseAttr(const ResourceNameRef& name,
+ std::unique_ptr<Attribute> ParseAttr(const ResourceNameRef& name,
const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Array> parseArray(const ResourceNameRef& name,
+ std::unique_ptr<Array> ParseArray(const ResourceNameRef& name,
const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Plural> parsePlural(const ResourceNameRef& name,
+ std::unique_ptr<Plural> ParsePlural(const ResourceNameRef& name,
const ConfigDescription& config,
const android::ResTable_map_entry* map);
@@ -92,30 +93,30 @@
* read and added to the Value.
* Returns true if the mapEntry was meta data.
*/
- bool collectMetaData(const android::ResTable_map& mapEntry, Value* value);
+ bool CollectMetaData(const android::ResTable_map& map_entry, Value* value);
- IAaptContext* mContext;
- ResourceTable* mTable;
+ IAaptContext* context_;
+ ResourceTable* table_;
- const Source mSource;
+ const Source source_;
- const void* mData;
- const size_t mDataLen;
+ const void* data_;
+ const size_t data_len_;
// The standard value string pool for resource values.
- android::ResStringPool mValuePool;
+ android::ResStringPool value_pool_;
// The string pool that holds the names of the types defined
// in this table.
- android::ResStringPool mTypePool;
+ android::ResStringPool type_pool_;
// The string pool that holds the names of the entries defined
// in this table.
- android::ResStringPool mKeyPool;
+ android::ResStringPool key_pool_;
// A mapping of resource ID to resource name. When we finish parsing
// we use this to convert all resource IDs to symbolic references.
- std::map<ResourceId, ResourceName> mIdIndex;
+ std::map<ResourceId, ResourceName> id_index_;
};
} // namespace aapt
@@ -128,11 +129,11 @@
inline const ResTable_map* begin(const ResTable_map_entry* map) {
return (const ResTable_map*)((const uint8_t*)map +
- aapt::util::deviceToHost32(map->size));
+ aapt::util::DeviceToHost32(map->size));
}
inline const ResTable_map* end(const ResTable_map_entry* map) {
- return begin(map) + aapt::util::deviceToHost32(map->count);
+ return begin(map) + aapt::util::DeviceToHost32(map->count);
}
} // namespace android
diff --git a/tools/aapt2/unflatten/ResChunkPullParser.cpp b/tools/aapt2/unflatten/ResChunkPullParser.cpp
index 6f8bb1b..5d71ff3 100644
--- a/tools/aapt2/unflatten/ResChunkPullParser.cpp
+++ b/tools/aapt2/unflatten/ResChunkPullParser.cpp
@@ -15,55 +15,60 @@
*/
#include "unflatten/ResChunkPullParser.h"
-#include "util/Util.h"
-#include <androidfw/ResourceTypes.h>
#include <cstddef>
+#include "android-base/logging.h"
+#include "androidfw/ResourceTypes.h"
+
+#include "util/Util.h"
+
namespace aapt {
using android::ResChunk_header;
-ResChunkPullParser::Event ResChunkPullParser::next() {
- if (!isGoodEvent(mEvent)) {
- return mEvent;
- }
+ResChunkPullParser::Event ResChunkPullParser::Next() {
+ if (!IsGoodEvent(event_)) {
+ return event_;
+ }
- if (mEvent == Event::StartDocument) {
- mCurrentChunk = mData;
- } else {
- mCurrentChunk = (const ResChunk_header*)
- (((const char*) mCurrentChunk) + util::deviceToHost32(mCurrentChunk->size));
- }
+ if (event_ == Event::kStartDocument) {
+ current_chunk_ = data_;
+ } else {
+ current_chunk_ =
+ (const ResChunk_header*)(((const char*)current_chunk_) +
+ util::DeviceToHost32(current_chunk_->size));
+ }
- const std::ptrdiff_t diff = (const char*) mCurrentChunk - (const char*) mData;
- assert(diff >= 0 && "diff is negative");
- const size_t offset = static_cast<const size_t>(diff);
+ const std::ptrdiff_t diff = (const char*)current_chunk_ - (const char*)data_;
+ CHECK(diff >= 0) << "diff is negative";
+ const size_t offset = static_cast<const size_t>(diff);
- if (offset == mLen) {
- mCurrentChunk = nullptr;
- return (mEvent = Event::EndDocument);
- } else if (offset + sizeof(ResChunk_header) > mLen) {
- mLastError = "chunk is past the end of the document";
- mCurrentChunk = nullptr;
- return (mEvent = Event::BadDocument);
- }
+ if (offset == len_) {
+ current_chunk_ = nullptr;
+ return (event_ = Event::kEndDocument);
+ } else if (offset + sizeof(ResChunk_header) > len_) {
+ error_ = "chunk is past the end of the document";
+ current_chunk_ = nullptr;
+ return (event_ = Event::kBadDocument);
+ }
- if (util::deviceToHost16(mCurrentChunk->headerSize) < sizeof(ResChunk_header)) {
- mLastError = "chunk has too small header";
- mCurrentChunk = nullptr;
- return (mEvent = Event::BadDocument);
- } else if (util::deviceToHost32(mCurrentChunk->size) <
- util::deviceToHost16(mCurrentChunk->headerSize)) {
- mLastError = "chunk's total size is smaller than header";
- mCurrentChunk = nullptr;
- return (mEvent = Event::BadDocument);
- } else if (offset + util::deviceToHost32(mCurrentChunk->size) > mLen) {
- mLastError = "chunk's data extends past the end of the document";
- mCurrentChunk = nullptr;
- return (mEvent = Event::BadDocument);
- }
- return (mEvent = Event::Chunk);
+ if (util::DeviceToHost16(current_chunk_->headerSize) <
+ sizeof(ResChunk_header)) {
+ error_ = "chunk has too small header";
+ current_chunk_ = nullptr;
+ return (event_ = Event::kBadDocument);
+ } else if (util::DeviceToHost32(current_chunk_->size) <
+ util::DeviceToHost16(current_chunk_->headerSize)) {
+ error_ = "chunk's total size is smaller than header";
+ current_chunk_ = nullptr;
+ return (event_ = Event::kBadDocument);
+ } else if (offset + util::DeviceToHost32(current_chunk_->size) > len_) {
+ error_ = "chunk's data extends past the end of the document";
+ current_chunk_ = nullptr;
+ return (event_ = Event::kBadDocument);
+ }
+ return (event_ = Event::kChunk);
}
-} // namespace aapt
+} // namespace aapt
diff --git a/tools/aapt2/unflatten/ResChunkPullParser.h b/tools/aapt2/unflatten/ResChunkPullParser.h
index 24fa63d..437fc5c 100644
--- a/tools/aapt2/unflatten/ResChunkPullParser.h
+++ b/tools/aapt2/unflatten/ResChunkPullParser.h
@@ -17,11 +17,13 @@
#ifndef AAPT_RES_CHUNK_PULL_PARSER_H
#define AAPT_RES_CHUNK_PULL_PARSER_H
-#include "util/Util.h"
-
-#include <androidfw/ResourceTypes.h>
#include <string>
+#include "android-base/macros.h"
+#include "androidfw/ResourceTypes.h"
+
+#include "util/Util.h"
+
namespace aapt {
/**
@@ -39,17 +41,17 @@
class ResChunkPullParser {
public:
enum class Event {
- StartDocument,
- EndDocument,
- BadDocument,
+ kStartDocument,
+ kEndDocument,
+ kBadDocument,
- Chunk,
+ kChunk,
};
/**
* Returns false if the event is EndDocument or BadDocument.
*/
- static bool isGoodEvent(Event event);
+ static bool IsGoodEvent(Event event);
/**
* Create a ResChunkPullParser to read android::ResChunk_headers
@@ -57,68 +59,66 @@
*/
ResChunkPullParser(const void* data, size_t len);
- ResChunkPullParser(const ResChunkPullParser&) = delete;
-
- Event getEvent() const;
- const std::string& getLastError() const;
- const android::ResChunk_header* getChunk() const;
+ Event event() const;
+ const std::string& error() const;
+ const android::ResChunk_header* chunk() const;
/**
* Move to the next android::ResChunk_header.
*/
- Event next();
+ Event Next();
private:
- Event mEvent;
- const android::ResChunk_header* mData;
- size_t mLen;
- const android::ResChunk_header* mCurrentChunk;
- std::string mLastError;
+ DISALLOW_COPY_AND_ASSIGN(ResChunkPullParser);
+
+ Event event_;
+ const android::ResChunk_header* data_;
+ size_t len_;
+ const android::ResChunk_header* current_chunk_;
+ std::string error_;
};
template <typename T>
-inline static const T* convertTo(const android::ResChunk_header* chunk) {
- if (util::deviceToHost16(chunk->headerSize) < sizeof(T)) {
+inline static const T* ConvertTo(const android::ResChunk_header* chunk) {
+ if (util::DeviceToHost16(chunk->headerSize) < sizeof(T)) {
return nullptr;
}
return reinterpret_cast<const T*>(chunk);
}
-inline static const uint8_t* getChunkData(
+inline static const uint8_t* GetChunkData(
const android::ResChunk_header* chunk) {
return reinterpret_cast<const uint8_t*>(chunk) +
- util::deviceToHost16(chunk->headerSize);
+ util::DeviceToHost16(chunk->headerSize);
}
-inline static uint32_t getChunkDataLen(const android::ResChunk_header* chunk) {
- return util::deviceToHost32(chunk->size) -
- util::deviceToHost16(chunk->headerSize);
+inline static uint32_t GetChunkDataLen(const android::ResChunk_header* chunk) {
+ return util::DeviceToHost32(chunk->size) -
+ util::DeviceToHost16(chunk->headerSize);
}
//
// Implementation
//
-inline bool ResChunkPullParser::isGoodEvent(ResChunkPullParser::Event event) {
- return event != Event::EndDocument && event != Event::BadDocument;
+inline bool ResChunkPullParser::IsGoodEvent(ResChunkPullParser::Event event) {
+ return event != Event::kEndDocument && event != Event::kBadDocument;
}
inline ResChunkPullParser::ResChunkPullParser(const void* data, size_t len)
- : mEvent(Event::StartDocument),
- mData(reinterpret_cast<const android::ResChunk_header*>(data)),
- mLen(len),
- mCurrentChunk(nullptr) {}
+ : event_(Event::kStartDocument),
+ data_(reinterpret_cast<const android::ResChunk_header*>(data)),
+ len_(len),
+ current_chunk_(nullptr) {}
-inline ResChunkPullParser::Event ResChunkPullParser::getEvent() const {
- return mEvent;
+inline ResChunkPullParser::Event ResChunkPullParser::event() const {
+ return event_;
}
-inline const std::string& ResChunkPullParser::getLastError() const {
- return mLastError;
-}
+inline const std::string& ResChunkPullParser::error() const { return error_; }
-inline const android::ResChunk_header* ResChunkPullParser::getChunk() const {
- return mCurrentChunk;
+inline const android::ResChunk_header* ResChunkPullParser::chunk() const {
+ return current_chunk_;
}
} // namespace aapt