|
|
|
@ -48,29 +48,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", |
|
|
|
|
"parent", "print", "private", "protected", "public", |
|
|
|
|
"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"}; |
|
|
|
|
"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", "parent", |
|
|
|
|
"self" |
|
|
|
|
"self", "readonly" |
|
|
|
|
}; |
|
|
|
|
const int kReservedNamesSize = 79; |
|
|
|
|
const int kValidConstantNamesSize = 11; |
|
|
|
|
const int kReservedNamesSize = 80; |
|
|
|
|
const int kValidConstantNamesSize = 12; |
|
|
|
|
const int kFieldSetter = 1; |
|
|
|
|
const int kFieldGetter = 2; |
|
|
|
|
const int kFieldProperty = 3; |
|
|
|
@ -420,6 +420,16 @@ std::string LegacyGeneratedClassFileName(const DescriptorType* desc, |
|
|
|
|
return result + ".php"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename DescriptorType> |
|
|
|
|
std::string LegacyReadOnlyGeneratedClassFileName(const DescriptorType* desc, |
|
|
|
|
const Options& options) { |
|
|
|
|
std::string php_namespace = RootPhpNamespace(desc, options); |
|
|
|
|
if (!php_namespace.empty()) { |
|
|
|
|
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"; |
|
|
|
@ -1302,6 +1312,32 @@ 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 filename = LegacyReadOnlyGeneratedClassFileName(desc, options); |
|
|
|
|
std::unique_ptr<io::ZeroCopyOutputStream> output( |
|
|
|
|
generator_context->Open(filename)); |
|
|
|
|
io::Printer printer(output.get(), '^'); |
|
|
|
|
|
|
|
|
|
GenerateHead(file, &printer); |
|
|
|
|
|
|
|
|
|
std::string php_namespace = RootPhpNamespace(desc, options); |
|
|
|
|
if (!php_namespace.empty()) { |
|
|
|
|
printer.Print( |
|
|
|
|
"namespace ^name^;\n\n", |
|
|
|
|
"name", php_namespace); |
|
|
|
|
} |
|
|
|
|
std::string newname = FullClassName(desc, options); |
|
|
|
|
printer.Print("class_exists(^new^::class);\n", |
|
|
|
|
"new", GeneratedClassNameImpl(desc)); |
|
|
|
|
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", newname); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, |
|
|
|
|
const Options& options, |
|
|
|
|
GeneratorContext* generator_context) { |
|
|
|
@ -1405,6 +1441,19 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, |
|
|
|
|
"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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, |
|
|
|
@ -1521,6 +1570,19 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, |
|
|
|
|
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.
|
|
|
|
|
for (int i = 0; i < message->nested_type_count(); i++) { |
|
|
|
|
GenerateMessageFile(file, message->nested_type(i), options, |
|
|
|
|