[ObjC] Properly scope enum names to avoid naming collisions.

PiperOrigin-RevId: 566314136
pull/14121/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent f718cd8f61
commit 2e5b1e50c4
  1. 4
      src/google/protobuf/compiler/objectivec/enum.cc
  2. 4
      src/google/protobuf/compiler/objectivec/helpers.cc
  3. 12
      src/google/protobuf/compiler/objectivec/helpers.h
  4. 2
      src/google/protobuf/compiler/objectivec/message.cc

@ -103,7 +103,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) const {
}},
{"enum_values",
[&] {
CommentStringFlags comment_flags = CommentStringFlags::kNone;
CommentStringFlags comment_flags = kCommentStringFlags_None;
for (const auto* v : all_values_) {
if (alias_values_to_skip_.contains(v)) continue;
printer->Emit(
@ -120,7 +120,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) const {
$comments$
$name$$ deprecated_attribute$ = $value$,
)objc");
comment_flags = CommentStringFlags::kAddLeadingNewline;
comment_flags = kCommentStringFlags_AddLeadingNewline;
}
}},
},

@ -364,11 +364,11 @@ void EmitCommentsString(io::Printer* printer, const SourceLocation& location,
{"*/", "*\\/"}}));
}
if (flags & CommentStringFlags::kAddLeadingNewline) {
if (flags & kCommentStringFlags_AddLeadingNewline) {
printer->Emit("\n");
}
if ((flags & CommentStringFlags::kForceMultiline) == 0 && lines.size() == 1) {
if ((flags & kCommentStringFlags_ForceMultiline) == 0 && lines.size() == 1) {
printer->Emit({{"text", lines[0]}}, R"(
/** $text$ */
)");

@ -97,21 +97,23 @@ std::string ObjCClassDeclaration(absl::string_view class_name);
// Flag to control the behavior of `EmitCommentsString`.
enum CommentStringFlags : unsigned int {
kNone = 0,
kAddLeadingNewline = 1 << 1, // Add a newline before the comment.
kForceMultiline = 1 << 2, // Force a multiline comment even if only 1 line.
kCommentStringFlags_None = 0,
// Add a newline before the comment.
kCommentStringFlags_AddLeadingNewline = 1 << 1,
// Force a multiline comment even if only 1 line.
kCommentStringFlags_ForceMultiline = 1 << 2,
};
// Emits HeaderDoc/appledoc style comments out of the comments in the .proto
// file.
void EmitCommentsString(io::Printer* printer, const SourceLocation& location,
CommentStringFlags flags = kNone);
CommentStringFlags flags = kCommentStringFlags_None);
// Emits HeaderDoc/appledoc style comments out of the comments in the .proto
// file.
template <class TDescriptor>
void EmitCommentsString(io::Printer* printer, const TDescriptor* descriptor,
CommentStringFlags flags = kNone) {
CommentStringFlags flags = kCommentStringFlags_None) {
SourceLocation location;
if (descriptor->GetSourceLocation(&location)) {
EmitCommentsString(printer, location, flags);

@ -290,7 +290,7 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) const {
{"message_comments",
[&] {
EmitCommentsString(printer, descriptor_,
CommentStringFlags::kForceMultiline);
kCommentStringFlags_ForceMultiline);
}},
{"message_fieldnum_enum",
[&] {

Loading…
Cancel
Save