aboutsummaryrefslogtreecommitdiff
path: root/generate_rust.cpp
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2021-01-05 19:13:17 +0900
committerJooyung Han <jooyung@google.com>2021-01-07 00:58:00 +0000
commit720253dc96d6d6b48b5490d6f0dbb8e9e8bc69c6 (patch)
tree9942f549a5d5f2687856699f4a20d75a584afa6a /generate_rust.cpp
parente9f5b27426f1d3ae2e82404ac488cba4a2dd8d5e (diff)
downloadaidl-720253dc96d6d6b48b5490d6f0dbb8e9e8bc69c6.tar.gz
Emit "deprecated"
We've supported /** @deprecated note */ but it's passed to only the Java backend as it is (as comments). Now the deprecation is emitted properly according to the backend types. - Java: @Deprecated + /** @deprecated note */ - C++/NDK: __attribute__((deprecated(note)) - Rust: #[deprecated = note] For now, "note" is only available for the Java backend. Supporting deprecation notes will be followed. Bug: 174514415 Test: aidl_unittests / aidl_integration_test Change-Id: Iefb216585d884b3195719c82748e573bb08922ab Merged-In: Iefb216585d884b3195719c82748e573bb08922ab Ignore-AOSP-First: topic with internal-only project (packages/services/Car) (cherry picked from commit ea571f8f53f30c08bc1b9a4ea02cb473522cbc9b)
Diffstat (limited to 'generate_rust.cpp')
-rw-r--r--generate_rust.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/generate_rust.cpp b/generate_rust.cpp
index c7510059..e5a27594 100644
--- a/generate_rust.cpp
+++ b/generate_rust.cpp
@@ -310,6 +310,13 @@ void GenerateServerItems(CodeWriter& out, const AidlInterface* iface,
out << "}\n";
}
+template <typename Type>
+void GenerateDeprecated(CodeWriter& out, const Type& type) {
+ if (type.IsDeprecated()) {
+ out << "#[deprecated]\n";
+ }
+}
+
template <typename TypeWithConstants>
void GenerateConstantDeclarations(CodeWriter& out, const TypeWithConstants& type,
const AidlTypenames& typenames) {
@@ -327,6 +334,7 @@ void GenerateConstantDeclarations(CodeWriter& out, const TypeWithConstants& type
AIDL_FATAL(value) << "Unrecognized constant type: " << type.Signature();
}
+ GenerateDeprecated(out, *constant);
out << "pub const " << constant->GetName() << ": " << const_type << " = "
<< constant->ValueString(ConstantValueDecoratorRef) << ";\n";
}
@@ -372,6 +380,7 @@ bool GenerateRustInterface(const string& filename, const AidlInterface* iface,
code_writer->Dedent();
*code_writer << "}\n";
+ GenerateDeprecated(*code_writer, *iface);
*code_writer << "pub trait " << trait_name << ": binder::Interface + Send {\n";
code_writer->Indent();
*code_writer << "fn get_descriptor() -> &'static str where Self: Sized { \""
@@ -379,6 +388,7 @@ bool GenerateRustInterface(const string& filename, const AidlInterface* iface,
for (const auto& method : iface->GetMethods()) {
// Generate the method
+ GenerateDeprecated(*code_writer, *method);
*code_writer << BuildMethod(*method, typenames) << " {\n";
code_writer->Indent();
if (method->IsUserDefined()) {
@@ -467,9 +477,11 @@ bool GenerateRustInterface(const string& filename, const AidlInterface* iface,
void GenerateParcelBody(CodeWriter& out, const AidlStructuredParcelable* parcel,
const AidlTypenames& typenames) {
+ GenerateDeprecated(out, *parcel);
out << "pub struct " << parcel->GetName() << " {\n";
out.Indent();
for (const auto& variable : parcel->GetFields()) {
+ GenerateDeprecated(out, *variable);
auto field_type = RustNameOf(variable->GetType(), typenames, StorageMode::PARCELABLE_FIELD);
out << "pub " << variable->GetName() << ": " << field_type << ",\n";
}
@@ -547,9 +559,11 @@ void GenerateParcelDeserializeBody(CodeWriter& out, const AidlStructuredParcelab
void GenerateParcelBody(CodeWriter& out, const AidlUnionDecl* parcel,
const AidlTypenames& typenames) {
+ GenerateDeprecated(out, *parcel);
out << "pub enum " << parcel->GetName() << " {\n";
out.Indent();
for (const auto& variable : parcel->GetFields()) {
+ GenerateDeprecated(out, *variable);
auto field_type = RustNameOf(variable->GetType(), typenames, StorageMode::PARCELABLE_FIELD);
out << variable->GetCapitalizedName() << "(" << field_type << "),\n";
}
@@ -726,6 +740,7 @@ bool GenerateRustEnumDeclaration(const string& filename, const AidlEnumDeclarati
const auto& aidl_backing_type = enum_decl->GetBackingType();
auto backing_type = RustNameOf(aidl_backing_type, typenames, StorageMode::VALUE);
+ // TODO(b/174514415) support "deprecated" for enum types
*code_writer << "#![allow(non_upper_case_globals)]\n";
*code_writer << "use binder::declare_binder_enum;\n";
*code_writer << "declare_binder_enum! { " << enum_decl->GetName() << " : " << backing_type