Allow method names, result names and argument names to be the same.

size(int32_t size) generates (int32_t size) is allowed.

result names and argument names themselves may still collide and
cause compilation error; for example, foo(int32_t bar, int32_t bar)
is not detected by hidl-gen.

Bug: 33277700

Test: compiles with mma (withe the new method added to IBar)
Change-Id: Ibfe6db03e2dff40f0cae1429fd94cd0db6ccb3a1
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 2da1759..9bf1b33 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -513,7 +513,7 @@
                 out << ", ";
             }
 
-            out << "const auto &" << arg->name();
+            out << "const auto &_hidl_out_" << arg->name();
 
             first = false;
         }
@@ -535,7 +535,7 @@
                 out << ", ";
             }
 
-            out << arg->name();
+            out << "_hidl_out_" << arg->name();
 
             first = false;
         }
@@ -546,7 +546,7 @@
         out << ");\n\n";
         if (elidedReturn != nullptr) {
             out << elidedReturn->type().getCppResultType()
-                << " "
+                << " _hidl_out_"
                 << elidedReturn->name()
                 << " = _hidl_return;\n";
         }
@@ -1345,9 +1345,9 @@
 
     if (elidedReturn != nullptr) {
         out << elidedReturn->type().getCppResultType()
-            << " "
+            << " _hidl_out_"
             << elidedReturn->name()
-            << " = "
+            << " = this->"
             << method->name()
             << "(";
 
@@ -1372,7 +1372,7 @@
 
         elidedReturn->type().emitReaderWriter(
                 out,
-                elidedReturn->name(),
+                "_hidl_out_" + elidedReturn->name(),
                 "_hidl_reply",
                 true, /* parcelObjIsPointer */
                 false, /* isReader */
@@ -1385,7 +1385,7 @@
                 elidedReturn,
                 false /* reader */,
                 Type::ErrorMode_Ignore,
-                false /* addPrefixToName */);
+                true /* addPrefixToName */);
 
         status_t status = generateCppInstrumentationCall(
                 out,
@@ -1431,7 +1431,7 @@
                     out << ", ";
                 }
 
-                out << "const auto &" << arg->name();
+                out << "const auto &_hidl_out_" << arg->name();
 
                 first = false;
             }
@@ -1459,7 +1459,7 @@
                         arg,
                         false /* reader */,
                         Type::ErrorMode_Ignore,
-                        false /* addPrefixToName */);
+                        true /* addPrefixToName */);
             }
 
             // Second DFS: resolve references
@@ -1471,7 +1471,7 @@
                         arg,
                         false /* reader */,
                         Type::ErrorMode_Ignore,
-                        false /* addPrefixToName */);
+                        true /* addPrefixToName */);
             }
 
             status_t status = generateCppInstrumentationCall(
@@ -1762,7 +1762,7 @@
         {
             event_str = "InstrumentationEvent::SERVER_API_EXIT";
             for (const auto &arg : method->results()) {
-                out << "_hidl_args.push_back((void *)&"
+                out << "_hidl_args.push_back((void *)&_hidl_out_"
                     << arg->name()
                     << ");\n";
             }
@@ -1804,7 +1804,7 @@
         {
             event_str = "InstrumentationEvent::PASSTHROUGH_EXIT";
             for (const auto &arg : method->results()) {
-                out << "_hidl_args.push_back((void *)&"
+                out << "_hidl_args.push_back((void *)&_hidl_out_"
                     << arg->name()
                     << ");\n";
             }