1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc. All rights reserved.
3
// http://code.google.com/p/protobuf/
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
9
// * Redistributions of source code must retain the above copyright
10
// notice, this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above
12
// copyright notice, this list of conditions and the following disclaimer
13
// in the documentation and/or other materials provided with the
15
// * Neither the name of Google Inc. nor the names of its
16
// contributors may be used to endorse or promote products derived from
17
// this software without specific prior written permission.
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31
// Author: kenton@google.com (Kenton Varda)
32
// Based on original Protocol Buffers design by
33
// Sanjay Ghemawat, Jeff Dean, and others.
35
#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
36
#define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
39
#include <google/protobuf/stubs/common.h>
40
#include <google/protobuf/compiler/cpp/cpp_field.h>
41
#include <google/protobuf/compiler/cpp/cpp_options.h>
46
class Printer; // printer.h
54
class EnumGenerator; // enum.h
55
class ExtensionGenerator; // extension.h
57
class MessageGenerator {
59
// See generator.cc for the meaning of dllexport_decl.
60
explicit MessageGenerator(const Descriptor* descriptor,
61
const Options& options);
66
// Generate foward declarations for this class and all its nested types.
67
void GenerateForwardDeclaration(io::Printer* printer);
69
// Generate definitions of all nested enums (must come before class
70
// definitions because those classes use the enums definitions).
71
void GenerateEnumDefinitions(io::Printer* printer);
73
// Generate specializations of GetEnumDescriptor<MyEnum>().
74
// Precondition: in ::google::protobuf namespace.
75
void GenerateGetEnumDescriptorSpecializations(io::Printer* printer);
77
// Generate definitions for this class and all its nested types.
78
void GenerateClassDefinition(io::Printer* printer);
80
// Generate definitions of inline methods (placed at the end of the header
82
void GenerateInlineMethods(io::Printer* printer);
86
// Generate code which declares all the global descriptor pointers which
87
// will be initialized by the methods below.
88
void GenerateDescriptorDeclarations(io::Printer* printer);
90
// Generate code that initializes the global variable storing the message's
92
void GenerateDescriptorInitializer(io::Printer* printer, int index);
94
// Generate code that calls MessageFactory::InternalRegisterGeneratedMessage()
96
void GenerateTypeRegistrations(io::Printer* printer);
98
// Generates code that allocates the message's default instance.
99
void GenerateDefaultInstanceAllocator(io::Printer* printer);
101
// Generates code that initializes the message's default instance. This
102
// is separate from allocating because all default instances must be
103
// allocated before any can be initialized.
104
void GenerateDefaultInstanceInitializer(io::Printer* printer);
106
// Generates code that should be run when ShutdownProtobufLibrary() is called,
107
// to delete all dynamically-allocated objects.
108
void GenerateShutdownCode(io::Printer* printer);
110
// Generate all non-inline methods for this class.
111
void GenerateClassMethods(io::Printer* printer);
114
// Generate declarations and definitions of accessors for fields.
115
void GenerateFieldAccessorDeclarations(io::Printer* printer);
116
void GenerateFieldAccessorDefinitions(io::Printer* printer);
118
// Generate the field offsets array.
119
void GenerateOffsets(io::Printer* printer);
121
// Generate constructors and destructor.
122
void GenerateStructors(io::Printer* printer);
124
// The compiler typically generates multiple copies of each constructor and
125
// destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx
126
// Placing common code in a separate method reduces the generated code size.
128
// Generate the shared constructor code.
129
void GenerateSharedConstructorCode(io::Printer* printer);
130
// Generate the shared destructor code.
131
void GenerateSharedDestructorCode(io::Printer* printer);
133
// Generate standard Message methods.
134
void GenerateClear(io::Printer* printer);
135
void GenerateMergeFromCodedStream(io::Printer* printer);
136
void GenerateSerializeWithCachedSizes(io::Printer* printer);
137
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer);
138
void GenerateSerializeWithCachedSizesBody(io::Printer* printer,
140
void GenerateByteSize(io::Printer* printer);
141
void GenerateMergeFrom(io::Printer* printer);
142
void GenerateCopyFrom(io::Printer* printer);
143
void GenerateSwap(io::Printer* printer);
144
void GenerateIsInitialized(io::Printer* printer);
146
// Helpers for GenerateSerializeWithCachedSizes().
147
void GenerateSerializeOneField(io::Printer* printer,
148
const FieldDescriptor* field,
150
void GenerateSerializeOneExtensionRange(
151
io::Printer* printer, const Descriptor::ExtensionRange* range,
155
const Descriptor* descriptor_;
158
FieldGeneratorMap field_generators_;
159
scoped_array<scoped_ptr<MessageGenerator> > nested_generators_;
160
scoped_array<scoped_ptr<EnumGenerator> > enum_generators_;
161
scoped_array<scoped_ptr<ExtensionGenerator> > extension_generators_;
163
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
167
} // namespace compiler
168
} // namespace protobuf
170
} // namespace google
171
#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__