Internal change

PiperOrigin-RevId: 521226781
This commit is contained in:
MediaPipe Team 2023-04-01 22:26:07 -07:00 committed by Copybara-Service
parent d9f940f8b2
commit 50a49fd16c

View File

@ -511,7 +511,7 @@ class TemplateParser::Parser::ParserImpl {
DO(ConsumeIdentifier(&field_name)); DO(ConsumeIdentifier(&field_name));
if (allow_field_number_) { if (allow_field_number_) {
int32 field_number = std::atoi(field_name.c_str()); // NOLINT int32_t field_number = std::atoi(field_name.c_str()); // NOLINT
if (descriptor->IsExtensionNumber(field_number)) { if (descriptor->IsExtensionNumber(field_number)) {
field = reflection->FindKnownExtensionByNumber(field_number); field = reflection->FindKnownExtensionByNumber(field_number);
} else if (descriptor->IsReservedNumber(field_number)) { } else if (descriptor->IsReservedNumber(field_number)) {
@ -765,28 +765,28 @@ class TemplateParser::Parser::ParserImpl {
switch (field->cpp_type()) { switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: { case FieldDescriptor::CPPTYPE_INT32: {
int64 value; int64_t value;
DO(ConsumeSignedInteger(&value, kint32max)); DO(ConsumeSignedInteger(&value, kint32max));
SET_FIELD(Int32, static_cast<int32>(value)); SET_FIELD(Int32, static_cast<int32_t>(value));
break; break;
} }
case FieldDescriptor::CPPTYPE_UINT32: { case FieldDescriptor::CPPTYPE_UINT32: {
uint64 value; uint64_t value;
DO(ConsumeUnsignedInteger(&value, kuint32max)); DO(ConsumeUnsignedInteger(&value, kuint32max));
SET_FIELD(UInt32, static_cast<uint32>(value)); SET_FIELD(UInt32, static_cast<uint32_t>(value));
break; break;
} }
case FieldDescriptor::CPPTYPE_INT64: { case FieldDescriptor::CPPTYPE_INT64: {
int64 value; int64_t value;
DO(ConsumeSignedInteger(&value, kint64max)); DO(ConsumeSignedInteger(&value, kint64max));
SET_FIELD(Int64, value); SET_FIELD(Int64, value);
break; break;
} }
case FieldDescriptor::CPPTYPE_UINT64: { case FieldDescriptor::CPPTYPE_UINT64: {
uint64 value; uint64_t value;
DO(ConsumeUnsignedInteger(&value, kuint64max)); DO(ConsumeUnsignedInteger(&value, kuint64max));
SET_FIELD(UInt64, value); SET_FIELD(UInt64, value);
break; break;
@ -815,7 +815,7 @@ class TemplateParser::Parser::ParserImpl {
case FieldDescriptor::CPPTYPE_BOOL: { case FieldDescriptor::CPPTYPE_BOOL: {
if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
uint64 value; uint64_t value;
DO(ConsumeUnsignedInteger(&value, 1)); DO(ConsumeUnsignedInteger(&value, 1));
SET_FIELD(Bool, value); SET_FIELD(Bool, value);
} else { } else {
@ -836,7 +836,7 @@ class TemplateParser::Parser::ParserImpl {
case FieldDescriptor::CPPTYPE_ENUM: { case FieldDescriptor::CPPTYPE_ENUM: {
std::string value; std::string value;
int64 int_value = kint64max; int64_t int_value = kint64max;
const EnumDescriptor* enum_type = field->enum_type(); const EnumDescriptor* enum_type = field->enum_type();
const EnumValueDescriptor* enum_value = NULL; const EnumValueDescriptor* enum_value = NULL;
@ -1037,7 +1037,7 @@ class TemplateParser::Parser::ParserImpl {
// Consumes a uint64 and saves its value in the value parameter. // Consumes a uint64 and saves its value in the value parameter.
// Returns false if the token is not of type INTEGER. // Returns false if the token is not of type INTEGER.
bool ConsumeUnsignedInteger(uint64* value, uint64 max_value) { bool ConsumeUnsignedInteger(uint64_t* value, uint64_t max_value) {
if (!LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (!LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
ReportError("Expected integer, got: " + tokenizer_.current().text); ReportError("Expected integer, got: " + tokenizer_.current().text);
return false; return false;
@ -1058,7 +1058,7 @@ class TemplateParser::Parser::ParserImpl {
// we actually may consume an additional token (for the minus sign) in this // we actually may consume an additional token (for the minus sign) in this
// method. Returns false if the token is not an integer // method. Returns false if the token is not an integer
// (signed or otherwise). // (signed or otherwise).
bool ConsumeSignedInteger(int64* value, uint64 max_value) { bool ConsumeSignedInteger(int64_t* value, uint64_t max_value) {
bool negative = false; bool negative = false;
#ifndef PROTO2_OPENSOURCE #ifndef PROTO2_OPENSOURCE
if (absl::StartsWith(tokenizer_.current().text, "0x")) { if (absl::StartsWith(tokenizer_.current().text, "0x")) {
@ -1075,18 +1075,18 @@ class TemplateParser::Parser::ParserImpl {
++max_value; ++max_value;
} }
uint64 unsigned_value; uint64_t unsigned_value;
DO(ConsumeUnsignedInteger(&unsigned_value, max_value)); DO(ConsumeUnsignedInteger(&unsigned_value, max_value));
if (negative) { if (negative) {
if ((static_cast<uint64>(kint64max) + 1) == unsigned_value) { if ((static_cast<uint64_t>(kint64max) + 1) == unsigned_value) {
*value = kint64min; *value = kint64min;
} else { } else {
*value = -static_cast<int64>(unsigned_value); *value = -static_cast<int64_t>(unsigned_value);
} }
} else { } else {
*value = static_cast<int64>(unsigned_value); *value = static_cast<int64_t>(unsigned_value);
} }
return true; return true;
@ -1094,7 +1094,7 @@ class TemplateParser::Parser::ParserImpl {
// Consumes a uint64 and saves its value in the value parameter. // Consumes a uint64 and saves its value in the value parameter.
// Accepts decimal numbers only, rejects hex or oct numbers. // Accepts decimal numbers only, rejects hex or oct numbers.
bool ConsumeUnsignedDecimalInteger(uint64* value, uint64 max_value) { bool ConsumeUnsignedDecimalInteger(uint64_t* value, uint64_t max_value) {
if (!LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (!LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
ReportError("Expected integer, got: " + tokenizer_.current().text); ReportError("Expected integer, got: " + tokenizer_.current().text);
return false; return false;
@ -1131,7 +1131,7 @@ class TemplateParser::Parser::ParserImpl {
// Therefore, we must check both cases here. // Therefore, we must check both cases here.
if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) {
// We have found an integer value for the double. // We have found an integer value for the double.
uint64 integer_value; uint64_t integer_value;
DO(ConsumeUnsignedDecimalInteger(&integer_value, kuint64max)); DO(ConsumeUnsignedDecimalInteger(&integer_value, kuint64max));
*value = static_cast<double>(integer_value); *value = static_cast<double>(integer_value);