Add dummy IFoo::castFrom(sp<IFoo>)

which returns the parameter directly.

Test: compiles

Change-Id: I7c03b113df2f6c6553513546ae4ef82038d70fce
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 0306385..2da1759 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -280,18 +280,16 @@
             }
         }
 
-        if (!iface->isRootType()) {
-            out << "// cast static functions\n";
-            std::string childTypeResult = iface->getCppResultType();
+        out << "// cast static functions\n";
+        std::string childTypeResult = iface->getCppResultType();
 
-            for (const Interface *superType : iface->superTypeChain()) {
-                out << "static "
-                    << childTypeResult
-                    << " castFrom("
-                    << superType->getCppArgumentType()
-                    << " parent"
-                    << ");\n";
-            }
+        for (const Interface *superType : iface->typeChain()) {
+            out << "static "
+                << childTypeResult
+                << " castFrom("
+                << superType->getCppArgumentType()
+                << " parent"
+                << ");\n";
         }
 
         out << "\nstatic const char* descriptor;\n\n";
@@ -1610,18 +1608,20 @@
     const Interface *iface = mRootScope->getInterface();
 
     // generate castFrom functions
-    if (!iface->isRootType()) {
-        std::string childTypeResult = iface->getCppResultType();
+    std::string childTypeResult = iface->getCppResultType();
 
-        for (const Interface *superType : iface->superTypeChain()) {
-            out << "// static \n"
-                << childTypeResult
-                << " I"
-                << iface->getBaseName()
-                << "::castFrom("
-                << superType->getCppArgumentType()
-                << " parent) {\n";
-            out.indent();
+    for (const Interface *superType : iface->typeChain()) {
+        out << "// static \n"
+            << childTypeResult
+            << " I"
+            << iface->getBaseName()
+            << "::castFrom("
+            << superType->getCppArgumentType()
+            << " parent) {\n";
+        out.indent();
+        if (iface == superType) {
+            out << "return parent;\n";
+        } else {
             out << "return ::android::hardware::castInterface<";
             out << "I" << iface->getBaseName() << ", "
                 << superType->fqName().cppName() << ", "
@@ -1635,9 +1635,9 @@
                 << "\");\n";
             out.unindent();
             out.unindent();
-            out.unindent();
-            out << "}\n\n";
         }
+        out.unindent();
+        out << "}\n\n";
     }
 
     return OK;