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

Support newer versions of protobuf #434

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
protoc/*.o
protoc/*.cc
protoc/*.h
protoc/protoc-gen-lisp
protoc/protoc-gen-cl-pb
protoc/protoc_middleman
3 changes: 1 addition & 2 deletions protoc/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "enum.h"

#include <google/protobuf/stubs/strutil.h>
#include "proto2-descriptor-extensions.pb.h"
#include "names.h"
#include <google/protobuf/io/printer.h>
Expand Down Expand Up @@ -43,7 +42,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
for (int i = 0; i < descriptor_->value_count(); i++) {
printer->Print("\n(:$name$ :index $number$)", "name",
ToLispEnumValue(descriptor_->value(i)->name()), "number",
StrCat(descriptor_->value(i)->number()));
absl::StrCat(descriptor_->value(i)->number()));
printer->Annotate("name", descriptor_);
}
printer->Print(")");
Expand Down
28 changes: 13 additions & 15 deletions protoc/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
#include <map>

#include <cstdint>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/stubs/strutil.h>
#include "proto2-descriptor-extensions.pb.h"
#include "literals.h"
#include "names.h"
Expand Down Expand Up @@ -82,7 +80,7 @@ const std::string FieldLispType(const FieldDescriptor* field) {
type = "cl-protobufs:sint64";
break;
default:
GOOGLE_LOG(FATAL) << "Unsupported FileDescriptorType: "
ABSL_LOG(FATAL) << "Unsupported FileDescriptorType: "
<< field->DebugString();
break;
}
Expand Down Expand Up @@ -149,7 +147,7 @@ const std::string FieldLispKind(const FieldDescriptor* field) {
proto_kind = ":enum";
break;
default:
GOOGLE_LOG(FATAL) << "Unsupported FileDescriptorType: "
ABSL_LOG(FATAL) << "Unsupported FileDescriptorType: "
<< field->DebugString();
break;
}
Expand Down Expand Up @@ -178,7 +176,7 @@ const std::string FieldLispLabel(const FieldDescriptor* field) {
}
}

GOOGLE_LOG(FATAL) << "Error determining field arity: " << field->DebugString();
ABSL_LOG(FATAL) << "Error determining field arity: " << field->DebugString();
return "(:error)";
}

Expand All @@ -192,20 +190,20 @@ const std::string FieldLispDefault(const FieldDescriptor* field) {
return LispBool(field->default_value_bool());
case FieldDescriptor::CPPTYPE_ENUM: {
const EnumValueDescriptor* value = field->default_value_enum();
return StrCat(":", ToLispName(value->name()));
return absl::StrCat(":", ToLispName(value->name()));
}
case FieldDescriptor::CPPTYPE_INT32:
return StrCat(field->default_value_int32());
return absl::StrCat(field->default_value_int32());
case FieldDescriptor::CPPTYPE_UINT32:
return StrCat(field->default_value_uint32());
return absl::StrCat(field->default_value_uint32());
case FieldDescriptor::CPPTYPE_INT64:
return StrCat(field->default_value_int64());
return absl::StrCat(field->default_value_int64());
case FieldDescriptor::CPPTYPE_UINT64:
return StrCat(field->default_value_uint64());
return absl::StrCat(field->default_value_uint64());
case FieldDescriptor::CPPTYPE_STRING: {
switch (field->type()) {
case FieldDescriptor::TYPE_BYTES:
return StrCat(
return absl::StrCat(
"(cl:make-array ", field->default_value_string().size(),
" :element-type '(cl:unsigned-byte 8)", " :initial-contents '(",
StringOctets(field->default_value_string()), "))");
Expand All @@ -220,7 +218,7 @@ const std::string FieldLispDefault(const FieldDescriptor* field) {
// Unsupported by cl_protobufs.
// case FieldDescriptor::CPPTYPE_MESSAGE:
// Report errors as early as possible.
GOOGLE_LOG(FATAL) << "Unsupported FileDescriptorType: " << field->DebugString();
ABSL_LOG(FATAL) << "Unsupported FileDescriptorType: " << field->DebugString();
return "";
}
} // namespace
Expand All @@ -241,7 +239,7 @@ const std::string FieldLispName(const FieldDescriptor* field) {
void GenerateField(io::Printer* printer, const FieldDescriptor* field) {
std::map<std::string, std::string> vars;
vars["name"] = FieldLispName(field);
vars["tag"] = StrCat(field->number());
vars["tag"] = absl::StrCat(field->number());
vars["json-name"] = field->json_name();
if (field->is_map()) {
vars["key-type"] = FieldLispType(field->message_type()->field(0));
Expand All @@ -250,7 +248,7 @@ void GenerateField(io::Printer* printer, const FieldDescriptor* field) {
vars["val-default"]
= field->message_type()->field(1)->cpp_type()
== FieldDescriptor::CPPTYPE_ENUM ?
StrCat("\n :val-default ",
absl::StrCat("\n :val-default ",
FieldLispDefault(field->message_type()->field(1))) : "";
printer->Print(vars,
"\n(pi:define-map $name$\n"
Expand All @@ -268,7 +266,7 @@ void GenerateField(io::Printer* printer, const FieldDescriptor* field) {
vars["default"] = field->has_default_value() ||
(field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM &&
field->label() != FieldDescriptor::Label::LABEL_REPEATED)
? StrCat(" :default ", FieldLispDefault(field))
? absl::StrCat(" :default ", FieldLispDefault(field))
: "";
printer->Print(vars,
"\n($name$\n"
Expand Down
1 change: 0 additions & 1 deletion protoc/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <memory>
#include <set>

#include <google/protobuf/stubs/strutil.h>
#include "proto2-descriptor-extensions.pb.h"
#include "enum.h"
#include "field.h"
Expand Down
4 changes: 2 additions & 2 deletions protoc/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool LispGenerator::Generate(const FileDescriptor* file,
if (annotate) {
std::unique_ptr<io::ZeroCopyOutputStream> meta(
output_directory->Open(file_name + ".meta"));
GOOGLE_CHECK(annotations.SerializeToZeroCopyStream(meta.get()));
ABSL_CHECK(annotations.SerializeToZeroCopyStream(meta.get()));
}

return true;
Expand Down Expand Up @@ -132,7 +132,7 @@ bool LispGenerator::GenerateAll(const std::vector<const FileDescriptor*>& files,
if (annotate) {
std::unique_ptr<io::ZeroCopyOutputStream> meta(
context->Open(file_name + ".meta"));
GOOGLE_CHECK(annotations.SerializeToZeroCopyStream(meta.get()));
ABSL_CHECK(annotations.SerializeToZeroCopyStream(meta.get()));
}
return true;
}
Expand Down
11 changes: 5 additions & 6 deletions protoc/literals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
// https://opensource.org/licenses/MIT.

#include "literals.h"

#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/strtod.h>

namespace google {
namespace protobuf {
namespace cl_protobufs {

const std::string LispSimpleFtoa(float value) {
std::string result = SimpleFtoa(value);
std::string result = io::SimpleFtoa(value);
if (result == "inf") {
return "float-features:single-float-positive-infinity";
} else if (result == "-inf") {
Expand All @@ -32,7 +31,7 @@ const std::string LispSimpleFtoa(float value) {
}

const std::string LispSimpleDtoa(double value) {
std::string result = SimpleDtoa(value);
std::string result = io::SimpleDtoa(value);
if (result == "inf") {
return "float-features:double-float-positive-infinity";
} else if (result == "-inf") {
Expand Down Expand Up @@ -65,7 +64,7 @@ const std::string StringOctets(const std::string& str) {
std::string octets;
for (char c : str) {
if (!octets.empty()) octets += " ";
octets += StrCat(c & 0xff);
octets += absl::StrCat(c & 0xff);
}
return octets;
}
Expand Down
11 changes: 5 additions & 6 deletions protoc/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#include <set>
#include <unordered_set>

#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/io/strtod.h>
#include "proto2-descriptor-extensions.pb.h"
#include "enum.h"
#include "field.h"
Expand Down Expand Up @@ -158,15 +157,15 @@ void MessageGenerator::GenerateSource(io::Printer* printer,
printer->Print("\n;; Extension ranges");
for (int i = 0; i < descriptor_->extension_range_count(); ++i) {
const Descriptor::ExtensionRange* range = descriptor_->extension_range(i);
int start = range->start;
int end = range->end;
int start = range->start_;
int end = range->end_;
printer->Print(
"\n(pi:define-extension $start$ $end$)", "start", StrCat(start),
"\n(pi:define-extension $start$ $end$)", "start", absl::StrCat(start),
// The end is inclusive in cl_protobufs.
// For some reason, the extension number is generated as
// 0x7ffffffe when specified as 'max', but the max must be
// (2^29 - 1).
"end", StrCat(std::min(kMaxExtensionNumber, end - 1)));
"end", absl::StrCat(std::min(kMaxExtensionNumber, end - 1)));
}
}

Expand Down
19 changes: 13 additions & 6 deletions protoc/names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

#include <ctype.h>

#include <google/protobuf/stubs/macros.h>
#include <absl/strings/ascii.h>
#include <absl/strings/str_join.h>
#include <absl/strings/str_replace.h>
#include <absl/strings/str_split.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/stubs/strutil.h>
// #include <google/protobuf/stubs/str_join.h>
// #include <google/protobuf/stubs/str_replace.h>
#include "proto2-descriptor-extensions.pb.h"
Expand Down Expand Up @@ -49,6 +51,11 @@ CharType CharacterType(const char c) {
}
}

const std::string ToUpper(std::string s) {
absl::AsciiStrToUpper(&s);
return s;
}

const std::string NonDestructiveStrToLower(std::string s) {
StrToLower(&s);
return s;
Expand Down Expand Up @@ -145,8 +152,8 @@ const std::string EnumLispName(const EnumDescriptor* descriptor) {

const std::string ToLispEnumValue(const std::string& name) {
// Enum values are usually uppercase separated by underscore.
std::string v = StringReplace(name, "_", "-", true);
LowerString(&v);
std::string v = absl::StrReplaceAll(name, {{"_", "-"}});
StrToLower(&v);
return v;
}

Expand Down Expand Up @@ -222,8 +229,8 @@ bool CamelIsSpitting(const std::string& name) {
}

const std::string ToLispAliasSymbolName(const std::string& symbol_name) {
auto splitter = Split(symbol_name, ":", true);
return NonDestructiveStrToLower(Join(splitter, "::"));
auto splitter = absl::StrSplit(symbol_name, ":");
return NonDestructiveStrToLower(absl::StrJoin(splitter, "::"));
}

} // namespace cl_protobufs
Expand Down
1 change: 1 addition & 0 deletions protoc/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace google {
namespace protobuf {
namespace cl_protobufs {

const std::string ToUpper(std::string s);
const std::string NonDestructiveStrToLower(std::string s);

const void StrToLower(std::string* s);
Expand Down
16 changes: 7 additions & 9 deletions protoc/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#include "service.h"

#include <cstdint>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/message.h>
#include <google/protobuf/stubs/strutil.h>
#include "literals.h"
#include "names.h"
#include <google/protobuf/io/printer.h>
Expand Down Expand Up @@ -56,13 +54,13 @@ std::string MethodOptionValue(const MethodOptions& method_options,
const Reflection* reflection = method_options.GetReflection();
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return StrCat(reflection->GetInt32(method_options, field));
return absl::StrCat(reflection->GetInt32(method_options, field));
case FieldDescriptor::CPPTYPE_INT64:
return StrCat(reflection->GetInt64(method_options, field));
return absl::StrCat(reflection->GetInt64(method_options, field));
case FieldDescriptor::CPPTYPE_UINT32:
return StrCat(reflection->GetUInt32(method_options, field));
return absl::StrCat(reflection->GetUInt32(method_options, field));
case FieldDescriptor::CPPTYPE_UINT64:
return StrCat(reflection->GetUInt64(method_options, field));
return absl::StrCat(reflection->GetUInt64(method_options, field));
case FieldDescriptor::CPPTYPE_DOUBLE:
return LispSimpleDtoa(reflection->GetDouble(method_options, field));
case FieldDescriptor::CPPTYPE_FLOAT:
Expand All @@ -72,12 +70,12 @@ std::string MethodOptionValue(const MethodOptions& method_options,
case FieldDescriptor::CPPTYPE_ENUM: {
const EnumValueDescriptor* value =
reflection->GetEnum(method_options, field);
return StrCat(":", ToLispName(value->name()));
return absl::StrCat(":", ToLispName(value->name()));
}
case FieldDescriptor::CPPTYPE_STRING:
return LispEscapeString(reflection->GetString(method_options, field));
case FieldDescriptor::CPPTYPE_MESSAGE:
GOOGLE_LOG(FATAL) << "Unsupported method option: " << field->name();
ABSL_LOG(FATAL) << "Unsupported method option: " << field->name();
}
return "";
}
Expand All @@ -93,7 +91,7 @@ void GenerateMethodOptions(io::Printer* printer,
continue;
}
// Currently every non-custom method option is non-repeated.
GOOGLE_CHECK(!field->is_repeated());
ABSL_CHECK(!field->is_repeated());
if (method_options.GetReflection()->HasField(method_options, field)) {
options.emplace_back(LispEscapeString(field->name()));
options.emplace_back(MethodOptionValue(method_options, field));
Expand Down
Loading