Restrict where annotations can be applied
Some annotations are only valid in specific contexts.
If an annotation is found in the incorrect context, return
an error when parsing the ADIL language.
Test: runtests.sh
Change-Id: I64bf6e6f5de7c38d6f6928acbe55022ab9de441a
diff --git a/aidl_language.h b/aidl_language.h
index 7a40427..55bed95 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -252,7 +252,8 @@
std::string ToString() const;
const vector<AidlAnnotation>& GetAnnotations() const { return annotations_; }
- bool CheckValidAnnotations() const;
+ virtual std::set<string> GetSupportedAnnotations() const = 0;
+ virtual bool CheckValid(const AidlTypenames&) const;
private:
vector<AidlAnnotation> annotations_;
@@ -309,7 +310,8 @@
// resolution fails.
bool Resolve(const AidlTypenames& typenames);
- bool CheckValid(const AidlTypenames& typenames) const;
+ std::set<string> GetSupportedAnnotations() const override;
+ bool CheckValid(const AidlTypenames& typenames) const override;
bool LanguageSpecificCheckValid(Options::Language lang) const;
const AidlNode& AsAidlNode() const override { return *this; }
@@ -659,7 +661,7 @@
virtual const AidlEnumDeclaration* AsEnumDeclaration() const { return nullptr; }
virtual const AidlInterface* AsInterface() const { return nullptr; }
virtual const AidlParameterizable<std::string>* AsParameterizable() const { return nullptr; }
- virtual bool CheckValid(const AidlTypenames&) const { return CheckValidAnnotations(); }
+ bool CheckValid(const AidlTypenames& typenames) const override;
virtual bool LanguageSpecificCheckValid(Options::Language lang) const = 0;
AidlStructuredParcelable* AsStructuredParcelable() {
return const_cast<AidlStructuredParcelable*>(
@@ -713,6 +715,7 @@
std::string GetCppName() const { return name_->GetColonName(); }
std::string GetCppHeader() const { return cpp_header_; }
+ std::set<string> GetSupportedAnnotations() const override;
bool CheckValid(const AidlTypenames& typenames) const override;
bool LanguageSpecificCheckValid(Options::Language lang) const override;
const AidlParcelable* AsParcelable() const override { return this; }
@@ -744,6 +747,7 @@
void Dump(CodeWriter* writer) const override;
+ std::set<string> GetSupportedAnnotations() const override;
bool CheckValid(const AidlTypenames& typenames) const override;
bool LanguageSpecificCheckValid(Options::Language lang) const override;
@@ -790,6 +794,7 @@
return enumerators_;
}
bool Autofill();
+ std::set<string> GetSupportedAnnotations() const override;
bool CheckValid(const AidlTypenames& typenames) const override;
bool LanguageSpecificCheckValid(Options::Language) const override { return true; }
std::string GetPreprocessDeclarationName() const override { return "enum"; }
@@ -824,6 +829,7 @@
void Dump(CodeWriter* writer) const override;
+ std::set<string> GetSupportedAnnotations() const override;
bool CheckValid(const AidlTypenames& typenames) const override;
bool LanguageSpecificCheckValid(Options::Language lang) const override;