Skip to content

Commit

Permalink
Miscellaneous cleanups of protobuf generator plugin (#405)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Oct 30, 2023
1 parent 8021595 commit 25759b6
Showing 1 changed file with 6 additions and 27 deletions.
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

0 comments on commit 25759b6

Please sign in to comment.