Skip to content

Commit 9da84f3

Browse files
ClaytonKnittelcopybara-github
authored andcommitted
Migrate remaining old-style $tag_size$ substitutions to $kTagBytes$ in field generators.
PiperOrigin-RevId: 904173188
1 parent 15cb988 commit 9da84f3

10 files changed

Lines changed: 285 additions & 325 deletions

File tree

src/google/protobuf/compiler/cpp/field.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,8 @@ std::vector<Sub> FieldVars(const FieldDescriptor* field, const Options& opts) {
8383
"::internal::TSanRead(&_impl_)")},
8484

8585
// Old-style names.
86-
{"field", FieldMemberName(field, split)},
87-
{"declared_type", DeclaredTypeMethodName(field->type())},
8886
{"classname", ClassName(FieldScope(field), false)},
8987
{"ns", Namespace(field)},
90-
{"tag_size", WireFormat::TagSize(field->number(), field->type())},
9188
{"deprecated_attr", DeprecatedAttribute(opts, field)},
9289
Sub("WeakDescriptorSelfPin",
9390
UsingImplicitWeakDescriptor(field->file(), opts)
@@ -202,7 +199,7 @@ void FieldGeneratorBase::GenerateOneofCopyConstruct(io::Printer* p) const {
202199
ABSL_CHECK(!field_->is_extension()) << "Not supported";
203200
ABSL_CHECK(!field_->is_repeated()) << "Not supported";
204201
ABSL_CHECK(!field_->is_map()) << "Not supported";
205-
p->Emit("$field$ = from.$field$;\n");
202+
p->Emit("$field_$ = from.$field_$;\n");
206203
}
207204

208205
void FieldGeneratorBase::GenerateAggregateInitializer(io::Printer* p) const {
@@ -212,22 +209,22 @@ void FieldGeneratorBase::GenerateAggregateInitializer(io::Printer* p) const {
212209
)cc");
213210
} else {
214211
p->Emit(R"cc(
215-
decltype($field$){arena},
212+
decltype($field_$){arena},
216213
)cc");
217214
}
218215
}
219216

220217
void FieldGeneratorBase::GenerateConstexprAggregateInitializer(
221218
io::Printer* p) const {
222219
p->Emit(R"cc(
223-
/*decltype($field$)*/ {},
220+
/*decltype($field_$)*/ {},
224221
)cc");
225222
}
226223

227224
void FieldGeneratorBase::GenerateCopyAggregateInitializer(
228225
io::Printer* p) const {
229226
p->Emit(R"cc(
230-
decltype($field$){from.$field$},
227+
decltype($field_$){from.$field_$},
231228
)cc");
232229
}
233230

@@ -236,7 +233,7 @@ void FieldGeneratorBase::GenerateCopyConstructorCode(io::Printer* p) const {
236233
// There is no copy constructor for the `Split` struct, so we need to copy
237234
// the value here.
238235
Formatter format(p, variables_);
239-
format("$field$ = from.$field$;\n");
236+
format("$field_$ = from.$field_$;\n");
240237
}
241238
}
242239

src/google/protobuf/compiler/cpp/field.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,11 @@ class FieldGenerator {
415415
// GeneratePrivateMembers().
416416
//
417417
// These go into the SharedCtor's aggregate initialization of the _impl_
418-
// struct and must follow the syntax `decltype($field$){$default$}`.
418+
// struct and must follow the syntax `decltype($field_$){$default$}`.
419419
// Does not include `:` or `,` separators. Default values should be specified
420420
// here when possible.
421421
//
422-
// NOTE: We use `decltype($field$)` for both explicit construction and the
422+
// NOTE: We use `decltype($field_$)` for both explicit construction and the
423423
// fact that it's self-documenting. Pre-C++17, copy elision isn't guaranteed
424424
// in aggregate initialization so a valid copy/move constructor must exist
425425
// (even though it's not used). Because of this, we need to comment out the
@@ -433,7 +433,7 @@ class FieldGenerator {
433433
// GeneratePrivateMembers().
434434
//
435435
// These go into the constexpr constructor's aggregate initialization of the
436-
// _impl_ struct and must follow the syntax `/*decltype($field$)*/{}` (see
436+
// _impl_ struct and must follow the syntax `/*decltype($field_$)*/{}` (see
437437
// above). Does not include `:` or `,` separators.
438438
void GenerateConstexprAggregateInitializer(io::Printer* p) const {
439439
auto vars = PushVarsForCall(p);
@@ -444,7 +444,7 @@ class FieldGenerator {
444444
// GeneratePrivateMembers().
445445
//
446446
// These go into the copy constructor's aggregate initialization of the _impl_
447-
// struct and must follow the syntax `decltype($field$){from.$field$}` (see
447+
// struct and must follow the syntax `decltype($field_$){from.$field_$}` (see
448448
// above). Does not include `:` or `,` separators.
449449
void GenerateCopyAggregateInitializer(io::Printer* p) const {
450450
auto vars = PushVarsForCall(p);

src/google/protobuf/compiler/cpp/field_generators/cord_field.cc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CordFieldGenerator : public FieldGeneratorBase {
111111
void GenerateOneofCopyConstruct(io::Printer* p) const override {
112112
auto vars = p->WithVars(variables_);
113113
p->Emit(R"cc(
114-
$field$ = $pb$::Arena::Create<absl::Cord>(arena, *from.$field$);
114+
$field_$ = $pb$::Arena::Create<absl::Cord>(arena, *from.$field_$);
115115
)cc");
116116
}
117117
};
@@ -188,7 +188,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions(
188188
auto v = p->WithVars(variables_);
189189
p->Emit(R"cc(
190190
inline const ::absl::Cord& $classname$::_internal_$name_internal$() const {
191-
return $field$;
191+
return $field_$;
192192
}
193193
)cc");
194194
p->Emit(R"cc(
@@ -204,7 +204,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions(
204204
inline void $classname$::_internal_set_$name_internal$(
205205
const ::absl::Cord& value) {
206206
$set_hasbit$;
207-
$field$ = value;
207+
$field_$ = value;
208208
}
209209
)cc");
210210
p->Emit(R"cc(
@@ -221,7 +221,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions(
221221
$WeakDescriptorSelfPin$;
222222
$PrepareSplitMessageForWrite$;
223223
$set_hasbit$;
224-
$field$ = value;
224+
$field_$ = value;
225225
$annotate_set$;
226226
// @@protoc_insertion_point(field_set_string_piece:$full_name$)
227227
}
@@ -230,7 +230,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions(
230230
inline ::absl::Cord* $nonnull$
231231
$classname$::_internal_mutable_$name_internal$() {
232232
$set_hasbit$;
233-
return &$field$;
233+
return &$field_$;
234234
}
235235
)cc");
236236
}
@@ -239,11 +239,11 @@ void CordFieldGenerator::GenerateClearingCode(io::Printer* p) const {
239239
auto v = p->WithVars(variables_);
240240
if (field_->default_value_string().empty()) {
241241
p->Emit(R"cc(
242-
$field$.Clear();
242+
$field_$.Clear();
243243
)cc");
244244
} else {
245245
p->Emit(R"cc(
246-
$field$ = ::absl::string_view($default$, $default_length$);
246+
$field_$ = ::absl::string_view($default$, $default_length$);
247247
)cc");
248248
}
249249
}
@@ -258,15 +258,15 @@ void CordFieldGenerator::GenerateMergingCode(io::Printer* p) const {
258258
void CordFieldGenerator::GenerateSwappingCode(io::Printer* p) const {
259259
auto v = p->WithVars(variables_);
260260
p->Emit(R"cc(
261-
$field$.swap(other->$field$);
261+
$field_$.swap(other->$field_$);
262262
)cc");
263263
}
264264

265265
void CordFieldGenerator::GenerateArenaDestructorCode(io::Printer* p) const {
266266
auto v = p->WithVars(variables_);
267267
// _this is the object being destructed (we are inside a static method here).
268268
p->Emit(R"cc(
269-
_this->$field$.::absl::Cord::~Cord();
269+
_this->$field_$.::absl::Cord::~Cord();
270270
)cc");
271271
}
272272

@@ -279,30 +279,30 @@ void CordFieldGenerator::GenerateSerializeWithCachedSizesToArray(
279279
absl::Substitute("this_._internal_$0(), ", p->LookupVar("name")));
280280
}
281281
p->Emit(R"cc(
282-
target = stream->Write$declared_type$($number$, this_._internal_$name$(),
283-
target);
282+
target =
283+
stream->Write$DeclaredType$($number$, this_._internal_$name$(), target);
284284
)cc");
285285
}
286286

287287
void CordFieldGenerator::GenerateByteSize(io::Printer* p) const {
288288
auto v = p->WithVars(variables_);
289289
p->Emit(R"cc(
290-
total_size += $tag_size$ + $pbi$::WireFormatLite::$declared_type$Size(
291-
this_._internal_$name$());
290+
total_size += $kTagBytes$ + $pbi$::WireFormatLite::$DeclaredType$Size(
291+
this_._internal_$name$());
292292
)cc");
293293
}
294294

295295
void CordFieldGenerator::GenerateConstexprAggregateInitializer(
296296
io::Printer* p) const {
297297
if (field_->default_value_string().empty()) {
298298
p->Emit(R"cc(
299-
/*decltype($field$)*/ {},
299+
/*decltype($field_$)*/ {},
300300
)cc");
301301
} else {
302302
p->Emit(
303303
{{"Split", should_split() ? "Split::" : ""}},
304304
R"cc(
305-
/*decltype($field$)*/ {::absl::strings_internal::MakeStringConstant(
305+
/*decltype($field_$)*/ {::absl::strings_internal::MakeStringConstant(
306306
$classname$::Impl_::$Split$_default_$name$_func_{})},
307307
)cc");
308308
}
@@ -315,7 +315,7 @@ void CordFieldGenerator::GenerateAggregateInitializer(io::Printer* p) const {
315315
)cc");
316316
} else {
317317
p->Emit(R"cc(
318-
decltype($field$){},
318+
decltype($field_$){},
319319
)cc");
320320
}
321321
}
@@ -353,7 +353,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions(
353353
p->Emit(R"cc(
354354
inline const ::absl::Cord& $classname$::_internal_$name_internal$() const {
355355
if ($has_field$) {
356-
return *$field$;
356+
return *$field_$;
357357
}
358358
return $default_variable$;
359359
}
@@ -373,9 +373,9 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions(
373373
if ($not_has_field$) {
374374
clear_$oneof_name$();
375375
set_has_$name_internal$();
376-
$field$ = $pb$::Arena::Create<::absl::Cord>(GetArena());
376+
$field_$ = $pb$::Arena::Create<::absl::Cord>(GetArena());
377377
}
378-
*$field$ = value;
378+
*$field_$ = value;
379379
$annotate_set$;
380380
// @@protoc_insertion_point(field_set:$full_name$)
381381
}
@@ -386,9 +386,9 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions(
386386
if ($not_has_field$) {
387387
clear_$oneof_name$();
388388
set_has_$name_internal$();
389-
$field$ = $pb$::Arena::Create<::absl::Cord>(GetArena());
389+
$field_$ = $pb$::Arena::Create<::absl::Cord>(GetArena());
390390
}
391-
*$field$ = value;
391+
*$field_$ = value;
392392
$annotate_set$;
393393
// @@protoc_insertion_point(field_set_string_piece:$full_name$)
394394
}
@@ -399,9 +399,9 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions(
399399
if ($not_has_field$) {
400400
clear_$oneof_name$();
401401
set_has_$name_internal$();
402-
$field$ = $pb$::Arena::Create<::absl::Cord>(GetArena());
402+
$field_$ = $pb$::Arena::Create<::absl::Cord>(GetArena());
403403
}
404-
return $field$;
404+
return $field_$;
405405
}
406406
)cc");
407407
}
@@ -431,7 +431,7 @@ void CordOneofFieldGenerator::GenerateClearingCode(io::Printer* p) const {
431431
auto v = p->WithVars(variables_);
432432
p->Emit(R"cc(
433433
if (GetArena() == nullptr) {
434-
delete $field$;
434+
delete $field_$;
435435
}
436436
)cc");
437437
}
@@ -449,9 +449,9 @@ void CordOneofFieldGenerator::GenerateArenaDestructorCode(
449449
void CordOneofFieldGenerator::GenerateMergingCode(io::Printer* p) const {
450450
p->Emit(R"cc(
451451
if (oneof_needs_init) {
452-
_this->$field$ = $pb$::Arena::Create<absl::Cord>(arena);
452+
_this->$field_$ = $pb$::Arena::Create<absl::Cord>(arena);
453453
}
454-
*_this->$field$ = *from.$field$;
454+
*_this->$field_$ = *from.$field_$;
455455
)cc");
456456
}
457457

0 commit comments

Comments
 (0)