Revert "Revert "ConstantExpression lazy evaluation""

This reverts commit a549b71629b6bc28ac1d99d34a0f3b3005c90aad.

Reason for revert: mac build issue fixed by adding virtual destructor

Test: builds, hidl_test
Test: builds on mac

Bug: 64532323

Change-Id: I10a142649bc1eb304b267372129e850235004f6e
diff --git a/Interface.cpp b/Interface.cpp
index 805d81c..78d42ad 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include <iostream>
+#include <memory>
 #include <sstream>
 
 #include <android-base/logging.h>
@@ -287,10 +288,8 @@
 }
 
 static void emitDigestChain(
-        Formatter &out,
-        const std::string &prefix,
-        const std::vector<const Interface *> &chain,
-        std::function<std::string(const ConstantExpression &)> byteToString) {
+    Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain,
+    std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) {
     out.join(chain.begin(), chain.end(), ",\n", [&] (const auto &iface) {
         const Hash &hash = Hash::getHash(iface->location().begin().filename());
         out << prefix;
@@ -319,8 +318,8 @@
             std::vector<const Interface *> chain = typeChain();
             out << "_hidl_cb(";
             out.block([&] {
-                emitDigestChain(out, "(" + digestType->getInternalDataCppType() + ")",
-                    chain, [](const auto &e){return e.cppValue();});
+                emitDigestChain(out, "(" + digestType->getInternalDataCppType() + ")", chain,
+                                [](const auto& e) { return e->cppValue(); });
             });
             out << ");\n";
             out << "return ::android::hardware::Void();\n";
@@ -333,7 +332,7 @@
             out.indent(2, [&] {
                 // No need for dimensions when elements are explicitly provided.
                 emitDigestChain(out, "new " + digestType->getJavaType(false /* forInitializer */),
-                    chain, [](const auto &e){return e.javaValue();});
+                                chain, [](const auto& e) { return e->javaValue(); });
             });
             out << "));\n";
         } } } /* javaImpl */