Rename FieldBeneratorBase::descriptor_ to field_.

PiperOrigin-RevId: 608825012
pull/15900/head
Protobuf Team Bot 9 months ago committed by Copybara-Service
parent b653a64514
commit 1f701a2ba9
  1. 56
      src/google/protobuf/compiler/cpp/field.cc
  2. 6
      src/google/protobuf/compiler/cpp/field.h
  3. 28
      src/google/protobuf/compiler/cpp/field_generators/cord_field.cc
  4. 5
      src/google/protobuf/compiler/cpp/field_generators/enum_field.cc
  5. 2
      src/google/protobuf/compiler/cpp/field_generators/map_field.cc
  6. 4
      src/google/protobuf/compiler/cpp/field_generators/message_field.cc
  7. 16
      src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc
  8. 6
      src/google/protobuf/compiler/cpp/field_generators/string_field.cc
  9. 6
      src/google/protobuf/compiler/cpp/field_generators/string_view_field.cc

@ -109,14 +109,14 @@ std::vector<Sub> FieldVars(const FieldDescriptor* field, const Options& opts) {
return vars;
}
FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* descriptor,
FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* field,
const Options& options,
MessageSCCAnalyzer* scc)
: descriptor_(descriptor), options_(options) {
bool is_repeated_or_map = descriptor->is_repeated();
should_split_ = ShouldSplit(descriptor, options);
is_oneof_ = descriptor->real_containing_oneof() != nullptr;
switch (descriptor->cpp_type()) {
: field_(field), options_(options) {
bool is_repeated_or_map = field->is_repeated();
should_split_ = ShouldSplit(field, options);
is_oneof_ = field->real_containing_oneof() != nullptr;
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_ENUM:
case FieldDescriptor::CPPTYPE_INT32:
case FieldDescriptor::CPPTYPE_INT64:
@ -130,55 +130,55 @@ FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* descriptor,
break;
case FieldDescriptor::CPPTYPE_STRING:
is_string_ = true;
string_type_ = descriptor->options().ctype();
is_inlined_ = IsStringInlined(descriptor, options);
is_bytes_ = descriptor->type() == FieldDescriptor::TYPE_BYTES;
string_type_ = field->options().ctype();
is_inlined_ = IsStringInlined(field, options);
is_bytes_ = field->type() == FieldDescriptor::TYPE_BYTES;
has_default_constexpr_constructor_ = is_repeated_or_map;
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
is_message_ = true;
is_group_ = descriptor->type() == FieldDescriptor::TYPE_GROUP;
is_foreign_ = IsCrossFileMessage(descriptor);
is_weak_ = IsImplicitWeakField(descriptor, options, scc);
is_lazy_ = IsLazy(descriptor, options, scc);
is_group_ = field->type() == FieldDescriptor::TYPE_GROUP;
is_foreign_ = IsCrossFileMessage(field);
is_weak_ = IsImplicitWeakField(field, options, scc);
is_lazy_ = IsLazy(field, options, scc);
has_trivial_value_ = !(is_repeated_or_map || is_lazy_);
has_default_constexpr_constructor_ = is_repeated_or_map || is_lazy_;
break;
}
has_trivial_zero_default_ = CanInitializeByZeroing(descriptor, options, scc);
has_trivial_zero_default_ = CanInitializeByZeroing(field, options, scc);
}
void FieldGeneratorBase::GenerateMemberConstexprConstructor(
io::Printer* p) const {
ABSL_CHECK(!descriptor_->is_extension());
if (descriptor_->is_repeated()) {
ABSL_CHECK(!field_->is_extension());
if (field_->is_repeated()) {
p->Emit("$name$_{}");
} else {
p->Emit({{"default", DefaultValue(options_, descriptor_)}},
p->Emit({{"default", DefaultValue(options_, field_)}},
"$name$_{$default$}");
}
}
void FieldGeneratorBase::GenerateMemberConstructor(io::Printer* p) const {
ABSL_CHECK(!descriptor_->is_extension());
if (descriptor_->is_map()) {
ABSL_CHECK(!field_->is_extension());
if (field_->is_map()) {
p->Emit("$name$_{visibility, arena}");
} else if (descriptor_->is_repeated()) {
if (ShouldSplit(descriptor_, options_)) {
} else if (field_->is_repeated()) {
if (ShouldSplit(field_, options_)) {
p->Emit("$name$_{}"); // RawPtr<Repeated>
} else {
p->Emit("$name$_{visibility, arena}");
}
} else {
p->Emit({{"default", DefaultValue(options_, descriptor_)}},
p->Emit({{"default", DefaultValue(options_, field_)}},
"$name$_{$default$}");
}
}
void FieldGeneratorBase::GenerateMemberCopyConstructor(io::Printer* p) const {
ABSL_CHECK(!descriptor_->is_extension());
if (descriptor_->is_repeated()) {
ABSL_CHECK(!field_->is_extension());
if (field_->is_repeated()) {
p->Emit("$name$_{visibility, arena, from.$name$_}");
} else {
p->Emit("$name$_{from.$name$_}");
@ -186,14 +186,14 @@ void FieldGeneratorBase::GenerateMemberCopyConstructor(io::Printer* p) const {
}
void FieldGeneratorBase::GenerateOneofCopyConstruct(io::Printer* p) const {
ABSL_CHECK(!descriptor_->is_extension()) << "Not supported";
ABSL_CHECK(!descriptor_->is_repeated()) << "Not supported";
ABSL_CHECK(!descriptor_->is_map()) << "Not supported";
ABSL_CHECK(!field_->is_extension()) << "Not supported";
ABSL_CHECK(!field_->is_repeated()) << "Not supported";
ABSL_CHECK(!field_->is_map()) << "Not supported";
p->Emit("$field$ = from.$field$;\n");
}
void FieldGeneratorBase::GenerateAggregateInitializer(io::Printer* p) const {
if (ShouldSplit(descriptor_, options_)) {
if (ShouldSplit(field_, options_)) {
p->Emit(R"cc(
decltype(Impl_::Split::$name$_){arena},
)cc");

@ -47,7 +47,7 @@ class FieldGeneratorBase {
// variable instead of calling GetArena()'
enum class GeneratorFunction { kMergeFrom };
FieldGeneratorBase(const FieldDescriptor* descriptor, const Options& options,
FieldGeneratorBase(const FieldDescriptor* field, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
FieldGeneratorBase(const FieldGeneratorBase&) = delete;
@ -142,7 +142,7 @@ class FieldGeneratorBase {
virtual void GenerateArenaDestructorCode(io::Printer* p) const {
ABSL_CHECK(NeedsArenaDestructor() == ArenaDtorNeeds::kNone)
<< descriptor_->cpp_type_name();
<< field_->cpp_type_name();
}
// Generates constexpr member initialization code, e.g.: `foo_{5}`.
@ -191,7 +191,7 @@ class FieldGeneratorBase {
}
protected:
const FieldDescriptor* descriptor_;
const FieldDescriptor* field_;
const Options& options_;
MessageSCCAnalyzer* scc_;
absl::flat_hash_map<absl::string_view, std::string> variables_;

@ -77,10 +77,10 @@ class CordFieldGenerator : public FieldGeneratorBase {
}
void GenerateMemberConstexprConstructor(io::Printer* p) const override {
if (descriptor_->default_value_string().empty()) {
if (field_->default_value_string().empty()) {
p->Emit("$name$_{}");
} else {
p->Emit({{"Split", ShouldSplit(descriptor_, options_) ? "Split::" : ""}},
p->Emit({{"Split", ShouldSplit(field_, options_) ? "Split::" : ""}},
"$name$_{::absl::strings_internal::MakeStringConstant("
"$classname$::Impl_::$Split$_default_$name$_func_{})}");
}
@ -88,7 +88,7 @@ class CordFieldGenerator : public FieldGeneratorBase {
void GenerateMemberConstructor(io::Printer* p) const override {
auto vars = p->WithVars(variables_);
if (descriptor_->default_value_string().empty()) {
if (field_->default_value_string().empty()) {
p->Emit("$name$_{}");
} else {
p->Emit("$name$_{::absl::string_view($default$, $default_length$)}");
@ -142,7 +142,7 @@ CordFieldGenerator::CordFieldGenerator(const FieldDescriptor* descriptor,
void CordFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const {
Formatter format(printer, variables_);
format("::absl::Cord $name$_;\n");
if (!descriptor_->default_value_string().empty()) {
if (!field_->default_value_string().empty()) {
format(
"struct _default_$name$_func_ {\n"
" constexpr absl::string_view operator()() const {\n"
@ -156,18 +156,18 @@ void CordFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$deprecated_attr$const ::absl::Cord& ${1$$name$$}$() const;\n",
descriptor_);
field_);
format(
"$deprecated_attr$void ${1$set_$name$$}$(const ::absl::Cord& value);\n"
"$deprecated_attr$void ${1$set_$name$$}$(::absl::string_view value);\n",
std::make_tuple(descriptor_, GeneratedCodeInfo::Annotation::SET));
std::make_tuple(field_, GeneratedCodeInfo::Annotation::SET));
format(
"private:\n"
"const ::absl::Cord& ${1$_internal_$name$$}$() const;\n"
"void ${1$_internal_set_$name$$}$(const ::absl::Cord& value);\n"
"::absl::Cord* ${1$_internal_mutable_$name$$}$();\n"
"public:\n",
descriptor_);
field_);
}
void CordFieldGenerator::GenerateInlineAccessorDefinitions(
@ -223,7 +223,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions(
void CordFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
if (descriptor_->default_value_string().empty()) {
if (field_->default_value_string().empty()) {
format("$field$.Clear();\n");
} else {
format("$field$ = ::absl::string_view($default$, $default_length$);\n");
@ -243,7 +243,7 @@ void CordFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
void CordFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
ABSL_CHECK(!should_split());
Formatter format(printer, variables_);
if (!descriptor_->default_value_string().empty()) {
if (!field_->default_value_string().empty()) {
format("$field$ = ::absl::string_view($default$, $default_length$);\n");
}
}
@ -259,9 +259,9 @@ void CordFieldGenerator::GenerateArenaDestructorCode(
void CordFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
if (field_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForCord(
descriptor_, options_, false,
field_, options_, false,
absl::Substitute("this->_internal_$0(), ", printer->LookupVar("name")),
format);
}
@ -281,7 +281,7 @@ void CordFieldGenerator::GenerateByteSize(io::Printer* printer) const {
void CordFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* p) const {
if (descriptor_->default_value_string().empty()) {
if (field_->default_value_string().empty()) {
p->Emit(R"cc(
/*decltype($field$)*/ {},
)cc");
@ -323,7 +323,7 @@ void CordOneofFieldGenerator::GeneratePrivateMembers(
void CordOneofFieldGenerator::GenerateStaticMembers(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (!descriptor_->default_value_string().empty()) {
if (!field_->default_value_string().empty()) {
format(
"struct _default_$name$_func_ {\n"
" constexpr absl::string_view operator()() const {\n"
@ -407,7 +407,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void CordOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (!descriptor_->default_value_string().empty()) {
if (!field_->default_value_string().empty()) {
format(
"PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT "
"const ::absl::Cord $classname$::$default_variable_field$(\n"

@ -55,7 +55,7 @@ class SingularEnum : public FieldGeneratorBase {
public:
SingularEnum(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~SingularEnum() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -142,7 +142,6 @@ class SingularEnum : public FieldGeneratorBase {
void GenerateInlineAccessorDefinitions(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
};
@ -221,7 +220,6 @@ class RepeatedEnum : public FieldGeneratorBase {
RepeatedEnum(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc),
field_(field),
opts_(&opts),
has_cached_size_(field_->is_packed() &&
HasGeneratedMethods(field_->file(), opts) &&
@ -369,7 +367,6 @@ class RepeatedEnum : public FieldGeneratorBase {
void GenerateByteSize(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
bool has_cached_size_;
};

@ -76,7 +76,6 @@ class Map : public FieldGeneratorBase {
Map(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc),
field_(field),
key_(field->message_type()->map_key()),
val_(field->message_type()->map_value()),
opts_(&opts),
@ -168,7 +167,6 @@ class Map : public FieldGeneratorBase {
void GenerateByteSize(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const FieldDescriptor* key_;
const FieldDescriptor* val_;
const Options* opts_;

@ -84,7 +84,6 @@ class SingularMessage : public FieldGeneratorBase {
SingularMessage(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc),
field_(field),
opts_(&opts),
has_required_(scc->HasRequiredFields(field->message_type())),
has_hasbit_(HasHasbit(field)) {}
@ -143,7 +142,6 @@ class SingularMessage : public FieldGeneratorBase {
private:
friend class OneofMessage;
const FieldDescriptor* field_;
const Options* opts_;
bool has_required_;
bool has_hasbit_;
@ -689,7 +687,6 @@ class RepeatedMessage : public FieldGeneratorBase {
RepeatedMessage(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc),
field_(field),
opts_(&opts),
has_required_(scc->HasRequiredFields(field->message_type())) {}
@ -713,7 +710,6 @@ class RepeatedMessage : public FieldGeneratorBase {
void GenerateIsInitialized(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
bool has_required_;
};

@ -89,7 +89,7 @@ class SingularPrimitive final : public FieldGeneratorBase {
public:
SingularPrimitive(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~SingularPrimitive() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -164,7 +164,6 @@ class SingularPrimitive final : public FieldGeneratorBase {
void GenerateByteSize(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
};
@ -239,10 +238,10 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions(
void SingularPrimitive::GenerateSerializeWithCachedSizesToArray(
io::Printer* p) const {
if ((descriptor_->number() < 16) &&
(descriptor_->type() == FieldDescriptor::TYPE_INT32 ||
descriptor_->type() == FieldDescriptor::TYPE_INT64 ||
descriptor_->type() == FieldDescriptor::TYPE_ENUM)) {
if ((field_->number() < 16) &&
(field_->type() == FieldDescriptor::TYPE_INT32 ||
field_->type() == FieldDescriptor::TYPE_INT64 ||
field_->type() == FieldDescriptor::TYPE_ENUM)) {
// Call special non-inlined routine with tag number hardcoded as a
// template parameter that handles the EnsureSpace and the writing
// of the tag+value to the array
@ -291,7 +290,7 @@ class RepeatedPrimitive final : public FieldGeneratorBase {
public:
RepeatedPrimitive(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~RepeatedPrimitive() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -421,7 +420,6 @@ class RepeatedPrimitive final : public FieldGeneratorBase {
)cc");
}
const FieldDescriptor* field_;
const Options* opts_;
};
@ -597,7 +595,7 @@ void RepeatedPrimitive::GenerateByteSize(io::Printer* p) const {
{
Sub{"data_size",
[&] {
auto fixed_size = FixedSize(descriptor_->type());
auto fixed_size = FixedSize(field_->type());
if (fixed_size.has_value()) {
p->Emit({{"kFixed", *fixed_size}}, R"cc(
std::size_t{$kFixed$} *

@ -68,7 +68,7 @@ class SingularString : public FieldGeneratorBase {
public:
SingularString(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~SingularString() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -201,7 +201,6 @@ class SingularString : public FieldGeneratorBase {
void ReleaseImpl(io::Printer* p) const;
void SetAllocatedImpl(io::Printer* p) const;
const FieldDescriptor* field_;
const Options* opts_;
};
@ -733,7 +732,7 @@ class RepeatedString : public FieldGeneratorBase {
public:
RepeatedString(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~RepeatedString() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -819,7 +818,6 @@ class RepeatedString : public FieldGeneratorBase {
void GenerateSerializeWithCachedSizesToArray(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
};

@ -67,7 +67,7 @@ class SingularStringView : public FieldGeneratorBase {
public:
SingularStringView(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~SingularStringView() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -198,7 +198,6 @@ class SingularStringView : public FieldGeneratorBase {
private:
bool EmptyDefault() const { return field_->default_value_string().empty(); }
const FieldDescriptor* field_;
const Options* opts_;
};
@ -559,7 +558,7 @@ class RepeatedStringView : public FieldGeneratorBase {
public:
RepeatedStringView(const FieldDescriptor* field, const Options& opts,
MessageSCCAnalyzer* scc)
: FieldGeneratorBase(field, opts, scc), field_(field), opts_(&opts) {}
: FieldGeneratorBase(field, opts, scc), opts_(&opts) {}
~RepeatedStringView() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
@ -645,7 +644,6 @@ class RepeatedStringView : public FieldGeneratorBase {
void GenerateSerializeWithCachedSizesToArray(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
};

Loading…
Cancel
Save