From bce0483dd09f592d6f9f989f0e34fc930d206810 Mon Sep 17 00:00:00 2001 From: Christopher Wiley Date: Wed, 13 Apr 2016 12:57:27 -0700 Subject: Don't generate code with unused private fields A recent update to libchrome reveals that we were previously suppressing warnings about unused private fields. Without that, the generated code can cause errors when interfaces have no methods. Bug: 28117776 Change-Id: Ic734c1ce9485797065e504c566cad8d6edf45d07 Test: Generated code now compiles. --- chromeos-dbus-bindings/adaptor_generator.cc | 23 ++++++++++++++++------- chromeos-dbus-bindings/adaptor_generator.h | 3 ++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/chromeos-dbus-bindings/adaptor_generator.cc b/chromeos-dbus-bindings/adaptor_generator.cc index 0f980b5..1916534 100644 --- a/chromeos-dbus-bindings/adaptor_generator.cc +++ b/chromeos-dbus-bindings/adaptor_generator.cc @@ -86,7 +86,7 @@ void AdaptorGenerator::GenerateInterfaceAdaptor( text->AddLine(StringPrintf("class %s {", class_name.c_str())); text->AddLineWithOffset("public:", kScopeOffset); text->PushOffset(kBlockOffset); - AddConstructor(class_name, itf_name, text); + AddConstructor(interface, class_name, itf_name, text); AddRegisterWithDBusObject(itf_name, interface, text); AddSendSignalMethods(interface, text); AddPropertyMethodImplementation(interface, text); @@ -107,9 +107,11 @@ void AdaptorGenerator::GenerateInterfaceAdaptor( AddSignalDataMembers(interface, text); AddPropertyDataMembers(interface, text); - text->AddLine(StringPrintf( - "%s* interface_; // Owned by container of this adapter.", - itf_name.c_str())); + if (!interface.methods.empty()) { + text->AddLine(StringPrintf( + "%s* interface_; // Owned by container of this adapter.", + itf_name.c_str())); + } text->AddBlankLine(); text->AddLine(StringPrintf("DISALLOW_COPY_AND_ASSIGN(%s);", @@ -122,11 +124,18 @@ void AdaptorGenerator::GenerateInterfaceAdaptor( } // static -void AdaptorGenerator::AddConstructor(const string& class_name, +void AdaptorGenerator::AddConstructor(const Interface& interface, + const string& class_name, const string& itf_name, IndentedText *text) { - text->AddLine(StringPrintf("%s(%s* interface) : interface_(interface) {}", - class_name.c_str(), itf_name.c_str())); + if (interface.methods.empty()) { + text->AddLine(StringPrintf("%s(%s* /* interface */) {}", + class_name.c_str(), itf_name.c_str())); + + } else { + text->AddLine(StringPrintf("%s(%s* interface) : interface_(interface) {}", + class_name.c_str(), itf_name.c_str())); + } } // static diff --git a/chromeos-dbus-bindings/adaptor_generator.h b/chromeos-dbus-bindings/adaptor_generator.h index 57e2bf5..5cd68a3 100644 --- a/chromeos-dbus-bindings/adaptor_generator.h +++ b/chromeos-dbus-bindings/adaptor_generator.h @@ -41,7 +41,8 @@ class AdaptorGenerator : public HeaderGenerator { IndentedText *text); // Generates the constructor for the adaptor. - static void AddConstructor(const std::string& class_name, + static void AddConstructor(const Interface& interface, + const std::string& class_name, const std::string& itf_name, IndentedText *text); -- cgit v1.2.3