Removed all use of STLDelete*() in ObjC and C# Generators.
Other languages will have this removed inside Google first. These functions are subject to ADL and cause problems.
This commit is contained in:
parent
f2a919f58f
commit
f98b3401bf
@ -77,23 +77,19 @@ class MockErrorCollector : public MultiFileErrorCollector {
|
||||
|
||||
class MockGeneratorContext : public GeneratorContext {
|
||||
public:
|
||||
MockGeneratorContext() {}
|
||||
~MockGeneratorContext() {
|
||||
STLDeleteValues(&files_);
|
||||
}
|
||||
|
||||
void ExpectFileMatches(const string& virtual_filename,
|
||||
const string& physical_filename) {
|
||||
string* expected_contents = FindPtrOrNull(files_, virtual_filename);
|
||||
ASSERT_TRUE(expected_contents != NULL)
|
||||
auto it = files_.find(virtual_filename);
|
||||
ASSERT_TRUE(it != files_.end())
|
||||
<< "Generator failed to generate file: " << virtual_filename;
|
||||
string expected_contents = *it->second;
|
||||
|
||||
string actual_contents;
|
||||
GOOGLE_CHECK_OK(
|
||||
File::GetContentsAsText(TestSourceDir() + "/" + physical_filename,
|
||||
&actual_contents, true))
|
||||
<< "Unable to get " << physical_filename;
|
||||
EXPECT_TRUE(actual_contents == *expected_contents)
|
||||
EXPECT_TRUE(actual_contents == expected_contents)
|
||||
<< physical_filename << " needs to be regenerated. Please run "
|
||||
"generate_descriptor_proto.sh. Then add this file "
|
||||
"to your CL.";
|
||||
@ -102,15 +98,13 @@ class MockGeneratorContext : public GeneratorContext {
|
||||
// implements GeneratorContext --------------------------------------
|
||||
|
||||
virtual io::ZeroCopyOutputStream* Open(const string& filename) {
|
||||
string** map_slot = &files_[filename];
|
||||
delete *map_slot;
|
||||
*map_slot = new string;
|
||||
|
||||
return new io::StringOutputStream(*map_slot);
|
||||
auto& map_slot = files_[filename];
|
||||
map_slot.reset(new std::string);
|
||||
return new io::StringOutputStream(map_slot.get());
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<string, string*> files_;
|
||||
std::map<std::string, std::unique_ptr<std::string>> files_;
|
||||
};
|
||||
|
||||
class GenerateAndTest {
|
||||
|
@ -192,27 +192,21 @@ FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options)
|
||||
options_(options) {
|
||||
for (int i = 0; i < file_->enum_type_count(); i++) {
|
||||
EnumGenerator *generator = new EnumGenerator(file_->enum_type(i));
|
||||
enum_generators_.push_back(generator);
|
||||
enum_generators_.emplace_back(generator);
|
||||
}
|
||||
for (int i = 0; i < file_->message_type_count(); i++) {
|
||||
MessageGenerator *generator =
|
||||
new MessageGenerator(root_class_name_, file_->message_type(i), options_);
|
||||
message_generators_.push_back(generator);
|
||||
message_generators_.emplace_back(generator);
|
||||
}
|
||||
for (int i = 0; i < file_->extension_count(); i++) {
|
||||
ExtensionGenerator *generator =
|
||||
new ExtensionGenerator(root_class_name_, file_->extension(i));
|
||||
extension_generators_.push_back(generator);
|
||||
extension_generators_.emplace_back(generator);
|
||||
}
|
||||
}
|
||||
|
||||
FileGenerator::~FileGenerator() {
|
||||
STLDeleteContainerPointers(enum_generators_.begin(), enum_generators_.end());
|
||||
STLDeleteContainerPointers(message_generators_.begin(),
|
||||
message_generators_.end());
|
||||
STLDeleteContainerPointers(extension_generators_.begin(),
|
||||
extension_generators_.end());
|
||||
}
|
||||
FileGenerator::~FileGenerator() {}
|
||||
|
||||
void FileGenerator::GenerateHeader(io::Printer *printer) {
|
||||
std::set<string> headers;
|
||||
@ -270,9 +264,8 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
|
||||
"\n");
|
||||
|
||||
std::set<string> fwd_decls;
|
||||
for (std::vector<MessageGenerator *>::iterator iter = message_generators_.begin();
|
||||
iter != message_generators_.end(); ++iter) {
|
||||
(*iter)->DetermineForwardDeclarations(&fwd_decls);
|
||||
for (const auto& generator : message_generators_) {
|
||||
generator->DetermineForwardDeclarations(&fwd_decls);
|
||||
}
|
||||
for (std::set<string>::const_iterator i(fwd_decls.begin());
|
||||
i != fwd_decls.end(); ++i) {
|
||||
@ -287,14 +280,12 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
|
||||
"\n");
|
||||
|
||||
// need to write out all enums first
|
||||
for (std::vector<EnumGenerator *>::iterator iter = enum_generators_.begin();
|
||||
iter != enum_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateHeader(printer);
|
||||
for (const auto& generator : enum_generators_) {
|
||||
generator->GenerateHeader(printer);
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator *>::iterator iter = message_generators_.begin();
|
||||
iter != message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateEnumHeader(printer);
|
||||
for (const auto& generator : message_generators_) {
|
||||
generator->GenerateEnumHeader(printer);
|
||||
}
|
||||
|
||||
// For extensions to chain together, the Root gets created even if there
|
||||
@ -323,18 +314,15 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
|
||||
"@interface $root_class_name$ (DynamicMethods)\n",
|
||||
"root_class_name", root_class_name_);
|
||||
|
||||
for (std::vector<ExtensionGenerator *>::iterator iter =
|
||||
extension_generators_.begin();
|
||||
iter != extension_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateMembersHeader(printer);
|
||||
for (const auto& generator : extension_generators_) {
|
||||
generator->GenerateMembersHeader(printer);
|
||||
}
|
||||
|
||||
printer->Print("@end\n\n");
|
||||
} // extension_generators_.size() > 0
|
||||
|
||||
for (std::vector<MessageGenerator *>::iterator iter = message_generators_.begin();
|
||||
iter != message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateMessageHeader(printer);
|
||||
for (const auto& generator : message_generators_) {
|
||||
generator->GenerateMessageHeader(printer);
|
||||
}
|
||||
|
||||
printer->Print(
|
||||
@ -403,9 +391,8 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
|
||||
}
|
||||
|
||||
bool includes_oneof = false;
|
||||
for (std::vector<MessageGenerator *>::iterator iter = message_generators_.begin();
|
||||
iter != message_generators_.end(); ++iter) {
|
||||
if ((*iter)->IncludesOneOfDefinition()) {
|
||||
for (const auto& generator : message_generators_) {
|
||||
if (generator->IncludesOneOfDefinition()) {
|
||||
includes_oneof = true;
|
||||
break;
|
||||
}
|
||||
@ -456,15 +443,11 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
|
||||
printer->Print(
|
||||
"static GPBExtensionDescription descriptions[] = {\n");
|
||||
printer->Indent();
|
||||
for (std::vector<ExtensionGenerator *>::iterator iter =
|
||||
extension_generators_.begin();
|
||||
iter != extension_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateStaticVariablesInitialization(printer);
|
||||
for (const auto& generator : extension_generators_) {
|
||||
generator->GenerateStaticVariablesInitialization(printer);
|
||||
}
|
||||
for (std::vector<MessageGenerator *>::iterator iter =
|
||||
message_generators_.begin();
|
||||
iter != message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateStaticVariablesInitialization(printer);
|
||||
for (const auto& generator : message_generators_) {
|
||||
generator->GenerateStaticVariablesInitialization(printer);
|
||||
}
|
||||
printer->Outdent();
|
||||
printer->Print(
|
||||
@ -561,13 +544,11 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
|
||||
"\n");
|
||||
}
|
||||
|
||||
for (std::vector<EnumGenerator *>::iterator iter = enum_generators_.begin();
|
||||
iter != enum_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateSource(printer);
|
||||
for (const auto& generator : enum_generators_) {
|
||||
generator->GenerateSource(printer);
|
||||
}
|
||||
for (std::vector<MessageGenerator *>::iterator iter = message_generators_.begin();
|
||||
iter != message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateSource(printer);
|
||||
for (const auto& generator : message_generators_) {
|
||||
generator->GenerateSource(printer);
|
||||
}
|
||||
|
||||
printer->Print(
|
||||
|
@ -65,9 +65,9 @@ class FileGenerator {
|
||||
string root_class_name_;
|
||||
bool is_bundled_proto_;
|
||||
|
||||
std::vector<EnumGenerator*> enum_generators_;
|
||||
std::vector<MessageGenerator*> message_generators_;
|
||||
std::vector<ExtensionGenerator*> extension_generators_;
|
||||
std::vector<std::unique_ptr<EnumGenerator>> enum_generators_;
|
||||
std::vector<std::unique_ptr<MessageGenerator>> message_generators_;
|
||||
std::vector<std::unique_ptr<ExtensionGenerator>> extension_generators_;
|
||||
|
||||
const Options options_;
|
||||
|
||||
|
@ -184,18 +184,18 @@ MessageGenerator::MessageGenerator(const string& root_classname,
|
||||
GetOptionalDeprecatedAttribute(descriptor, descriptor->file(), false, true)) {
|
||||
|
||||
for (int i = 0; i < descriptor_->extension_count(); i++) {
|
||||
extension_generators_.push_back(
|
||||
extension_generators_.emplace_back(
|
||||
new ExtensionGenerator(class_name_, descriptor_->extension(i)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
|
||||
OneofGenerator* generator = new OneofGenerator(descriptor_->oneof_decl(i));
|
||||
oneof_generators_.push_back(generator);
|
||||
oneof_generators_.emplace_back(generator);
|
||||
}
|
||||
|
||||
for (int i = 0; i < descriptor_->enum_type_count(); i++) {
|
||||
EnumGenerator* generator = new EnumGenerator(descriptor_->enum_type(i));
|
||||
enum_generators_.push_back(generator);
|
||||
enum_generators_.emplace_back(generator);
|
||||
}
|
||||
|
||||
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
|
||||
@ -203,32 +203,20 @@ MessageGenerator::MessageGenerator(const string& root_classname,
|
||||
new MessageGenerator(root_classname_,
|
||||
descriptor_->nested_type(i),
|
||||
options);
|
||||
nested_message_generators_.push_back(generator);
|
||||
nested_message_generators_.emplace_back(generator);
|
||||
}
|
||||
}
|
||||
|
||||
MessageGenerator::~MessageGenerator() {
|
||||
STLDeleteContainerPointers(extension_generators_.begin(),
|
||||
extension_generators_.end());
|
||||
STLDeleteContainerPointers(enum_generators_.begin(), enum_generators_.end());
|
||||
STLDeleteContainerPointers(nested_message_generators_.begin(),
|
||||
nested_message_generators_.end());
|
||||
STLDeleteContainerPointers(oneof_generators_.begin(),
|
||||
oneof_generators_.end());
|
||||
}
|
||||
MessageGenerator::~MessageGenerator() {}
|
||||
|
||||
void MessageGenerator::GenerateStaticVariablesInitialization(
|
||||
io::Printer* printer) {
|
||||
for (std::vector<ExtensionGenerator*>::iterator iter =
|
||||
extension_generators_.begin();
|
||||
iter != extension_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateStaticVariablesInitialization(printer);
|
||||
for (const auto& generator : extension_generators_) {
|
||||
generator->GenerateStaticVariablesInitialization(printer);
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateStaticVariablesInitialization(printer);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->GenerateStaticVariablesInitialization(printer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,10 +229,8 @@ void MessageGenerator::DetermineForwardDeclarations(std::set<string>* fwd_decls)
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->DetermineForwardDeclarations(fwd_decls);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->DetermineForwardDeclarations(fwd_decls);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,10 +239,8 @@ bool MessageGenerator::IncludesOneOfDefinition() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::const_iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
if ((*iter)->IncludesOneOfDefinition()) {
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
if (generator->IncludesOneOfDefinition()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -265,40 +249,31 @@ bool MessageGenerator::IncludesOneOfDefinition() const {
|
||||
}
|
||||
|
||||
void MessageGenerator::GenerateEnumHeader(io::Printer* printer) {
|
||||
for (std::vector<EnumGenerator*>::iterator iter = enum_generators_.begin();
|
||||
iter != enum_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateHeader(printer);
|
||||
for (const auto& generator : enum_generators_) {
|
||||
generator->GenerateHeader(printer);
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateEnumHeader(printer);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->GenerateEnumHeader(printer);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageGenerator::GenerateExtensionRegistrationSource(
|
||||
io::Printer* printer) {
|
||||
for (std::vector<ExtensionGenerator*>::iterator iter =
|
||||
extension_generators_.begin();
|
||||
iter != extension_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateRegistrationSource(printer);
|
||||
for (const auto& generator : extension_generators_) {
|
||||
generator->GenerateRegistrationSource(printer);
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateExtensionRegistrationSource(printer);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->GenerateExtensionRegistrationSource(printer);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
|
||||
// This a a map entry message, just recurse and do nothing directly.
|
||||
if (IsMapEntryMessage(descriptor_)) {
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateMessageHeader(printer);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->GenerateMessageHeader(printer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -325,9 +300,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
|
||||
printer->Print("};\n\n");
|
||||
}
|
||||
|
||||
for (std::vector<OneofGenerator*>::iterator iter = oneof_generators_.begin();
|
||||
iter != oneof_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateCaseEnum(printer);
|
||||
for (const auto& generator : oneof_generators_) {
|
||||
generator->GenerateCaseEnum(printer);
|
||||
}
|
||||
|
||||
string message_comments;
|
||||
@ -366,9 +340,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
|
||||
}
|
||||
|
||||
if (!oneof_generators_.empty()) {
|
||||
for (std::vector<OneofGenerator*>::iterator iter = oneof_generators_.begin();
|
||||
iter != oneof_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateClearFunctionDeclaration(printer);
|
||||
for (const auto& generator : oneof_generators_) {
|
||||
generator->GenerateClearFunctionDeclaration(printer);
|
||||
}
|
||||
printer->Print("\n");
|
||||
}
|
||||
@ -376,18 +349,14 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
|
||||
if (descriptor_->extension_count() > 0) {
|
||||
printer->Print("@interface $classname$ (DynamicMethods)\n\n",
|
||||
"classname", class_name_);
|
||||
for (std::vector<ExtensionGenerator*>::iterator iter =
|
||||
extension_generators_.begin();
|
||||
iter != extension_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateMembersHeader(printer);
|
||||
for (const auto& generator : extension_generators_) {
|
||||
generator->GenerateMembersHeader(printer);
|
||||
}
|
||||
printer->Print("@end\n\n");
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateMessageHeader(printer);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->GenerateMessageHeader(printer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,9 +378,8 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
|
||||
printer->Print("@implementation $classname$\n\n",
|
||||
"classname", class_name_);
|
||||
|
||||
for (std::vector<OneofGenerator*>::iterator iter = oneof_generators_.begin();
|
||||
iter != oneof_generators_.end(); ++iter) {
|
||||
(*iter)->GeneratePropertyImplementation(printer);
|
||||
for (const auto& generator : oneof_generators_) {
|
||||
generator->GeneratePropertyImplementation(printer);
|
||||
}
|
||||
|
||||
for (int i = 0; i < descriptor_->field_count(); i++) {
|
||||
@ -447,9 +415,8 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
|
||||
sizeof_has_storage = 1;
|
||||
}
|
||||
// Tell all the fields the oneof base.
|
||||
for (std::vector<OneofGenerator*>::iterator iter = oneof_generators_.begin();
|
||||
iter != oneof_generators_.end(); ++iter) {
|
||||
(*iter)->SetOneofIndexBase(sizeof_has_storage);
|
||||
for (const auto& generator : oneof_generators_) {
|
||||
generator->SetOneofIndexBase(sizeof_has_storage);
|
||||
}
|
||||
field_generators_.SetOneofIndexBase(sizeof_has_storage);
|
||||
// sizeof_has_storage needs enough bits for the single fields that aren't in
|
||||
@ -547,11 +514,9 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
|
||||
if (oneof_generators_.size() != 0) {
|
||||
printer->Print(
|
||||
" static const char *oneofs[] = {\n");
|
||||
for (std::vector<OneofGenerator*>::iterator iter = oneof_generators_.begin();
|
||||
iter != oneof_generators_.end(); ++iter) {
|
||||
printer->Print(
|
||||
" \"$name$\",\n",
|
||||
"name", (*iter)->DescriptorName());
|
||||
for (const auto& generator : oneof_generators_) {
|
||||
printer->Print(" \"$name$\",\n", "name",
|
||||
generator->DescriptorName());
|
||||
}
|
||||
printer->Print(
|
||||
" };\n"
|
||||
@ -624,21 +589,17 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
|
||||
.GenerateCFunctionImplementations(printer);
|
||||
}
|
||||
|
||||
for (std::vector<OneofGenerator*>::iterator iter = oneof_generators_.begin();
|
||||
iter != oneof_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateClearFunctionImplementation(printer);
|
||||
for (const auto& generator : oneof_generators_) {
|
||||
generator->GenerateClearFunctionImplementation(printer);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<EnumGenerator*>::iterator iter = enum_generators_.begin();
|
||||
iter != enum_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateSource(printer);
|
||||
for (const auto& generator : enum_generators_) {
|
||||
generator->GenerateSource(printer);
|
||||
}
|
||||
|
||||
for (std::vector<MessageGenerator*>::iterator iter =
|
||||
nested_message_generators_.begin();
|
||||
iter != nested_message_generators_.end(); ++iter) {
|
||||
(*iter)->GenerateSource(printer);
|
||||
for (const auto& generator : nested_message_generators_) {
|
||||
generator->GenerateSource(printer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,10 +85,10 @@ class MessageGenerator {
|
||||
FieldGeneratorMap field_generators_;
|
||||
const string class_name_;
|
||||
const string deprecated_attribute_;
|
||||
std::vector<ExtensionGenerator*> extension_generators_;
|
||||
std::vector<EnumGenerator*> enum_generators_;
|
||||
std::vector<MessageGenerator*> nested_message_generators_;
|
||||
std::vector<OneofGenerator*> oneof_generators_;
|
||||
std::vector<std::unique_ptr<ExtensionGenerator>> extension_generators_;
|
||||
std::vector<std::unique_ptr<EnumGenerator>> enum_generators_;
|
||||
std::vector<std::unique_ptr<MessageGenerator>> nested_message_generators_;
|
||||
std::vector<std::unique_ptr<OneofGenerator>> oneof_generators_;
|
||||
};
|
||||
|
||||
} // namespace objectivec
|
||||
|
Loading…
Reference in New Issue
Block a user