summaryrefslogtreecommitdiff
path: root/tools/aapt2/process
diff options
context:
space:
mode:
author Ryan Mitchell <rtmitchell@google.com> 2021-07-14 12:53:01 -0700
committer Ryan Mitchell <rtmitchell@google.com> 2021-07-15 13:42:13 -0700
commit4382e44c42d2a1edf92a9ef11dbf34843025e64f (patch)
treef4b2855b1df909e526a298300ee55f79a65ccc79 /tools/aapt2/process
parent3947c9b56c2e79d76b6941fb5bdcdf25e359b0a4 (diff)
Replace Maybe with std::optional
With c++17, std::optional provides the functionality that Maybe provided. Bug: 183215655 Test: aapt2_tests Change-Id: I62bb9c2fa4985dc5217a6ed153df92b85ad9a034
Diffstat (limited to 'tools/aapt2/process')
-rw-r--r--tools/aapt2/process/SymbolTable.cpp17
-rw-r--r--tools/aapt2/process/SymbolTable.h4
2 files changed, 10 insertions, 11 deletions
diff --git a/tools/aapt2/process/SymbolTable.cpp b/tools/aapt2/process/SymbolTable.cpp
index d385267fe5ed..2d58cbfb3dbe 100644
--- a/tools/aapt2/process/SymbolTable.cpp
+++ b/tools/aapt2/process/SymbolTable.cpp
@@ -75,8 +75,8 @@ const SymbolTable::Symbol* SymbolTable::FindByName(const ResourceName& name) {
// Fill in the package name if necessary.
// If there is no package in `name`, we will need to copy the ResourceName
- // and store it somewhere; we use the Maybe<> class to reserve storage.
- Maybe<ResourceName> name_with_package_impl;
+ // and store it somewhere; we use the std::optional<> class to reserve storage.
+ std::optional<ResourceName> name_with_package_impl;
if (name.package.empty()) {
name_with_package_impl = ResourceName(mangler_->GetTargetPackageName(), name.type, name.entry);
name_with_package = &name_with_package_impl.value();
@@ -88,9 +88,9 @@ const SymbolTable::Symbol* SymbolTable::FindByName(const ResourceName& name) {
}
// The name was not found in the cache. Mangle it (if necessary) and find it in our sources.
- // Again, here we use a Maybe<> object to reserve storage if we need to mangle.
+ // Again, here we use a std::optional<> object to reserve storage if we need to mangle.
const ResourceName* mangled_name = name_with_package;
- Maybe<ResourceName> mangled_name_impl;
+ std::optional<ResourceName> mangled_name_impl;
if (mangler_->ShouldMangle(name_with_package->package)) {
mangled_name_impl = mangler_->MangleName(*name_with_package);
mangled_name = &mangled_name_impl.value();
@@ -183,7 +183,7 @@ std::unique_ptr<SymbolTable::Symbol> DefaultSymbolTableDelegate::FindById(
std::unique_ptr<SymbolTable::Symbol> ResourceTableSymbolSource::FindByName(
const ResourceName& name) {
- Maybe<ResourceTable::SearchResult> result = table_->FindResource(name);
+ std::optional<ResourceTable::SearchResult> result = table_->FindResource(name);
if (!result) {
if (name.type == ResourceType::kAttr) {
// Recurse and try looking up a private attribute.
@@ -306,7 +306,7 @@ static std::unique_ptr<SymbolTable::Symbol> LookupAttributeInTable(
return nullptr;
}
- Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name);
+ std::optional<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name);
if (!parsed_name) {
return nullptr;
}
@@ -382,8 +382,7 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName(
return {};
}
-static Maybe<ResourceName> GetResourceName(android::AssetManager2& am,
- ResourceId id) {
+static std::optional<ResourceName> GetResourceName(android::AssetManager2& am, ResourceId id) {
auto name = am.GetResourceName(id.id);
if (!name.has_value()) {
return {};
@@ -402,7 +401,7 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById(
return {};
}
- Maybe<ResourceName> maybe_name = GetResourceName(asset_manager_, id);
+ std::optional<ResourceName> maybe_name = GetResourceName(asset_manager_, id);
if (!maybe_name) {
return {};
}
diff --git a/tools/aapt2/process/SymbolTable.h b/tools/aapt2/process/SymbolTable.h
index 06eaf63ad442..65ae7beadc07 100644
--- a/tools/aapt2/process/SymbolTable.h
+++ b/tools/aapt2/process/SymbolTable.h
@@ -56,7 +56,7 @@ class SymbolTable {
struct Symbol {
Symbol() = default;
- explicit Symbol(const Maybe<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
+ explicit Symbol(const std::optional<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
bool pub = false)
: id(i), attribute(attr), is_public(pub) {
}
@@ -66,7 +66,7 @@ class SymbolTable {
Symbol& operator=(const Symbol&) = default;
Symbol& operator=(Symbol&&) = default;
- Maybe<ResourceId> id;
+ std::optional<ResourceId> id;
std::shared_ptr<Attribute> attribute;
bool is_public = false;
bool is_dynamic = false;