Source code refactoring. Extracted common functionality in cpp_helpers.cc and python/python_generator.cc

pull/128/head
Krishna 10 years ago
parent 77931993f4
commit a761f061f4
  1. 20
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  2. 28
      src/google/protobuf/compiler/python/python_generator.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.

@ -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)

Loading…
Cancel
Save