Use ConstantExpression for FLAG_ONE_WAY.
In order to simplify printing it in comments (and later simplify
|'ing it).
Bug: 37525755
Test: hidl_test
Change-Id: Ifcf23b92966e29abe42c267e2b56b2d7fe45c217
diff --git a/ConstantExpression.cpp b/ConstantExpression.cpp
index aa2ebec..a025dd2 100644
--- a/ConstantExpression.cpp
+++ b/ConstantExpression.cpp
@@ -173,7 +173,7 @@
CHECK(!expr.empty());
CHECK(isSupported(kind));
- mTrivialDescription = true;
+ mTrivialDescription = std::to_string(value) == expr;
mExpr = expr;
mValueKind = kind;
mValue = value;
diff --git a/ConstantExpression.h b/ConstantExpression.h
index 43d8070..c5bdbe3 100644
--- a/ConstantExpression.h
+++ b/ConstantExpression.h
@@ -162,13 +162,11 @@
struct LiteralConstantExpression : public ConstantExpression {
LiteralConstantExpression(ScalarType::Kind kind, uint64_t value);
+ LiteralConstantExpression(ScalarType::Kind kind, uint64_t value, const std::string& expr);
void evaluate() override;
std::vector<const ConstantExpression*> getConstantExpressions() const override;
static LiteralConstantExpression* tryParse(const std::string& value);
-
-private:
- LiteralConstantExpression(ScalarType::Kind kind, uint64_t value, const std::string& expr);
};
struct UnaryConstantExpression : public ConstantExpression {
diff --git a/Interface.cpp b/Interface.cpp
index 8370c36..44eb872 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -68,6 +68,9 @@
LAST_HIDL_TRANSACTION = 0x0fffffff,
};
+const std::unique_ptr<ConstantExpression> Interface::FLAG_ONE_WAY =
+ std::make_unique<LiteralConstantExpression>(ScalarType::KIND_UINT32, 0x01, "oneway");
+
Interface::Interface(const char* localName, const FQName& fullName, const Location& location,
Scope* parent, const Reference<Type>& superType, const Hash* fileHash)
: Scope(localName, fullName, location, parent), mSuperType(superType), mFileHash(fileHash) {}
diff --git a/Interface.h b/Interface.h
index 005beff..2604c77 100644
--- a/Interface.h
+++ b/Interface.h
@@ -22,6 +22,7 @@
#include <hidl-hash/Hash.h>
+#include "ConstantExpression.h"
#include "Reference.h"
#include "Scope.h"
@@ -31,10 +32,7 @@
struct InterfaceAndMethod;
struct Interface : public Scope {
- enum {
- /////////////////// Flag(s) - DO NOT CHANGE
- FLAG_ONEWAY = 0x00000001,
- };
+ const static std::unique_ptr<ConstantExpression> FLAG_ONE_WAY;
Interface(const char* localName, const FQName& fullName, const Location& location,
Scope* parent, const Reference<Type>& superType, const Hash* fileHash);
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 5bf1ee5..a2889b5 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -1093,7 +1093,7 @@
<< " */, _hidl_data, &_hidl_reply";
if (method->isOneway()) {
- out << ", " << Interface::FLAG_ONEWAY << " /* oneway */";
+ out << ", " << Interface::FLAG_ONE_WAY->cppValue();
}
out << ");\n";
@@ -1324,8 +1324,8 @@
out.indent();
- out << "bool _hidl_is_oneway = _hidl_flags & " << Interface::FLAG_ONEWAY
- << " /* oneway */;\n";
+ out << "bool _hidl_is_oneway = _hidl_flags & " << Interface::FLAG_ONE_WAY->cppValue()
+ << ";\n";
out << "if (_hidl_is_oneway != " << (method->isOneway() ? "true" : "false") << ") ";
out.block([&] { out << "return ::android::UNKNOWN_ERROR;\n"; }).endl().endl();
diff --git a/generateJava.cpp b/generateJava.cpp
index 9b2f593..fcc1823 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -383,7 +383,7 @@
<< " */, _hidl_request, _hidl_reply, ";
if (method->isOneway()) {
- out << Interface::FLAG_ONEWAY << " /* oneway */";
+ out << Interface::FLAG_ONE_WAY->javaValue();
} else {
out << "0 /* flags */";
}
@@ -535,8 +535,8 @@
out.indent();
- out << "boolean _hidl_is_oneway = (_hidl_flags & " << Interface::FLAG_ONEWAY
- << " /* oneway */) != 0\n;";
+ out << "boolean _hidl_is_oneway = (_hidl_flags & " << Interface::FLAG_ONE_WAY->javaValue()
+ << ") != 0;\n";
out << "if (_hidl_is_oneway != " << (method->isOneway() ? "true" : "false") << ") ";
out.block([&] {
out << "_hidl_reply.writeStatus(" << UNKNOWN_ERROR << ");\n";