aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/cpp/cpp_field.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_field.h')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_field.h73
1 files changed, 50 insertions, 23 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h
index 8cdbe886..43a3e367 100644
--- a/src/google/protobuf/compiler/cpp/cpp_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_field.h
@@ -45,11 +45,13 @@
namespace google {
namespace protobuf {
- namespace io {
- class Printer; // printer.h
- }
+namespace io {
+class Printer; // printer.h
}
+} // namespace protobuf
+} // namespace google
+namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {
@@ -59,15 +61,17 @@ namespace cpp {
// ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size',
// 'deprecation'].
void SetCommonFieldVariables(const FieldDescriptor* descriptor,
- std::map<string, string>* variables,
+ std::map<std::string, std::string>* variables,
const Options& options);
void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor,
- std::map<string, string>* variables);
+ std::map<std::string, std::string>* variables);
class FieldGenerator {
public:
- explicit FieldGenerator(const Options& options) : options_(options) {}
+ explicit FieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options)
+ : descriptor_(descriptor), options_(options) {}
virtual ~FieldGenerator();
// Generate lines of code declaring members fields of the message class
@@ -95,17 +99,27 @@ class FieldGenerator {
virtual void GenerateNonInlineAccessorDefinitions(
io::Printer* /*printer*/) const {}
+ // Generate declarations of accessors that are for internal purposes only.
+ // Most field types don't need this, so the default implementation is empty.
+ virtual void GenerateInternalAccessorDefinitions(
+ io::Printer* /*printer*/) const {}
+
+ // Generate definitions of accessors that are for internal purposes only.
+ // Most field types don't need this, so the default implementation is empty.
+ virtual void GenerateInternalAccessorDeclarations(
+ io::Printer* /*printer*/) const {}
+
// Generate lines of code (statements, not declarations) which clear the
// field. This is used to define the clear_$name$() method
virtual void GenerateClearingCode(io::Printer* printer) const = 0;
- // Generate lines of code (statements, not declarations) which clear the field
- // as part of the Clear() method for the whole message. For message types
- // which have field presence bits, MessageGenerator::GenerateClear will have
- // already checked the presence bits.
+ // Generate lines of code (statements, not declarations) which clear the
+ // field as part of the Clear() method for the whole message. For message
+ // types which have field presence bits, MessageGenerator::GenerateClear
+ // will have already checked the presence bits.
//
- // Since most field types can re-use GenerateClearingCode, this method is not
- // pure virtual.
+ // Since most field types can re-use GenerateClearingCode, this method is
+ // not pure virtual.
virtual void GenerateMessageClearingCode(io::Printer* printer) const {
GenerateClearingCode(printer);
}
@@ -140,17 +154,17 @@ class FieldGenerator {
// Generate a manual destructor invocation for use when the message is on an
// arena. The code that this method generates will be executed inside a
- // shared-for-the-whole-message-class method registered with OwnDestructor().
- // The method should return |true| if it generated any code that requires a
- // call; this allows the message generator to eliminate the OwnDestructor()
- // registration if no fields require it.
+ // shared-for-the-whole-message-class method registered with
+ // OwnDestructor(). The method should return |true| if it generated any code
+ // that requires a call; this allows the message generator to eliminate the
+ // OwnDestructor() registration if no fields require it.
virtual bool GenerateArenaDestructorCode(io::Printer* printer) const {
return false;
}
// Generate code that allocates the fields's default instance.
- virtual void GenerateDefaultInstanceAllocator(io::Printer* /*printer*/)
- const {}
+ virtual void GenerateDefaultInstanceAllocator(
+ io::Printer* /*printer*/) const {}
// Generate lines to decode this field, which will be placed inside the
// message's MergeFromCodedStream() method.
@@ -162,8 +176,8 @@ class FieldGenerator {
// Generate lines to decode this field from a packed value, which will be
// placed inside the message's MergeFromCodedStream() method.
- virtual void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer)
- const;
+ virtual void GenerateMergeFromCodedStreamWithPacking(
+ io::Printer* printer) const;
// Generate lines to serialize this field, which are placed within the
// message's SerializeWithCachedSizes() method.
@@ -184,8 +198,12 @@ class FieldGenerator {
virtual uint32 CalculateFieldTag() const { return 0; }
virtual bool IsInlined() const { return false; }
+ void SetHasBitIndex(int32 has_bit_index);
+
protected:
+ const FieldDescriptor* descriptor_;
const Options& options_;
+ std::map<std::string, std::string> variables_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
@@ -195,19 +213,28 @@ class FieldGenerator {
class FieldGeneratorMap {
public:
FieldGeneratorMap(const Descriptor* descriptor, const Options& options,
- SCCAnalyzer* scc_analyzer);
+ MessageSCCAnalyzer* scc_analyzer);
~FieldGeneratorMap();
const FieldGenerator& get(const FieldDescriptor* field) const;
+ void SetHasBitIndices(const std::vector<int>& has_bit_indices_) {
+ for (int i = 0; i < descriptor_->field_count(); ++i) {
+ field_generators_[i]->SetHasBitIndex(has_bit_indices_[i]);
+ }
+ }
+
private:
const Descriptor* descriptor_;
const Options& options_;
std::vector<std::unique_ptr<FieldGenerator>> field_generators_;
+ static FieldGenerator* MakeGoogleInternalGenerator(
+ const FieldDescriptor* field, const Options& options,
+ MessageSCCAnalyzer* scc_analyzer);
static FieldGenerator* MakeGenerator(const FieldDescriptor* field,
const Options& options,
- SCCAnalyzer* scc_analyzer);
+ MessageSCCAnalyzer* scc_analyzer);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
};
@@ -215,6 +242,6 @@ class FieldGeneratorMap {
} // namespace cpp
} // namespace compiler
} // namespace protobuf
-
} // namespace google
+
#endif // GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__