ConstantExpression: description included in value.

Now the value when it is used always includes the description which simplifies
code that wants to print values (they don't have to check if the description is
trivial and then create a comment themselves).

Bug: 37525755
Test: hidl_test
Test: run_all_host_tests.sh
Change-Id: I82ad50f45cc47095897a416bcbff4c886cfe1924
diff --git a/ConstantExpression.cpp b/ConstantExpression.cpp
index 97e1317..aa2ebec 100644
--- a/ConstantExpression.cpp
+++ b/ConstantExpression.cpp
@@ -254,7 +254,7 @@
     CHECK(mUnary->isEvaluated());
     mIsEvaluated = true;
 
-    mExpr = std::string("(") + mOp + mUnary->description() + ")";
+    mExpr = std::string("(") + mOp + mUnary->mExpr + ")";
     mValueKind = mUnary->mValueKind;
 
 #define CASE_UNARY(__type__)                                          \
@@ -270,7 +270,7 @@
     CHECK(mRval->isEvaluated());
     mIsEvaluated = true;
 
-    mExpr = std::string("(") + mLval->description() + " " + mOp + " " + mRval->description() + ")";
+    mExpr = std::string("(") + mLval->mExpr + " " + mOp + " " + mRval->mExpr + ")";
 
     bool isArithmeticOrBitflip = OP_IS_BIN_ARITHMETIC || OP_IS_BIN_BITFLIP;
 
@@ -330,8 +330,7 @@
     CHECK(mFalseVal->isEvaluated());
     mIsEvaluated = true;
 
-    mExpr = std::string("(") + mCond->description() + "?" + mTrueVal->description() + ":" +
-            mFalseVal->description() + ")";
+    mExpr = std::string("(") + mCond->mExpr + "?" + mTrueVal->mExpr + ":" + mFalseVal->mExpr + ")";
 
     // note: for ?:, unlike arithmetic ops, integral promotion is not processed.
     mValueKind = usualArithmeticConversion(mTrueVal->mValueKind, mFalseVal->mValueKind);
@@ -362,28 +361,16 @@
     return ret;
 }
 
-const std::string& ConstantExpression::description() const {
-    CHECK(isEvaluated());
-    return mExpr;
-}
-
-bool ConstantExpression::descriptionIsTrivial() const {
-    CHECK(isEvaluated());
-    return mTrivialDescription;
-}
-
 std::string ConstantExpression::value() const {
-    CHECK(isEvaluated());
-    return rawValue(mValueKind);
+    return value(mValueKind);
 }
 
 std::string ConstantExpression::value(ScalarType::Kind castKind) const {
     CHECK(isEvaluated());
-    return rawValue(castKind);
+    return rawValue(castKind) + descriptionSuffix();
 }
 
 std::string ConstantExpression::cppValue() const {
-    CHECK(isEvaluated());
     return cppValue(mValueKind);
 }
 
@@ -399,35 +386,60 @@
     // -(uint64_t)9223372036854775808 == 9223372036854775808 could not
     // be narrowed to int64_t.
     if(castKind == SK(INT64) && (int64_t)mValue == INT64_MIN) {
-        return "static_cast<" +
-               ScalarType(SK(INT64), nullptr /* parent */).getCppStackType()  // "int64_t"
-               + ">(" + literal + "ull)";
+        literal = "static_cast<" +
+                  ScalarType(SK(INT64), nullptr /* parent */).getCppStackType()  // "int64_t"
+                  + ">(" + literal + "ull)";
+    } else {
+        // add suffix if necessary.
+        if (castKind == SK(UINT32) || castKind == SK(UINT64)) literal += "u";
+        if (castKind == SK(UINT64) || castKind == SK(INT64)) literal += "ll";
     }
 
-    // add suffix if necessary.
-    if(castKind == SK(UINT32) || castKind == SK(UINT64)) literal += "u";
-    if(castKind == SK(UINT64) || castKind == SK(INT64)) literal += "ll";
-    return literal;
+    return literal + descriptionSuffix();
 }
 
 std::string ConstantExpression::javaValue() const {
-    CHECK(isEvaluated());
     return javaValue(mValueKind);
 }
 
 std::string ConstantExpression::javaValue(ScalarType::Kind castKind) const {
     CHECK(isEvaluated());
+    std::string literal;
+
     switch(castKind) {
-        case SK(UINT64): return rawValue(SK(INT64)) + "L";
-        case SK(INT64):  return rawValue(SK(INT64)) + "L";
-        case SK(UINT32): return rawValue(SK(INT32));
-        case SK(UINT16): return rawValue(SK(INT16));
-        case SK(UINT8) : return rawValue(SK(INT8));
+        case SK(UINT64):
+            literal = rawValue(SK(INT64)) + "L";
+            break;
+        case SK(INT64):
+            literal = rawValue(SK(INT64)) + "L";
+            break;
+        case SK(UINT32):
+            literal = rawValue(SK(INT32));
+            break;
+        case SK(UINT16):
+            literal = rawValue(SK(INT16));
+            break;
+        case SK(UINT8):
+            literal = rawValue(SK(INT8));
+            break;
         case SK(BOOL)  :
-            return this->cast<bool>() ? "true" : "false";
-        default: break;
+            literal = this->cast<bool>() ? "true" : "false";
+            break;
+        default:
+            literal = rawValue(castKind);
+            break;
     }
-    return rawValue(castKind);
+
+    return literal + descriptionSuffix();
+}
+
+const std::string& ConstantExpression::expression() const {
+    CHECK(isEvaluated());
+    return mExpr;
+}
+
+std::string ConstantExpression::rawValue() const {
+    return rawValue(mValueKind);
 }
 
 std::string ConstantExpression::rawValue(ScalarType::Kind castKind) const {
@@ -447,6 +459,17 @@
     SWITCH_KIND(mValueKind, CASE_CAST_T, SHOULD_NOT_REACH(); return 0; );
 }
 
+std::string ConstantExpression::descriptionSuffix() const {
+    CHECK(isEvaluated());
+
+    if (!mTrivialDescription) {
+        CHECK(!mExpr.empty());
+
+        return " /* " + mExpr + " */";
+    }
+    return "";
+}
+
 size_t ConstantExpression::castSizeT() const {
     CHECK(isEvaluated());
     return this->cast<size_t>();