• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MESSAGE_H__
9 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_H__
10 
11 #include <cstddef>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include "absl/container/btree_set.h"
17 #include "absl/container/flat_hash_set.h"
18 #include "google/protobuf/compiler/objectivec/field.h"
19 #include "google/protobuf/compiler/objectivec/oneof.h"
20 #include "google/protobuf/compiler/objectivec/options.h"
21 #include "google/protobuf/descriptor.h"
22 #include "google/protobuf/io/printer.h"
23 
24 namespace google {
25 namespace protobuf {
26 namespace compiler {
27 namespace objectivec {
28 
29 class ExtensionGenerator;
30 
31 class MessageGenerator {
32  public:
33   MessageGenerator(const std::string& file_description_name,
34                    const Descriptor* descriptor,
35                    const GenerationOptions& generation_options);
36   ~MessageGenerator() = default;
37 
38   MessageGenerator(const MessageGenerator&) = delete;
39   MessageGenerator& operator=(const MessageGenerator&) = delete;
40 
41   void AddExtensionGenerators(
42       std::vector<std::unique_ptr<ExtensionGenerator>>* extension_generators);
43 
44   void GenerateMessageHeader(io::Printer* printer) const;
45   void GenerateSource(io::Printer* printer) const;
46   void DetermineObjectiveCClassDefinitions(
47       absl::btree_set<std::string>* fwd_decls) const;
48   void DetermineForwardDeclarations(absl::btree_set<std::string>* fwd_decls,
49                                     bool include_external_types) const;
50   void DetermineNeededFiles(
51       absl::flat_hash_set<const FileDescriptor*>* deps) const;
52 
53   // Checks if the message or a nested message includes a oneof definition.
IncludesOneOfDefinition()54   bool IncludesOneOfDefinition() const { return !oneof_generators_.empty(); }
55 
56  private:
57   const std::string file_description_name_;
58   const Descriptor* descriptor_;
59   const GenerationOptions& generation_options_;
60   FieldGeneratorMap field_generators_;
61   const std::string class_name_;
62   const std::string deprecated_attribute_;
63   std::vector<const ExtensionGenerator*> extension_generators_;
64   std::vector<std::unique_ptr<OneofGenerator>> oneof_generators_;
65   size_t sizeof_has_storage_;
66 };
67 
68 }  // namespace objectivec
69 }  // namespace compiler
70 }  // namespace protobuf
71 }  // namespace google
72 
73 #endif  // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_H__
74