aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrishna <krishna.nm86@gmail.com>2014-12-10 20:39:34 +0100
committerKrishna <krishna.nm86@gmail.com>2014-12-10 20:39:34 +0100
commita761f061f4cc0e50324261cc1eb12526ae8783e3 (patch)
tree7a9dce2151b0ea3ea51a08e195d04adf12eab164
parent77931993f4fbb6f7e46327934e1f65c2b4f247eb (diff)
downloadprotobuf-a761f061f4cc0e50324261cc1eb12526ae8783e3.tar.gz
protobuf-a761f061f4cc0e50324261cc1eb12526ae8783e3.tar.bz2
protobuf-a761f061f4cc0e50324261cc1eb12526ae8783e3.zip
Source code refactoring. Extracted common functionality in cpp_helpers.cc and python/python_generator.cc
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_helpers.cc20
-rw-r--r--src/google/protobuf/compiler/python/python_generator.cc28
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)