Avoid all leading/trailing doc comments during codegen tests.

Prototiller has subtley different rules about attaching these to objects, and relatively harmless transformations can cause codegen diffs where these move around.

PiperOrigin-RevId: 608648976
pull/15875/head
Mike Kruskal 12 months ago committed by Copybara-Service
parent d9f37f7757
commit 038007e748
  1. 14
      src/google/protobuf/compiler/objectivec/enum.cc
  2. 1
      src/google/protobuf/compiler/objectivec/enum.h
  3. 6
      src/google/protobuf/compiler/objectivec/extension.cc
  4. 1
      src/google/protobuf/compiler/objectivec/extension.h
  5. 19
      src/google/protobuf/compiler/objectivec/field.cc
  6. 1
      src/google/protobuf/compiler/objectivec/field.h
  7. 9
      src/google/protobuf/compiler/objectivec/helpers.cc
  8. 9
      src/google/protobuf/compiler/objectivec/helpers.h
  9. 2
      src/google/protobuf/compiler/objectivec/message.cc
  10. 9
      src/google/protobuf/compiler/objectivec/oneof.cc
  11. 1
      src/google/protobuf/compiler/objectivec/oneof.h

@ -39,7 +39,9 @@ std::string SafelyPrintIntToCode(int v) {
EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,
const GenerationOptions& generation_options)
: descriptor_(descriptor), name_(EnumName(descriptor_)) {
: descriptor_(descriptor),
generation_options_(generation_options),
name_(EnumName(descriptor_)) {
// Track the names for the enum values, and if an alias overlaps a base
// value, skip making a name for it. Likewise if two alias overlap, the
// first one wins.
@ -86,7 +88,10 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) const {
printer->Emit(
{
{"enum_name", name_},
{"enum_comments", [&] { EmitCommentsString(printer, descriptor_); }},
{"enum_comments",
[&] {
EmitCommentsString(printer, generation_options_, descriptor_);
}},
{"enum_deprecated_attribute",
GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file())},
{"maybe_unknown_value",
@ -112,7 +117,10 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) const {
{
{"name", EnumValueName(v)},
{"comments",
[&] { EmitCommentsString(printer, v, comment_flags); }},
[&] {
EmitCommentsString(printer, generation_options_, v,
comment_flags);
}},
{"deprecated_attribute",
GetOptionalDeprecatedAttribute(v)},
{"value", SafelyPrintIntToCode(v->number())},

@ -37,6 +37,7 @@ class EnumGenerator {
private:
const EnumDescriptor* descriptor_;
const GenerationOptions& generation_options_;
std::vector<const EnumValueDescriptor*> base_values_;
std::vector<const EnumValueDescriptor*> all_values_;
absl::flat_hash_set<const EnumValueDescriptor*> alias_values_to_skip_;

@ -34,7 +34,8 @@ ExtensionGenerator::ExtensionGenerator(
: method_name_(ExtensionMethodName(descriptor)),
full_method_name_(
absl::StrCat(root_or_message_class_name, "_", method_name_)),
descriptor_(descriptor) {
descriptor_(descriptor),
generation_options_(generation_options) {
ABSL_CHECK(!descriptor->is_map())
<< "error: Extension is a map<>!"
<< " That used to be blocked by the compiler.";
@ -43,7 +44,8 @@ ExtensionGenerator::ExtensionGenerator(
void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) const {
printer->Emit(
{{"method_name", method_name_},
{"comments", [&] { EmitCommentsString(printer, descriptor_); }},
{"comments",
[&] { EmitCommentsString(printer, generation_options_, descriptor_); }},
{"storage_attribute",
IsRetainedName(method_name_) ? "NS_RETURNS_NOT_RETAINED" : ""},
{"deprecated_attribute",

@ -44,6 +44,7 @@ class ExtensionGenerator {
std::string method_name_;
std::string full_method_name_;
const FieldDescriptor* descriptor_;
const GenerationOptions& generation_options_;
};
} // namespace objectivec

@ -192,7 +192,7 @@ FieldGenerator* FieldGenerator::Make(
FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor,
const GenerationOptions& generation_options)
: descriptor_(descriptor) {
: descriptor_(descriptor), generation_options_(generation_options) {
SetCommonFieldVariables(descriptor, &variables_);
}
@ -294,8 +294,11 @@ void SingleFieldGenerator::GenerateFieldStorageDeclaration(
void SingleFieldGenerator::GeneratePropertyDeclaration(
io::Printer* printer) const {
auto vars = printer->WithVars(variables_);
printer->Emit(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
printer->Emit({{"comments",
[&] {
EmitCommentsString(printer, generation_options_,
descriptor_);
}}},
R"objc(
$comments$
@property(nonatomic, readwrite) $property_type$$name$$ deprecated_attribute$;
@ -349,8 +352,11 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
// conventions (init*, new*, etc.)
auto vars = printer->WithVars(variables_);
printer->Emit(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
printer->Emit({{"comments",
[&] {
EmitCommentsString(printer, generation_options_,
descriptor_);
}}},
R"objc(
$comments$
@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$$name$$storage_attribute$$ deprecated_attribute$;
@ -398,7 +404,8 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
auto vars = printer->WithVars(variables_);
printer->Emit(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }},
{{"comments",
[&] { EmitCommentsString(printer, generation_options_, descriptor_); }},
{"array_comment", [&] { EmitArrayComment(printer); }}},
R"objc(
$comments$

@ -88,6 +88,7 @@ class FieldGenerator {
bool WantsHasProperty() const;
const FieldDescriptor* descriptor_;
const GenerationOptions& generation_options_;
absl::flat_hash_map<absl::string_view, std::string> variables_;
};

@ -24,6 +24,7 @@
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/compiler/objectivec/options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/strtod.h"
#include "google/protobuf/stubs/common.h"
@ -331,8 +332,14 @@ std::string ObjCClassDeclaration(absl::string_view class_name) {
return absl::StrCat("GPBObjCClassDeclaration(", class_name, ");");
}
void EmitCommentsString(io::Printer* printer, const SourceLocation& location,
void EmitCommentsString(io::Printer* printer, const GenerationOptions& opts,
const SourceLocation& location,
CommentStringFlags flags) {
if (opts.experimental_strip_nonfunctional_codegen) {
// Comments are inherently non-functional, and may change subtly on
// transformations.
return;
}
absl::string_view comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;

@ -15,6 +15,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/objectivec/options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"
@ -106,17 +107,19 @@ enum CommentStringFlags : unsigned int {
// Emits HeaderDoc/appledoc style comments out of the comments in the .proto
// file.
void EmitCommentsString(io::Printer* printer, const SourceLocation& location,
void EmitCommentsString(io::Printer* printer, const GenerationOptions& opts,
const SourceLocation& location,
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,
void EmitCommentsString(io::Printer* printer, const GenerationOptions& opts,
const TDescriptor* descriptor,
CommentStringFlags flags = kCommentStringFlags_None) {
SourceLocation location;
if (descriptor->GetSourceLocation(&location)) {
EmitCommentsString(printer, location, flags);
EmitCommentsString(printer, opts, location, flags);
}
}

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

@ -23,7 +23,7 @@ namespace objectivec {
OneofGenerator::OneofGenerator(const OneofDescriptor* descriptor,
const GenerationOptions& generation_options)
: descriptor_(descriptor) {
: descriptor_(descriptor), generation_options_(generation_options) {
variables_["enum_name"] = OneofEnumName(descriptor_);
variables_["name"] = OneofName(descriptor_);
variables_["capitalized_name"] = OneofNameCapitalized(descriptor_);
@ -64,8 +64,11 @@ void OneofGenerator::GenerateCaseEnum(io::Printer* printer) const {
void OneofGenerator::GeneratePublicCasePropertyDeclaration(
io::Printer* printer) const {
auto vars = printer->WithVars(variables_);
printer->Emit(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
printer->Emit({{"comments",
[&] {
EmitCommentsString(printer, generation_options_,
descriptor_);
}}},
R"objc(
$comments$;
@property(nonatomic, readonly) $enum_name$ $name$OneOfCase;

@ -45,6 +45,7 @@ class OneofGenerator {
private:
const OneofDescriptor* descriptor_;
const GenerationOptions& generation_options_;
absl::flat_hash_map<absl::string_view, std::string> variables_;
};

Loading…
Cancel
Save