| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include <google/protobuf/stubs/stl_util.h> | 38 #include <google/protobuf/stubs/stl_util.h> |
| 39 #include <google/protobuf/stubs/strutil.h> | 39 #include <google/protobuf/stubs/strutil.h> |
| 40 #include <sstream> | 40 #include <sstream> |
| 41 | 41 |
| 42 namespace google { | 42 namespace google { |
| 43 namespace protobuf { | 43 namespace protobuf { |
| 44 | 44 |
| 45 // This is also found in GPBBootstrap.h, and needs to be kept in sync. It | 45 // This is also found in GPBBootstrap.h, and needs to be kept in sync. It |
| 46 // is the version check done to ensure generated code works with the current | 46 // is the version check done to ensure generated code works with the current |
| 47 // runtime being used. | 47 // runtime being used. |
| 48 const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30000; | 48 const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30001; |
| 49 | 49 |
| 50 namespace compiler { | 50 namespace compiler { |
| 51 namespace objectivec { | 51 namespace objectivec { |
| 52 | 52 |
| 53 FileGenerator::FileGenerator(const FileDescriptor *file) | 53 FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options) |
| 54 : file_(file), | 54 : file_(file), |
| 55 root_class_name_(FileClassName(file)), | 55 root_class_name_(FileClassName(file)), |
| 56 is_public_dep_(false) { | 56 is_public_dep_(false), |
| 57 options_(options) { |
| 57 for (int i = 0; i < file_->enum_type_count(); i++) { | 58 for (int i = 0; i < file_->enum_type_count(); i++) { |
| 58 EnumGenerator *generator = new EnumGenerator(file_->enum_type(i)); | 59 EnumGenerator *generator = new EnumGenerator(file_->enum_type(i)); |
| 59 enum_generators_.push_back(generator); | 60 enum_generators_.push_back(generator); |
| 60 } | 61 } |
| 61 for (int i = 0; i < file_->message_type_count(); i++) { | 62 for (int i = 0; i < file_->message_type_count(); i++) { |
| 62 MessageGenerator *generator = | 63 MessageGenerator *generator = |
| 63 new MessageGenerator(root_class_name_, file_->message_type(i)); | 64 new MessageGenerator(root_class_name_, file_->message_type(i), options_)
; |
| 64 message_generators_.push_back(generator); | 65 message_generators_.push_back(generator); |
| 65 } | 66 } |
| 66 for (int i = 0; i < file_->extension_count(); i++) { | 67 for (int i = 0; i < file_->extension_count(); i++) { |
| 67 ExtensionGenerator *generator = | 68 ExtensionGenerator *generator = |
| 68 new ExtensionGenerator(root_class_name_, file_->extension(i)); | 69 new ExtensionGenerator(root_class_name_, file_->extension(i)); |
| 69 extension_generators_.push_back(generator); | 70 extension_generators_.push_back(generator); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 FileGenerator::~FileGenerator() { | 74 FileGenerator::~FileGenerator() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 iter != dependency_generators.end(); ++iter) { | 108 iter != dependency_generators.end(); ++iter) { |
| 108 if ((*iter)->IsPublicDependency()) { | 109 if ((*iter)->IsPublicDependency()) { |
| 109 printer->Print("#import \"$header$.pbobjc.h\"\n", | 110 printer->Print("#import \"$header$.pbobjc.h\"\n", |
| 110 "header", (*iter)->Path()); | 111 "header", (*iter)->Path()); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 printer->Print( | 115 printer->Print( |
| 115 "// @@protoc_insertion_point(imports)\n" | 116 "// @@protoc_insertion_point(imports)\n" |
| 116 "\n" | 117 "\n" |
| 118 "#pragma clang diagnostic push\n" |
| 119 "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n" |
| 120 "\n" |
| 117 "CF_EXTERN_C_BEGIN\n" | 121 "CF_EXTERN_C_BEGIN\n" |
| 118 "\n"); | 122 "\n"); |
| 119 | 123 |
| 120 set<string> fwd_decls; | 124 set<string> fwd_decls; |
| 121 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); | 125 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); |
| 122 iter != message_generators_.end(); ++iter) { | 126 iter != message_generators_.end(); ++iter) { |
| 123 (*iter)->DetermineForwardDeclarations(&fwd_decls); | 127 (*iter)->DetermineForwardDeclarations(&fwd_decls); |
| 124 } | 128 } |
| 125 for (set<string>::const_iterator i(fwd_decls.begin()); | 129 for (set<string>::const_iterator i(fwd_decls.begin()); |
| 126 i != fwd_decls.end(); ++i) { | 130 i != fwd_decls.end(); ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 143 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); | 147 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); |
| 144 iter != message_generators_.end(); ++iter) { | 148 iter != message_generators_.end(); ++iter) { |
| 145 (*iter)->GenerateEnumHeader(printer); | 149 (*iter)->GenerateEnumHeader(printer); |
| 146 } | 150 } |
| 147 | 151 |
| 148 // For extensions to chain together, the Root gets created even if there | 152 // For extensions to chain together, the Root gets created even if there |
| 149 // are no extensions. | 153 // are no extensions. |
| 150 printer->Print( | 154 printer->Print( |
| 151 "#pragma mark - $root_class_name$\n" | 155 "#pragma mark - $root_class_name$\n" |
| 152 "\n" | 156 "\n" |
| 157 "/// Exposes the extension registry for this file.\n" |
| 158 "///\n" |
| 159 "/// The base class provides:\n" |
| 160 "/// @code\n" |
| 161 "/// + (GPBExtensionRegistry *)extensionRegistry;\n" |
| 162 "/// @endcode\n" |
| 163 "/// which is a @c GPBExtensionRegistry that includes all the extensions d
efined by\n" |
| 164 "/// this file and all files that it depends on.\n" |
| 153 "@interface $root_class_name$ : GPBRootObject\n" | 165 "@interface $root_class_name$ : GPBRootObject\n" |
| 154 "\n" | |
| 155 "// The base class provides:\n" | |
| 156 "// + (GPBExtensionRegistry *)extensionRegistry;\n" | |
| 157 "// which is an GPBExtensionRegistry that includes all the extensions defi
ned by\n" | |
| 158 "// this file and all files that it depends on.\n" | |
| 159 "\n" | |
| 160 "@end\n" | 166 "@end\n" |
| 161 "\n", | 167 "\n", |
| 162 "root_class_name", root_class_name_); | 168 "root_class_name", root_class_name_); |
| 163 | 169 |
| 164 if (extension_generators_.size() > 0) { | 170 if (extension_generators_.size() > 0) { |
| 165 // The dynamic methods block is only needed if there are extensions. | 171 // The dynamic methods block is only needed if there are extensions. |
| 166 printer->Print( | 172 printer->Print( |
| 167 "@interface $root_class_name$ (DynamicMethods)\n", | 173 "@interface $root_class_name$ (DynamicMethods)\n", |
| 168 "root_class_name", root_class_name_); | 174 "root_class_name", root_class_name_); |
| 169 | 175 |
| 170 for (vector<ExtensionGenerator *>::iterator iter = | 176 for (vector<ExtensionGenerator *>::iterator iter = |
| 171 extension_generators_.begin(); | 177 extension_generators_.begin(); |
| 172 iter != extension_generators_.end(); ++iter) { | 178 iter != extension_generators_.end(); ++iter) { |
| 173 (*iter)->GenerateMembersHeader(printer); | 179 (*iter)->GenerateMembersHeader(printer); |
| 174 } | 180 } |
| 175 | 181 |
| 176 printer->Print("@end\n\n"); | 182 printer->Print("@end\n\n"); |
| 177 } // extension_generators_.size() > 0 | 183 } // extension_generators_.size() > 0 |
| 178 | 184 |
| 179 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); | 185 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); |
| 180 iter != message_generators_.end(); ++iter) { | 186 iter != message_generators_.end(); ++iter) { |
| 181 (*iter)->GenerateMessageHeader(printer); | 187 (*iter)->GenerateMessageHeader(printer); |
| 182 } | 188 } |
| 183 | 189 |
| 184 printer->Print( | 190 printer->Print( |
| 185 "NS_ASSUME_NONNULL_END\n" | 191 "NS_ASSUME_NONNULL_END\n" |
| 186 "\n" | 192 "\n" |
| 187 "CF_EXTERN_C_END\n" | 193 "CF_EXTERN_C_END\n" |
| 188 "\n" | 194 "\n" |
| 195 "#pragma clang diagnostic pop\n" |
| 196 "\n" |
| 189 "// @@protoc_insertion_point(global_scope)\n"); | 197 "// @@protoc_insertion_point(global_scope)\n"); |
| 190 } | 198 } |
| 191 | 199 |
| 192 void FileGenerator::GenerateSource(io::Printer *printer) { | 200 void FileGenerator::GenerateSource(io::Printer *printer) { |
| 193 printer->Print( | 201 printer->Print( |
| 194 "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" | 202 "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" |
| 195 "// source: $filename$\n" | 203 "// source: $filename$\n" |
| 196 "\n", | 204 "\n", |
| 197 "filename", file_->name()); | 205 "filename", file_->name()); |
| 198 | 206 |
| 199 string header_file = Path() + ".pbobjc.h"; | 207 string header_file = Path() + ".pbobjc.h"; |
| 200 printer->Print( | 208 printer->Print( |
| 201 "#import \"GPBProtocolBuffers_RuntimeSupport.h\"\n" | 209 "#import \"GPBProtocolBuffers_RuntimeSupport.h\"\n" |
| 202 "#import \"$header_file$\"\n", | 210 "#import \"$header_file$\"\n", |
| 203 "header_file", header_file); | 211 "header_file", header_file); |
| 204 const vector<FileGenerator *> &dependency_generators = | 212 const vector<FileGenerator *> &dependency_generators = |
| 205 DependencyGenerators(); | 213 DependencyGenerators(); |
| 206 for (vector<FileGenerator *>::const_iterator iter = | 214 for (vector<FileGenerator *>::const_iterator iter = |
| 207 dependency_generators.begin(); | 215 dependency_generators.begin(); |
| 208 iter != dependency_generators.end(); ++iter) { | 216 iter != dependency_generators.end(); ++iter) { |
| 209 if (!(*iter)->IsPublicDependency()) { | 217 if (!(*iter)->IsPublicDependency()) { |
| 210 printer->Print("#import \"$header$.pbobjc.h\"\n", | 218 printer->Print("#import \"$header$.pbobjc.h\"\n", |
| 211 "header", (*iter)->Path()); | 219 "header", (*iter)->Path()); |
| 212 } | 220 } |
| 213 } | 221 } |
| 214 printer->Print( | 222 printer->Print( |
| 215 "// @@protoc_insertion_point(imports)\n" | 223 "// @@protoc_insertion_point(imports)\n" |
| 224 "\n" |
| 225 "#pragma clang diagnostic push\n" |
| 226 "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n" |
| 216 "\n"); | 227 "\n"); |
| 217 | 228 |
| 218 printer->Print( | 229 printer->Print( |
| 219 "#pragma mark - $root_class_name$\n" | 230 "#pragma mark - $root_class_name$\n" |
| 220 "\n" | 231 "\n" |
| 221 "@implementation $root_class_name$\n\n", | 232 "@implementation $root_class_name$\n\n", |
| 222 "root_class_name", root_class_name_); | 233 "root_class_name", root_class_name_); |
| 223 | 234 |
| 224 // Generate the extension initialization structures for the top level and | 235 // Generate the extension initialization structures for the top level and |
| 225 // any nested messages. | 236 // any nested messages. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 iter != enum_generators_.end(); ++iter) { | 344 iter != enum_generators_.end(); ++iter) { |
| 334 (*iter)->GenerateSource(printer); | 345 (*iter)->GenerateSource(printer); |
| 335 } | 346 } |
| 336 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); | 347 for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); |
| 337 iter != message_generators_.end(); ++iter) { | 348 iter != message_generators_.end(); ++iter) { |
| 338 (*iter)->GenerateSource(printer); | 349 (*iter)->GenerateSource(printer); |
| 339 } | 350 } |
| 340 | 351 |
| 341 printer->Print( | 352 printer->Print( |
| 342 "\n" | 353 "\n" |
| 354 "#pragma clang diagnostic pop\n" |
| 355 "\n" |
| 343 "// @@protoc_insertion_point(global_scope)\n"); | 356 "// @@protoc_insertion_point(global_scope)\n"); |
| 344 } | 357 } |
| 345 | 358 |
| 346 const string FileGenerator::Path() const { return FilePath(file_); } | 359 const string FileGenerator::Path() const { return FilePath(file_); } |
| 347 | 360 |
| 348 const vector<FileGenerator *> &FileGenerator::DependencyGenerators() { | 361 const vector<FileGenerator *> &FileGenerator::DependencyGenerators() { |
| 349 if (file_->dependency_count() != dependency_generators_.size()) { | 362 if (file_->dependency_count() != dependency_generators_.size()) { |
| 350 set<string> public_import_names; | 363 set<string> public_import_names; |
| 351 for (int i = 0; i < file_->public_dependency_count(); i++) { | 364 for (int i = 0; i < file_->public_dependency_count(); i++) { |
| 352 public_import_names.insert(file_->public_dependency(i)->name()); | 365 public_import_names.insert(file_->public_dependency(i)->name()); |
| 353 } | 366 } |
| 354 for (int i = 0; i < file_->dependency_count(); i++) { | 367 for (int i = 0; i < file_->dependency_count(); i++) { |
| 355 FileGenerator *generator = new FileGenerator(file_->dependency(i)); | 368 FileGenerator *generator = |
| 369 new FileGenerator(file_->dependency(i), options_); |
| 356 const string& name = file_->dependency(i)->name(); | 370 const string& name = file_->dependency(i)->name(); |
| 357 bool public_import = (public_import_names.count(name) != 0); | 371 bool public_import = (public_import_names.count(name) != 0); |
| 358 generator->SetIsPublicDependency(public_import); | 372 generator->SetIsPublicDependency(public_import); |
| 359 dependency_generators_.push_back(generator); | 373 dependency_generators_.push_back(generator); |
| 360 } | 374 } |
| 361 } | 375 } |
| 362 return dependency_generators_; | 376 return dependency_generators_; |
| 363 } | 377 } |
| 364 | 378 |
| 365 } // namespace objectivec | 379 } // namespace objectivec |
| 366 } // namespace compiler | 380 } // namespace compiler |
| 367 } // namespace protobuf | 381 } // namespace protobuf |
| 368 } // namespace google | 382 } // namespace google |
| OLD | NEW |