Skip to content

Commit

Permalink
Migrate C++ type name getters from intXX to standard integer types …
Browse files Browse the repository at this point in the history
…`intXX_t`

PiperOrigin-RevId: 591730569
  • Loading branch information
gribozavr authored and copybara-github committed Dec 19, 2023
1 parent 1427a85 commit 3f25ed1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/google/protobuf/compiler/php/php_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,9 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options,
"utf8",
field->type() == FieldDescriptor::TYPE_STRING ? "True": "False");
} else {
printer->Print(
"GPBUtil::check^type^($var);\n",
"type", UnderscoresToCamelCase(field->cpp_type_name(), true));
printer->Print("GPBUtil::check^type^($var);\n", "type",
UnderscoresToCamelCase(
absl::StripSuffix(field->cpp_type_name(), "_t"), true));
}

if (oneof != NULL) {
Expand Down
20 changes: 10 additions & 10 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,16 @@ const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = {
const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = {
"ERROR", // 0 is reserved for errors

"int32", // CPPTYPE_INT32
"int64", // CPPTYPE_INT64
"uint32", // CPPTYPE_UINT32
"uint64", // CPPTYPE_UINT64
"double", // CPPTYPE_DOUBLE
"float", // CPPTYPE_FLOAT
"bool", // CPPTYPE_BOOL
"enum", // CPPTYPE_ENUM
"string", // CPPTYPE_STRING
"message", // CPPTYPE_MESSAGE
"int32_t", // CPPTYPE_INT32
"int64_t", // CPPTYPE_INT64
"uint32_t", // CPPTYPE_UINT32
"uint64_t", // CPPTYPE_UINT64
"double", // CPPTYPE_DOUBLE
"float", // CPPTYPE_FLOAT
"bool", // CPPTYPE_BOOL
"enum", // CPPTYPE_ENUM
"string", // CPPTYPE_STRING
"message", // CPPTYPE_MESSAGE
};

const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = {
Expand Down
28 changes: 14 additions & 14 deletions src/google/protobuf/descriptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2729,33 +2729,33 @@ TEST_F(MiscTest, CppTypeNames) {

EXPECT_STREQ("double", GetCppTypeNameForFieldType(FD::TYPE_DOUBLE));
EXPECT_STREQ("float", GetCppTypeNameForFieldType(FD::TYPE_FLOAT));
EXPECT_STREQ("int64", GetCppTypeNameForFieldType(FD::TYPE_INT64));
EXPECT_STREQ("uint64", GetCppTypeNameForFieldType(FD::TYPE_UINT64));
EXPECT_STREQ("int32", GetCppTypeNameForFieldType(FD::TYPE_INT32));
EXPECT_STREQ("uint64", GetCppTypeNameForFieldType(FD::TYPE_FIXED64));
EXPECT_STREQ("uint32", GetCppTypeNameForFieldType(FD::TYPE_FIXED32));
EXPECT_STREQ("int64_t", GetCppTypeNameForFieldType(FD::TYPE_INT64));
EXPECT_STREQ("uint64_t", GetCppTypeNameForFieldType(FD::TYPE_UINT64));
EXPECT_STREQ("int32_t", GetCppTypeNameForFieldType(FD::TYPE_INT32));
EXPECT_STREQ("uint64_t", GetCppTypeNameForFieldType(FD::TYPE_FIXED64));
EXPECT_STREQ("uint32_t", GetCppTypeNameForFieldType(FD::TYPE_FIXED32));
EXPECT_STREQ("bool", GetCppTypeNameForFieldType(FD::TYPE_BOOL));
EXPECT_STREQ("string", GetCppTypeNameForFieldType(FD::TYPE_STRING));
EXPECT_STREQ("message", GetCppTypeNameForFieldType(FD::TYPE_GROUP));
EXPECT_STREQ("message", GetCppTypeNameForFieldType(FD::TYPE_MESSAGE));
EXPECT_STREQ("string", GetCppTypeNameForFieldType(FD::TYPE_BYTES));
EXPECT_STREQ("uint32", GetCppTypeNameForFieldType(FD::TYPE_UINT32));
EXPECT_STREQ("uint32_t", GetCppTypeNameForFieldType(FD::TYPE_UINT32));
EXPECT_STREQ("enum", GetCppTypeNameForFieldType(FD::TYPE_ENUM));
EXPECT_STREQ("int32", GetCppTypeNameForFieldType(FD::TYPE_SFIXED32));
EXPECT_STREQ("int64", GetCppTypeNameForFieldType(FD::TYPE_SFIXED64));
EXPECT_STREQ("int32", GetCppTypeNameForFieldType(FD::TYPE_SINT32));
EXPECT_STREQ("int64", GetCppTypeNameForFieldType(FD::TYPE_SINT64));
EXPECT_STREQ("int32_t", GetCppTypeNameForFieldType(FD::TYPE_SFIXED32));
EXPECT_STREQ("int64_t", GetCppTypeNameForFieldType(FD::TYPE_SFIXED64));
EXPECT_STREQ("int32_t", GetCppTypeNameForFieldType(FD::TYPE_SINT32));
EXPECT_STREQ("int64_t", GetCppTypeNameForFieldType(FD::TYPE_SINT64));
}

TEST_F(MiscTest, StaticCppTypeNames) {
// Test that correct CPP type names are returned.

typedef FieldDescriptor FD; // avoid ugly line wrapping

EXPECT_STREQ("int32", FD::CppTypeName(FD::CPPTYPE_INT32));
EXPECT_STREQ("int64", FD::CppTypeName(FD::CPPTYPE_INT64));
EXPECT_STREQ("uint32", FD::CppTypeName(FD::CPPTYPE_UINT32));
EXPECT_STREQ("uint64", FD::CppTypeName(FD::CPPTYPE_UINT64));
EXPECT_STREQ("int32_t", FD::CppTypeName(FD::CPPTYPE_INT32));
EXPECT_STREQ("int64_t", FD::CppTypeName(FD::CPPTYPE_INT64));
EXPECT_STREQ("uint32_t", FD::CppTypeName(FD::CPPTYPE_UINT32));
EXPECT_STREQ("uint64_t", FD::CppTypeName(FD::CPPTYPE_UINT64));
EXPECT_STREQ("double", FD::CppTypeName(FD::CPPTYPE_DOUBLE));
EXPECT_STREQ("float", FD::CppTypeName(FD::CPPTYPE_FLOAT));
EXPECT_STREQ("bool", FD::CppTypeName(FD::CPPTYPE_BOOL));
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/map_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ TEST_F(MapImplTest, UsageErrors) {
EXPECT_DEATH(key.GetUInt64Value(),
"Protocol Buffer map usage error:\n"
"MapKey::GetUInt64Value type does not match\n"
" Expected : uint64\n"
" Actual : int64");
" Expected : uint64_t\n"
" Actual : int64_t");

MapValueRef value;
EXPECT_DEATH(
Expand Down

0 comments on commit 3f25ed1

Please sign in to comment.