hidl-gen: clean up generateCpp.cpp and generateCppImpl.cpp

Test: hidl_test
Change-Id: I18a9e0b27d40d607dc8b277d9e04eaa6f529f225
diff --git a/generateCppImpl.cpp b/generateCppImpl.cpp
index 11ec1d6..570635f 100644
--- a/generateCppImpl.cpp
+++ b/generateCppImpl.cpp
@@ -48,15 +48,14 @@
 
 status_t AST::generateStubImplMethod(Formatter &out,
                                      const std::string &className,
-                                     const Method *method,
-                                     bool specifyNamespaces) const {
+                                     const Method *method) const {
 
     // ignore HIDL reserved methods -- implemented in IFoo already.
     if (method->isHidlReserved()) {
         return OK;
     }
 
-    method->generateCppSignature(out, className, specifyNamespaces);
+    method->generateCppSignature(out, className, false /* specifyNamespaces */);
 
     out << " {\n";
 
@@ -81,24 +80,6 @@
     return OK;
 }
 
-status_t AST::generateStubImplDeclaration(Formatter &out,
-                                          const std::string &className,
-                                          const Method *method,
-                                          bool specifyNamespaces) const {
-
-    // ignore HIDL reserved methods -- implemented in IFoo already.
-    if (method->isHidlReserved()) {
-        return OK;
-    }
-
-    method->generateCppSignature(out,
-                                 className,
-                                 specifyNamespaces);
-    out << " override;\n";
-
-    return OK;
-}
-
 status_t AST::generateStubImplHeader(const std::string &outputPath) const {
     std::string ifaceName;
     if (!AST::isInterface(&ifaceName)) {
@@ -192,10 +173,16 @@
 
     out.indent();
 
-    status_t err = generateMethods(out,
-                                   "", /* class name */
-                                   MethodLocation::IMPL_HEADER,
-                                   false /* specify namespaces */);
+    status_t err = generateMethods(out, [&](const Method *method, const Interface *) {
+        // ignore HIDL reserved methods -- implemented in IFoo already.
+        if (method->isHidlReserved()) {
+            return OK;
+        }
+        method->generateCppSignature(out, "" /* className */,
+                false /* specifyNamespaces */);
+        out << " override;\n";
+        return OK;
+    });
 
     if (err != OK) {
         return err;
@@ -250,11 +237,9 @@
     // this is namespace aware code and doesn't require post-processing
     out.setNamespace("");
 
-    generateMethods(out,
-                    baseName,
-                    MethodLocation::IMPL_SOURCE,
-                    false /* specify namespaces */);
-
+    status_t err = generateMethods(out, [&](const Method *method, const Interface *) {
+        return generateStubImplMethod(out, baseName, method);
+    });
 
     out << ifaceName
         << "* ";