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_CPP_PARSE_FUNCTION_GENERATOR_H__ 9 #define GOOGLE_PROTOBUF_COMPILER_CPP_PARSE_FUNCTION_GENERATOR_H__ 10 11 #include <memory> 12 #include <string> 13 #include <vector> 14 15 #include "absl/container/flat_hash_map.h" 16 #include "absl/strings/string_view.h" 17 #include "google/protobuf/compiler/cpp/helpers.h" 18 #include "google/protobuf/compiler/cpp/options.h" 19 #include "google/protobuf/descriptor.h" 20 #include "google/protobuf/generated_message_tctable_gen.h" 21 #include "google/protobuf/io/printer.h" 22 23 namespace google { 24 namespace protobuf { 25 namespace compiler { 26 namespace cpp { 27 28 // ParseFunctionGenerator generates the _InternalParse function for a message 29 // (and any associated supporting members). 30 class ParseFunctionGenerator { 31 public: 32 ParseFunctionGenerator( 33 const Descriptor* descriptor, int max_has_bit_index, 34 const std::vector<int>& has_bit_indices, 35 const std::vector<int>& inlined_string_indices, const Options& options, 36 MessageSCCAnalyzer* scc_analyzer, 37 const absl::flat_hash_map<absl::string_view, std::string>& vars, 38 int index_in_file_messages); 39 40 // Emits class-level data member declarations to `printer`: 41 void GenerateDataDecls(io::Printer* printer); 42 43 // Emits out-of-class data member definitions to `printer`: 44 void GenerateDataDefinitions(io::Printer* printer); 45 46 private: 47 class GeneratedOptionProvider; 48 49 // Generates the tail-call table definition. 50 void GenerateTailCallTable(io::Printer* printer); 51 void GenerateFastFieldEntries(Formatter& format); 52 void GenerateFieldEntries(Formatter& format); 53 void GenerateFieldNames(Formatter& format); 54 55 const Descriptor* descriptor_; 56 MessageSCCAnalyzer* scc_analyzer_; 57 const Options& options_; 58 absl::flat_hash_map<absl::string_view, std::string> variables_; 59 std::unique_ptr<internal::TailCallTableInfo> tc_table_info_; 60 std::vector<int> inlined_string_indices_; 61 const std::vector<const FieldDescriptor*> ordered_fields_; 62 int num_hasbits_; 63 int index_in_file_messages_; 64 }; 65 66 } // namespace cpp 67 } // namespace compiler 68 } // namespace protobuf 69 } // namespace google 70 71 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_PARSE_FUNCTION_GENERATOR_H__ 72