// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <google/protobuf/compiler/objectivec/objectivec_file.h> #include <google/protobuf/compiler/objectivec/objectivec_enum.h> #include <google/protobuf/compiler/objectivec/objectivec_extension.h> #include <google/protobuf/compiler/objectivec/objectivec_helpers.h> #include <google/protobuf/compiler/objectivec/objectivec_message.h> #include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/stubs/stl_util.h> #include <google/protobuf/stubs/strutil.h> #include <algorithm> // std::find() #include <iostream> #include <sstream> // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. namespace google { namespace protobuf { namespace compiler { namespace objectivec { namespace { // This is also found in GPBBootstrap.h, and needs to be kept in sync. const int32_t GOOGLE_PROTOBUF_OBJC_VERSION = …; const char* kHeaderExtension = …; std::string BundledFileName(const FileDescriptor* file) { … } // Checks if a message contains any enums definitions (on the message or // a nested message under it). bool MessageContainsEnums(const Descriptor* message) { … } // Checks if a message contains any extension definitions (on the message or // a nested message under it). bool MessageContainsExtensions(const Descriptor* message) { … } // Checks if the file contains any enum definitions (at the root or // nested under a message). bool FileContainsEnums(const FileDescriptor* file) { … } // Checks if the file contains any extensions definitions (at the root or // nested under a message). bool FileContainsExtensions(const FileDescriptor* file) { … } bool IsDirectDependency(const FileDescriptor* dep, const FileDescriptor* file) { … } struct FileDescriptorsOrderedByName { … }; } // namespace FileGenerator::CommonState::CommonState() { … } const FileGenerator::CommonState::MinDepsEntry& FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( const FileDescriptor* file) { … } // Collect the deps of the given file that contain extensions. This can be used to // create the chain of roots that need to be wired together. // // NOTE: If any changes are made to this and the supporting functions, you will // need to manually validate what the generated code is for the test files: // objectivec/Tests/unittest_extension_chain_*.proto // There are comments about what the expected code should be line and limited // testing objectivec/Tests/GPBUnittestProtos2.m around compilation (#imports // specifically). const std::vector<const FileDescriptor*> FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensions( const FileDescriptor* file) { … } FileGenerator::FileGenerator(const FileDescriptor* file, const GenerationOptions& generation_options, CommonState& common_state) : … { … } FileGenerator::~FileGenerator() { … } void FileGenerator::GenerateHeader(io::Printer* printer) { … } void FileGenerator::GenerateSource(io::Printer* printer) { … } // Helper to print the import of the runtime support at the top of generated // files. This currently only supports the runtime coming from a framework // as defined by the official CocoaPod. void FileGenerator::PrintFileRuntimePreamble( io::Printer* printer, const std::vector<std::string>& headers_to_import) const { … } } // namespace objectivec } // namespace compiler } // namespace protobuf } // namespace google