hidl-gen: add sanitizedName to emitReaderWriterEmbedded.

* Fix weird variable names in autogenerated code for vec<vec<T>>.

Bug: 31955917

Test: hidl_test
Change-Id: I83363a6d12babae1aba8e118451e1ec80492012c
diff --git a/VectorType.cpp b/VectorType.cpp
index b7bebe4..2e7d932 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -120,6 +120,7 @@
             out,
             0 /* depth */,
             name,
+            name /* sanitizedName */ ,
             isReader /* nameIsPointer */,
             parcelObj,
             parcelObjIsPointer,
@@ -129,20 +130,11 @@
             "0 /* parentOffset */");
 }
 
-// Remove any trailing array indices from the given name, i.e. foo[2][3] => foo
-static std::string StripIndex(const std::string &name) {
-    size_t pos = name.find("[");
-    if (pos == std::string::npos) {
-        return name;
-    }
-
-    return name.substr(0, pos);
-}
-
 void VectorType::emitReaderWriterEmbedded(
         Formatter &out,
         size_t depth,
         const std::string &name,
+        const std::string &sanitizedName,
         bool nameIsPointer,
         const std::string &parcelObj,
         bool parcelObjIsPointer,
@@ -153,7 +145,7 @@
     std::string baseExtra;
     std::string baseType = Type::getCppType(&baseExtra);
 
-    const std::string childName = "_hidl_" + StripIndex(name) + "_child";
+    const std::string childName = "_hidl_" + sanitizedName + "_child";
     out << "size_t " << childName << ";\n\n";
 
     emitReaderWriterEmbeddedForTypeName(
@@ -196,6 +188,7 @@
             depth + 1,
             (nameIsPointer ? "(*" + name + ")" : name)
                 + "[" + iteratorName + "]",
+            sanitizedName + (nameIsPointer ? "_deref" : "") + "_indexed",
             false /* nameIsPointer */,
             parcelObj,
             parcelObjIsPointer,