Skip to content

Commit

Permalink
When the proto file does not contain a package, do not generate names…
Browse files Browse the repository at this point in the history
…pace
  • Loading branch information
yang-g committed Apr 10, 2015
1 parent 0a43b34 commit 1dc1a43
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/compiler/cpp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,18 @@ grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file,

temp.append("\n");

std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");
if (!file->package().empty()) {
std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");

for (auto part = parts.begin(); part != parts.end(); part++) {
temp.append("namespace ");
temp.append(*part);
temp.append(" {\n");
for (auto part = parts.begin(); part != parts.end(); part++) {
temp.append("namespace ");
temp.append(*part);
temp.append(" {\n");
}
temp.append("\n");
}

temp.append("\n");

return temp;
}

Expand Down Expand Up @@ -431,15 +432,18 @@ grpc::string GetHeaderEpilogue(const grpc::protobuf::FileDescriptor *file,
vars["filename"] = file->name();
vars["filename_identifier"] = FilenameIdentifier(file->name());

std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");
if (!file->package().empty()) {
std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");

for (auto part = parts.rbegin(); part != parts.rend(); part++) {
vars["part"] = *part;
printer.Print(vars, "} // namespace $part$\n");
for (auto part = parts.rbegin(); part != parts.rend(); part++) {
vars["part"] = *part;
printer.Print(vars, "} // namespace $part$\n");
}
printer.Print(vars, "\n");
}

printer.Print(vars, "\n\n");
printer.Print(vars, "\n");
printer.Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n");

return output;
Expand Down Expand Up @@ -480,12 +484,14 @@ grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file,
printer.Print(vars, "#include <grpc++/impl/service_type.h>\n");
printer.Print(vars, "#include <grpc++/stream.h>\n");

std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");
if (!file->package().empty()) {
std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");

for (auto part = parts.begin(); part != parts.end(); part++) {
vars["part"] = *part;
printer.Print(vars, "namespace $part$ {\n");
for (auto part = parts.begin(); part != parts.end(); part++) {
vars["part"] = *part;
printer.Print(vars, "namespace $part$ {\n");
}
}

printer.Print(vars, "\n");
Expand Down Expand Up @@ -860,17 +866,18 @@ grpc::string GetSourceEpilogue(const grpc::protobuf::FileDescriptor *file,
const Parameters &params) {
grpc::string temp;

std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");
if (!file->package().empty()) {
std::vector<grpc::string> parts =
grpc_generator::tokenize(file->package(), ".");

for (auto part = parts.begin(); part != parts.end(); part++) {
temp.append("} // namespace ");
temp.append(*part);
for (auto part = parts.begin(); part != parts.end(); part++) {
temp.append("} // namespace ");
temp.append(*part);
temp.append("\n");
}
temp.append("\n");
}

temp.append("\n");

return temp;
}

Expand Down

0 comments on commit 1dc1a43

Please sign in to comment.