aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Wouter van Oortmerssen <wvo@google.com>2016-04-13 18:18:08 -0700
committerGravatar Wouter van Oortmerssen <wvo@google.com>2016-04-25 17:46:20 -0700
commitb695b9b035472ee4ce7454eb7c8e3b8914021a27 (patch)
treea3bcad07ac9d3930a18eacd7f99df1bc91b1899d
parent241dea56c8f3688c17c01c96edb497ab89fce582 (diff)
Some additional fixes to make the C++ codegen not depend on protobuf.
-rw-r--r--src/compiler/cpp_generator.cc21
-rw-r--r--src/compiler/cpp_generator.h3
-rw-r--r--src/compiler/cpp_plugin.cc5
3 files changed, 19 insertions, 10 deletions
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc
index b133699306..9319c41934 100644
--- a/src/compiler/cpp_generator.cc
+++ b/src/compiler/cpp_generator.cc
@@ -86,7 +86,7 @@ void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, c
}
}
-grpc::string GetHeaderPrologue(File *file, const Parameters &params) {
+grpc::string GetHeaderPrologue(File *file, const Parameters & /*params*/) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -96,6 +96,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters &params) {
vars["filename"] = file->filename();
vars["filename_identifier"] = FilenameIdentifier(file->filename());
vars["filename_base"] = file->filename_without_ext();
+ vars["message_header_ext"] = file->message_header_ext();
printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n");
printer->Print(vars,
@@ -104,7 +105,7 @@ grpc::string GetHeaderPrologue(File *file, const Parameters &params) {
printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n");
printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n");
printer->Print(vars, "\n");
- printer->Print(vars, "#include \"$filename_base$.pb.h\"\n");
+ printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
printer->Print(vars, "\n");
}
return output;
@@ -794,8 +795,7 @@ grpc::string GetHeaderServices(File *file,
return output;
}
-grpc::string GetHeaderEpilogue(File *file,
- const Parameters &params) {
+grpc::string GetHeaderEpilogue(File *file, const Parameters & /*params*/) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -821,8 +821,7 @@ grpc::string GetHeaderEpilogue(File *file,
return output;
}
-grpc::string GetSourcePrologue(File *file,
- const Parameters &params) {
+grpc::string GetSourcePrologue(File *file, const Parameters & /*params*/) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -831,13 +830,16 @@ grpc::string GetSourcePrologue(File *file,
vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext();
+ vars["message_header_ext"] = file->message_header_ext();
+ vars["service_header_ext"] = file->service_header_ext();
printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n");
printer->Print(vars,
"// If you make any local change, they will be lost.\n");
printer->Print(vars, "// source: $filename$\n\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$$message_header_ext$\"\n");
+ printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
+ printer->Print(vars, file->additional_headers().c_str());
printer->Print(vars, "\n");
}
return output;
@@ -1180,8 +1182,7 @@ grpc::string GetSourceServices(File *file,
return output;
}
-grpc::string GetSourceEpilogue(File *file,
- const Parameters &params) {
+grpc::string GetSourceEpilogue(File *file, const Parameters & /*params*/) {
grpc::string temp;
if (!file->package().empty()) {
diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h
index 99a60a2eae..953ddfd569 100644
--- a/src/compiler/cpp_generator.h
+++ b/src/compiler/cpp_generator.h
@@ -106,8 +106,11 @@ struct File {
virtual grpc::string filename() const = 0;
virtual grpc::string filename_without_ext() const = 0;
+ virtual grpc::string message_header_ext() const = 0;
+ virtual grpc::string service_header_ext() const = 0;
virtual grpc::string package() const = 0;
virtual std::vector<grpc::string> package_parts() const = 0;
+ virtual grpc::string additional_headers() const = 0;
virtual int service_count() const = 0;
virtual std::unique_ptr<const Service> service(int i) const = 0;
diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc
index f703c6453d..e321c64639 100644
--- a/src/compiler/cpp_plugin.cc
+++ b/src/compiler/cpp_plugin.cc
@@ -120,11 +120,16 @@ class ProtoBufFile : public grpc_cpp_generator::File {
return grpc_generator::StripProto(filename());
}
+ grpc::string message_header_ext() const { return ".pb.h"; }
+ grpc::string service_header_ext() const { return ".grpc.pb.h"; }
+
grpc::string package() const { return file_->package(); }
std::vector<grpc::string> package_parts() const {
return grpc_generator::tokenize(package(), ".");
}
+ grpc::string additional_headers() const { return ""; }
+
int service_count() const { return file_->service_count(); };
std::unique_ptr<const grpc_cpp_generator::Service> service(int i) const {
return std::unique_ptr<const grpc_cpp_generator::Service> (