Source code refactoring. Extracted common functionality in cpp_helpers.cc and python/python_generator.cc
This commit is contained in:
parent
77931993f4
commit
a761f061f4
@ -361,18 +361,26 @@ string FilenameIdentifier(const string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the name of the AddDescriptors() function for a given file.
|
// Return the name of the AddDescriptors() function for a given file.
|
||||||
string GlobalAddDescriptorsName(const string& filename) {
|
string GlobalAddDescriptorsName(const string& filename)
|
||||||
return "protobuf_AddDesc_" + FilenameIdentifier(filename);
|
{
|
||||||
|
return GlobalSymbolName(filename,"protobuf_AddDesc_");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the name of the AssignDescriptors() function for a given file.
|
// Return the name of the AssignDescriptors() function for a given file.
|
||||||
string GlobalAssignDescriptorsName(const string& filename) {
|
string GlobalAssignDescriptorsName(const string& filename)
|
||||||
return "protobuf_AssignDesc_" + FilenameIdentifier(filename);
|
{
|
||||||
|
return GlobalSymbolName(filename,"protobuf_AssignDesc_");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the name of the ShutdownFile() function for a given file.
|
// Return the name of the ShutdownFile() function for a given file.
|
||||||
string GlobalShutdownFileName(const string& filename) {
|
string GlobalShutdownFileName(const string& filename)
|
||||||
return "protobuf_ShutdownFile_" + FilenameIdentifier(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.
|
// Return the qualified C++ name for a file level symbol.
|
||||||
|
@ -580,11 +580,9 @@ void Generator::PrintServiceDescriptor(
|
|||||||
printer_->Print("])\n\n");
|
printer_->Print("])\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const {
|
|
||||||
// Print the service.
|
void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor, string keyandmodule) {
|
||||||
printer_->Print("$class_name$ = service_reflection.GeneratedServiceType("
|
printer_->Print(keyandmodule,"class_name", descriptor.name());
|
||||||
"'$class_name$', (_service.Service,), dict(\n",
|
|
||||||
"class_name", descriptor.name());
|
|
||||||
printer_->Indent();
|
printer_->Indent();
|
||||||
printer_->Print(
|
printer_->Print(
|
||||||
"$descriptor_key$ = $descriptor_name$,\n",
|
"$descriptor_key$ = $descriptor_name$,\n",
|
||||||
@ -597,22 +595,12 @@ void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const {
|
|||||||
printer_->Outdent();
|
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 {
|
void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const {
|
||||||
// Print the service stub.
|
Generator::PrintDescriptorKeyAndModuleName(descriptor, "$class_name$ = service_reflection.GeneratedServiceType('$class_name$', (_service.Service,), dict(\n");
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints statement assigning ModuleLevelDescriptorName(message_descriptor)
|
// Prints statement assigning ModuleLevelDescriptorName(message_descriptor)
|
||||||
|
Loading…
Reference in New Issue
Block a user