Reverting bad merges due to OSS changes since last sync

pull/10462/head
Mike Kruskal 2 years ago
parent 465653e9e4
commit b393dace83
  1. 6
      src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
  2. 2
      src/google/protobuf/compiler/csharp/csharp_enum_field.cc
  3. 9
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  4. 1
      src/google/protobuf/compiler/csharp/csharp_field_base.h
  5. 16
      src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
  6. 56
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  7. 6
      src/google/protobuf/compiler/csharp/csharp_helpers.h
  8. 2
      src/google/protobuf/compiler/csharp/csharp_map_field.cc
  9. 12
      src/google/protobuf/compiler/csharp/csharp_message.cc
  10. 4
      src/google/protobuf/compiler/csharp/csharp_message_field.cc
  11. 4
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  12. 4
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  13. 4
      src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
  14. 13
      src/google/protobuf/compiler/objectivec/objectivec_enum.cc
  15. 2
      src/google/protobuf/compiler/objectivec/objectivec_field.cc
  16. 217
      src/google/protobuf/compiler/php/php_generator.cc
  17. 30
      src/google/protobuf/compiler/ruby/ruby_generated_code.proto
  18. 30
      src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto
  19. 30
      src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto
  20. 30
      src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto
  21. 30
      src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto
  22. 30
      src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto
  23. 6
      src/google/protobuf/compiler/ruby/ruby_generator.cc

@ -180,12 +180,6 @@ TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) {
"WellKnownTypes/Wrappers.cs",
"../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs");
generate_test.SetParameter("");
source_tree.MapPath("", TestSourceDir() + "/../conformance");
generate_test.Run(importer.Import("conformance.proto"),
"Conformance.cs",
"../csharp/src/Google.Protobuf.Conformance/Conformance.cs");
EXPECT_EQ("", error_collector.text_);
}

@ -109,7 +109,7 @@ void EnumOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print(
variables_,
"$oneof_name$_ = input.ReadEnum();\n"
"$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
"$oneof_name$Case_ = $oneof_property_name$OneofCase.$oneof_case_name$;\n");
}
void EnumOneofFieldGenerator::GenerateSerializationCode(io::Printer* printer) {

@ -137,8 +137,9 @@ void FieldGeneratorBase::SetCommonOneofFieldVariables(
} else {
(*variables)["has_property_check"] =
oneof_name() + "Case_ == " + oneof_property_name() +
"OneofCase." + property_name();
"OneofCase." + oneof_case_name();
}
(*variables)["oneof_case_name"] = oneof_case_name();
(*variables)["oneof_property_name"] = oneof_property_name();
}
@ -164,7 +165,7 @@ void FieldGeneratorBase::GenerateCodecCode(io::Printer* printer) {
}
void FieldGeneratorBase::GenerateExtensionCode(io::Printer* printer) {
// No-op: only message fields, enum fields, primitives,
// No-op: only message fields, enum fields, primitives,
// and repeated fields need this default is to not generate any code
}
@ -194,6 +195,10 @@ void FieldGeneratorBase::AddPublicMemberAttributes(io::Printer* printer) {
WriteGeneratedCodeAttributes(printer);
}
std::string FieldGeneratorBase::oneof_case_name() {
return GetOneofCaseName(descriptor_);
}
std::string FieldGeneratorBase::oneof_property_name() {
return UnderscoresToCamelCase(descriptor_->containing_oneof()->name(), true);
}

@ -89,6 +89,7 @@ class FieldGeneratorBase : public SourceGeneratorBase {
std::map<std::string, std::string>* variables);
std::string oneof_property_name();
std::string oneof_case_name();
std::string oneof_name();
std::string property_name();
std::string name();

@ -73,6 +73,22 @@ TEST(DescriptorProtoHelpers, IsDescriptorOptionMessage) {
EXPECT_FALSE(IsDescriptorOptionMessage(DescriptorProto::descriptor()));
}
TEST(CSharpIdentifiers, UnderscoresToCamelCase) {
EXPECT_EQ("FooBar", UnderscoresToCamelCase("Foo_Bar", true));
EXPECT_EQ("fooBar", UnderscoresToCamelCase("FooBar", false));
EXPECT_EQ("foo123", UnderscoresToCamelCase("foo_123", false));
// remove leading underscores
EXPECT_EQ("Foo123", UnderscoresToCamelCase("_Foo_123", true));
// this one has slight unexpected output as it capitalises the first
// letter after consuming the underscores, but this was the existing
// behaviour so I have not changed it
EXPECT_EQ("FooBar", UnderscoresToCamelCase("___fooBar", false));
// leave a leading underscore for identifiers that would otherwise
// be invalid because they would start with a digit
EXPECT_EQ("_123Foo", UnderscoresToCamelCase("_123_foo", true));
EXPECT_EQ("_123Foo", UnderscoresToCamelCase("___123_foo", true));
}
} // namespace
} // namespace csharp
} // namespace compiler

@ -114,7 +114,7 @@ CSharpType GetCSharpType(FieldDescriptor::Type type) {
}
std::string StripDotProto(const std::string& proto_file) {
int lastindex = proto_file.find_last_of(".");
int lastindex = proto_file.find_last_of('.');
return proto_file.substr(0, lastindex);
}
@ -129,7 +129,7 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) {
// input of "google/protobuf/foo_bar.proto" would result in "FooBar".
std::string GetFileNameBase(const FileDescriptor* descriptor) {
std::string proto_file = descriptor->name();
int lastslash = proto_file.find_last_of("/");
int lastslash = proto_file.find_last_of('/');
std::string base = proto_file.substr(lastslash + 1);
return UnderscoresToPascalCase(StripDotProto(base));
}
@ -151,6 +151,7 @@ std::string UnderscoresToCamelCase(const std::string& input,
bool cap_next_letter,
bool preserve_period) {
std::string result;
// Note: I distrust ctype.h due to locales.
for (int i = 0; i < input.size(); i++) {
if ('a' <= input[i] && input[i] <= 'z') {
@ -184,6 +185,23 @@ std::string UnderscoresToCamelCase(const std::string& input,
if (input.size() > 0 && input[input.size() - 1] == '#') {
result += '_';
}
// https://github.com/protocolbuffers/protobuf/issues/8101
// To avoid generating invalid identifiers - if the input string
// starts with _<digit> (or multiple underscores then digit) then
// we need to preserve the underscore as an identifier cannot start
// with a digit.
// This check is being done after the loop rather than before
// to handle the case where there are multiple underscores before the
// first digit. We let them all be consumed so we can see if we would
// start with a digit.
// Note: not preserving leading underscores for all otherwise valid identifiers
// so as to not break anything that relies on the existing behaviour
if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9')
&& input.size() > 0 && input[0] == '_')
{
result.insert(0, 1, '_');
}
return result;
}
@ -386,20 +404,42 @@ std::string GetFieldConstantName(const FieldDescriptor* field) {
}
std::string GetPropertyName(const FieldDescriptor* descriptor) {
// Names of members declared or overridden in the message.
static const auto& reserved_member_names = *new absl::flat_hash_set<absl::string_view>({
"Types",
"Descriptor",
"Equals",
"ToString",
"GetHashCode",
"WriteTo",
"Clone",
"CalculateSize",
"MergeFrom",
"OnConstruction",
"Parser"
});
// TODO(jtattermusch): consider introducing csharp_property_name field option
std::string property_name = UnderscoresToPascalCase(GetFieldName(descriptor));
// Avoid either our own type name or reserved names. Note that not all names
// are reserved - a field called to_string, write_to etc would still cause a problem.
// Avoid either our own type name or reserved names.
// There are various ways of ending up with naming collisions, but we try to avoid obvious
// ones.
// ones. In particular, we avoid the names of all the members we generate.
// Note that we *don't* add an underscore for MemberwiseClone or GetType. Those generate
// warnings, but not errors; changing the name now could be a breaking change.
if (property_name == descriptor->containing_type()->name()
|| property_name == "Types"
|| property_name == "Descriptor") {
|| reserved_member_names.find(property_name) != reserved_member_names.end()) {
property_name += "_";
}
return property_name;
}
std::string GetOneofCaseName(const FieldDescriptor* descriptor) {
// The name in a oneof case enum is the same as for the property, but as we always have a "None"
// value as well, we need to reserve that by appending an underscore.
std::string property_name = GetPropertyName(descriptor);
return property_name == "None" ? "None_" : property_name;
}
std::string GetOutputFile(const FileDescriptor* descriptor,
const std::string file_extension,
const bool generate_directories,
@ -422,7 +462,7 @@ std::string GetOutputFile(const FileDescriptor* descriptor,
return ""; // This will be ignored, because we've set an error.
}
namespace_suffix = ns.substr(base_namespace.length());
if (namespace_suffix.find(".") == 0) {
if (namespace_suffix.find('.') == 0) {
namespace_suffix = namespace_suffix.substr(1);
}
}

@ -87,9 +87,13 @@ std::string GetFieldConstantName(const FieldDescriptor* field);
std::string GetPropertyName(const FieldDescriptor* descriptor);
std::string GetOneofCaseName(const FieldDescriptor* descriptor);
int GetFixedSize(FieldDescriptor::Type type);
std::string UnderscoresToCamelCase(const std::string& input,
// Note that we wouldn't normally want to export this (we're not expecting
// it to be used outside libprotoc itself) but this exposes it for testing.
std::string PROTOC_EXPORT UnderscoresToCamelCase(const std::string& input,
bool cap_next_letter,
bool preserve_period);

@ -94,7 +94,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) {
void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) {
printer->Print(
variables_,
"$name$_.Add(other.$name$_);\n");
"$name$_.MergeFrom(other.$name$_);\n");
}
void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) {

@ -245,8 +245,8 @@ void MessageGenerator::Generate(io::Printer* printer) {
printer->Print("None = 0,\n");
for (int j = 0; j < oneof->field_count(); j++) {
const FieldDescriptor* field = oneof->field(j);
printer->Print("$field_property_name$ = $index$,\n",
"field_property_name", GetPropertyName(field),
printer->Print("$oneof_case_name$ = $index$,\n",
"oneof_case_name", GetOneofCaseName(field),
"index", absl::StrCat(field->number()));
}
printer->Outdent();
@ -410,10 +410,10 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) {
for (int j = 0; j < oneof->field_count(); j++) {
const FieldDescriptor* field = oneof->field(j);
std::unique_ptr<FieldGeneratorBase> generator(CreateFieldGeneratorInternal(field));
vars["field_property_name"] = GetPropertyName(field);
vars["oneof_case_name"] = GetOneofCaseName(field);
printer->Print(
vars,
"case $property_name$OneofCase.$field_property_name$:\n");
"case $property_name$OneofCase.$oneof_case_name$:\n");
printer->Indent();
generator->GenerateCloningCode(printer);
printer->Print("break;\n");
@ -642,10 +642,10 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
printer->Indent();
for (int j = 0; j < oneof->field_count(); j++) {
const FieldDescriptor* field = oneof->field(j);
vars["field_property_name"] = GetPropertyName(field);
vars["oneof_case_name"] = GetOneofCaseName(field);
printer->Print(
vars,
"case $property_name$OneofCase.$field_property_name$:\n");
"case $property_name$OneofCase.$oneof_case_name$:\n");
printer->Indent();
std::unique_ptr<FieldGeneratorBase> generator(CreateFieldGeneratorInternal(field));
generator->GenerateMergingCode(printer);

@ -229,7 +229,7 @@ void MessageOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
" get { return $has_property_check$ ? ($type_name$) $oneof_name$_ : null; }\n"
" set {\n"
" $oneof_name$_ = value;\n"
" $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n"
" $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$oneof_case_name$;\n"
" }\n"
"}\n");
if (SupportsPresenceApi(descriptor_)) {
@ -240,7 +240,7 @@ void MessageOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
printer->Print(
variables_,
"$access_level$ bool Has$property_name$ {\n"
" get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$property_name$; }\n"
" get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$oneof_case_name$; }\n"
"}\n");
printer->Print(
variables_,

@ -300,7 +300,7 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
}
printer->Print(
variables_,
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n"
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$oneof_case_name$;\n"
" }\n"
"}\n");
if (SupportsPresenceApi(descriptor_)) {
@ -311,7 +311,7 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
printer->Print(
variables_,
"$access_level$ bool Has$property_name$ {\n"
" get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$property_name$; }\n"
" get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$oneof_case_name$; }\n"
"}\n");
printer->Print(
variables_,

@ -134,7 +134,7 @@ void ReflectionClassGenerator::WriteIntroduction(io::Printer* printer) {
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $file_name$\n"
"// </auto-generated>\n"
"#pragma warning disable 1591, 0612, 3021\n"
"#pragma warning disable 1591, 0612, 3021, 8981\n"
"#region Designer generated code\n"
"\n"
"using pb = global::Google.Protobuf;\n"
@ -213,7 +213,7 @@ void ReflectionClassGenerator::WriteDescriptor(io::Printer* printer) {
}
else {
printer->Print("null, ");
}
}
if (file_->extension_count() > 0) {
std::vector<std::string> extensions;
for (int i = 0; i < file_->extension_count(); i++) {

@ -233,7 +233,7 @@ void WrapperOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
" get { return $has_property_check$ ? ($type_name$) $oneof_name$_ : ($type_name$) null; }\n"
" set {\n"
" $oneof_name$_ = value;\n"
" $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n"
" $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$oneof_case_name$;\n"
" }\n"
"}\n");
if (SupportsPresenceApi(descriptor_)) {
@ -244,7 +244,7 @@ void WrapperOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
printer->Print(
variables_,
"$access_level$ bool Has$property_name$ {\n"
" get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$property_name$; }\n"
" get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$oneof_case_name$; }\n"
"}\n");
printer->Print(
variables_,

@ -45,6 +45,17 @@ namespace google {
namespace protobuf {
namespace compiler {
namespace objectivec {
namespace {
std::string SafelyPrintIntToCode(int v) {
if (v == std::numeric_limits<int>::min()) {
// Some compilers try to parse -2147483648 as two tokens and then get spicy
// about the fact that +2147483648 cannot be represented as an int.
return absl::StrCat(v + 1, " - 1");
} else {
return absl::StrCat(v);
}
}
} // namespace
EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor)
: descriptor_(descriptor),
@ -145,7 +156,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
"$name$$deprecated_attribute$ = $value$,\n",
"name", EnumValueName(all_values_[i]),
"deprecated_attribute", GetOptionalDeprecatedAttribute(all_values_[i]),
"value", absl::StrCat(all_values_[i]->number()));
"value", SafelyPrintIntToCode(all_values_[i]->number()));
}
printer->Outdent();
printer->Print(

@ -392,7 +392,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
"$comments$"
"$array_comment$"
"@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n"
"/** The number of items in @c $name$ without causing the array to be created. */\n"
"/** The number of items in @c $name$ without causing the container to be created. */\n"
"@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$;\n");
if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC.

@ -52,28 +52,29 @@ const std::string kDescriptorMetadataFile =
const std::string kDescriptorDirName = "Google/Protobuf/Internal";
const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
const char* const kReservedNames[] = {
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"finally", "fn", "for", "foreach", "function",
"global", "goto", "if", "implements", "include",
"include_once", "instanceof", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "or",
"print", "private", "protected", "public", "require",
"require_once", "return", "static", "switch", "throw",
"trait", "try", "unset", "use", "var",
"while", "xor", "yield", "int", "float",
"bool", "string", "true", "false", "null",
"void", "iterable"};
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"finally", "fn", "for", "foreach", "function",
"global", "goto", "if", "implements", "include",
"include_once", "instanceof", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "or",
"parent", "print", "private", "protected", "public",
"readonly", "require", "require_once", "return", "self",
"static", "switch", "throw", "trait", "try",
"unset", "use", "var", "while", "xor",
"yield", "int", "float", "bool", "string",
"true", "false", "null", "void", "iterable"};
const char* const kValidConstantNames[] = {
"int", "float", "bool", "string", "true",
"false", "null", "void", "iterable",
"false", "null", "void", "iterable", "parent",
"self", "readonly"
};
const int kReservedNamesSize = 77;
const int kValidConstantNamesSize = 9;
const int kReservedNamesSize = 80;
const int kValidConstantNamesSize = 12;
const int kFieldSetter = 1;
const int kFieldGetter = 2;
const int kFieldProperty = 3;
@ -337,7 +338,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
const Options& options) {
const std::string& proto_file = file->name();
int start_index = 0;
int first_index = proto_file.find_first_of("/", start_index);
int first_index = proto_file.find_first_of('/', start_index);
std::string result = "";
std::string segment = "";
@ -350,7 +351,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
// Append directory name.
std::string file_no_suffix;
int lastindex = proto_file.find_last_of(".");
int lastindex = proto_file.find_last_of('.');
if (proto_file == kEmptyFile) {
return kEmptyMetadataFile;
} else {
@ -374,12 +375,12 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
file_no_suffix.substr(start_index, first_index - start_index), true);
result += ReservedNamePrefix(segment, file) + segment + "/";
start_index = first_index + 1;
first_index = file_no_suffix.find_first_of("/", start_index);
first_index = file_no_suffix.find_first_of('/', start_index);
}
}
// Append file name.
int file_name_start = file_no_suffix.find_last_of("/");
int file_name_start = file_no_suffix.find_last_of('/');
if (file_name_start == std::string::npos) {
file_name_start = 0;
} else {
@ -423,6 +424,21 @@ std::string LegacyGeneratedClassFileName(const DescriptorType* desc,
return result + ".php";
}
template <typename DescriptorType>
std::string LegacyReadOnlyGeneratedClassFileName(std::string php_namespace,
const DescriptorType* desc) {
if (!php_namespace.empty()) {
for (int i = 0; i < php_namespace.size(); i++) {
if (php_namespace[i] == '\\') {
php_namespace[i] = '/';
}
}
return php_namespace + "/" + desc->name() + ".php";
}
return desc->name() + ".php";
}
std::string GeneratedServiceFileName(const ServiceDescriptor* service,
const Options& options) {
std::string result = FullClassName(service, options) + "Interface";
@ -491,11 +507,11 @@ std::string PhpSetterTypeName(const FieldDescriptor* field,
}
if (field->is_repeated()) {
// accommodate for edge case with multiple types.
size_t start_pos = type.find("|");
size_t start_pos = type.find('|');
if (start_pos != std::string::npos) {
type.replace(start_pos, 1, "[]|");
type.replace(start_pos, 1, ">|array<");
}
type += "[]|\\Google\\Protobuf\\Internal\\RepeatedField";
type = "array<" + type + ">|\\Google\\Protobuf\\Internal\\RepeatedField";
}
return type;
}
@ -1118,7 +1134,7 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
std::map<const FileDescriptor*, int> dependency_count;
std::set<const FileDescriptor*> nodes_without_dependency;
FileDescriptorSet sorted_file_set;
AnalyzeDependencyForFile(
file, &nodes_without_dependency, &deps, &dependency_count);
@ -1223,7 +1239,7 @@ void GenerateHead(const FileDescriptor* file, io::Printer* printer) {
}
std::string FilenameToClassname(const std::string& filename) {
int lastindex = filename.find_last_of(".");
int lastindex = filename.find_last_of('.');
std::string result = filename.substr(0, lastindex);
for (int i = 0; i < result.size(); i++) {
if (result[i] == '/') {
@ -1243,7 +1259,7 @@ void GenerateMetadataFile(const FileDescriptor* file, const Options& options,
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (lastindex != std::string::npos) {
printer.Print(
@ -1305,6 +1321,45 @@ void LegacyGenerateClassFile(const FileDescriptor* file,
"fullname", newname);
}
template <typename DescriptorType>
void LegacyReadOnlyGenerateClassFile(const FileDescriptor* file,
const DescriptorType* desc, const Options& options,
GeneratorContext* generator_context) {
std::string fullname = FullClassName(desc, options);
std::string php_namespace;
std::string classname;
int lastindex = fullname.find_last_of("\\");
if (lastindex != std::string::npos) {
php_namespace = fullname.substr(0, lastindex);
classname = fullname.substr(lastindex + 1);
} else {
php_namespace = "";
classname = fullname;
}
std::string filename = LegacyReadOnlyGeneratedClassFileName(php_namespace, desc);
std::unique_ptr<io::ZeroCopyOutputStream> output(
generator_context->Open(filename));
io::Printer printer(output.get(), '^');
GenerateHead(file, &printer);
if (!php_namespace.empty()) {
printer.Print(
"namespace ^name^;\n\n",
"name", php_namespace);
}
printer.Print("class_exists(^new^::class); // autoload the new class, which "
"will also create an alias to the deprecated class\n",
"new", classname);
printer.Print("@trigger_error(__NAMESPACE__ . '\\^old^ is deprecated and will be removed in "
"the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n",
"old", desc->name(),
"fullname", classname);
}
void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
const Options& options,
GeneratorContext* generator_context) {
@ -1316,7 +1371,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (lastindex != std::string::npos) {
printer.Print(
@ -1340,11 +1395,18 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
"name", fullname);
Indent(&printer);
bool hasReserved = false;
for (int i = 0; i < en->value_count(); i++) {
const EnumValueDescriptor* value = en->value(i);
GenerateEnumValueDocComment(&printer, value);
std::string prefix = ConstantNamePrefix(value->name());
if (!prefix.empty()) {
hasReserved = true;
}
printer.Print("const ^name^ = ^number^;\n",
"name", ConstantNamePrefix(value->name()) + value->name(),
"name", prefix + value->name(),
"number", IntToString(value->number()));
}
@ -1352,8 +1414,9 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
Indent(&printer);
for (int i = 0; i < en->value_count(); i++) {
const EnumValueDescriptor* value = en->value(i);
printer.Print("self::^name^ => '^name^',\n",
"name", ConstantNamePrefix(value->name()) + value->name());
printer.Print("self::^constant^ => '^name^',\n",
"constant", ConstantNamePrefix(value->name()) + value->name(),
"name", value->name());
}
Outdent(&printer);
printer.Print("];\n");
@ -1383,12 +1446,22 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
printer.Print("$const = __CLASS__ . '::' . strtoupper($name);\n"
"if (!defined($const)) {\n");
Indent(&printer);
if (hasReserved) {
printer.Print("$pbconst = __CLASS__. '::PB' . strtoupper($name);\n"
"if (!defined($pbconst)) {\n");
Indent(&printer);
}
printer.Print("throw new UnexpectedValueException(sprintf(\n");
Indent(&printer);
Indent(&printer);
printer.Print("'Enum %s has no value defined for name %s', __CLASS__, $name));\n");
Outdent(&printer);
Outdent(&printer);
if (hasReserved) {
Outdent(&printer);
printer.Print("}\n"
"return constant($pbconst);\n");
}
Outdent(&printer);
printer.Print("}\n"
"return constant($const);\n");
@ -1398,7 +1471,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
Outdent(&printer);
printer.Print("}\n\n");
// write legacy file for backwards compatibility with nested messages and enums
// write legacy alias for backwards compatibility with nested messages and enums
if (en->containing_type() != NULL) {
printer.Print(
"// Adding a class alias for backwards compatibility with the previous class name.\n");
@ -1406,7 +1479,19 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
"class_alias(^new^::class, \\^old^::class);\n\n",
"new", fullname,
"old", LegacyFullClassName(en, options));
LegacyGenerateClassFile(file, en, options, generator_context);
}
// Write legacy file for backwards compatibility with "readonly" keywword
std::string lower = en->name();
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "readonly") {
printer.Print(
"// Adding a class alias for backwards compatibility with the \"readonly\" keyword.\n");
printer.Print(
"class_alias(^new^::class, __NAMESPACE__ . '\\^old^');\n\n",
"new", fullname,
"old", en->name());
LegacyReadOnlyGenerateClassFile(file, en, options, generator_context);
}
}
@ -1427,7 +1512,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (lastindex != std::string::npos) {
printer.Print(
@ -1513,7 +1598,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
Outdent(&printer);
printer.Print("}\n\n");
// write legacy file for backwards compatibility with nested messages and enums
// write legacy alias for backwards compatibility with nested messages and enums
if (message->containing_type() != NULL) {
printer.Print(
"// Adding a class alias for backwards compatibility with the previous class name.\n");
@ -1521,7 +1606,19 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
"class_alias(^new^::class, \\^old^::class);\n\n",
"new", fullname,
"old", LegacyFullClassName(message, options));
LegacyGenerateClassFile(file, message, options, generator_context);
}
// Write legacy file for backwards compatibility with "readonly" keywword
std::string lower = message->name();
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "readonly") {
printer.Print(
"// Adding a class alias for backwards compatibility with the \"readonly\" keyword.\n");
printer.Print(
"class_alias(^new^::class, __NAMESPACE__ . '\\^old^');\n\n",
"new", fullname,
"old", message->name());
LegacyReadOnlyGenerateClassFile(file, message, options, generator_context);
}
// Nested messages and enums.
@ -1545,7 +1642,7 @@ void GenerateServiceFile(
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (!file->options().php_namespace().empty() ||
(!file->options().has_php_namespace() && !file->package().empty()) ||
@ -1873,44 +1970,45 @@ void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) {
"\n"
"PHP_METHOD($c_name$, name) {\n"
" $file_c_name$_AddDescriptor();\n"
" const upb_symtab *symtab = DescriptorPool_GetSymbolTable();\n"
" const upb_enumdef *e = upb_symtab_lookupenum(symtab, \"$name$\");\n"
" const char *name;\n"
" const upb_DefPool *symtab = DescriptorPool_GetSymbolTable();\n"
" const upb_EnumDef *e = upb_DefPool_FindEnumByName(symtab, \"$name$\");\n"
" zend_long value;\n"
" if (zend_parse_parameters(ZEND_NUM_ARGS(), \"l\", &value) ==\n"
" FAILURE) {\n"
" return;\n"
" }\n"
" name = upb_enumdef_iton(e, value);\n"
" if (!name) {\n"
" const upb_EnumValueDef* ev =\n"
" upb_EnumDef_FindValueByNumber(e, value);\n"
" if (!ev) {\n"
" zend_throw_exception_ex(NULL, 0,\n"
" \"$php_name$ has no name \"\n"
" \"defined for value \" ZEND_LONG_FMT \".\",\n"
" value);\n"
" return;\n"
" }\n"
" RETURN_STRING(name);\n"
" RETURN_STRING(upb_EnumValueDef_Name(ev));\n"
"}\n"
"\n"
"PHP_METHOD($c_name$, value) {\n"
" $file_c_name$_AddDescriptor();\n"
" const upb_symtab *symtab = DescriptorPool_GetSymbolTable();\n"
" const upb_enumdef *e = upb_symtab_lookupenum(symtab, \"$name$\");\n"
" const upb_DefPool *symtab = DescriptorPool_GetSymbolTable();\n"
" const upb_EnumDef *e = upb_DefPool_FindEnumByName(symtab, \"$name$\");\n"
" char *name = NULL;\n"
" size_t name_len;\n"
" int32_t num;\n"
" if (zend_parse_parameters(ZEND_NUM_ARGS(), \"s\", &name,\n"
" &name_len) == FAILURE) {\n"
" return;\n"
" }\n"
" if (!upb_enumdef_ntoi(e, name, name_len, &num)) {\n"
" const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNameWithSize(\n"
" e, name, name_len);\n"
" if (!ev) {\n"
" zend_throw_exception_ex(NULL, 0,\n"
" \"$php_name$ has no value \"\n"
" \"defined for name %s.\",\n"
" name);\n"
" return;\n"
" }\n"
" RETURN_LONG(num);\n"
" RETURN_LONG(upb_EnumValueDef_Number(ev));\n"
"}\n"
"\n"
"static zend_function_entry $c_name$_phpmethods[] = {\n"
@ -1969,8 +2067,8 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
printer->Print(
"static PHP_METHOD($c_name$, get$camel_name$) {\n"
" Message* intern = (Message*)Z_OBJ_P(getThis());\n"
" const upb_fielddef *f = upb_msgdef_ntofz(intern->desc->msgdef,\n"
" \"$name$\");\n"
" const upb_FieldDef *f = upb_MessageDef_FindFieldByName(\n"
" intern->desc->msgdef, \"$name$\");\n"
" zval ret;\n"
" Message_get(intern, f, &ret);\n"
" RETURN_COPY_VALUE(&ret);\n"
@ -1978,8 +2076,8 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
"\n"
"static PHP_METHOD($c_name$, set$camel_name$) {\n"
" Message* intern = (Message*)Z_OBJ_P(getThis());\n"
" const upb_fielddef *f = upb_msgdef_ntofz(intern->desc->msgdef,\n"
" \"$name$\");\n"
" const upb_FieldDef *f = upb_MessageDef_FindFieldByName(\n"
" intern->desc->msgdef, \"$name$\");\n"
" zval *val;\n"
" if (zend_parse_parameters(ZEND_NUM_ARGS(), \"z\", &val)\n"
" == FAILURE) {\n"
@ -1999,10 +2097,11 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
printer->Print(
"static PHP_METHOD($c_name$, get$camel_name$) {\n"
" Message* intern = (Message*)Z_OBJ_P(getThis());\n"
" const upb_oneofdef *oneof = upb_msgdef_ntooz(intern->desc->msgdef,\n"
" \"$name$\");\n"
" const upb_fielddef *field = upb_msg_whichoneof(intern->msg, oneof);\n"
" RETURN_STRING(field ? upb_fielddef_name(field) : \"\");\n"
" const upb_OneofDef *oneof = upb_MessageDef_FindOneofByName(\n"
" intern->desc->msgdef, \"$name$\");\n"
" const upb_FieldDef *field = \n"
" upb_Message_WhichOneof(intern->msg, oneof);\n"
" RETURN_STRING(field ? upb_FieldDef_Name(field) : \"\");\n"
"}\n",
"c_name", c_name,
"name", oneof->name(),
@ -2069,7 +2168,7 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
break;
default:
break;
}
}
printer->Print(
" ZEND_FE_END\n"

@ -1,33 +1,3 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";
package A.B.C;

@ -1,33 +1,3 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2";
package A.B.C;

@ -1,33 +1,3 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2";
package A.B.C;

@ -1,33 +1,3 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";
package one.two.a_three;

@ -1,33 +1,3 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";
package one.two.a_three.and;

@ -1,33 +1,3 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";
package one.two.a_three;

@ -68,7 +68,7 @@ std::string NumberToString(numeric_type value) {
}
std::string GetRequireName(const std::string& proto_file) {
int lastindex = proto_file.find_last_of(".");
int lastindex = proto_file.find_last_of('.');
return proto_file.substr(0, lastindex) + "_pb";
}
@ -158,7 +158,7 @@ std::string DefaultValueForField(const FieldDescriptor* field) {
for (int i = 0; i < default_str.length(); ++i) {
// Write the hex form of each byte.
os << "\\x" << std::hex << std::setw(2)
<< ((uint16)((unsigned char)default_str.at(i)));
<< ((uint16_t)((unsigned char)default_str.at(i)));
}
os << "\".force_encoding(\"ASCII-8BIT\")";
}
@ -421,7 +421,7 @@ int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) {
// -> A.B.C
if (package_name.find("::") != std::string::npos) {
need_change_to_module = false;
} else if (package_name.find(".") != std::string::npos) {
} else if (package_name.find('.') != std::string::npos) {
GOOGLE_LOG(WARNING) << "ruby_package option should be in the form of:"
<< " 'A::B::C' and not 'A.B.C'";
}

Loading…
Cancel
Save