Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous cleanups of protobuf generator plugin #405

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions core/generator/Generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,20 @@

#include "Generator.hh"

namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {

/////////////////////////////////////////////////
void replaceAll(std::string &_src, const std::string &_oldValue,
const std::string &_newValue)
{
for (size_t i = 0; (i = _src.find(_oldValue, i)) != std::string::npos;)
{
_src.replace(i, _oldValue.length(), _newValue);
i += _newValue.length() - _oldValue.length() + 1;
}
}
namespace google::protobuf::compiler::cpp {

/////////////////////////////////////////////////
std::vector<std::string> getNamespaces(const std::string &_package)
{
std::vector<std::string> result;
std::stringstream ss(_package);
std::string item;
while (getline (ss, item, '.')) {
result.push_back (item);
while(getline (ss, item, '.')) {
result.push_back(item);
}
return result;
}


/////////////////////////////////////////////////
Generator::Generator(const std::string &/*_name*/)
{
Expand Down Expand Up @@ -102,16 +87,14 @@ bool Generator::Generate(const FileDescriptor *_file,
std::string identifier;
std::string headerFilename;
std::string newHeaderFilename;
std::string sourceFilename;

// Can't use pathJoin because protoc always expects forward slashes
// regardless of platform
for (auto part : parent_path)
for (const auto &part : parent_path)
{
identifier += part.string() + "_";
headerFilename += part.string() + "/";
newHeaderFilename += part.string() + "/";
sourceFilename += part.string() + "/";
}

std::unique_ptr<io::ZeroCopyOutputStream> message_type_index(
Expand All @@ -121,7 +104,6 @@ bool Generator::Generate(const FileDescriptor *_file,
identifier += fileStem;
headerFilename += fileStem + ".gz.h";
newHeaderFilename += "details/" + fileStem + ".pb.h";
sourceFilename += fileStem + ".pb.cc";

std::map<std::string, std::string> variables;
variables["filename"] = _file->name();
Expand Down Expand Up @@ -154,7 +136,7 @@ bool Generator::Generate(const FileDescriptor *_file,

for (auto i = 0; i < _file->message_type_count(); ++i)
{
auto desc = _file->message_type(i);
const auto *desc = _file->message_type(i);
std::string ptrTypes;

indexPrinter.PrintRaw(desc->name());
Expand Down Expand Up @@ -195,7 +177,4 @@ bool Generator::Generate(const FileDescriptor *_file,

return true;
}
}
}
}
}
} // namespace google::protobuf::compiler::cpp