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 // http://code.google.com/p/protobuf/ | 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. |
11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
(...skipping 14 matching lines...) Expand all Loading... |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 // Author: kenton@google.com (Kenton Varda) | 31 // Author: kenton@google.com (Kenton Varda) |
32 // Based on original Protocol Buffers design by | 32 // Based on original Protocol Buffers design by |
33 // Sanjay Ghemawat, Jeff Dean, and others. | 33 // Sanjay Ghemawat, Jeff Dean, and others. |
34 | 34 |
35 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ | 35 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ |
36 #define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ | 36 #define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ |
37 | 37 |
| 38 #include <memory> |
| 39 #ifndef _SHARED_PTR_H |
| 40 #include <google/protobuf/stubs/shared_ptr.h> |
| 41 #endif |
38 #include <string> | 42 #include <string> |
39 #include <vector> | 43 #include <vector> |
40 #include <google/protobuf/stubs/common.h> | 44 #include <google/protobuf/stubs/common.h> |
41 #include <google/protobuf/compiler/cpp/cpp_field.h> | 45 #include <google/protobuf/compiler/cpp/cpp_field.h> |
42 #include <google/protobuf/compiler/cpp/cpp_options.h> | 46 #include <google/protobuf/compiler/cpp/cpp_options.h> |
43 | 47 |
44 namespace google { | 48 namespace google { |
45 namespace protobuf { | 49 namespace protobuf { |
46 class FileDescriptor; // descriptor.h | 50 class FileDescriptor; // descriptor.h |
47 namespace io { | 51 namespace io { |
(...skipping 10 matching lines...) Expand all Loading... |
58 class ServiceGenerator; // service.h | 62 class ServiceGenerator; // service.h |
59 class ExtensionGenerator; // extension.h | 63 class ExtensionGenerator; // extension.h |
60 | 64 |
61 class FileGenerator { | 65 class FileGenerator { |
62 public: | 66 public: |
63 // See generator.cc for the meaning of dllexport_decl. | 67 // See generator.cc for the meaning of dllexport_decl. |
64 explicit FileGenerator(const FileDescriptor* file, | 68 explicit FileGenerator(const FileDescriptor* file, |
65 const Options& options); | 69 const Options& options); |
66 ~FileGenerator(); | 70 ~FileGenerator(); |
67 | 71 |
68 void GenerateHeader(io::Printer* printer); | 72 void GenerateProtoHeader(io::Printer* printer); |
| 73 void GeneratePBHeader(io::Printer* printer); |
69 void GenerateSource(io::Printer* printer); | 74 void GenerateSource(io::Printer* printer); |
70 | 75 |
71 private: | 76 private: |
| 77 // Internal type used by GenerateForwardDeclarations (defined in file.cc). |
| 78 class ForwardDeclarations; |
| 79 |
72 // Generate the BuildDescriptors() procedure, which builds all descriptors | 80 // Generate the BuildDescriptors() procedure, which builds all descriptors |
73 // for types defined in the file. | 81 // for types defined in the file. |
74 void GenerateBuildDescriptors(io::Printer* printer); | 82 void GenerateBuildDescriptors(io::Printer* printer); |
75 | 83 |
76 void GenerateNamespaceOpeners(io::Printer* printer); | 84 void GenerateNamespaceOpeners(io::Printer* printer); |
77 void GenerateNamespaceClosers(io::Printer* printer); | 85 void GenerateNamespaceClosers(io::Printer* printer); |
78 | 86 |
| 87 // For other imports, generates their forward-declarations. |
| 88 void GenerateForwardDeclarations(io::Printer* printer); |
| 89 |
| 90 // Internal helper used by GenerateForwardDeclarations: fills 'decls' |
| 91 // with all necessary forward-declarations for this file and its |
| 92 // transient depednencies. |
| 93 void FillForwardDeclarations(ForwardDeclarations* decls); |
| 94 |
| 95 // Generates top or bottom of a header file. |
| 96 void GenerateTopHeaderGuard(io::Printer* printer, |
| 97 const string& filename_identifier); |
| 98 void GenerateBottomHeaderGuard(io::Printer* printer, |
| 99 const string& filename_identifier); |
| 100 |
| 101 // Generates #include directives. |
| 102 void GenerateLibraryIncludes(io::Printer* printer); |
| 103 void GenerateDependencyIncludes(io::Printer* printer); |
| 104 |
| 105 // Generates a couple of different pieces before definitions: |
| 106 void GenerateGlobalStateFunctionDeclarations(io::Printer* printer); |
| 107 |
| 108 // Generates types for classes. |
| 109 void GenerateMessageDefinitions(io::Printer* printer); |
| 110 |
| 111 // Generates forward-declarations for just this file's classes. This is |
| 112 // used for .pb.h headers, but not in proto_h mode. |
| 113 void GenerateMessageForwardDeclarations(io::Printer* printer); |
| 114 |
| 115 // Fills in types for forward declarations. This is used internally, and |
| 116 // also by other FileGenerators to determine imports' declarations. |
| 117 void FillMessageForwardDeclarations(ForwardDeclarations* decls); |
| 118 void FillMessageDefinitions(ForwardDeclarations* decls); |
| 119 |
| 120 // Generates enum definitions. |
| 121 void GenerateEnumForwardDeclarations(io::Printer* printer); |
| 122 void FillEnumForwardDeclarations(ForwardDeclarations* decls); |
| 123 void GenerateEnumDefinitions(io::Printer* printer); |
| 124 |
| 125 // Generates generic service definitions. |
| 126 void GenerateServiceDefinitions(io::Printer* printer); |
| 127 |
| 128 // Generates extension identifiers. |
| 129 void GenerateExtensionIdentifiers(io::Printer* printer); |
| 130 |
| 131 // Generates inline function defintions. |
| 132 void GenerateInlineFunctionDefinitions(io::Printer* printer); |
| 133 |
| 134 void GenerateProto2NamespaceEnumSpecializations(io::Printer* printer); |
| 135 |
79 const FileDescriptor* file_; | 136 const FileDescriptor* file_; |
80 | 137 |
81 scoped_array<scoped_ptr<MessageGenerator> > message_generators_; | 138 google::protobuf::scoped_array<google::protobuf::scoped_ptr<MessageGenerator>
> message_generators_; |
82 scoped_array<scoped_ptr<EnumGenerator> > enum_generators_; | 139 google::protobuf::scoped_array<google::protobuf::scoped_ptr<EnumGenerator> > e
num_generators_; |
83 scoped_array<scoped_ptr<ServiceGenerator> > service_generators_; | 140 google::protobuf::scoped_array<google::protobuf::scoped_ptr<ServiceGenerator>
> service_generators_; |
84 scoped_array<scoped_ptr<ExtensionGenerator> > extension_generators_; | 141 google::protobuf::scoped_array<google::protobuf::scoped_ptr<ExtensionGenerator
> > extension_generators_; |
85 | 142 |
86 // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. | 143 // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. |
87 vector<string> package_parts_; | 144 vector<string> package_parts_; |
88 | |
89 const Options options_; | 145 const Options options_; |
90 | 146 |
91 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); | 147 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); |
92 }; | 148 }; |
93 | 149 |
94 } // namespace cpp | 150 } // namespace cpp |
95 } // namespace compiler | 151 } // namespace compiler |
96 } // namespace protobuf | 152 } // namespace protobuf |
97 | 153 |
98 } // namespace google | 154 } // namespace google |
99 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ | 155 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ |
OLD | NEW |