Merge pull request #1772 from jtattermusch/generator_fixes

Flush printers in protoc plugins properly
pull/1778/head
Nicolas Noble 10 years ago
commit f381f2596f
  1. 23
      src/compiler/cpp_generator.cc
  2. 4
      src/compiler/csharp_generator.cc
  3. 6
      src/compiler/objective_c_generator.cc
  4. 5
      src/compiler/ruby_generator.cc

@ -86,6 +86,8 @@ grpc::string FilenameIdentifier(const grpc::string &filename) {
grpc::string GetHeaderPrologue(const grpc::protobuf::FileDescriptor *file, grpc::string GetHeaderPrologue(const grpc::protobuf::FileDescriptor *file,
const Parameters &params) { const Parameters &params) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$'); grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars; std::map<grpc::string, grpc::string> vars;
@ -102,7 +104,7 @@ grpc::string GetHeaderPrologue(const grpc::protobuf::FileDescriptor *file,
printer.Print(vars, "\n"); printer.Print(vars, "\n");
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); printer.Print(vars, "#include \"$filename_base$.pb.h\"\n");
printer.Print(vars, "\n"); printer.Print(vars, "\n");
}
return output; return output;
} }
@ -626,6 +628,8 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer,
grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file, grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file,
const Parameters &params) { const Parameters &params) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$'); grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars; std::map<grpc::string, grpc::string> vars;
@ -643,13 +647,15 @@ grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file,
if (!params.services_namespace.empty()) { if (!params.services_namespace.empty()) {
printer.Print(vars, "} // namespace $services_namespace$\n\n"); printer.Print(vars, "} // namespace $services_namespace$\n\n");
} }
}
return output; return output;
} }
grpc::string GetHeaderEpilogue(const grpc::protobuf::FileDescriptor *file, grpc::string GetHeaderEpilogue(const grpc::protobuf::FileDescriptor *file,
const Parameters &params) { const Parameters &params) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$'); grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars; std::map<grpc::string, grpc::string> vars;
@ -670,13 +676,15 @@ grpc::string GetHeaderEpilogue(const grpc::protobuf::FileDescriptor *file,
printer.Print(vars, "\n"); printer.Print(vars, "\n");
printer.Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n"); printer.Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n");
}
return output; return output;
} }
grpc::string GetSourcePrologue(const grpc::protobuf::FileDescriptor *file, grpc::string GetSourcePrologue(const grpc::protobuf::FileDescriptor *file,
const Parameters &params) { const Parameters &params) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$'); grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars; std::map<grpc::string, grpc::string> vars;
@ -690,13 +698,15 @@ grpc::string GetSourcePrologue(const grpc::protobuf::FileDescriptor *file,
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); printer.Print(vars, "#include \"$filename_base$.pb.h\"\n");
printer.Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); printer.Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n");
printer.Print(vars, "\n"); printer.Print(vars, "\n");
}
return output; return output;
} }
grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file, grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file,
const Parameters &param) { const Parameters &param) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$'); grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars; std::map<grpc::string, grpc::string> vars;
@ -719,7 +729,7 @@ grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file,
} }
printer.Print(vars, "\n"); printer.Print(vars, "\n");
}
return output; return output;
} }
@ -1077,6 +1087,8 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer,
grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file, grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file,
const Parameters &params) { const Parameters &params) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$'); grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars; std::map<grpc::string, grpc::string> vars;
@ -1098,6 +1110,7 @@ grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file,
PrintSourceService(&printer, file->service(i), &vars); PrintSourceService(&printer, file->service(i), &vars);
printer.Print("\n"); printer.Print("\n");
} }
}
return output; return output;
} }

@ -474,6 +474,9 @@ void GenerateService(Printer* out, const ServiceDescriptor *service) {
grpc::string GetServices(const FileDescriptor *file) { grpc::string GetServices(const FileDescriptor *file) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
StringOutputStream output_stream(&output); StringOutputStream output_stream(&output);
Printer out(&output_stream, '$'); Printer out(&output_stream, '$');
@ -503,6 +506,7 @@ grpc::string GetServices(const FileDescriptor *file) {
out.Outdent(); out.Outdent();
out.Print("}\n"); out.Print("}\n");
out.Print("#endregion\n"); out.Print("#endregion\n");
}
return output; return output;
} }

@ -176,6 +176,8 @@ void PrintMethodImplementations(Printer *printer,
string GetHeader(const ServiceDescriptor *service, const string prefix) { string GetHeader(const ServiceDescriptor *service, const string prefix) {
string output; string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$'); Printer printer(&output_stream, '$');
@ -198,11 +200,14 @@ string GetHeader(const ServiceDescriptor *service, const string prefix) {
printer.Print("- (instancetype)initWithHost:(NSString *)host" printer.Print("- (instancetype)initWithHost:(NSString *)host"
" NS_DESIGNATED_INITIALIZER;\n"); " NS_DESIGNATED_INITIALIZER;\n");
printer.Print("@end\n"); printer.Print("@end\n");
}
return output; return output;
} }
string GetSource(const ServiceDescriptor *service, const string prefix) { string GetSource(const ServiceDescriptor *service, const string prefix) {
string output; string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$'); Printer printer(&output_stream, '$');
@ -235,6 +240,7 @@ string GetSource(const ServiceDescriptor *service, const string prefix) {
} }
printer.Print("@end\n"); printer.Print("@end\n");
}
return output; return output;
} }

@ -119,6 +119,9 @@ void PrintService(const ServiceDescriptor *service, const grpc::string &package,
grpc::string GetServices(const FileDescriptor *file) { grpc::string GetServices(const FileDescriptor *file) {
grpc::string output; grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
StringOutputStream output_stream(&output); StringOutputStream output_stream(&output);
Printer out(&output_stream, '$'); Printer out(&output_stream, '$');
@ -161,7 +164,7 @@ grpc::string GetServices(const FileDescriptor *file) {
out.Outdent(); out.Outdent();
out.Print("end\n"); out.Print("end\n");
} }
}
return output; return output;
} }

Loading…
Cancel
Save