Split AnnotaionParam into String and Constant Expression params
This is needed to support constant expression lazy evaluation.
Test: build hidl-gen, hidl_test
Test: build hidl-gen on mac :)
Change-Id: I5f38b0d2cbea5928408379bff7f282a2cd63d03b
diff --git a/Annotation.cpp b/Annotation.cpp
index a3e49f8..7f3fc88 100644
--- a/Annotation.cpp
+++ b/Annotation.cpp
@@ -23,33 +23,12 @@
namespace android {
+AnnotationParam::AnnotationParam(const std::string& name) : mName(name) {}
-AnnotationParam::AnnotationParam(const std::string &name,
- std::vector<std::string> *values)
-: mName(name), mValues(values) {}
-
-AnnotationParam::AnnotationParam(const std::string &name,
- std::vector<ConstantExpression *> *values)
- : mName(name) {
- mValues = new std::vector<std::string>();
- for(ConstantExpression *ce : *values) {
- mValues->push_back(ce->value() + " /* " + ce->description() + " */");
- }
-}
-
-const std::string &AnnotationParam::getName() const {
+const std::string& AnnotationParam::getName() const {
return mName;
}
-const std::vector<std::string> *AnnotationParam::getValues() const {
- return mValues;
-}
-
-const std::string &AnnotationParam::getSingleValue() const {
- CHECK_EQ(mValues->size(), 1u) << mName << " requires one values but has multiple";
- return mValues->at(0);
-}
-
std::string AnnotationParam::getSingleString() const {
std::string value = getSingleValue();
@@ -75,11 +54,44 @@
return false;
}
-Annotation::Annotation(const char *name,AnnotationParamVector *params)
- : mName(name),
- mParams(params) {
+StringAnnotationParam::StringAnnotationParam(const std::string& name,
+ std::vector<std::string>* values)
+ : AnnotationParam(name), mValues(values) {}
+
+std::vector<std::string> StringAnnotationParam::getValues() const {
+ return *mValues;
}
+std::string StringAnnotationParam::getSingleValue() const {
+ CHECK_EQ(mValues->size(), 1u) << mName << " requires one value but has multiple";
+ return mValues->at(0);
+}
+
+ConstantExpressionAnnotationParam::ConstantExpressionAnnotationParam(
+ const std::string& name, std::vector<ConstantExpression*>* values)
+ : AnnotationParam(name), mValues(values) {}
+
+std::vector<std::string> ConstantExpressionAnnotationParam::getValues() const {
+ std::vector<std::string> ret;
+ for (const auto* ce : *mValues) {
+ ret.push_back(convertToString(ce));
+ };
+
+ return ret;
+}
+
+std::string ConstantExpressionAnnotationParam::getSingleValue() const {
+ CHECK_EQ(mValues->size(), 1u) << mName << " requires one value but has multiple";
+ return convertToString(mValues->at(0));
+}
+
+std::string ConstantExpressionAnnotationParam::convertToString(const ConstantExpression* ce) {
+ return ce->value() + " /* " + ce->description() + " */";
+}
+
+Annotation::Annotation(const char* name, AnnotationParamVector* params)
+ : mName(name), mParams(params) {}
+
std::string Annotation::name() const {
return mName;
}
@@ -116,14 +128,14 @@
out << param->getName() << "=";
- const std::vector<std::string> *values = param->getValues();
- if (values->size() > 1) {
+ const std::vector<std::string>& values = param->getValues();
+ if (values.size() > 1) {
out << "{";
}
- out << StringHelper::JoinStrings(*values, ", ");
+ out << StringHelper::JoinStrings(values, ", ");
- if (values->size() > 1) {
+ if (values.size() > 1) {
out << "}";
}
}