Emit toString functions for all types.
* toString() is mainly for debugging purposes only.
* For HIDL internal types (hidl_string, hidl_vec, etc.)
toString() is found in ::android::hardware::details.
* For a user defined type
android.hardware.foo@1.0::IFoo.Type,
toString() is found in ::android::hardware::foo::V1_0.
* For bitfield<::anroid::hardware::foo::V1_0::T>
that gets translated to the underlying
numeric type of T, it doesn't make sense to override toString().
A templated toString() function for each user-defined HIDL enum \
is introduced into the same namespace; call it with
using namespace ::android::hardware::foo::V1_0;
toString<IFoo::MyEnumType>(value);
Test: hidl_test and look at the output of logcat
Bug: 33459772
Change-Id: I70eee018e31d700bf1376334276dbd343af5615f
diff --git a/Type.cpp b/Type.cpp
index 7e67702..f155816 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -189,6 +189,26 @@
CHECK(!"Should not be here");
}
+void Type::emitDump(
+ Formatter &out,
+ const std::string &streamName,
+ const std::string &name) const {
+ emitDumpWithMethod(out, streamName, "::android::hardware::details::toString", name);
+}
+
+void Type::emitDumpWithMethod(
+ Formatter &out,
+ const std::string &streamName,
+ const std::string &methodName,
+ const std::string &name) const {
+ out << streamName
+ << " += "
+ << methodName
+ << "("
+ << name
+ << ");\n";
+}
+
bool Type::useParentInEmitResolveReferencesEmbedded() const {
return needsResolveReferences();
}