Remove extra from getCppType.

The argument is used for array type originally. We
now use hidl_array instead of T[], so there is no
need to use extra.

Renamed the convenience getCppType to getCppStackType
to avoid casting to (Type *) before using this
method (which makes it inconvenient)

Also fixes:
* RefType::getCppType ignores specifyNamespaces
* ConstantExpression.cpp emits a C-style cast instead
  of static_cast

Bug: 32559427

Test: mma passes
Test: hidl_test

Change-Id: I7e2e31c34c1ca1aa83c4a5a4dbdf7fd6b9aff30c
diff --git a/ArrayType.cpp b/ArrayType.cpp
index 13c861e..24f2a2c 100644
--- a/ArrayType.cpp
+++ b/ArrayType.cpp
@@ -59,10 +59,8 @@
 }
 
 std::string ArrayType::getCppType(StorageMode mode,
-                                  std::string *extra,
                                   bool specifyNamespaces) const {
-    const std::string base = mElementType->getCppType(extra, specifyNamespaces);
-    CHECK(extra->empty());
+    const std::string base = mElementType->getCppStackType(specifyNamespaces);
 
     std::string space = specifyNamespaces ? "::android::hardware::" : "";
     std::string arrayType = space + "hidl_array<" + base;
@@ -138,9 +136,7 @@
         bool parcelObjIsPointer,
         bool isReader,
         ErrorMode mode) const {
-    std::string baseExtra;
-    std::string baseType = mElementType->getCppType(&baseExtra);
-    CHECK(baseExtra.empty());
+    std::string baseType = mElementType->getCppStackType();
 
     const std::string parentName = "_hidl_" + name + "_parent";
 
@@ -150,11 +146,10 @@
         parcelObj + (parcelObjIsPointer ? "->" : ".");
 
     if (isReader) {
-        std::string extra;
 
         out << name
             << " = ("
-            << getCppResultType(&extra)
+            << getCppResultType()
             << ")"
             << parcelObjDeref
             << "readBuffer(&"
@@ -223,9 +218,7 @@
 
     const std::string nameDeref = name + (nameIsPointer ? "->" : ".");
 
-    std::string baseExtra;
-    std::string baseType = mElementType->getCppType(&baseExtra);
-    CHECK(baseExtra.empty());
+    std::string baseType = mElementType->getCppStackType();
 
     std::string iteratorName = "_hidl_index_" + std::to_string(depth);
 
@@ -300,8 +293,7 @@
 
     const std::string nameDeref = name + (nameIsPointer ? "->" : ".");
 
-    std::string baseExtra;
-    std::string baseType = mElementType->getCppType(&baseExtra);
+    std::string baseType = mElementType->getCppStackType();
 
     std::string iteratorName = "_hidl_index_" + std::to_string(depth);
 
diff --git a/ArrayType.h b/ArrayType.h
index e46c09a..d993960 100644
--- a/ArrayType.h
+++ b/ArrayType.h
@@ -41,7 +41,6 @@
     size_t countDimensions() const;
 
     std::string getCppType(StorageMode mode,
-                           std::string *extra,
                            bool specifyNamespaces) const override;
 
     void addNamedTypesToSet(std::set<const FQName> &set) const override;
diff --git a/CompoundType.cpp b/CompoundType.cpp
index a262e17..b55b4ea 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -66,10 +66,7 @@
 
 std::string CompoundType::getCppType(
         StorageMode mode,
-        std::string *extra,
         bool specifyNamespaces) const {
-
-    extra->clear();
     const std::string base =
         specifyNamespaces ? fullName() : partialCppName();
 
@@ -335,11 +332,9 @@
     Scope::emitTypeDeclarations(out);
 
     for (const auto &field : *mFields) {
-        std::string extra;
-        out << field->type().getCppType(&extra)
+        out << field->type().getCppStackType()
             << " "
             << field->name()
-            << extra
             << ";\n";
     }
 
diff --git a/CompoundType.h b/CompoundType.h
index c48f57e..4d1a8e9 100644
--- a/CompoundType.h
+++ b/CompoundType.h
@@ -39,7 +39,6 @@
     bool isCompoundType() const override;
 
     std::string getCppType(StorageMode mode,
-                           std::string *extra,
                            bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/ConstantExpression.cpp b/ConstantExpression.cpp
index 06edf0c..ea80151 100644
--- a/ConstantExpression.cpp
+++ b/ConstantExpression.cpp
@@ -358,13 +358,9 @@
     // -(uint64_t)9223372036854775808 == 9223372036854775808 could not
     // be narrowed to int64_t.
     if(castKind == SK(INT64) && (int64_t)mValue == INT64_MIN) {
-        std::string extra;
-        return strdup(("("
-            + ScalarType(SK(INT64)).getCppType(
-                    android::Type::StorageMode_Stack,
-                    &extra,
-                    true /* specify namespaces */) // "int64_t"
-            + ")(" + literal + "ull)").c_str());
+        return strdup(("static_cast<"
+            + ScalarType(SK(INT64)).getCppStackType() // "int64_t"
+            + ">(" + literal + "ull)").c_str());
     }
 
     // add suffix if necessary.
diff --git a/EnumType.cpp b/EnumType.cpp
index 9903b3e..4a25bbe 100644
--- a/EnumType.cpp
+++ b/EnumType.cpp
@@ -72,10 +72,7 @@
 }
 
 std::string EnumType::getCppType(StorageMode,
-                                 std::string *extra,
                                  bool specifyNamespaces) const {
-    extra->clear();
-
     return specifyNamespaces ? fullName() : partialCppName();
 }
 
@@ -147,8 +144,7 @@
     const ScalarType *scalarType = mStorageType->resolveToScalarType();
     CHECK(scalarType != nullptr);
 
-    std::string extra;
-    const std::string storageType = ((Type *)scalarType)->getCppType(&extra);
+    const std::string storageType = scalarType->getCppStackType();
 
     out << "enum class "
         << localName()
@@ -192,8 +188,7 @@
     const ScalarType *scalarType = mStorageType->resolveToScalarType();
     CHECK(scalarType != nullptr);
 
-    std::string extra;
-    const std::string storageType = ((Type *)scalarType)->getCppType(&extra);
+    const std::string storageType = scalarType->getCppStackType();
 
     out << "inline "
         << fullName()
diff --git a/EnumType.h b/EnumType.h
index f9afb31..7fd3ea7 100644
--- a/EnumType.h
+++ b/EnumType.h
@@ -43,7 +43,6 @@
     bool isEnum() const override;
 
     std::string getCppType(StorageMode mode,
-                           std::string *extra,
                            bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/GenericBinder.cpp b/GenericBinder.cpp
index 170611e..6f5e636 100644
--- a/GenericBinder.cpp
+++ b/GenericBinder.cpp
@@ -32,9 +32,7 @@
 
 std::string GenericBinder::getCppType(
         StorageMode mode,
-        std::string *extra,
         bool specifyNamespaces) const {
-    extra->clear();
     const std::string base =
           std::string(specifyNamespaces ? "::android::" : "")
         + "sp<"
diff --git a/GenericBinder.h b/GenericBinder.h
index db7c6cc..e1fdb2d 100644
--- a/GenericBinder.h
+++ b/GenericBinder.h
@@ -31,7 +31,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/HandleType.cpp b/HandleType.cpp
index 210d5ad..a3e4a7d 100644
--- a/HandleType.cpp
+++ b/HandleType.cpp
@@ -28,10 +28,7 @@
 }
 
 std::string HandleType::getCppType(StorageMode,
-                                   std::string *extra,
                                    bool specifyNamespaces) const {
-    extra->clear();
-
     const std::string base =
           std::string(specifyNamespaces ? "::" : "")
         + "native_handle_t";
diff --git a/HandleType.h b/HandleType.h
index 9bf79b9..527c930 100644
--- a/HandleType.h
+++ b/HandleType.h
@@ -29,7 +29,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     void emitReaderWriter(
diff --git a/Interface.cpp b/Interface.cpp
index be4f4fe..64bde04 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -188,9 +188,7 @@
 }
 
 std::string Interface::getCppType(StorageMode mode,
-                                  std::string *extra,
                                   bool specifyNamespaces) const {
-    extra->clear();
     const std::string base =
           std::string(specifyNamespaces ? "::android::" : "")
         + "sp<"
diff --git a/Interface.h b/Interface.h
index 1c23186..414516d 100644
--- a/Interface.h
+++ b/Interface.h
@@ -65,7 +65,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/Method.cpp b/Method.cpp
index d9b2edb..fabf801 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -106,10 +106,9 @@
     if (elidedReturn == nullptr) {
         out << space << "Return<void> ";
     } else {
-        std::string extra;
         out << space
             << "Return<"
-            << elidedReturn->type().getCppResultType(&extra, specifyNamespaces)
+            << elidedReturn->type().getCppResultType( specifyNamespaces)
             << "> ";
     }
 
@@ -142,12 +141,9 @@
             out += ", ";
         }
 
-        std::string extra;
-        out += arg->type().getCppArgumentType(&extra,
-                                              specifyNamespaces);
+        out += arg->type().getCppArgumentType(specifyNamespaces);
         out += " ";
         out += arg->name();
-        out += extra;
 
         first = false;
     }
diff --git a/PredefinedType.cpp b/PredefinedType.cpp
index f6b744f..ba2842b 100644
--- a/PredefinedType.cpp
+++ b/PredefinedType.cpp
@@ -30,9 +30,7 @@
 }
 std::string PredefinedType::getCppType(
         StorageMode mode,
-        std::string *extra,
         bool) const {
-    extra->clear();
 
     const std::string base = mName;
 
diff --git a/PredefinedType.h b/PredefinedType.h
index f11e437..cbfbcf9 100644
--- a/PredefinedType.h
+++ b/PredefinedType.h
@@ -29,7 +29,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     void emitReaderWriter(
diff --git a/RefType.cpp b/RefType.cpp
index 8c949b8..16b24b6 100644
--- a/RefType.cpp
+++ b/RefType.cpp
@@ -29,17 +29,9 @@
  * ref<ref<ref<T>>> t_3ptr;
  * in this case the const's will get stacked on the left (const const const T *** t_3ptr)
  * but in this implementation it would be clearer (T const* const* const* t_3ptr) */
-std::string RefType::getCppType(StorageMode /*mode*/, std::string *extra, bool /*specifyNamespaces*/) const {
-    const std::string elementBase = mElementType->getCppType(extra);
-    std::string base;
-    if(extra->empty())
-        base = elementBase + " const*";
-    else { // for pointer to array: e.g. int32_t (*meow)[5]
-        base = elementBase + " const(*";
-        extra->insert(0, 1, ')');
-    }
-
-    return base;
+std::string RefType::getCppType(StorageMode /*mode*/, bool specifyNamespaces) const {
+    return mElementType->getCppStackType(specifyNamespaces)
+            + " const*";
 }
 
 void RefType::addNamedTypesToSet(std::set<const FQName> &set) const {
@@ -93,12 +85,9 @@
             const std::string &parentName,
             const std::string &offsetText) const {
 
-    std::string elementExtra;
-    std::string elementBase = mElementType->getCppType(&elementExtra);
-    std::string elementType = elementBase + elementExtra;
+    std::string elementType = mElementType->getCppStackType();
 
-    std::string baseExtra;
-    std::string baseType = Type::getCppType(&baseExtra);
+    std::string baseType = getCppStackType();
 
     const std::string parcelObjDeref =
         parcelObjIsPointer ? ("*" + parcelObj) : parcelObj;
@@ -126,9 +115,7 @@
             << elementType
             << ">(const_cast<"
             << baseType
-            << " *"
-            << baseExtra
-            << ">("
+            << " *>("
             << namePointer
             << "),";
     } else {
diff --git a/RefType.h b/RefType.h
index 153ddb3..afbfb16 100644
--- a/RefType.h
+++ b/RefType.h
@@ -26,7 +26,7 @@
     RefType();
 
     void addNamedTypesToSet(std::set<const FQName> &set) const override;
-    std::string getCppType(StorageMode mode, std::string *extra,
+    std::string getCppType(StorageMode mode,
                            bool specifyNamespaces) const override;
 
     void emitReaderWriter(
diff --git a/ScalarType.cpp b/ScalarType.cpp
index b89001f..f537310 100644
--- a/ScalarType.cpp
+++ b/ScalarType.cpp
@@ -37,7 +37,7 @@
     // do nothing
 }
 
-std::string ScalarType::getCppType(StorageMode, std::string *extra, bool) const {
+std::string ScalarType::getCppType(StorageMode, bool) const {
     static const char *const kName[] = {
         "bool",
         "int8_t",
@@ -52,8 +52,6 @@
         "double"
     };
 
-    extra->clear();
-
     return kName[mKind];
 }
 
@@ -184,10 +182,8 @@
         << "(";
 
     if (needsCast) {
-        std::string extra;
-
         out << "("
-            << Type::getCppType(&extra)
+            << getCppStackType()
             << (isReader ? " *)" : ")");
     }
 
diff --git a/ScalarType.h b/ScalarType.h
index 135f6fb..21e0d3a 100644
--- a/ScalarType.h
+++ b/ScalarType.h
@@ -47,7 +47,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/StringType.cpp b/StringType.cpp
index 62fed1c..66a3fb7 100644
--- a/StringType.cpp
+++ b/StringType.cpp
@@ -27,10 +27,7 @@
 }
 
 std::string StringType::getCppType(StorageMode mode,
-                                   std::string *extra,
                                    bool specifyNamespaces) const {
-    extra->clear();
-
     const std::string base =
           std::string(specifyNamespaces ? "::android::hardware::" : "")
         + "hidl_string";
diff --git a/StringType.h b/StringType.h
index 7322554..587cc68 100644
--- a/StringType.h
+++ b/StringType.h
@@ -29,7 +29,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/Type.cpp b/Type.cpp
index d0b8f9d..f97af23 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -88,11 +88,16 @@
     return scalarType->isValidEnumStorageType();
 }
 
-std::string Type::getCppType(StorageMode, std::string *, bool) const {
+std::string Type::getCppType(StorageMode, bool) const {
     CHECK(!"Should not be here");
     return std::string();
 }
 
+std::string Type::decorateCppName(
+        const std::string &name, StorageMode mode, bool specifyNamespaces) const {
+    return getCppType(mode, specifyNamespaces) + " " + name;
+}
+
 std::string Type::getJavaType(
         std::string *extra, bool /* forInitializer */) const {
     CHECK(!"Should not be here");
@@ -346,19 +351,16 @@
     return false;
 }
 
-std::string Type::getCppType(std::string *extra,
-                             bool specifyNamespaces) const {
-    return getCppType(StorageMode_Stack, extra, specifyNamespaces);
+std::string Type::getCppStackType(bool specifyNamespaces) const {
+    return getCppType(StorageMode_Stack, specifyNamespaces);
 }
 
-std::string Type::getCppResultType(std::string *extra,
-                                   bool specifyNamespaces) const {
-    return getCppType(StorageMode_Result, extra, specifyNamespaces);
+std::string Type::getCppResultType(bool specifyNamespaces) const {
+    return getCppType(StorageMode_Result, specifyNamespaces);
 }
 
-std::string Type::getCppArgumentType(std::string *extra,
-                                     bool specifyNamespaces) const {
-    return getCppType(StorageMode_Argument, extra, specifyNamespaces);
+std::string Type::getCppArgumentType(bool specifyNamespaces) const {
+    return getCppType(StorageMode_Argument, specifyNamespaces);
 }
 
 void Type::emitJavaReaderWriterWithSuffix(
diff --git a/Type.h b/Type.h
index b65ce4b..473af85 100644
--- a/Type.h
+++ b/Type.h
@@ -54,9 +54,14 @@
         StorageMode_Argument,
         StorageMode_Result
     };
+
     virtual std::string getCppType(
             StorageMode mode,
-            std::string *extra,
+            bool specifyNamespaces) const;
+
+    std::string decorateCppName(
+            const std::string &name,
+            StorageMode mode,
             bool specifyNamespaces) const;
 
     /* gets all hidl-defined types used when this item is
@@ -71,15 +76,11 @@
      */
     virtual void addNamedTypesToSet(std::set<const FQName> &set) const = 0;
 
-    // Convenience, gets StorageMode_Stack type.
-    std::string getCppType(
-            std::string *extra, bool specifyNamespaces = true) const;
+    std::string getCppStackType(bool specifyNamespaces = true) const;
 
-    std::string getCppResultType(
-            std::string *extra, bool specifyNamespaces = true) const;
+    std::string getCppResultType(bool specifyNamespaces = true) const;
 
-    std::string getCppArgumentType(
-            std::string *extra, bool specifyNamespaces = true) const;
+    std::string getCppArgumentType(bool specifyNamespaces = true) const;
 
     // For an array type, "extra" accumulates dimensionality information,
     // if forInitializer == true, actual dimensions are included, i.e. [3][5],
diff --git a/TypeDef.cpp b/TypeDef.cpp
index 5261829..cf7c0ab 100644
--- a/TypeDef.cpp
+++ b/TypeDef.cpp
@@ -59,9 +59,11 @@
 }
 
 status_t TypeDef::emitTypeDeclarations(Formatter &out) const {
-    std::string extra;
-    std::string type{mReferencedType->getCppType(&extra)};
-    out << "typedef " << type << " " << localName() << extra << ";\n\n";
+    out << "typedef "
+        << mReferencedType->getCppStackType()
+        << " "
+        << localName()
+        << ";\n\n";
 
     return OK;
 }
diff --git a/VectorType.cpp b/VectorType.cpp
index 461a05b..99449ab 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -39,21 +39,13 @@
 }
 
 std::string VectorType::getCppType(StorageMode mode,
-                                   std::string *extra,
                                    bool specifyNamespaces) const {
-    std::string elementExtra;
-    const std::string elementBase =
-        mElementType->getCppType(&elementExtra, specifyNamespaces);
-
     const std::string base =
           std::string(specifyNamespaces ? "::android::hardware::" : "")
         + "hidl_vec<"
-        + mElementType->getCppType(extra, specifyNamespaces)
-        + (*extra)
+        + mElementType->getCppStackType( specifyNamespaces)
         + ">";
 
-    extra->clear();
-
     switch (mode) {
         case StorageMode_Stack:
             return base;
@@ -106,8 +98,7 @@
         return;
     }
 
-    std::string baseExtra;
-    std::string baseType = mElementType->getCppType(&baseExtra);
+    std::string baseType = mElementType->getCppStackType();
 
     const std::string parentName = "_hidl_" + name + "_parent";
 
@@ -120,7 +111,6 @@
         out << name
             << " = (const ::android::hardware::hidl_vec<"
             << baseType
-            << baseExtra
             << "> *)"
             << parcelObjDeref
             << "readBuffer(&"
@@ -202,8 +192,7 @@
 
         out.indent();
 
-        std::string extra;
-        out << mElementType->getCppType(&extra, true /* specifyNamespaces */)
+        out << mElementType->getCppStackType(true /* specifyNamespaces */)
             << " _hidl_binder;\n";
 
         mElementType->emitReaderWriter(
@@ -262,8 +251,7 @@
         ErrorMode mode,
         const std::string &parentName,
         const std::string &offsetText) const {
-    std::string baseExtra;
-    std::string baseType = Type::getCppType(&baseExtra);
+    std::string baseType = getCppStackType();
 
     const std::string childName = "_hidl_" + sanitizedName + "_child";
     out << "size_t " << childName << ";\n\n";
@@ -287,7 +275,7 @@
 
     const std::string nameDeref = name + (nameIsPointer ? "->" : ".");
 
-    baseType = mElementType->getCppType(&baseExtra);
+    baseType = mElementType->getCppStackType();
 
     std::string iteratorName = "_hidl_index_" + std::to_string(depth);
 
@@ -315,7 +303,7 @@
             isReader,
             mode,
             childName,
-            iteratorName + " * sizeof(" + baseType + baseExtra + ")");
+            iteratorName + " * sizeof(" + baseType + ")");
 
     out.unindent();
 
@@ -381,8 +369,7 @@
     CHECK(needsResolveReferences() && mElementType->needsResolveReferences());
 
     const std::string nameDeref = name + (nameIsPointer ? "->" : ".");
-    std::string elementExtra;
-    std::string elementType = mElementType->getCppType(&elementExtra);
+    std::string elementType = mElementType->getCppStackType();
 
     std::string myChildName = childName, myChildOffset = childOffsetText;
 
@@ -425,7 +412,7 @@
         mode,
         myChildName,
         myChildOffset + " + " +
-                iteratorName + " * sizeof(" + elementType + elementExtra + ")");
+                iteratorName + " * sizeof(" + elementType + ")");
 
     out.unindent();
 
diff --git a/VectorType.h b/VectorType.h
index 333d69d..1bf9a54 100644
--- a/VectorType.h
+++ b/VectorType.h
@@ -32,7 +32,6 @@
 
     std::string getCppType(
             StorageMode mode,
-            std::string *extra,
             bool specifyNamespaces) const override;
 
     std::string getJavaType(
diff --git a/generateCpp.cpp b/generateCpp.cpp
index f834f78..6c721da 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -250,9 +250,8 @@
 
             const TypedVar *elidedReturn = method->canElideCallback();
             if (elidedReturn) {
-                std::string extra;
                 out << "virtual ::android::hardware::Return<";
-                out << elidedReturn->type().getCppResultType(&extra) << "> ";
+                out << elidedReturn->type().getCppResultType() << "> ";
             } else {
                 out << "virtual ::android::hardware::Return<void> ";
             }
@@ -285,18 +284,14 @@
 
         if (!iface->isRootType()) {
             out << "// cast static functions\n";
-            std::string childTypeExtra;
-            std::string childTypeResult = iface->getCppResultType(&childTypeExtra);
-            childTypeResult += childTypeExtra;
+            std::string childTypeResult = iface->getCppResultType();
 
             for (const Interface *superType : iface->superTypeChain()) {
-                std::string superTypeExtra;
                 out << "static "
                     << childTypeResult
                     << " castFrom("
-                    << superType->getCppArgumentType(&superTypeExtra)
+                    << superType->getCppArgumentType()
                     << " parent"
-                    << superTypeExtra
                     << ");\n";
             }
         }
@@ -837,12 +832,9 @@
     for (const auto &arg : args) {
         const Type &type = arg->type();
 
-        std::string extra;
-        out << type.getCppResultType(&extra)
+        out << type.getCppResultType()
             << " "
-            << (forResults ? "_hidl_out_" : "")
-            << arg->name()
-            << extra
+            << (forResults ? "_hidl_out_" : "") + arg->name()
             << ";\n";
     }
 
@@ -1033,10 +1025,9 @@
     }
 
     if (elidedReturn != nullptr) {
-        std::string extra;
         out << "_hidl_status.setFromStatusT(_hidl_err);\n";
         out << "return ::android::hardware::Return<";
-        out << elidedReturn->type().getCppResultType(&extra)
+        out << elidedReturn->type().getCppResultType()
             << ">(_hidl_out_" << elidedReturn->name() << ");\n\n";
     } else {
         out << "_hidl_status.setFromStatusT(_hidl_err);\n";
@@ -1049,8 +1040,7 @@
     out << "_hidl_status.setFromStatusT(_hidl_err);\n";
     out << "return ::android::hardware::Return<";
     if (elidedReturn != nullptr) {
-        std::string extra;
-        out << method->results().at(0)->type().getCppResultType(&extra);
+        out << method->results().at(0)->type().getCppResultType();
     } else {
         out << "void";
     }
@@ -1276,11 +1266,12 @@
     const TypedVar *elidedReturn = method->canElideCallback();
 
     if (elidedReturn != nullptr) {
-        std::string extra;
-
-        out << elidedReturn->type().getCppResultType(&extra) << " ";
-        out << elidedReturn->name() << " = ";
-        out << method->name() << "(";
+        out << elidedReturn->type().getCppResultType()
+            << " "
+            << elidedReturn->name()
+            << " = "
+            << method->name()
+            << "(";
 
         bool first = true;
         for (const auto &arg : method->args()) {
@@ -1561,22 +1552,16 @@
 
     // generate castFrom functions
     if (!iface->isRootType()) {
-        std::string childTypeExtra;
-        std::string childTypeResult = iface->getCppResultType(&childTypeExtra);
-        childTypeResult += childTypeExtra;
+        std::string childTypeResult = iface->getCppResultType();
 
         for (const Interface *superType : iface->superTypeChain()) {
-            std::string superTypeExtra;
             out << "// static \n"
                 << childTypeResult
                 << " I"
                 << iface->getBaseName()
                 << "::castFrom("
-                << superType->getCppArgumentType(&superTypeExtra)
-                << " parent"
-                << superTypeExtra
-                << ")";
-            out << " {\n";
+                << superType->getCppArgumentType()
+                << " parent) {\n";
             out.indent();
             out << "return ::android::hardware::castInterface<";
             out << "I" << iface->getBaseName() << ", "
diff --git a/generateCppImpl.cpp b/generateCppImpl.cpp
index 6b5888c..bfd8950 100644
--- a/generateCppImpl.cpp
+++ b/generateCppImpl.cpp
@@ -67,9 +67,8 @@
     if (elidedReturn == nullptr) {
         out << "return Void();\n";
     } else {
-        std::string extra;
         out << "return "
-            << elidedReturn->type().getCppResultType(&extra)
+            << elidedReturn->type().getCppResultType()
             << " {};\n";
     }