aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler/objective_c_plugin.cc
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@google.com>2015-05-13 12:04:03 -0700
committerGravatar Jorge Canizales <jcanizales@google.com>2015-05-15 09:56:30 -0700
commit1a7918bc6e83db04822cafe06e69ee99a6d666c1 (patch)
tree65b798b9ccbc3ca8a7743d33f4c29d165cda009f /src/compiler/objective_c_plugin.cc
parent472f0b0a6b52119698197c221958af959f95d87f (diff)
Generate separate files until either of GeneratorContext::OpenForAppend/Insert work.
Diffstat (limited to 'src/compiler/objective_c_plugin.cc')
-rw-r--r--src/compiler/objective_c_plugin.cc67
1 files changed, 50 insertions, 17 deletions
diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc
index dec8594673..1fe382cfdb 100644
--- a/src/compiler/objective_c_plugin.cc
+++ b/src/compiler/objective_c_plugin.cc
@@ -39,44 +39,59 @@
#include "src/compiler/objective_c_generator.h"
#include "src/compiler/objective_c_generator_helpers.h"
+using ::grpc::string;
+
class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
public:
ObjectiveCGrpcGenerator() {}
virtual ~ObjectiveCGrpcGenerator() {}
virtual bool Generate(const grpc::protobuf::FileDescriptor *file,
- const grpc::string &parameter,
+ const string &parameter,
grpc::protobuf::compiler::GeneratorContext *context,
- grpc::string *error) const {
+ string *error) const {
if (file->service_count() == 0) {
// No services. Do nothing.
return true;
}
- grpc::string file_name = grpc_generator::FileNameInUpperCamel(file);
- grpc::string prefix = "RMT"; // TODO
+ string file_name = grpc_generator::FileNameInUpperCamel(file);
+ string prefix = "RMT"; // TODO
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor *service = file->service(i);
- // Generate .pb.h
+ {
+ // Generate .pbrpc.h
+
+ string imports = string("#import \"") + file_name + ".pbobjc.h\"\n"
+ "#import <gRPC/ProtoService.h>\n";
+ //Append(context, file_name + ".pbobjc.h",/* "imports",*/ imports);
- Insert(context, file_name + ".pbobjc.h", "imports",
- "#import <gRPC/ProtoService.h>\n");
+ string declarations =
+ grpc_objective_c_generator::GetHeader(service, prefix);
+ //Append(context, file_name + ".pbobjc.h",/* "global_scope",*/
+ // declarations);
- Insert(context, file_name + ".pbobjc.h", "global_scope",
- grpc_objective_c_generator::GetHeader(service, prefix));
+ Write(context, file_name + ".pbrpc.h", imports + declarations);
+ }
- // Generate .pb.m
+ {
+ // Generate .pbrpc.m
- Insert(context, file_name + ".pbobjc.m", "imports",
+ string imports = string("#import \"") + file_name + ".pbrpc.h\"\n"
"#import <gRPC/GRXWriteable.h>\n"
"#import <gRPC/GRXWriter+Immediate.h>\n"
- "#import <gRPC/ProtoRPC.h>\n");
-
- Insert(context, file_name + ".pbobjc.m", "global_scope",
- grpc_objective_c_generator::GetSource(service, prefix));
+ "#import <gRPC/ProtoRPC.h>\n";
+ //Append(context, file_name + ".pbobjc.m",/* "imports",*/ imports);
+
+ string definitions =
+ grpc_objective_c_generator::GetSource(service, prefix);
+ //Append(context, file_name + ".pbobjc.m",/* "global_scope",*/
+ // definitions);
+ Write(context, file_name + ".pbrpc.m", imports + definitions);
+ }
}
return true;
@@ -85,13 +100,31 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
private:
// Insert the given code into the given file at the given insertion point.
void Insert(grpc::protobuf::compiler::GeneratorContext *context,
- const grpc::string &filename, const grpc::string &insertion_point,
- const grpc::string &code) const {
+ const string &filename, const string &insertion_point,
+ const string &code) const {
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
context->OpenForInsert(filename, insertion_point));
grpc::protobuf::io::CodedOutputStream coded_out(output.get());
coded_out.WriteRaw(code.data(), code.size());
}
+
+ // Append the given code into the given file.
+ void Append(grpc::protobuf::compiler::GeneratorContext *context,
+ const string &filename, const string &code) const {
+ std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
+ context->OpenForAppend(filename));
+ grpc::protobuf::io::CodedOutputStream coded_out(output.get());
+ coded_out.WriteRaw(code.data(), code.size());
+ }
+
+ // Write the given code into the given file.
+ void Write(grpc::protobuf::compiler::GeneratorContext *context,
+ const string &filename, const string &code) const {
+ std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
+ context->Open(filename));
+ grpc::protobuf::io::CodedOutputStream coded_out(output.get());
+ coded_out.WriteRaw(code.data(), code.size());
+ }
};
int main(int argc, char *argv[]) {