Merge "Wrap compound native_handle_t* in hidl_pointer."
am: 935d073c73

Change-Id: I81cccc31c66a189df0d9d39a6a1cf24da268a8dc
diff --git a/ArrayType.cpp b/ArrayType.cpp
index 14e375a..e429411 100644
--- a/ArrayType.cpp
+++ b/ArrayType.cpp
@@ -79,6 +79,7 @@
     arrayType += ">";
 
     switch (mode) {
+        case StorageMode_Compound:
         case StorageMode_Stack:
             return arrayType;
 
diff --git a/CompoundType.cpp b/CompoundType.cpp
index a07882d..b00f114 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -75,6 +75,7 @@
         specifyNamespaces ? fullName() : partialCppName();
 
     switch (mode) {
+        case StorageMode_Compound:
         case StorageMode_Stack:
             return base;
 
@@ -342,7 +343,7 @@
     Scope::emitTypeDeclarations(out);
 
     for (const auto &field : *mFields) {
-        out << field->type().getCppStackType()
+        out << field->type().getCppCompoundType()
             << " "
             << field->name()
             << ";\n";
diff --git a/GenericBinder.cpp b/GenericBinder.cpp
index 935da31..8dad4e0 100644
--- a/GenericBinder.cpp
+++ b/GenericBinder.cpp
@@ -40,6 +40,7 @@
         + "IBinder>";
 
     switch (mode) {
+        case StorageMode_Compound:
         case StorageMode_Stack:
         case StorageMode_Result:
             return base;
diff --git a/HandleType.cpp b/HandleType.cpp
index 3ff0f89..29afb1a 100644
--- a/HandleType.cpp
+++ b/HandleType.cpp
@@ -27,13 +27,19 @@
     // do nothing
 }
 
-std::string HandleType::getCppType(StorageMode,
+std::string HandleType::getCppType(StorageMode mode,
                                    bool specifyNamespaces) const {
     const std::string base =
           std::string(specifyNamespaces ? "::" : "")
         + "native_handle_t";
-
-    return "const " + base + "*";
+    if (mode == StorageMode_Compound) {
+        const std::string hidl_pointer_type =
+            std::string(specifyNamespaces ? "::android::hardware::details::hidl_pointer" :
+                                            "hidl_pointer");
+        return hidl_pointer_type + "<" + base  + ">";
+    } else {
+        return "const " + base + "*";
+    }
 }
 
 void HandleType::emitReaderWriter(
diff --git a/Interface.cpp b/Interface.cpp
index 9f5351c..35cbce3 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -217,6 +217,7 @@
     switch (mode) {
         case StorageMode_Stack:
         case StorageMode_Result:
+        case StorageMode_Compound:
             return base;
 
         case StorageMode_Argument:
diff --git a/PredefinedType.cpp b/PredefinedType.cpp
index fb015a4..c904a7d 100644
--- a/PredefinedType.cpp
+++ b/PredefinedType.cpp
@@ -42,6 +42,7 @@
     const std::string base = fullName();
 
     switch (mode) {
+        case StorageMode_Compound:
         case StorageMode_Stack:
             return base;
 
diff --git a/StringType.cpp b/StringType.cpp
index e449369..d729efb 100644
--- a/StringType.cpp
+++ b/StringType.cpp
@@ -33,6 +33,7 @@
         + "hidl_string";
 
     switch (mode) {
+        case StorageMode_Compound:
         case StorageMode_Stack:
             return base;
 
diff --git a/Type.cpp b/Type.cpp
index 47cea08..e139b8e 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -375,6 +375,10 @@
     return getCppType(StorageMode_Argument, specifyNamespaces);
 }
 
+std::string Type::getCppCompoundType(bool specifyNamespaces) const {
+    return getCppType(StorageMode_Compound, specifyNamespaces);
+}
+
 void Type::emitJavaReaderWriterWithSuffix(
         Formatter &out,
         const std::string &parcelObj,
diff --git a/Type.h b/Type.h
index 4f90232..e137043 100644
--- a/Type.h
+++ b/Type.h
@@ -52,7 +52,8 @@
     enum StorageMode {
         StorageMode_Stack,
         StorageMode_Argument,
-        StorageMode_Result
+        StorageMode_Result,
+        StorageMode_Compound // when stored in a compound type
     };
 
     virtual std::string getCppType(
@@ -82,6 +83,8 @@
 
     std::string getCppArgumentType(bool specifyNamespaces = true) const;
 
+    std::string getCppCompoundType(bool specifyNamespaces = true) const;
+
     // For an array type, dimensionality information will be accumulated at the
     // end of the returned string.
     // if forInitializer == true, actual dimensions are included, i.e. [3][5],
diff --git a/VectorType.cpp b/VectorType.cpp
index da09884..26eac76 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -47,6 +47,7 @@
         + ">";
 
     switch (mode) {
+        case StorageMode_Compound:
         case StorageMode_Stack:
             return base;