Upgrade linux protobuf

This commit is contained in:
John Colvin committed 2021-12-12 15:56:55 -05:00
1 parent 79f2f356d5
commit 0f3130fb47
689 files changed
+141922 -132057

No files matched your search

@@ -36,6 +36,7 @@
#include <vector>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
@@ -44,13 +45,13 @@ namespace protobuf {
namespace compiler {
namespace java {
string EscapeJavadoc(const string& input) {
string result;
std::string EscapeJavadoc(const std::string& input) {
std::string result;
result.reserve(input.size() * 2);
char prev = '*';
for (string::size_type i = 0; i < input.size(); i++) {
for (std::string::size_type i = 0; i < input.size(); i++) {
char c = input[i];
switch (c) {
case '*':
@@ -102,10 +103,11 @@ string EscapeJavadoc(const string& input) {
return result;
}
static void WriteDocCommentBodyForLocation(
io::Printer* printer, const SourceLocation& location) {
string comments = location.leading_comments.empty() ?
location.trailing_comments : location.leading_comments;
static void WriteDocCommentBodyForLocation(io::Printer* printer,
const SourceLocation& location) {
std::string comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
if (!comments.empty()) {
// TODO(kenton): Ideally we should parse the comment text as Markdown and
// write it back as HTML, but this requires a Markdown parser. For now
@@ -115,7 +117,7 @@ static void WriteDocCommentBodyForLocation(
// HTML-escape them so that they don't accidentally close the doc comment.
comments = EscapeJavadoc(comments);
std::vector<string> lines = Split(comments, "\n");
std::vector<std::string> lines = Split(comments, "\n");
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
@@ -138,19 +140,19 @@ static void WriteDocCommentBodyForLocation(
}
template <typename DescriptorType>
static void WriteDocCommentBody(
io::Printer* printer, const DescriptorType* descriptor) {
static void WriteDocCommentBody(io::Printer* printer,
const DescriptorType* descriptor) {
SourceLocation location;
if (descriptor->GetSourceLocation(&location)) {
WriteDocCommentBodyForLocation(printer, location);
}
}
static string FirstLineOf(const string& value) {
string result = value;
static std::string FirstLineOf(const std::string& value) {
std::string result = value;
string::size_type pos = result.find_first_of('\n');
if (pos != string::npos) {
std::string::size_type pos = result.find_first_of('\n');
if (pos != std::string::npos) {
result.erase(pos);
}
@@ -166,35 +168,235 @@ void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) {
printer->Print("/**\n");
WriteDocCommentBody(printer, message);
printer->Print(
" * Protobuf type {@code $fullname$}\n"
" */\n",
"fullname", EscapeJavadoc(message->full_name()));
" * Protobuf type {@code $fullname$}\n"
" */\n",
"fullname", EscapeJavadoc(message->full_name()));
}
void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) {
// In theory we should have slightly different comments for setters, getters,
// etc., but in practice everyone already knows the difference between these
// so it's redundant information.
// We start the comment with the main body based on the comments from the
// .proto file (if present). We then end with the field declaration, e.g.:
// .proto file (if present). We then continue with the field declaration,
// e.g.:
// optional string foo = 5;
// And then we end with the javadoc tags if applicable.
// If the field is a group, the debug string might end with {.
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(
" * <code>$def$</code>\n",
"def", EscapeJavadoc(FirstLineOf(field->DebugString())));
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
printer->Print(" */\n");
}
void WriteDeprecatedJavadoc(io::Printer* printer, const FieldDescriptor* field,
const FieldAccessorType type) {
if (!field->options().deprecated()) {
return;
}
// Lite codegen does not annotate set & clear methods with @Deprecated.
if (field->file()->options().optimize_for() == FileOptions::LITE_RUNTIME &&
(type == SETTER || type == CLEARER)) {
return;
}
printer->Print(" * @deprecated\n");
}
void WriteFieldAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
WriteDeprecatedJavadoc(printer, field, type);
switch (type) {
case HAZZER:
printer->Print(" * @return Whether the $name$ field is set.\n", "name",
field->camelcase_name());
break;
case GETTER:
printer->Print(" * @return The $name$.\n", "name",
field->camelcase_name());
break;
case SETTER:
printer->Print(" * @param value The $name$ to set.\n", "name",
field->camelcase_name());
break;
case CLEARER:
// Print nothing
break;
// Repeated
case LIST_COUNT:
printer->Print(" * @return The count of $name$.\n", "name",
field->camelcase_name());
break;
case LIST_GETTER:
printer->Print(" * @return A list containing the $name$.\n", "name",
field->camelcase_name());
break;
case LIST_INDEXED_GETTER:
printer->Print(" * @param index The index of the element to return.\n");
printer->Print(" * @return The $name$ at the given index.\n", "name",
field->camelcase_name());
break;
case LIST_INDEXED_SETTER:
printer->Print(" * @param index The index to set the value at.\n");
printer->Print(" * @param value The $name$ to set.\n", "name",
field->camelcase_name());
break;
case LIST_ADDER:
printer->Print(" * @param value The $name$ to add.\n", "name",
field->camelcase_name());
break;
case LIST_MULTI_ADDER:
printer->Print(" * @param values The $name$ to add.\n", "name",
field->camelcase_name());
break;
}
if (builder) {
printer->Print(" * @return This builder for chaining.\n");
}
printer->Print(" */\n");
}
void WriteFieldEnumValueAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
WriteDeprecatedJavadoc(printer, field, type);
switch (type) {
case HAZZER:
// Should never happen
break;
case GETTER:
printer->Print(
" * @return The enum numeric value on the wire for $name$.\n", "name",
field->camelcase_name());
break;
case SETTER:
printer->Print(
" * @param value The enum numeric value on the wire for $name$ to "
"set.\n",
"name", field->camelcase_name());
break;
case CLEARER:
// Print nothing
break;
// Repeated
case LIST_COUNT:
// Should never happen
break;
case LIST_GETTER:
printer->Print(
" * @return A list containing the enum numeric values on the wire "
"for $name$.\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_GETTER:
printer->Print(" * @param index The index of the value to return.\n");
printer->Print(
" * @return The enum numeric value on the wire of $name$ at the "
"given index.\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_SETTER:
printer->Print(" * @param index The index to set the value at.\n");
printer->Print(
" * @param value The enum numeric value on the wire for $name$ to "
"set.\n",
"name", field->camelcase_name());
break;
case LIST_ADDER:
printer->Print(
" * @param value The enum numeric value on the wire for $name$ to "
"add.\n",
"name", field->camelcase_name());
break;
case LIST_MULTI_ADDER:
printer->Print(
" * @param values The enum numeric values on the wire for $name$ to "
"add.\n",
"name", field->camelcase_name());
break;
}
if (builder) {
printer->Print(" * @return This builder for chaining.\n");
}
printer->Print(" */\n");
}
void WriteFieldStringBytesAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
WriteDeprecatedJavadoc(printer, field, type);
switch (type) {
case HAZZER:
// Should never happen
break;
case GETTER:
printer->Print(" * @return The bytes for $name$.\n", "name",
field->camelcase_name());
break;
case SETTER:
printer->Print(" * @param value The bytes for $name$ to set.\n", "name",
field->camelcase_name());
break;
case CLEARER:
// Print nothing
break;
// Repeated
case LIST_COUNT:
// Should never happen
break;
case LIST_GETTER:
printer->Print(" * @return A list containing the bytes for $name$.\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_GETTER:
printer->Print(" * @param index The index of the value to return.\n");
printer->Print(" * @return The bytes of the $name$ at the given index.\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_SETTER:
printer->Print(" * @param index The index to set the value at.\n");
printer->Print(" * @param value The bytes of the $name$ to set.\n",
"name", field->camelcase_name());
break;
case LIST_ADDER:
printer->Print(" * @param value The bytes of the $name$ to add.\n",
"name", field->camelcase_name());
break;
case LIST_MULTI_ADDER:
printer->Print(" * @param values The bytes of the $name$ to add.\n",
"name", field->camelcase_name());
break;
}
if (builder) {
printer->Print(" * @return This builder for chaining.\n");
}
printer->Print(" */\n");
}
// Enum
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) {
printer->Print("/**\n");
WriteDocCommentBody(printer, enum_);
printer->Print(
" * Protobuf enum {@code $fullname$}\n"
" */\n",
"fullname", EscapeJavadoc(enum_->full_name()));
" * Protobuf enum {@code $fullname$}\n"
" */\n",
"fullname", EscapeJavadoc(enum_->full_name()));
}
void WriteEnumValueDocComment(io::Printer* printer,
@@ -202,9 +404,9 @@ void WriteEnumValueDocComment(io::Printer* printer,
printer->Print("/**\n");
WriteDocCommentBody(printer, value);
printer->Print(
" * <code>$def$</code>\n"
" */\n",
"def", EscapeJavadoc(FirstLineOf(value->DebugString())));
" * <code>$def$</code>\n"
" */\n",
"def", EscapeJavadoc(FirstLineOf(value->DebugString())));
}
void WriteServiceDocComment(io::Printer* printer,
@@ -212,9 +414,9 @@ void WriteServiceDocComment(io::Printer* printer,
printer->Print("/**\n");
WriteDocCommentBody(printer, service);
printer->Print(
" * Protobuf service {@code $fullname$}\n"
" */\n",
"fullname", EscapeJavadoc(service->full_name()));
" * Protobuf service {@code $fullname$}\n"
" */\n",
"fullname", EscapeJavadoc(service->full_name()));
}
void WriteMethodDocComment(io::Printer* printer,
@@ -222,9 +424,9 @@ void WriteMethodDocComment(io::Printer* printer,
printer->Print("/**\n");
WriteDocCommentBody(printer, method);
printer->Print(
" * <code>$def$</code>\n"
" */\n",
"def", EscapeJavadoc(FirstLineOf(method->DebugString())));
" * <code>$def$</code>\n"
" */\n",
"def", EscapeJavadoc(FirstLineOf(method->DebugString())));
}
} // namespace java