1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ 9 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ 10 11 #include <string> 12 #include <vector> 13 14 #include "absl/container/flat_hash_map.h" 15 #include "google/protobuf/descriptor.h" 16 17 namespace google { 18 namespace protobuf { 19 namespace compiler { 20 namespace objectivec { 21 22 // Helper class for parsing framework import mappings and generating 23 // import statements. 24 class ImportWriter { 25 public: 26 ImportWriter(const std::string& generate_for_named_framework, 27 const std::string& named_framework_to_proto_path_mappings_path, 28 const std::string& runtime_import_prefix, 29 bool for_bundled_proto); 30 ~ImportWriter() = default; 31 32 void AddFile(const FileDescriptor* file, const std::string& header_extension); 33 void AddRuntimeImport(const std::string& header_name); 34 // This can return an empty string if there is no module for the file. It also 35 // does not handle bundled proto files. 36 std::string ModuleForFile(const FileDescriptor* file); 37 38 void PrintFileImports(io::Printer* p) const; 39 void PrintRuntimeImports(io::Printer* p, bool default_cpp_symbol) const; 40 41 private: 42 void ParseFrameworkMappings(); 43 44 const std::string generate_for_named_framework_; 45 const std::string named_framework_to_proto_path_mappings_path_; 46 const std::string runtime_import_prefix_; 47 absl::flat_hash_map<std::string, std::string> proto_file_to_framework_name_; 48 bool for_bundled_proto_; 49 bool need_to_parse_mapping_file_; 50 51 std::vector<std::string> protobuf_imports_; 52 std::vector<std::string> other_framework_imports_; 53 std::vector<std::string> other_imports_; 54 }; 55 56 } // namespace objectivec 57 } // namespace compiler 58 } // namespace protobuf 59 } // namespace google 60 61 #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ 62