Merge "Remove toString + operator== from server libraries." into pi-dev
diff --git a/CompoundType.cpp b/CompoundType.cpp
index 64ec2c2..fc3c27d 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -460,19 +460,6 @@
 void CompoundType::emitPackageTypeDeclarations(Formatter& out) const {
     Scope::emitPackageTypeDeclarations(out);
 
-    // TODO(b/65200821): remove these ifdefs
-    out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
-    out << "std::string toString("
-        << getCppArgumentType()
-        << ");\n\n";
-    if (canCheckEquality()) {
-        out << "bool operator==("
-            << getCppArgumentType() << ", " << getCppArgumentType() << ");\n\n";
-
-        out << "bool operator!=("
-            << getCppArgumentType() << ", " << getCppArgumentType() << ");\n\n";
-    }
-    out << "#else\n";
     out << "static inline std::string toString("
         << getCppArgumentType()
         << (mFields->empty() ? "" : " o")
@@ -517,7 +504,6 @@
     } else {
         out << "// operator== and operator!= are not generated for " << localName() << "\n\n";
     }
-    out << "#endif  // REALLY_IS_HIDL_INTERNAL_LIB\n";
 }
 
 void CompoundType::emitPackageHwDeclarations(Formatter& out) const {
@@ -574,53 +560,6 @@
         emitResolveReferenceDef(out, prefix, true /* isReader */);
         emitResolveReferenceDef(out, prefix, false /* isReader */);
     }
-
-    // TODO(b/65200821): remove toString + operator== from .cpp once all prebuilts are rebuilt
-
-    out << "std::string toString("
-        << getCppArgumentType()
-        << (mFields->empty() ? "" : " o")
-        << ") ";
-
-    out.block([&] {
-        // include toString for scalar types
-        out << "using ::android::hardware::toString;\n"
-            << "std::string os;\n";
-        out << "os += \"{\";\n";
-
-        for (const NamedReference<Type>* field : *mFields) {
-            out << "os += \"";
-            if (field != *(mFields->begin())) {
-                out << ", ";
-            }
-            out << "." << field->name() << " = \";\n";
-            field->type().emitDump(out, "os", "o." + field->name());
-        }
-
-        out << "os += \"}\"; return os;\n";
-    }).endl().endl();
-
-    if (canCheckEquality()) {
-        out << "bool operator==("
-            << getCppArgumentType() << " " << (mFields->empty() ? "/* lhs */" : "lhs") << ", "
-            << getCppArgumentType() << " " << (mFields->empty() ? "/* rhs */" : "rhs") << ") ";
-        out.block([&] {
-            for (const auto &field : *mFields) {
-                out.sIf("lhs." + field->name() + " != rhs." + field->name(), [&] {
-                    out << "return false;\n";
-                }).endl();
-            }
-            out << "return true;\n";
-        }).endl().endl();
-
-        out << "bool operator!=("
-            << getCppArgumentType() << " lhs," << getCppArgumentType() << " rhs)";
-        out.block([&] {
-            out << "return !(lhs == rhs);\n";
-        }).endl().endl();
-    } else {
-        out << "// operator== and operator!= are not generated for " << localName() << "\n";
-    }
 }
 
 void CompoundType::emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const {
diff --git a/EnumType.cpp b/EnumType.cpp
index 745604f..1984693 100644
--- a/EnumType.cpp
+++ b/EnumType.cpp
@@ -397,23 +397,6 @@
     emitBitFieldBitwiseAssignmentOperator(out, "|");
     emitBitFieldBitwiseAssignmentOperator(out, "&");
 
-    // TODO(b/65200821): remove these ifndefs
-    out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
-        // toString for bitfields, equivalent to dumpBitfield in Java
-        out << "template<typename>\n"
-            << "std::string toString("
-            << resolveToScalarType()->getCppArgumentType()
-            << " o);\n";
-        out << "template<>\n"
-            << "std::string toString<" << getCppStackType() << ">("
-            << resolveToScalarType()->getCppArgumentType()
-            << " o);\n\n";
-
-        // toString for enum itself
-        out << "std::string toString("
-            << getCppArgumentType()
-            << " o);\n\n";
-    out << "#else\n";
     const ScalarType *scalarType = mStorageType->resolveToScalarType();
     CHECK(scalarType != NULL);
 
@@ -466,67 +449,6 @@
             "static_cast<" + scalarType->getCppStackType() + ">(o)");
         out << "return os;\n";
     }).endl().endl();
-    out << "#endif  // REALLY_IS_HIDL_INTERNAL_LIB\n";
-}
-
-void EnumType::emitTypeDefinitions(Formatter& out, const std::string& /* prefix */) const {
-    // TODO(b/65200821): remove toString from .cpp once all prebuilts are rebuilt
-
-    const ScalarType *scalarType = mStorageType->resolveToScalarType();
-    CHECK(scalarType != NULL);
-
-    out << "template<>\n"
-        << "std::string toString<" << getCppStackType() << ">("
-        << scalarType->getCppArgumentType()
-        << " o) ";
-    out.block([&] {
-        // include toHexString for scalar types
-        out << "using ::android::hardware::details::toHexString;\n"
-            << "std::string os;\n"
-            << getBitfieldCppType(StorageMode_Stack) << " flipped = 0;\n"
-            << "bool first = true;\n";
-
-        forEachValueFromRoot([&](EnumValue* value) {
-            std::string valueName = fullName() + "::" + value->name();
-            out.sIf("(o & " + valueName + ")" +
-                    " == static_cast<" + scalarType->getCppStackType() +
-                    ">(" + valueName + ")", [&] {
-                out << "os += (first ? \"\" : \" | \");\n"
-                    << "os += \"" << value->name() << "\";\n"
-                    << "first = false;\n"
-                    << "flipped |= " << valueName << ";\n";
-            }).endl();
-        });
-        // put remaining bits
-        out.sIf("o != flipped", [&] {
-            out << "os += (first ? \"\" : \" | \");\n";
-            scalarType->emitHexDump(out, "os", "o & (~flipped)");
-        });
-        out << "os += \" (\";\n";
-        scalarType->emitHexDump(out, "os", "o");
-        out << "os += \")\";\n";
-
-        out << "return os;\n";
-    }).endl().endl();
-
-    out << "std::string toString("
-        << getCppArgumentType()
-        << " o) ";
-
-    out.block([&] {
-        out << "using ::android::hardware::details::toHexString;\n";
-
-        forEachValueFromRoot([&](EnumValue* value) {
-            out.sIf("o == " + fullName() + "::" + value->name(), [&] {
-                out << "return \"" << value->name() << "\";\n";
-            }).endl();
-        });
-
-        out << "std::string os;\n";
-        scalarType->emitHexDump(out, "os",
-            "static_cast<" + scalarType->getCppStackType() + ">(o)");
-        out << "return os;\n";
-    }).endl().endl();
 }
 
 void EnumType::emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const {
diff --git a/EnumType.h b/EnumType.h
index ca0374e..d219506 100644
--- a/EnumType.h
+++ b/EnumType.h
@@ -94,7 +94,6 @@
     void emitTypeForwardDeclaration(Formatter& out) const override;
     void emitGlobalTypeDeclarations(Formatter& out) const override;
     void emitPackageTypeDeclarations(Formatter& out) const override;
-    void emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
 
     void emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const override;
 
diff --git a/Interface.cpp b/Interface.cpp
index 6c5c764..d18ceaa 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -848,12 +848,6 @@
 void Interface::emitPackageTypeDeclarations(Formatter& out) const {
     Scope::emitPackageTypeDeclarations(out);
 
-    // TODO(b/65200821): remove these ifndefs
-    out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
-    out << "std::string toString("
-        << getCppArgumentType()
-        << ");\n";
-    out << "#else\n";
     out << "static inline std::string toString(" << getCppArgumentType() << " o) ";
 
     out.block([&] {
@@ -863,25 +857,12 @@
             << "os += o->isRemote() ? \"@remote\" : \"@local\";\n"
             << "return os;\n";
     }).endl().endl();
-    out << "#endif  // REALLY_IS_HIDL_INTERNAL_LIB\n";
 }
 
 void Interface::emitTypeDefinitions(Formatter& out, const std::string& prefix) const {
     std::string space = prefix.empty() ? "" : (prefix + "::");
+
     Scope::emitTypeDefinitions(out, space + localName());
-
-    // TODO(b/65200821): remove toString from .cpp once all prebuilts are rebuilt
-    out << "std::string toString("
-        << getCppArgumentType()
-        << " o) ";
-
-    out.block([&] {
-        out << "std::string os = \"[class or subclass of \";\n"
-            << "os += " << fullName() << "::descriptor;\n"
-            << "os += \"]\";\n"
-            << "os += o->isRemote() ? \"@remote\" : \"@local\";\n"
-            << "return os;\n";
-    }).endl().endl();
 }
 
 void Interface::emitJavaReaderWriter(
diff --git a/Type.cpp b/Type.cpp
index 23bc745..84be36f 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -28,9 +28,6 @@
 
 namespace android {
 
-// TODO(b/65200821): remove
-std::string gCurrentCompileName;
-
 Type::Type(Scope* parent) : mParent(parent) {}
 
 Type::~Type() {}
diff --git a/Type.h b/Type.h
index db278d2..b1b97f4 100644
--- a/Type.h
+++ b/Type.h
@@ -30,10 +30,6 @@
 
 namespace android {
 
-// TODO(b/65200821): remove
-// HACK because no no type can depend or see AST
-extern std::string gCurrentCompileName;
-
 struct ConstantExpression;
 struct Formatter;
 struct FQName;
diff --git a/generateCpp.cpp b/generateCpp.cpp
index c2a7a4b..93bfef4 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -777,9 +777,6 @@
         << mPackage.string() << "::" << baseName
         << "\"\n\n";
 
-    // TODO(b/65200821): remove define
-    out << "#define REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
-
     out << "#include <android/log.h>\n";
     out << "#include <cutils/trace.h>\n";
     out << "#include <hidl/HidlTransportSupport.h>\n\n";
diff --git a/main.cpp b/main.cpp
index cf8970b..dabbdaa 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1377,9 +1377,6 @@
             exit(1);
         }
 
-        // TODO(b/65200821): remove
-        gCurrentCompileName = "_" + StringHelper::Uppercase(fqName.tokenName());
-
         // Dump extra verbose output
         if (coordinator.isVerbose()) {
             status_t err =