|
@@ -82,18 +82,20 @@ namespace php {
|
|
std::string PhpName(const std::string& full_name, bool is_descriptor);
|
|
std::string PhpName(const std::string& full_name, bool is_descriptor);
|
|
std::string DefaultForField(FieldDescriptor* field);
|
|
std::string DefaultForField(FieldDescriptor* field);
|
|
std::string IntToString(int32 value);
|
|
std::string IntToString(int32 value);
|
|
-std::string FilenameToClassname(const string& filename);
|
|
|
|
|
|
+std::string FilenameToClassname(const std::string& filename);
|
|
std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
bool is_descriptor);
|
|
bool is_descriptor);
|
|
std::string LabelForField(FieldDescriptor* field);
|
|
std::string LabelForField(FieldDescriptor* field);
|
|
std::string TypeName(FieldDescriptor* field);
|
|
std::string TypeName(FieldDescriptor* field);
|
|
-std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter);
|
|
|
|
-std::string BinaryToHex(const string& binary);
|
|
|
|
|
|
+std::string UnderscoresToCamelCase(const std::string& name,
|
|
|
|
+ bool cap_first_letter);
|
|
|
|
+std::string BinaryToHex(const std::string& binary);
|
|
void Indent(io::Printer* printer);
|
|
void Indent(io::Printer* printer);
|
|
void Outdent(io::Printer* printer);
|
|
void Outdent(io::Printer* printer);
|
|
-void GenerateAddFilesToPool(const FileDescriptor* file,
|
|
|
|
- const std::set<string>& aggregate_metadata_prefixes,
|
|
|
|
- io::Printer* printer);
|
|
|
|
|
|
+void GenerateAddFilesToPool(
|
|
|
|
+ const FileDescriptor* file,
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes,
|
|
|
|
+ io::Printer* printer);
|
|
void GenerateMessageDocComment(io::Printer* printer, const Descriptor* message,
|
|
void GenerateMessageDocComment(io::Printer* printer, const Descriptor* message,
|
|
int is_descriptor);
|
|
int is_descriptor);
|
|
void GenerateMessageConstructorDocComment(io::Printer* printer,
|
|
void GenerateMessageConstructorDocComment(io::Printer* printer,
|
|
@@ -114,11 +116,11 @@ void GenerateServiceDocComment(io::Printer* printer,
|
|
void GenerateServiceMethodDocComment(io::Printer* printer,
|
|
void GenerateServiceMethodDocComment(io::Printer* printer,
|
|
const MethodDescriptor* method);
|
|
const MethodDescriptor* method);
|
|
|
|
|
|
-std::string ReservedNamePrefix(const string& classname,
|
|
|
|
|
|
+std::string ReservedNamePrefix(const std::string& classname,
|
|
const FileDescriptor* file) {
|
|
const FileDescriptor* file) {
|
|
bool is_reserved = false;
|
|
bool is_reserved = false;
|
|
|
|
|
|
- string lower = classname;
|
|
|
|
|
|
+ std::string lower = classname;
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
|
|
|
|
for (int i = 0; i < kReservedNamesSize; i++) {
|
|
for (int i = 0; i < kReservedNamesSize; i++) {
|
|
@@ -151,9 +153,9 @@ std::string DescriptorFullName(const DescriptorType* desc, bool is_descriptor) {
|
|
}
|
|
}
|
|
|
|
|
|
template <typename DescriptorType>
|
|
template <typename DescriptorType>
|
|
-std::string ClassNamePrefix(const string& classname,
|
|
|
|
|
|
+std::string ClassNamePrefix(const std::string& classname,
|
|
const DescriptorType* desc) {
|
|
const DescriptorType* desc) {
|
|
- const string& prefix = (desc->file()->options()).php_class_prefix();
|
|
|
|
|
|
+ const std::string& prefix = (desc->file()->options()).php_class_prefix();
|
|
if (!prefix.empty()) {
|
|
if (!prefix.empty()) {
|
|
return prefix;
|
|
return prefix;
|
|
}
|
|
}
|
|
@@ -201,8 +203,8 @@ std::string LegacyGeneratedClassName(const DescriptorType* desc) {
|
|
return ClassNamePrefix(classname, desc) + classname;
|
|
return ClassNamePrefix(classname, desc) + classname;
|
|
}
|
|
}
|
|
|
|
|
|
-std::string ClassNamePrefix(const string& classname) {
|
|
|
|
- string lower = classname;
|
|
|
|
|
|
+std::string ClassNamePrefix(const std::string& classname) {
|
|
|
|
+ std::string lower = classname;
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
|
|
|
|
for (int i = 0; i < kReservedNamesSize; i++) {
|
|
for (int i = 0; i < kReservedNamesSize; i++) {
|
|
@@ -214,10 +216,10 @@ std::string ClassNamePrefix(const string& classname) {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
-std::string ConstantNamePrefix(const string& classname) {
|
|
|
|
|
|
+std::string ConstantNamePrefix(const std::string& classname) {
|
|
bool is_reserved = false;
|
|
bool is_reserved = false;
|
|
|
|
|
|
- string lower = classname;
|
|
|
|
|
|
+ std::string lower = classname;
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
|
|
|
|
for (int i = 0; i < kReservedNamesSize; i++) {
|
|
for (int i = 0; i < kReservedNamesSize; i++) {
|
|
@@ -244,7 +246,7 @@ std::string ConstantNamePrefix(const string& classname) {
|
|
template <typename DescriptorType>
|
|
template <typename DescriptorType>
|
|
std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
|
|
std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
|
|
if (desc->file()->options().has_php_namespace()) {
|
|
if (desc->file()->options().has_php_namespace()) {
|
|
- const string& php_namespace = desc->file()->options().php_namespace();
|
|
|
|
|
|
+ const std::string& php_namespace = desc->file()->options().php_namespace();
|
|
if (!php_namespace.empty()) {
|
|
if (!php_namespace.empty()) {
|
|
return php_namespace;
|
|
return php_namespace;
|
|
}
|
|
}
|
|
@@ -259,8 +261,8 @@ 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 = GeneratedClassNameImpl(desc);
|
|
|
|
- string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
|
|
|
|
+ std::string classname = GeneratedClassNameImpl(desc);
|
|
|
|
+ std::string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
if (!php_namespace.empty()) {
|
|
if (!php_namespace.empty()) {
|
|
return php_namespace + "\\" + classname;
|
|
return php_namespace + "\\" + classname;
|
|
}
|
|
}
|
|
@@ -269,8 +271,8 @@ std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
|
|
|
|
|
|
template <typename DescriptorType>
|
|
template <typename DescriptorType>
|
|
std::string LegacyFullClassName(const DescriptorType* desc, bool is_descriptor) {
|
|
std::string LegacyFullClassName(const DescriptorType* desc, bool is_descriptor) {
|
|
- string classname = LegacyGeneratedClassName(desc);
|
|
|
|
- string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
|
|
|
|
+ std::string classname = LegacyGeneratedClassName(desc);
|
|
|
|
+ std::string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
if (!php_namespace.empty()) {
|
|
if (!php_namespace.empty()) {
|
|
return php_namespace + "\\" + classname;
|
|
return php_namespace + "\\" + classname;
|
|
}
|
|
}
|
|
@@ -328,7 +330,7 @@ std::string DefaultForField(const FieldDescriptor* field) {
|
|
|
|
|
|
std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
bool is_descriptor) {
|
|
bool is_descriptor) {
|
|
- const string& proto_file = file->name();
|
|
|
|
|
|
+ const std::string& proto_file = file->name();
|
|
int start_index = 0;
|
|
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 result = "";
|
|
@@ -351,7 +353,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
}
|
|
}
|
|
|
|
|
|
if (file->options().has_php_metadata_namespace()) {
|
|
if (file->options().has_php_metadata_namespace()) {
|
|
- const string& php_metadata_namespace =
|
|
|
|
|
|
+ const std::string& php_metadata_namespace =
|
|
file->options().php_metadata_namespace();
|
|
file->options().php_metadata_namespace();
|
|
if (!php_metadata_namespace.empty() && php_metadata_namespace != "\\") {
|
|
if (!php_metadata_namespace.empty() && php_metadata_namespace != "\\") {
|
|
result += php_metadata_namespace;
|
|
result += php_metadata_namespace;
|
|
@@ -362,7 +364,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
result += "GPBMetadata/";
|
|
result += "GPBMetadata/";
|
|
- while (first_index != string::npos) {
|
|
|
|
|
|
+ while (first_index != std::string::npos) {
|
|
segment = UnderscoresToCamelCase(
|
|
segment = UnderscoresToCamelCase(
|
|
file_no_suffix.substr(start_index, first_index - start_index), true);
|
|
file_no_suffix.substr(start_index, first_index - start_index), true);
|
|
result += ReservedNamePrefix(segment, file) + segment + "/";
|
|
result += ReservedNamePrefix(segment, file) + segment + "/";
|
|
@@ -373,7 +375,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
|
|
|
|
// Append file name.
|
|
// 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 == string::npos) {
|
|
|
|
|
|
+ if (file_name_start == std::string::npos) {
|
|
file_name_start = 0;
|
|
file_name_start = 0;
|
|
} else {
|
|
} else {
|
|
file_name_start += 1;
|
|
file_name_start += 1;
|
|
@@ -463,7 +465,7 @@ std::string PhpSetterTypeName(const FieldDescriptor* field, bool is_descriptor)
|
|
if (field->is_map()) {
|
|
if (field->is_map()) {
|
|
return "array|\\Google\\Protobuf\\Internal\\MapField";
|
|
return "array|\\Google\\Protobuf\\Internal\\MapField";
|
|
}
|
|
}
|
|
- string type;
|
|
|
|
|
|
+ std::string type;
|
|
switch (field->type()) {
|
|
switch (field->type()) {
|
|
case FieldDescriptor::TYPE_INT32:
|
|
case FieldDescriptor::TYPE_INT32:
|
|
case FieldDescriptor::TYPE_UINT32:
|
|
case FieldDescriptor::TYPE_UINT32:
|
|
@@ -553,7 +555,8 @@ std::string EnumOrMessageSuffix(
|
|
|
|
|
|
// Converts a name to camel-case. If cap_first_letter is true, capitalize the
|
|
// Converts a name to camel-case. If cap_first_letter is true, capitalize the
|
|
// first letter.
|
|
// first letter.
|
|
-std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter) {
|
|
|
|
|
|
+std::string UnderscoresToCamelCase(const std::string& name,
|
|
|
|
+ bool cap_first_letter) {
|
|
std::string result;
|
|
std::string result;
|
|
for (int i = 0; i < name.size(); i++) {
|
|
for (int i = 0; i < name.size(); i++) {
|
|
if ('a' <= name[i] && name[i] <= 'z') {
|
|
if ('a' <= name[i] && name[i] <= 'z') {
|
|
@@ -587,8 +590,8 @@ std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
-std::string BinaryToHex(const string& binary) {
|
|
|
|
- string dest;
|
|
|
|
|
|
+std::string BinaryToHex(const std::string& binary) {
|
|
|
|
+ std::string dest;
|
|
size_t i;
|
|
size_t i;
|
|
unsigned char symbol[16] = {
|
|
unsigned char symbol[16] = {
|
|
'0', '1', '2', '3',
|
|
'0', '1', '2', '3',
|
|
@@ -844,15 +847,16 @@ void GenerateServiceMethod(const MethodDescriptor* method,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
-void GenerateMessageToPool(const string& name_prefix, const Descriptor* message,
|
|
|
|
- io::Printer* printer) {
|
|
|
|
|
|
+void GenerateMessageToPool(const std::string& name_prefix,
|
|
|
|
+ const Descriptor* message, io::Printer* printer) {
|
|
// Don't generate MapEntry messages -- we use the PHP extension's native
|
|
// Don't generate MapEntry messages -- we use the PHP extension's native
|
|
// support for map fields instead.
|
|
// support for map fields instead.
|
|
if (message->options().map_entry()) {
|
|
if (message->options().map_entry()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- string class_name = (name_prefix.empty() ? "" : name_prefix + "\\") +
|
|
|
|
- ReservedNamePrefix(message->name(), message->file()) + message->name();
|
|
|
|
|
|
+ std::string class_name =
|
|
|
|
+ (name_prefix.empty() ? "" : name_prefix + "\\") +
|
|
|
|
+ ReservedNamePrefix(message->name(), message->file()) + message->name();
|
|
|
|
|
|
printer->Print(
|
|
printer->Print(
|
|
"$pool->addMessage('^message^', "
|
|
"$pool->addMessage('^message^', "
|
|
@@ -926,10 +930,8 @@ void GenerateMessageToPool(const string& name_prefix, const Descriptor* message,
|
|
}
|
|
}
|
|
|
|
|
|
void GenerateAddFileToPool(
|
|
void GenerateAddFileToPool(
|
|
- const FileDescriptor* file,
|
|
|
|
- bool is_descriptor,
|
|
|
|
- bool aggregate_metadata,
|
|
|
|
- const std::set<string>& aggregate_metadata_prefixes,
|
|
|
|
|
|
+ const FileDescriptor* file, bool is_descriptor, bool aggregate_metadata,
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes,
|
|
io::Printer* printer) {
|
|
io::Printer* printer) {
|
|
printer->Print(
|
|
printer->Print(
|
|
"public static $is_initialized = false;\n\n"
|
|
"public static $is_initialized = false;\n\n"
|
|
@@ -978,8 +980,9 @@ void GenerateAddFileToPool(
|
|
file->CopyTo(file_proto);
|
|
file->CopyTo(file_proto);
|
|
|
|
|
|
// Filter out descriptor.proto as it cannot be depended on for now.
|
|
// Filter out descriptor.proto as it cannot be depended on for now.
|
|
- RepeatedPtrField<string>* dependency = file_proto->mutable_dependency();
|
|
|
|
- for (RepeatedPtrField<string>::iterator it = dependency->begin();
|
|
|
|
|
|
+ RepeatedPtrField<std::string>* dependency =
|
|
|
|
+ file_proto->mutable_dependency();
|
|
|
|
+ for (RepeatedPtrField<std::string>::iterator it = dependency->begin();
|
|
it != dependency->end(); ++it) {
|
|
it != dependency->end(); ++it) {
|
|
if (*it != kDescriptorFile) {
|
|
if (*it != kDescriptorFile) {
|
|
dependency->erase(it);
|
|
dependency->erase(it);
|
|
@@ -996,7 +999,7 @@ void GenerateAddFileToPool(
|
|
it->clear_extension();
|
|
it->clear_extension();
|
|
}
|
|
}
|
|
|
|
|
|
- string files_data;
|
|
|
|
|
|
+ std::string files_data;
|
|
files.SerializeToString(&files_data);
|
|
files.SerializeToString(&files_data);
|
|
|
|
|
|
printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
|
|
printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
|
|
@@ -1053,7 +1056,7 @@ static void AnalyzeDependencyForFile(
|
|
|
|
|
|
static bool NeedsUnwrapping(
|
|
static bool NeedsUnwrapping(
|
|
const FileDescriptor* file,
|
|
const FileDescriptor* file,
|
|
- const std::set<string>& aggregate_metadata_prefixes) {
|
|
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes) {
|
|
bool has_aggregate_metadata_prefix = false;
|
|
bool has_aggregate_metadata_prefix = false;
|
|
if (aggregate_metadata_prefixes.empty()) {
|
|
if (aggregate_metadata_prefixes.empty()) {
|
|
has_aggregate_metadata_prefix = true;
|
|
has_aggregate_metadata_prefix = true;
|
|
@@ -1071,7 +1074,7 @@ static bool NeedsUnwrapping(
|
|
|
|
|
|
void GenerateAddFilesToPool(
|
|
void GenerateAddFilesToPool(
|
|
const FileDescriptor* file,
|
|
const FileDescriptor* file,
|
|
- const std::set<string>& aggregate_metadata_prefixes,
|
|
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes,
|
|
io::Printer* printer) {
|
|
io::Printer* printer) {
|
|
printer->Print(
|
|
printer->Print(
|
|
"$pool = \\Google\\Protobuf\\Internal\\"
|
|
"$pool = \\Google\\Protobuf\\Internal\\"
|
|
@@ -1108,8 +1111,9 @@ void GenerateAddFilesToPool(
|
|
file->CopyTo(file_proto);
|
|
file->CopyTo(file_proto);
|
|
|
|
|
|
// Filter out descriptor.proto as it cannot be depended on for now.
|
|
// Filter out descriptor.proto as it cannot be depended on for now.
|
|
- RepeatedPtrField<string>* dependency = file_proto->mutable_dependency();
|
|
|
|
- for (RepeatedPtrField<string>::iterator it = dependency->begin();
|
|
|
|
|
|
+ RepeatedPtrField<std::string>* dependency =
|
|
|
|
+ file_proto->mutable_dependency();
|
|
|
|
+ for (RepeatedPtrField<std::string>::iterator it = dependency->begin();
|
|
it != dependency->end(); ++it) {
|
|
it != dependency->end(); ++it) {
|
|
if (*it != kDescriptorFile) {
|
|
if (*it != kDescriptorFile) {
|
|
dependency->erase(it);
|
|
dependency->erase(it);
|
|
@@ -1134,7 +1138,7 @@ void GenerateAddFilesToPool(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- string files_data;
|
|
|
|
|
|
+ std::string files_data;
|
|
sorted_file_set.SerializeToString(&files_data);
|
|
sorted_file_set.SerializeToString(&files_data);
|
|
|
|
|
|
printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
|
|
printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
|
|
@@ -1177,7 +1181,7 @@ void GenerateHead(const FileDescriptor* file, io::Printer* printer) {
|
|
"filename", file->name());
|
|
"filename", file->name());
|
|
}
|
|
}
|
|
|
|
|
|
-std::string FilenameToClassname(const string& filename) {
|
|
|
|
|
|
+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);
|
|
std::string result = filename.substr(0, lastindex);
|
|
for (int i = 0; i < result.size(); i++) {
|
|
for (int i = 0; i < result.size(); i++) {
|
|
@@ -1188,11 +1192,10 @@ std::string FilenameToClassname(const string& filename) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
-void GenerateMetadataFile(const FileDescriptor* file,
|
|
|
|
- bool is_descriptor,
|
|
|
|
- bool aggregate_metadata,
|
|
|
|
- const std::set<string>& aggregate_metadata_prefixes,
|
|
|
|
- GeneratorContext* generator_context) {
|
|
|
|
|
|
+void GenerateMetadataFile(
|
|
|
|
+ const FileDescriptor* file, bool is_descriptor, bool aggregate_metadata,
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes,
|
|
|
|
+ GeneratorContext* generator_context) {
|
|
std::string filename = GeneratedMetadataFileName(file, is_descriptor);
|
|
std::string filename = GeneratedMetadataFileName(file, is_descriptor);
|
|
std::unique_ptr<io::ZeroCopyOutputStream> output(
|
|
std::unique_ptr<io::ZeroCopyOutputStream> output(
|
|
generator_context->Open(filename));
|
|
generator_context->Open(filename));
|
|
@@ -1203,7 +1206,7 @@ void GenerateMetadataFile(const FileDescriptor* file,
|
|
std::string fullname = FilenameToClassname(filename);
|
|
std::string fullname = FilenameToClassname(filename);
|
|
int lastindex = fullname.find_last_of("\\");
|
|
int lastindex = fullname.find_last_of("\\");
|
|
|
|
|
|
- if (lastindex != string::npos) {
|
|
|
|
|
|
+ if (lastindex != std::string::npos) {
|
|
printer.Print(
|
|
printer.Print(
|
|
"namespace ^name^;\n\n",
|
|
"namespace ^name^;\n\n",
|
|
"name", fullname.substr(0, lastindex));
|
|
"name", fullname.substr(0, lastindex));
|
|
@@ -1277,7 +1280,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
|
|
std::string fullname = FilenameToClassname(filename);
|
|
std::string fullname = FilenameToClassname(filename);
|
|
int lastindex = fullname.find_last_of("\\");
|
|
int lastindex = fullname.find_last_of("\\");
|
|
|
|
|
|
- if (lastindex != string::npos) {
|
|
|
|
|
|
+ if (lastindex != std::string::npos) {
|
|
printer.Print(
|
|
printer.Print(
|
|
"namespace ^name^;\n\n",
|
|
"namespace ^name^;\n\n",
|
|
"name", fullname.substr(0, lastindex));
|
|
"name", fullname.substr(0, lastindex));
|
|
@@ -1289,7 +1292,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
|
|
|
|
|
|
GenerateEnumDocComment(&printer, en, is_descriptor);
|
|
GenerateEnumDocComment(&printer, en, is_descriptor);
|
|
|
|
|
|
- if (lastindex != string::npos) {
|
|
|
|
|
|
+ if (lastindex != std::string::npos) {
|
|
fullname = fullname.substr(lastindex + 1);
|
|
fullname = fullname.substr(lastindex + 1);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1389,7 +1392,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
|
|
std::string fullname = FilenameToClassname(filename);
|
|
std::string fullname = FilenameToClassname(filename);
|
|
int lastindex = fullname.find_last_of("\\");
|
|
int lastindex = fullname.find_last_of("\\");
|
|
|
|
|
|
- if (lastindex != string::npos) {
|
|
|
|
|
|
+ if (lastindex != std::string::npos) {
|
|
printer.Print(
|
|
printer.Print(
|
|
"namespace ^name^;\n\n",
|
|
"namespace ^name^;\n\n",
|
|
"name", fullname.substr(0, lastindex));
|
|
"name", fullname.substr(0, lastindex));
|
|
@@ -1398,7 +1401,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
|
|
GenerateUseDeclaration(is_descriptor, &printer);
|
|
GenerateUseDeclaration(is_descriptor, &printer);
|
|
|
|
|
|
GenerateMessageDocComment(&printer, message, is_descriptor);
|
|
GenerateMessageDocComment(&printer, message, is_descriptor);
|
|
- if (lastindex != string::npos) {
|
|
|
|
|
|
+ if (lastindex != std::string::npos) {
|
|
fullname = fullname.substr(lastindex + 1);
|
|
fullname = fullname.substr(lastindex + 1);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1497,7 +1500,7 @@ void GenerateServiceFile(const FileDescriptor* file,
|
|
|
|
|
|
if (!file->options().php_namespace().empty() ||
|
|
if (!file->options().php_namespace().empty() ||
|
|
(!file->options().has_php_namespace() && !file->package().empty()) ||
|
|
(!file->options().has_php_namespace() && !file->package().empty()) ||
|
|
- lastindex != string::npos) {
|
|
|
|
|
|
+ lastindex != std::string::npos) {
|
|
printer.Print(
|
|
printer.Print(
|
|
"namespace ^name^;\n\n",
|
|
"namespace ^name^;\n\n",
|
|
"name", fullname.substr(0, lastindex));
|
|
"name", fullname.substr(0, lastindex));
|
|
@@ -1505,13 +1508,13 @@ void GenerateServiceFile(const FileDescriptor* file,
|
|
|
|
|
|
GenerateServiceDocComment(&printer, service);
|
|
GenerateServiceDocComment(&printer, service);
|
|
|
|
|
|
- if (lastindex != string::npos) {
|
|
|
|
- printer.Print(
|
|
|
|
|
|
+ if (lastindex != std::string::npos) {
|
|
|
|
+ printer.Print(
|
|
"interface ^name^\n"
|
|
"interface ^name^\n"
|
|
"{\n",
|
|
"{\n",
|
|
"name", fullname.substr(lastindex + 1));
|
|
"name", fullname.substr(lastindex + 1));
|
|
} else {
|
|
} else {
|
|
- printer.Print(
|
|
|
|
|
|
+ printer.Print(
|
|
"interface ^name^\n"
|
|
"interface ^name^\n"
|
|
"{\n",
|
|
"{\n",
|
|
"name", fullname);
|
|
"name", fullname);
|
|
@@ -1531,7 +1534,7 @@ void GenerateServiceFile(const FileDescriptor* file,
|
|
|
|
|
|
void GenerateFile(const FileDescriptor* file, bool is_descriptor,
|
|
void GenerateFile(const FileDescriptor* file, bool is_descriptor,
|
|
bool aggregate_metadata,
|
|
bool aggregate_metadata,
|
|
- const std::set<string>& aggregate_metadata_prefixes,
|
|
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes,
|
|
GeneratorContext* generator_context) {
|
|
GeneratorContext* generator_context) {
|
|
GenerateMetadataFile(file, is_descriptor, aggregate_metadata,
|
|
GenerateMetadataFile(file, is_descriptor, aggregate_metadata,
|
|
aggregate_metadata_prefixes, generator_context);
|
|
aggregate_metadata_prefixes, generator_context);
|
|
@@ -1553,13 +1556,13 @@ void GenerateFile(const FileDescriptor* file, bool is_descriptor,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static string EscapePhpdoc(const string& input) {
|
|
|
|
- string result;
|
|
|
|
|
|
+static std::string EscapePhpdoc(const std::string& input) {
|
|
|
|
+ std::string result;
|
|
result.reserve(input.size() * 2);
|
|
result.reserve(input.size() * 2);
|
|
|
|
|
|
char prev = '*';
|
|
char prev = '*';
|
|
|
|
|
|
- for (string::size_type i = 0; i < input.size(); i++) {
|
|
|
|
|
|
+ for (std::string::size_type i = 0; i < input.size(); i++) {
|
|
char c = input[i];
|
|
char c = input[i];
|
|
switch (c) {
|
|
switch (c) {
|
|
case '*':
|
|
case '*':
|
|
@@ -1598,8 +1601,9 @@ static string EscapePhpdoc(const string& input) {
|
|
static void GenerateDocCommentBodyForLocation(
|
|
static void GenerateDocCommentBodyForLocation(
|
|
io::Printer* printer, const SourceLocation& location, bool trailingNewline,
|
|
io::Printer* printer, const SourceLocation& location, bool trailingNewline,
|
|
int indentCount) {
|
|
int indentCount) {
|
|
- string comments = location.leading_comments.empty() ?
|
|
|
|
- location.trailing_comments : location.leading_comments;
|
|
|
|
|
|
+ std::string comments = location.leading_comments.empty()
|
|
|
|
+ ? location.trailing_comments
|
|
|
|
+ : location.leading_comments;
|
|
if (!comments.empty()) {
|
|
if (!comments.empty()) {
|
|
// TODO(teboring): Ideally we should parse the comment text as Markdown and
|
|
// TODO(teboring): Ideally we should parse the comment text as Markdown and
|
|
// write it back as HTML, but this requires a Markdown parser. For now
|
|
// write it back as HTML, but this requires a Markdown parser. For now
|
|
@@ -1609,7 +1613,7 @@ static void GenerateDocCommentBodyForLocation(
|
|
// HTML-escape them so that they don't accidentally close the doc comment.
|
|
// HTML-escape them so that they don't accidentally close the doc comment.
|
|
comments = EscapePhpdoc(comments);
|
|
comments = EscapePhpdoc(comments);
|
|
|
|
|
|
- std::vector<string> lines = Split(comments, "\n", true);
|
|
|
|
|
|
+ std::vector<std::string> lines = Split(comments, "\n", true);
|
|
while (!lines.empty() && lines.back().empty()) {
|
|
while (!lines.empty() && lines.back().empty()) {
|
|
lines.pop_back();
|
|
lines.pop_back();
|
|
}
|
|
}
|
|
@@ -1640,11 +1644,11 @@ static void GenerateDocCommentBody(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static string FirstLineOf(const string& value) {
|
|
|
|
- string result = value;
|
|
|
|
|
|
+static std::string FirstLineOf(const std::string& value) {
|
|
|
|
+ std::string result = value;
|
|
|
|
|
|
- string::size_type pos = result.find_first_of('\n');
|
|
|
|
- if (pos != string::npos) {
|
|
|
|
|
|
+ std::string::size_type pos = result.find_first_of('\n');
|
|
|
|
+ if (pos != std::string::npos) {
|
|
result.erase(pos);
|
|
result.erase(pos);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1801,20 +1805,18 @@ void GenerateServiceMethodDocComment(io::Printer* printer,
|
|
"return_type", EscapePhpdoc(FullClassName(method->output_type(), false)));
|
|
"return_type", EscapePhpdoc(FullClassName(method->output_type(), false)));
|
|
}
|
|
}
|
|
|
|
|
|
-bool Generator::Generate(const FileDescriptor* file, const string& parameter,
|
|
|
|
|
|
+bool Generator::Generate(const FileDescriptor* file,
|
|
|
|
+ const std::string& parameter,
|
|
GeneratorContext* generator_context,
|
|
GeneratorContext* generator_context,
|
|
- string* error) const {
|
|
|
|
- return Generate(file, false, false, std::set<string>(),
|
|
|
|
|
|
+ std::string* error) const {
|
|
|
|
+ return Generate(file, false, false, std::set<std::string>(),
|
|
generator_context, error);
|
|
generator_context, error);
|
|
}
|
|
}
|
|
|
|
|
|
bool Generator::Generate(
|
|
bool Generator::Generate(
|
|
- const FileDescriptor* file,
|
|
|
|
- bool is_descriptor,
|
|
|
|
- bool aggregate_metadata,
|
|
|
|
- const std::set<string>& aggregate_metadata_prefixes,
|
|
|
|
- GeneratorContext* generator_context,
|
|
|
|
- string* error) const {
|
|
|
|
|
|
+ const FileDescriptor* file, bool is_descriptor, bool aggregate_metadata,
|
|
|
|
+ const std::set<std::string>& aggregate_metadata_prefixes,
|
|
|
|
+ GeneratorContext* generator_context, std::string* error) const {
|
|
if (is_descriptor && file->name() != kDescriptorFile) {
|
|
if (is_descriptor && file->name() != kDescriptorFile) {
|
|
*error =
|
|
*error =
|
|
"Can only generate PHP code for google/protobuf/descriptor.proto.\n";
|
|
"Can only generate PHP code for google/protobuf/descriptor.proto.\n";
|
|
@@ -1840,12 +1842,12 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
|
|
std::string* error) const {
|
|
std::string* error) const {
|
|
bool is_descriptor = false;
|
|
bool is_descriptor = false;
|
|
bool aggregate_metadata = false;
|
|
bool aggregate_metadata = false;
|
|
- std::set<string> aggregate_metadata_prefixes;
|
|
|
|
|
|
+ std::set<std::string> aggregate_metadata_prefixes;
|
|
|
|
|
|
for (const auto& option : Split(parameter, ",", true)) {
|
|
for (const auto& option : Split(parameter, ",", true)) {
|
|
const std::vector<std::string> option_pair = Split(option, "=", true);
|
|
const std::vector<std::string> option_pair = Split(option, "=", true);
|
|
if (HasPrefixString(option_pair[0], "aggregate_metadata")) {
|
|
if (HasPrefixString(option_pair[0], "aggregate_metadata")) {
|
|
- string options_string = option_pair[1];
|
|
|
|
|
|
+ std::string options_string = option_pair[1];
|
|
const std::vector<std::string> options =
|
|
const std::vector<std::string> options =
|
|
Split(options_string, "#", false);
|
|
Split(options_string, "#", false);
|
|
aggregate_metadata = true;
|
|
aggregate_metadata = true;
|