Remove ArrayBase
This is the only place we really make copies of types. Removing it to
make it easier to avoid copy constructors to make it easier to add
invariants to the compiler.
Bug: 201584220
Test: aidl_unittests
Change-Id: I1898e7eeed866b3b175fcecc87a395ec701f75c8
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 387941c..e694212 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -500,16 +500,14 @@
is_array_(is_array),
split_name_(Split(unresolved_name, ".")) {}
-const AidlTypeSpecifier& AidlTypeSpecifier::ArrayBase() const {
+void AidlTypeSpecifier::ViewAsArrayBase(std::function<void(const AidlTypeSpecifier&)> func) const {
AIDL_FATAL_IF(!is_array_, this);
// Declaring array of generic type cannot happen, it is grammar error.
AIDL_FATAL_IF(IsGeneric(), this);
- if (!array_base_) {
- array_base_.reset(new AidlTypeSpecifier(*this));
- array_base_->is_array_ = false;
- }
- return *array_base_;
+ is_array_ = false;
+ func(*this);
+ is_array_ = true;
}
string AidlTypeSpecifier::Signature() const {
@@ -1204,8 +1202,6 @@
template <typename T>
AidlParameterizable<T>::AidlParameterizable(const AidlParameterizable& other) {
// Copying is not supported if it has type parameters.
- // It doesn't make a problem because only ArrayBase() makes a copy,
- // and it can be called only if a type is not generic.
AIDL_FATAL_IF(other.IsGeneric(), AIDL_LOCATION_HERE);
}