From a761f061f4cc0e50324261cc1eb12526ae8783e3 Mon Sep 17 00:00:00 2001 From: Krishna Date: Wed, 10 Dec 2014 20:39:34 +0100 Subject: Source code refactoring. Extracted common functionality in cpp_helpers.cc and python/python_generator.cc --- src/google/protobuf/compiler/cpp/cpp_helpers.cc | 20 +++++++++++----- .../protobuf/compiler/python/python_generator.cc | 28 +++++++--------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 28c4dd54..e293b413 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -361,18 +361,26 @@ string FilenameIdentifier(const string& filename) { } // Return the name of the AddDescriptors() function for a given file. -string GlobalAddDescriptorsName(const string& filename) { - return "protobuf_AddDesc_" + FilenameIdentifier(filename); +string GlobalAddDescriptorsName(const string& filename) +{ + return GlobalSymbolName(filename,"protobuf_AddDesc_"); } // Return the name of the AssignDescriptors() function for a given file. -string GlobalAssignDescriptorsName(const string& filename) { - return "protobuf_AssignDesc_" + FilenameIdentifier(filename); +string GlobalAssignDescriptorsName(const string& filename) +{ + return GlobalSymbolName(filename,"protobuf_AssignDesc_"); } // Return the name of the ShutdownFile() function for a given file. -string GlobalShutdownFileName(const string& filename) { - return "protobuf_ShutdownFile_" + FilenameIdentifier(filename); +string GlobalShutdownFileName(const string& filename) +{ + return GlobalSymbolName(filename,"protobuf_ShutdownFile_"); +} + +string GlobalSymbolName(const string& filename, string prefix) +{ + return prefix + FilenameIdentifier(filename); } // Return the qualified C++ name for a file level symbol. diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index e6faf7ef..508cab0d 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -580,11 +580,9 @@ void Generator::PrintServiceDescriptor( printer_->Print("])\n\n"); } -void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { - // Print the service. - printer_->Print("$class_name$ = service_reflection.GeneratedServiceType(" - "'$class_name$', (_service.Service,), dict(\n", - "class_name", descriptor.name()); + +void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, string keyandmodule) { + printer_->Print(keyandmodule,"class_name", descriptor.name()); printer_->Indent(); printer_->Print( "$descriptor_key$ = $descriptor_name$,\n", @@ -597,22 +595,12 @@ void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { printer_->Outdent(); } +void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { + Generator::PrintDescriptorKeyAndModuleName(descriptor, "$class_name$_Stub = service_reflection.GeneratedServiceStubType('$class_name$_Stub', ($class_name$,), dict(\n"); +} + void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { - // Print the service stub. - printer_->Print("$class_name$_Stub = " - "service_reflection.GeneratedServiceStubType(" - "'$class_name$_Stub', ($class_name$,), dict(\n", - "class_name", descriptor.name()); - printer_->Indent(); - printer_->Print( - "$descriptor_key$ = $descriptor_name$,\n", - "descriptor_key", kDescriptorKey, - "descriptor_name", ModuleLevelServiceDescriptorName(descriptor)); - printer_->Print( - "__module__ = '$module_name$'\n", - "module_name", ModuleName(file_->name())); - printer_->Print("))\n\n"); - printer_->Outdent(); + Generator::PrintDescriptorKeyAndModuleName(descriptor, "$class_name$ = service_reflection.GeneratedServiceType('$class_name$', (_service.Service,), dict(\n"); } // Prints statement assigning ModuleLevelDescriptorName(message_descriptor) -- cgit v1.2.3 From 7654f78029030238c6dff3826671393f4e6db359 Mon Sep 17 00:00:00 2001 From: Krishna Date: Wed, 10 Dec 2014 21:02:12 +0100 Subject: Fixed bugs --- src/google/protobuf/compiler/cpp/cpp_helpers.cc | 10 ++++++---- src/google/protobuf/compiler/python/python_generator.cc | 2 +- src/google/protobuf/compiler/python/python_generator.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index e293b413..cd8364f5 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -360,6 +360,12 @@ string FilenameIdentifier(const string& filename) { return result; } + +string GlobalSymbolName(const string& filename, string prefix) +{ + return prefix + FilenameIdentifier(filename); +} + // Return the name of the AddDescriptors() function for a given file. string GlobalAddDescriptorsName(const string& filename) { @@ -378,10 +384,6 @@ string GlobalShutdownFileName(const string& filename) return GlobalSymbolName(filename,"protobuf_ShutdownFile_"); } -string GlobalSymbolName(const string& filename, string prefix) -{ - return prefix + FilenameIdentifier(filename); -} // Return the qualified C++ name for a file level symbol. string QualifiedFileLevelSymbol(const string& package, const string& name) { diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index 508cab0d..e4b73f94 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -581,7 +581,7 @@ void Generator::PrintServiceDescriptor( } -void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, string keyandmodule) { +void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, const char* keyandmodule) const { printer_->Print(keyandmodule,"class_name", descriptor.name()); printer_->Indent(); printer_->Print( diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h index 7e8f58e5..6b8b76f3 100644 --- a/src/google/protobuf/compiler/python/python_generator.h +++ b/src/google/protobuf/compiler/python/python_generator.h @@ -127,6 +127,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; void PrintServiceClass(const ServiceDescriptor& descriptor) const; void PrintServiceStub(const ServiceDescriptor& descriptor) const; + void PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, const char* keyandmodule) const ; void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; string OptionsValue(const string& class_name, -- cgit v1.2.3 From 060a2096a3f3d7c66a64a1a41a1d2e1e18aea82d Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 11 Dec 2014 07:45:32 +0100 Subject: Reverted changes to cpp_helpers.cc and made code reviews to python_geenerator.cc --- src/google/protobuf/compiler/cpp/cpp_helpers.cc | 24 +++++++--------------- .../protobuf/compiler/python/python_generator.cc | 16 +++++++++++---- .../protobuf/compiler/python/python_generator.h | 2 +- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index cd8364f5..f8ed7b1c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -360,31 +360,21 @@ string FilenameIdentifier(const string& filename) { return result; } - -string GlobalSymbolName(const string& filename, string prefix) -{ - return prefix + FilenameIdentifier(filename); -} - // Return the name of the AddDescriptors() function for a given file. -string GlobalAddDescriptorsName(const string& filename) -{ - return GlobalSymbolName(filename,"protobuf_AddDesc_"); +string GlobalAddDescriptorsName(const string& filename) { + return "protobuf_AddDesc_" + FilenameIdentifier(filename); } // Return the name of the AssignDescriptors() function for a given file. -string GlobalAssignDescriptorsName(const string& filename) -{ - return GlobalSymbolName(filename,"protobuf_AssignDesc_"); +string GlobalAssignDescriptorsName(const string& filename) { + return "protobuf_AssignDesc_" + FilenameIdentifier(filename); } // Return the name of the ShutdownFile() function for a given file. -string GlobalShutdownFileName(const string& filename) -{ - return GlobalSymbolName(filename,"protobuf_ShutdownFile_"); +string GlobalShutdownFileName(const string& filename) { + return "protobuf_ShutdownFile_" + FilenameIdentifier(filename); } - // Return the qualified C++ name for a file level symbol. string QualifiedFileLevelSymbol(const string& package, const string& name) { if (package.empty()) { @@ -521,4 +511,4 @@ bool IsStringOrMessage(const FieldDescriptor* field) { } // namespace cpp } // namespace compiler } // namespace protobuf -} // namespace google +} // namespace google \ No newline at end of file diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index e4b73f94..fca94a31 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -581,8 +581,7 @@ void Generator::PrintServiceDescriptor( } -void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, const char* keyandmodule) const { - printer_->Print(keyandmodule,"class_name", descriptor.name()); +void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const { printer_->Indent(); printer_->Print( "$descriptor_key$ = $descriptor_name$,\n", @@ -596,11 +595,20 @@ void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descrip } void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { - Generator::PrintDescriptorKeyAndModuleName(descriptor, "$class_name$_Stub = service_reflection.GeneratedServiceStubType('$class_name$_Stub', ($class_name$,), dict(\n"); + // Print the service. + printer_->Print("$class_name$ = service_reflection.GeneratedServiceType(" + "'$class_name$', (_service.Service,), dict(\n", + "class_name", descriptor.name()); + Generator::PrintDescriptorKeyAndModuleName(descriptor); } void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { - Generator::PrintDescriptorKeyAndModuleName(descriptor, "$class_name$ = service_reflection.GeneratedServiceType('$class_name$', (_service.Service,), dict(\n"); + // Print the service stub. + printer_->Print("$class_name$_Stub = " + "service_reflection.GeneratedServiceStubType(" + "'$class_name$_Stub', ($class_name$,), dict(\n", + "class_name", descriptor.name()); + Generator::PrintDescriptorKeyAndModuleName(descriptor); } // Prints statement assigning ModuleLevelDescriptorName(message_descriptor) diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h index 6b8b76f3..ee68ad72 100644 --- a/src/google/protobuf/compiler/python/python_generator.h +++ b/src/google/protobuf/compiler/python/python_generator.h @@ -127,7 +127,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; void PrintServiceClass(const ServiceDescriptor& descriptor) const; void PrintServiceStub(const ServiceDescriptor& descriptor) const; - void PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, const char* keyandmodule) const ; + void PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const ; void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; string OptionsValue(const string& class_name, -- cgit v1.2.3 From 22f96a713cd68d051466de7aa4585cc64e674d80 Mon Sep 17 00:00:00 2001 From: Krishna Date: Fri, 12 Dec 2014 10:22:48 +0100 Subject: Returned print_indent and print_outdent back to printservicestub and printserviceclass in python generator --- src/google/protobuf/compiler/python/python_generator.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index fca94a31..b30d1972 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -581,17 +581,14 @@ void Generator::PrintServiceDescriptor( } -void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const { - printer_->Indent(); +void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const { printer_->Print( "$descriptor_key$ = $descriptor_name$,\n", "descriptor_key", kDescriptorKey, "descriptor_name", ModuleLevelServiceDescriptorName(descriptor)); printer_->Print( "__module__ = '$module_name$'\n", - "module_name", ModuleName(file_->name())); - printer_->Print("))\n\n"); - printer_->Outdent(); + "module_name", ModuleName(file_->name())); } void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { @@ -599,7 +596,10 @@ void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { printer_->Print("$class_name$ = service_reflection.GeneratedServiceType(" "'$class_name$', (_service.Service,), dict(\n", "class_name", descriptor.name()); + printer_->Indent(); Generator::PrintDescriptorKeyAndModuleName(descriptor); + printer_->Print("))\n\n"); + printer_->Outdent(); } void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { @@ -608,7 +608,10 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { "service_reflection.GeneratedServiceStubType(" "'$class_name$_Stub', ($class_name$,), dict(\n", "class_name", descriptor.name()); + printer_->Indent(); Generator::PrintDescriptorKeyAndModuleName(descriptor); + printer_->Print("))\n\n"); + printer_->Outdent(); } // Prints statement assigning ModuleLevelDescriptorName(message_descriptor) -- cgit v1.2.3 From 91552adb77687eb4a15145f7a311c3c479a2a4c3 Mon Sep 17 00:00:00 2001 From: Krishna Date: Fri, 12 Dec 2014 10:25:06 +0100 Subject: Reverting the space at the end --- src/google/protobuf/compiler/python/python_generator.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index b30d1972..588394db 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -1309,4 +1309,4 @@ void Generator::CopyPublicDependenciesAliases( } // namespace python } // namespace compiler } // namespace protobuf -} // namespace google +} // namespace google \ No newline at end of file -- cgit v1.2.3 From 2e9f5e3bac9f6c0db0a285a429546db866b90051 Mon Sep 17 00:00:00 2001 From: Krishna Date: Fri, 12 Dec 2014 10:26:25 +0100 Subject: Reverting the space at the end for both files changed --- src/google/protobuf/compiler/cpp/cpp_helpers.cc | 2 +- src/google/protobuf/compiler/python/python_generator.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index f8ed7b1c..28c4dd54 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -511,4 +511,4 @@ bool IsStringOrMessage(const FieldDescriptor* field) { } // namespace cpp } // namespace compiler } // namespace protobuf -} // namespace google \ No newline at end of file +} // namespace google diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index 588394db..b30d1972 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -1309,4 +1309,4 @@ void Generator::CopyPublicDependenciesAliases( } // namespace python } // namespace compiler } // namespace protobuf -} // namespace google \ No newline at end of file +} // namespace google -- cgit v1.2.3