Unverified Commit a239ed2b authored by Paul Yang's avatar Paul Yang Committed by GitHub

Merge pull request #4702 from TeBoring/3.6.x

Cherry-pick changes into 3.6.x
parents d31864a7 4f5eb100
...@@ -157,7 +157,7 @@ std::string ClassNamePrefix(const string& classname, ...@@ -157,7 +157,7 @@ std::string ClassNamePrefix(const string& classname,
} }
template <typename DescriptorType> template <typename DescriptorType>
std::string GeneratedClassName(const DescriptorType* desc) { std::string GeneratedClassNameImpl(const DescriptorType* desc) {
std::string classname = ClassNamePrefix(desc->name(), desc) + desc->name(); std::string classname = ClassNamePrefix(desc->name(), desc) + desc->name();
const Descriptor* containing = desc->containing_type(); const Descriptor* containing = desc->containing_type();
while (containing != NULL) { while (containing != NULL) {
...@@ -168,11 +168,23 @@ std::string GeneratedClassName(const DescriptorType* desc) { ...@@ -168,11 +168,23 @@ std::string GeneratedClassName(const DescriptorType* desc) {
return classname; return classname;
} }
std::string GeneratedClassName(const ServiceDescriptor* desc) { std::string GeneratedClassNameImpl(const ServiceDescriptor* desc) {
std::string classname = desc->name(); std::string classname = desc->name();
return ClassNamePrefix(classname, desc) + classname; return ClassNamePrefix(classname, desc) + classname;
} }
std::string GeneratedClassName(const Descriptor* desc) {
return GeneratedClassNameImpl(desc);
}
std::string GeneratedClassName(const EnumDescriptor* desc) {
return GeneratedClassNameImpl(desc);
}
std::string GeneratedClassName(const ServiceDescriptor* desc) {
return GeneratedClassNameImpl(desc);
}
template <typename DescriptorType> template <typename DescriptorType>
std::string LegacyGeneratedClassName(const DescriptorType* desc) { std::string LegacyGeneratedClassName(const DescriptorType* desc) {
std::string classname = desc->name(); std::string classname = desc->name();
...@@ -242,7 +254,7 @@ std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) { ...@@ -242,7 +254,7 @@ std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
template <typename DescriptorType> template <typename DescriptorType>
std::string FullClassName(const DescriptorType* desc, bool is_descriptor) { std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
string classname = GeneratedClassName(desc); string classname = GeneratedClassNameImpl(desc);
string php_namespace = RootPhpNamespace(desc, is_descriptor); string php_namespace = RootPhpNamespace(desc, is_descriptor);
if (php_namespace != "") { if (php_namespace != "") {
return php_namespace + "\\" + classname; return php_namespace + "\\" + classname;
...@@ -1074,7 +1086,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file, const DescriptorType* d ...@@ -1074,7 +1086,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file, const DescriptorType* d
Outdent(&printer); Outdent(&printer);
printer.Print("}\n"); printer.Print("}\n");
printer.Print("class_exists(^new^::class);\n", printer.Print("class_exists(^new^::class);\n",
"new", GeneratedClassName(desc)); "new", GeneratedClassNameImpl(desc));
printer.Print("@trigger_error('^old^ is deprecated and will be removed in " printer.Print("@trigger_error('^old^ is deprecated and will be removed in "
"the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n", "the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n",
"old", LegacyFullClassName(desc, is_descriptor), "old", LegacyFullClassName(desc, is_descriptor),
......
...@@ -48,9 +48,18 @@ class LIBPROTOC_EXPORT Generator ...@@ -48,9 +48,18 @@ class LIBPROTOC_EXPORT Generator
const string& parameter, const string& parameter,
GeneratorContext* generator_context, GeneratorContext* generator_context,
string* error) const; string* error) const;
}; };
// To skip reserved keywords in php, some generated classname are prefixed.
// Other code generators may need following API to figure out the actual
// classname.
LIBPROTOC_EXPORT std::string GeneratedClassName(
const google::protobuf::Descriptor* desc);
LIBPROTOC_EXPORT std::string GeneratedClassName(
const google::protobuf::EnumDescriptor* desc);
LIBPROTOC_EXPORT std::string GeneratedClassName(
const google::protobuf::ServiceDescriptor* desc);
} // namespace php } // namespace php
} // namespace compiler } // namespace compiler
} // namespace protobuf } // namespace protobuf
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment