Validate @Enforce expression earlier
As suggested by Jooyung in a previous change, validate the expression
when parsing the interface. Add unit tests to confirm that the expected
errors are raised for empty or malformed expressions. With this
implementation, the condition expression is parsed twice (once when
loaded and once when generating the Java code).
Test: out/host/linux-x86/nativetest64/aidl_unittests/aidl_unittests
Bug: 197828948
Change-Id: I8d6008c33b17dc1b0e473c6299cd601f86d9629a
diff --git a/aidl_language.h b/aidl_language.h
index db92535..c2cffd6 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -22,6 +22,7 @@
#include <unordered_set>
#include <vector>
+#include <android-base/result.h>
#include <android-base/strings.h>
#include "aidl_typenames.h"
@@ -38,6 +39,7 @@
using android::aidl::CodeWriter;
using android::aidl::Comments;
using android::aidl::Options;
+using android::base::Result;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
@@ -281,6 +283,8 @@
void TraverseChildren(std::function<void(const AidlNode&)> traverse) const override;
void DispatchVisit(AidlVisitor& v) const override { v.Visit(*this); }
+ Result<unique_ptr<perm::Expression>> EnforceExpression() const;
+
private:
struct ParamType {
std::string name;