Commit 4a3ebd71 authored by Robert Edmonds's avatar Robert Edmonds

protoc-gen-c/: Rename namespace google::protobuf::compiler::c → protobuf_c

Also rename GOOGLE_PROTOBUF_* include guard defines.
parent 44b90935
...@@ -69,14 +69,9 @@ ...@@ -69,14 +69,9 @@
#include "c_bytes_field.h" #include "c_bytes_field.h"
#include "c_helpers.h" #include "c_helpers.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
using internal::WireFormat; void SetBytesVariables(const google::protobuf::FieldDescriptor* descriptor,
void SetBytesVariables(const FieldDescriptor* descriptor,
std::map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["default"] = (*variables)["default"] =
...@@ -87,7 +82,7 @@ void SetBytesVariables(const FieldDescriptor* descriptor, ...@@ -87,7 +82,7 @@ void SetBytesVariables(const FieldDescriptor* descriptor,
// =================================================================== // ===================================================================
BytesFieldGenerator:: BytesFieldGenerator::
BytesFieldGenerator(const FieldDescriptor* descriptor) BytesFieldGenerator(const google::protobuf::FieldDescriptor* descriptor)
: FieldGenerator(descriptor) { : FieldGenerator(descriptor) {
SetBytesVariables(descriptor, &variables_); SetBytesVariables(descriptor, &variables_);
variables_["default_value"] = descriptor->has_default_value() variables_["default_value"] = descriptor->has_default_value()
...@@ -97,24 +92,24 @@ BytesFieldGenerator(const FieldDescriptor* descriptor) ...@@ -97,24 +92,24 @@ BytesFieldGenerator(const FieldDescriptor* descriptor)
BytesFieldGenerator::~BytesFieldGenerator() {} BytesFieldGenerator::~BytesFieldGenerator() {}
void BytesFieldGenerator::GenerateStructMembers(io::Printer* printer) const void BytesFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n"); printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2)
printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n"); printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n");
printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n"); printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); printer->Print(variables_, "size_t n_$name$$deprecated$;\n");
printer->Print(variables_, "ProtobufCBinaryData *$name$$deprecated$;\n"); printer->Print(variables_, "ProtobufCBinaryData *$name$$deprecated$;\n");
break; break;
} }
} }
void BytesFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer) const void BytesFieldGenerator::GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["default_value_data"] = FullNameToLower(descriptor_->full_name(), descriptor_->file()) vars["default_value_data"] = FullNameToLower(descriptor_->full_name(), descriptor_->file())
...@@ -122,7 +117,7 @@ void BytesFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer) ...@@ -122,7 +117,7 @@ void BytesFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer)
printer->Print(vars, "extern uint8_t $default_value_data$[];\n"); printer->Print(vars, "extern uint8_t $default_value_data$[];\n");
} }
void BytesFieldGenerator::GenerateDefaultValueImplementations(io::Printer* printer) const void BytesFieldGenerator::GenerateDefaultValueImplementations(google::protobuf::io::Printer* printer) const
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["default_value_data"] = FullNameToLower(descriptor_->full_name(), descriptor_->file()) vars["default_value_data"] = FullNameToLower(descriptor_->full_name(), descriptor_->file())
...@@ -138,29 +133,26 @@ std::string BytesFieldGenerator::GetDefaultValue(void) const ...@@ -138,29 +133,26 @@ std::string BytesFieldGenerator::GetDefaultValue(void) const
+ FullNameToLower(descriptor_->full_name(), descriptor_->file()) + FullNameToLower(descriptor_->full_name(), descriptor_->file())
+ "__default_value_data }"; + "__default_value_data }";
} }
void BytesFieldGenerator::GenerateStaticInit(io::Printer* printer) const void BytesFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables_, "$default_value$"); printer->Print(variables_, "$default_value$");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (FieldSyntax(descriptor_) == 2) if (FieldSyntax(descriptor_) == 2)
printer->Print(variables_, "0, "); printer->Print(variables_, "0, ");
printer->Print(variables_, "$default_value$"); printer->Print(variables_, "$default_value$");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
// no support for default? // no support for default?
printer->Print("0,NULL"); printer->Print("0,NULL");
break; break;
} }
} }
void BytesFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void BytesFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const
{ {
GenerateDescriptorInitializerGeneric(printer, true, "BYTES", "NULL"); GenerateDescriptorInitializerGeneric(printer, true, "BYTES", "NULL");
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,40 +61,35 @@ ...@@ -61,40 +61,35 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_BYTES_FIELD_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_BYTES_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_C_BYTES_FIELD_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_BYTES_FIELD_H__
#include <map> #include <map>
#include <string> #include <string>
#include <google/protobuf/io/printer.h>
#include "c_field.h" #include "c_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class BytesFieldGenerator : public FieldGenerator { class BytesFieldGenerator : public FieldGenerator {
public: public:
explicit BytesFieldGenerator(const FieldDescriptor* descriptor); explicit BytesFieldGenerator(const google::protobuf::FieldDescriptor* descriptor);
~BytesFieldGenerator(); ~BytesFieldGenerator();
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(google::protobuf::io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const;
void GenerateDefaultValueDeclarations(io::Printer* printer) const; void GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const;
void GenerateDefaultValueImplementations(io::Printer* printer) const; void GenerateDefaultValueImplementations(google::protobuf::io::Printer* printer) const;
std::string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(google::protobuf::io::Printer* printer) const;
private: private:
std::map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
} // namespace protobuf_c
} // namespace c #endif // PROTOBUF_C_PROTOC_GEN_C_C_BYTES_FIELD_H__
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__
...@@ -62,19 +62,15 @@ ...@@ -62,19 +62,15 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <map> #include <map>
#include <set>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include "c_enum.h" #include "c_enum.h"
#include "c_helpers.h" #include "c_helpers.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, EnumGenerator::EnumGenerator(const google::protobuf::EnumDescriptor* descriptor,
const std::string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor), : descriptor_(descriptor),
dllexport_decl_(dllexport_decl) { dllexport_decl_(dllexport_decl) {
...@@ -82,21 +78,21 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, ...@@ -82,21 +78,21 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,
EnumGenerator::~EnumGenerator() {} EnumGenerator::~EnumGenerator() {}
void EnumGenerator::GenerateDefinition(io::Printer* printer) { void EnumGenerator::GenerateDefinition(google::protobuf::io::Printer* printer) {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["classname"] = FullNameToC(descriptor_->full_name(), descriptor_->file()); vars["classname"] = FullNameToC(descriptor_->full_name(), descriptor_->file());
vars["shortname"] = descriptor_->name(); vars["shortname"] = descriptor_->name();
vars["uc_name"] = FullNameToUpper(descriptor_->full_name(), descriptor_->file()); vars["uc_name"] = FullNameToUpper(descriptor_->full_name(), descriptor_->file());
SourceLocation sourceLoc; google::protobuf::SourceLocation sourceLoc;
descriptor_->GetSourceLocation(&sourceLoc); descriptor_->GetSourceLocation(&sourceLoc);
PrintComment (printer, sourceLoc.leading_comments); PrintComment (printer, sourceLoc.leading_comments);
printer->Print(vars, "typedef enum _$classname$ {\n"); printer->Print(vars, "typedef enum _$classname$ {\n");
printer->Indent(); printer->Indent();
const EnumValueDescriptor* min_value = descriptor_->value(0); const google::protobuf::EnumValueDescriptor* min_value = descriptor_->value(0);
const EnumValueDescriptor* max_value = descriptor_->value(0); const google::protobuf::EnumValueDescriptor* max_value = descriptor_->value(0);
vars["opt_comma"] = ","; vars["opt_comma"] = ",";
...@@ -107,7 +103,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) { ...@@ -107,7 +103,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
if (i + 1 == descriptor_->value_count()) if (i + 1 == descriptor_->value_count())
vars["opt_comma"] = ""; vars["opt_comma"] = "";
SourceLocation valSourceLoc; google::protobuf::SourceLocation valSourceLoc;
descriptor_->value(i)->GetSourceLocation(&valSourceLoc); descriptor_->value(i)->GetSourceLocation(&valSourceLoc);
PrintComment (printer, valSourceLoc.leading_comments); PrintComment (printer, valSourceLoc.leading_comments);
...@@ -127,7 +123,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) { ...@@ -127,7 +123,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
printer->Print(vars, "} $classname$;\n"); printer->Print(vars, "} $classname$;\n");
} }
void EnumGenerator::GenerateDescriptorDeclarations(io::Printer* printer) { void EnumGenerator::GenerateDescriptorDeclarations(google::protobuf::io::Printer* printer) {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
if (dllexport_decl_.empty()) { if (dllexport_decl_.empty()) {
vars["dllexport"] = ""; vars["dllexport"] = "";
...@@ -148,13 +144,13 @@ struct ValueIndex ...@@ -148,13 +144,13 @@ struct ValueIndex
unsigned final_index; /* index in uniqified array of values */ unsigned final_index; /* index in uniqified array of values */
const char *name; const char *name;
}; };
void EnumGenerator::GenerateValueInitializer(io::Printer *printer, int index) void EnumGenerator::GenerateValueInitializer(google::protobuf::io::Printer *printer, int index)
{ {
const EnumValueDescriptor *vd = descriptor_->value(index); const google::protobuf::EnumValueDescriptor *vd = descriptor_->value(index);
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
bool optimize_code_size = descriptor_->file()->options().has_optimize_for() && bool optimize_code_size = descriptor_->file()->options().has_optimize_for() &&
descriptor_->file()->options().optimize_for() == descriptor_->file()->options().optimize_for() ==
FileOptions_OptimizeMode_CODE_SIZE; google::protobuf::FileOptions_OptimizeMode_CODE_SIZE;
vars["enum_value_name"] = vd->name(); vars["enum_value_name"] = vd->name();
vars["c_enum_value_name"] = FullNameToUpper(descriptor_->full_name(), descriptor_->file()) + "__" + vd->name(); vars["c_enum_value_name"] = FullNameToUpper(descriptor_->full_name(), descriptor_->file()) + "__" + vd->name();
vars["value"] = SimpleItoa(vd->number()); vars["value"] = SimpleItoa(vd->number());
...@@ -183,7 +179,7 @@ static int compare_value_indices_by_name(const void *a, const void *b) ...@@ -183,7 +179,7 @@ static int compare_value_indices_by_name(const void *a, const void *b)
return strcmp (vi_a->name, vi_b->name); return strcmp (vi_a->name, vi_b->name);
} }
void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) { void EnumGenerator::GenerateEnumDescriptor(google::protobuf::io::Printer* printer) {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["fullname"] = descriptor_->full_name(); vars["fullname"] = descriptor_->full_name();
vars["lcclassname"] = FullNameToLower(descriptor_->full_name(), descriptor_->file()); vars["lcclassname"] = FullNameToLower(descriptor_->full_name(), descriptor_->file());
...@@ -194,14 +190,14 @@ void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) { ...@@ -194,14 +190,14 @@ void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) {
bool optimize_code_size = descriptor_->file()->options().has_optimize_for() && bool optimize_code_size = descriptor_->file()->options().has_optimize_for() &&
descriptor_->file()->options().optimize_for() == descriptor_->file()->options().optimize_for() ==
FileOptions_OptimizeMode_CODE_SIZE; google::protobuf::FileOptions_OptimizeMode_CODE_SIZE;
// Sort by name and value, dropping duplicate values if they appear later. // Sort by name and value, dropping duplicate values if they appear later.
// TODO: use a c++ paradigm for this! // TODO: use a c++ paradigm for this!
NameIndex *name_index = new NameIndex[descriptor_->value_count()]; NameIndex *name_index = new NameIndex[descriptor_->value_count()];
ValueIndex *value_index = new ValueIndex[descriptor_->value_count()]; ValueIndex *value_index = new ValueIndex[descriptor_->value_count()];
for (int j = 0; j < descriptor_->value_count(); j++) { for (int j = 0; j < descriptor_->value_count(); j++) {
const EnumValueDescriptor *vd = descriptor_->value(j); const google::protobuf::EnumValueDescriptor *vd = descriptor_->value(j);
name_index[j].index = j; name_index[j].index = j;
name_index[j].name = vd->name().c_str(); name_index[j].name = vd->name().c_str();
value_index[j].index = j; value_index[j].index = j;
...@@ -328,9 +324,4 @@ void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) { ...@@ -328,9 +324,4 @@ void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) {
delete[] name_index; delete[] name_index;
} }
} // namespace protobuf_c
} // namespace c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,23 +61,20 @@ ...@@ -61,23 +61,20 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_ENUM_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_ENUM_H__
#define GOOGLE_PROTOBUF_COMPILER_C_ENUM_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_ENUM_H__
#include <string> #include <string>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class EnumGenerator { class EnumGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl. // See generator.cc for the meaning of dllexport_decl.
explicit EnumGenerator(const EnumDescriptor* descriptor, explicit EnumGenerator(const google::protobuf::EnumDescriptor* descriptor,
const std::string& dllexport_decl); const std::string& dllexport_decl);
~EnumGenerator(); ~EnumGenerator();
...@@ -86,28 +83,25 @@ class EnumGenerator { ...@@ -86,28 +83,25 @@ class EnumGenerator {
// Generate header code defining the enum. This code should be placed // Generate header code defining the enum. This code should be placed
// within the enum's package namespace, but NOT within any class, even for // within the enum's package namespace, but NOT within any class, even for
// nested enums. // nested enums.
void GenerateDefinition(io::Printer* printer); void GenerateDefinition(google::protobuf::io::Printer* printer);
void GenerateDescriptorDeclarations(io::Printer* printer); void GenerateDescriptorDeclarations(google::protobuf::io::Printer* printer);
// Source file stuff. // Source file stuff.
// Generate the ProtobufCEnumDescriptor for this enum // Generate the ProtobufCEnumDescriptor for this enum
void GenerateEnumDescriptor(io::Printer* printer); void GenerateEnumDescriptor(google::protobuf::io::Printer* printer);
// Generate static initializer for a ProtobufCEnumValue // Generate static initializer for a ProtobufCEnumValue
// given the index of the value in the enum. // given the index of the value in the enum.
void GenerateValueInitializer(io::Printer *printer, int index); void GenerateValueInitializer(google::protobuf::io::Printer *printer, int index);
private: private:
const EnumDescriptor* descriptor_; const google::protobuf::EnumDescriptor* descriptor_;
std::string dllexport_decl_; std::string dllexport_decl_;
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_ENUM_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_ENUM_H__
...@@ -67,21 +67,16 @@ ...@@ -67,21 +67,16 @@
#include "c_enum_field.h" #include "c_enum_field.h"
#include "c_helpers.h" #include "c_helpers.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
using internal::WireFormat;
// TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of // TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of
// repeat code between this and the other field types. // repeat code between this and the other field types.
void SetEnumVariables(const FieldDescriptor* descriptor, void SetEnumVariables(const google::protobuf::FieldDescriptor* descriptor,
std::map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name(), descriptor->enum_type()->file()); (*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name(), descriptor->enum_type()->file());
const EnumValueDescriptor* default_value = descriptor->default_value_enum(); const google::protobuf::EnumValueDescriptor* default_value = descriptor->default_value_enum();
(*variables)["default"] = FullNameToUpper(default_value->type()->full_name(), default_value->type()->file()) (*variables)["default"] = FullNameToUpper(default_value->type()->full_name(), default_value->type()->file())
+ "__" + default_value->name(); + "__" + default_value->name();
(*variables)["deprecated"] = FieldDeprecated(descriptor); (*variables)["deprecated"] = FieldDeprecated(descriptor);
...@@ -90,7 +85,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, ...@@ -90,7 +85,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
// =================================================================== // ===================================================================
EnumFieldGenerator:: EnumFieldGenerator::
EnumFieldGenerator(const FieldDescriptor* descriptor) EnumFieldGenerator(const google::protobuf::FieldDescriptor* descriptor)
: FieldGenerator(descriptor) : FieldGenerator(descriptor)
{ {
SetEnumVariables(descriptor, &variables_); SetEnumVariables(descriptor, &variables_);
...@@ -98,18 +93,18 @@ EnumFieldGenerator(const FieldDescriptor* descriptor) ...@@ -98,18 +93,18 @@ EnumFieldGenerator(const FieldDescriptor* descriptor)
EnumFieldGenerator::~EnumFieldGenerator() {} EnumFieldGenerator::~EnumFieldGenerator() {}
void EnumFieldGenerator::GenerateStructMembers(io::Printer* printer) const void EnumFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables_, "$type$ $name$$deprecated$;\n"); printer->Print(variables_, "$type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2)
printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n"); printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n");
printer->Print(variables_, "$type$ $name$$deprecated$;\n"); printer->Print(variables_, "$type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); printer->Print(variables_, "size_t n_$name$$deprecated$;\n");
printer->Print(variables_, "$type$ *$name$$deprecated$;\n"); printer->Print(variables_, "$type$ *$name$$deprecated$;\n");
break; break;
...@@ -120,32 +115,28 @@ std::string EnumFieldGenerator::GetDefaultValue(void) const ...@@ -120,32 +115,28 @@ std::string EnumFieldGenerator::GetDefaultValue(void) const
{ {
return variables_.find("default")->second; return variables_.find("default")->second;
} }
void EnumFieldGenerator::GenerateStaticInit(io::Printer* printer) const void EnumFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables_, "$default$"); printer->Print(variables_, "$default$");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (FieldSyntax(descriptor_) == 2) if (FieldSyntax(descriptor_) == 2)
printer->Print(variables_, "0, "); printer->Print(variables_, "0, ");
printer->Print(variables_, "$default$"); printer->Print(variables_, "$default$");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
// no support for default? // no support for default?
printer->Print("0,NULL"); printer->Print("0,NULL");
break; break;
} }
} }
void EnumFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void EnumFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const
{ {
std::string addr = "&" + FullNameToLower(descriptor_->enum_type()->full_name(), descriptor_->enum_type()->file()) + "__descriptor"; std::string addr = "&" + FullNameToLower(descriptor_->enum_type()->full_name(), descriptor_->enum_type()->file()) + "__descriptor";
GenerateDescriptorInitializerGeneric(printer, true, "ENUM", addr); GenerateDescriptorInitializerGeneric(printer, true, "ENUM", addr);
} }
} // namespace protobuf_c
} // namespace c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,38 +61,34 @@ ...@@ -61,38 +61,34 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_ENUM_FIELD_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_ENUM_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_C_ENUM_FIELD_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_ENUM_FIELD_H__
#include <map> #include <map>
#include <string> #include <string>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h>
#include "c_field.h" #include "c_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class EnumFieldGenerator : public FieldGenerator { class EnumFieldGenerator : public FieldGenerator {
public: public:
explicit EnumFieldGenerator(const FieldDescriptor* descriptor); explicit EnumFieldGenerator(const google::protobuf::FieldDescriptor* descriptor);
~EnumFieldGenerator(); ~EnumFieldGenerator();
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(google::protobuf::io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const;
std::string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(google::protobuf::io::Printer* printer) const;
private: private:
std::map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
} // namespace protobuf_c
} // namespace c #endif // PROTOBUF_C_PROTOC_GEN_C_C_ENUM_FIELD_H__
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_C_ENUM_FIELD_H__
...@@ -61,16 +61,14 @@ ...@@ -61,16 +61,14 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include "c_extension.h" #include "c_extension.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, ExtensionGenerator::ExtensionGenerator(const google::protobuf::FieldDescriptor* descriptor,
const std::string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor), : descriptor_(descriptor),
dllexport_decl_(dllexport_decl) { dllexport_decl_(dllexport_decl) {
...@@ -78,14 +76,10 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, ...@@ -78,14 +76,10 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
ExtensionGenerator::~ExtensionGenerator() {} ExtensionGenerator::~ExtensionGenerator() {}
void ExtensionGenerator::GenerateDeclaration(io::Printer* printer) { void ExtensionGenerator::GenerateDeclaration(google::protobuf::io::Printer* printer) {
} }
void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { void ExtensionGenerator::GenerateDefinition(google::protobuf::io::Printer* printer) {
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_EXTENSION_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_EXTENSION_H__
#define GOOGLE_PROTOBUF_COMPILER_C_EXTENSION_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_EXTENSION_H__
#include <string> #include <string>
...@@ -70,10 +70,7 @@ ...@@ -70,10 +70,7 @@
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
// Generates code for an extension, which may be within the scope of some // Generates code for an extension, which may be within the scope of some
// message or may be at file scope. This is much simpler than FieldGenerator // message or may be at file scope. This is much simpler than FieldGenerator
...@@ -81,25 +78,22 @@ namespace c { ...@@ -81,25 +78,22 @@ namespace c {
class ExtensionGenerator { class ExtensionGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl. // See generator.cc for the meaning of dllexport_decl.
explicit ExtensionGenerator(const FieldDescriptor* descriptor, explicit ExtensionGenerator(const google::protobuf::FieldDescriptor* descriptor,
const std::string& dllexport_decl); const std::string& dllexport_decl);
~ExtensionGenerator(); ~ExtensionGenerator();
// Header stuff. // Header stuff.
void GenerateDeclaration(io::Printer* printer); void GenerateDeclaration(google::protobuf::io::Printer* printer);
// Source file stuff. // Source file stuff.
void GenerateDefinition(io::Printer* printer); void GenerateDefinition(google::protobuf::io::Printer* printer);
private: private:
const FieldDescriptor* descriptor_; const google::protobuf::FieldDescriptor* descriptor_;
std::string type_traits_; std::string type_traits_;
std::string dllexport_decl_; std::string dllexport_decl_;
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_EXTENSION_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
...@@ -74,43 +75,41 @@ ...@@ -74,43 +75,41 @@
#include "c_primitive_field.h" #include "c_primitive_field.h"
#include "c_string_field.h" #include "c_string_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
FieldGenerator::~FieldGenerator() FieldGenerator::~FieldGenerator()
{ {
} }
static bool is_packable_type(FieldDescriptor::Type type)
static bool is_packable_type(google::protobuf::FieldDescriptor::Type type)
{ {
return type == FieldDescriptor::TYPE_DOUBLE return type == google::protobuf::FieldDescriptor::TYPE_DOUBLE
|| type == FieldDescriptor::TYPE_FLOAT || type == google::protobuf::FieldDescriptor::TYPE_FLOAT
|| type == FieldDescriptor::TYPE_INT64 || type == google::protobuf::FieldDescriptor::TYPE_INT64
|| type == FieldDescriptor::TYPE_UINT64 || type == google::protobuf::FieldDescriptor::TYPE_UINT64
|| type == FieldDescriptor::TYPE_INT32 || type == google::protobuf::FieldDescriptor::TYPE_INT32
|| type == FieldDescriptor::TYPE_FIXED64 || type == google::protobuf::FieldDescriptor::TYPE_FIXED64
|| type == FieldDescriptor::TYPE_FIXED32 || type == google::protobuf::FieldDescriptor::TYPE_FIXED32
|| type == FieldDescriptor::TYPE_BOOL || type == google::protobuf::FieldDescriptor::TYPE_BOOL
|| type == FieldDescriptor::TYPE_UINT32 || type == google::protobuf::FieldDescriptor::TYPE_UINT32
|| type == FieldDescriptor::TYPE_ENUM || type == google::protobuf::FieldDescriptor::TYPE_ENUM
|| type == FieldDescriptor::TYPE_SFIXED32 || type == google::protobuf::FieldDescriptor::TYPE_SFIXED32
|| type == FieldDescriptor::TYPE_SFIXED64 || type == google::protobuf::FieldDescriptor::TYPE_SFIXED64
|| type == FieldDescriptor::TYPE_SINT32 || type == google::protobuf::FieldDescriptor::TYPE_SINT32
|| type == FieldDescriptor::TYPE_SINT64; || type == google::protobuf::FieldDescriptor::TYPE_SINT64;
//TYPE_BYTES //TYPE_BYTES
//TYPE_STRING //TYPE_STRING
//TYPE_GROUP //TYPE_GROUP
//TYPE_MESSAGE //TYPE_MESSAGE
} }
void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, void FieldGenerator::GenerateDescriptorInitializerGeneric(google::protobuf::io::Printer* printer,
bool optional_uses_has, bool optional_uses_has,
const std::string &type_macro, const std::string &type_macro,
const std::string &descriptor_addr) const const std::string &descriptor_addr) const
{ {
std::map<std::string, std::string> variables; std::map<std::string, std::string> variables;
const OneofDescriptor *oneof = descriptor_->containing_oneof(); const google::protobuf::OneofDescriptor *oneof = descriptor_->containing_oneof();
const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file); const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file);
variables["TYPE"] = type_macro; variables["TYPE"] = type_macro;
variables["classname"] = FullNameToC(FieldScope(descriptor_)->full_name(), FieldScope(descriptor_)->file()); variables["classname"] = FullNameToC(FieldScope(descriptor_)->full_name(), FieldScope(descriptor_)->file());
...@@ -125,7 +124,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -125,7 +124,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
variables["oneofname"] = CamelToLower(oneof->name()); variables["oneofname"] = CamelToLower(oneof->name());
if (FieldSyntax(descriptor_) == 3 && if (FieldSyntax(descriptor_) == 3 &&
descriptor_->label() == FieldDescriptor::LABEL_OPTIONAL) { descriptor_->label() == google::protobuf::FieldDescriptor::LABEL_OPTIONAL) {
variables["LABEL"] = "NONE"; variables["LABEL"] = "NONE";
optional_uses_has = false; optional_uses_has = false;
} else { } else {
...@@ -137,7 +136,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -137,7 +136,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
+ FullNameToLower(descriptor_->full_name(), descriptor_->file()) + FullNameToLower(descriptor_->full_name(), descriptor_->file())
+ "__default_value"; + "__default_value";
} else if (FieldSyntax(descriptor_) == 3 && } else if (FieldSyntax(descriptor_) == 3 &&
descriptor_->type() == FieldDescriptor::TYPE_STRING) { descriptor_->type() == google::protobuf::FieldDescriptor::TYPE_STRING) {
variables["default_value"] = "&protobuf_c_empty_string"; variables["default_value"] = "&protobuf_c_empty_string";
} else { } else {
variables["default_value"] = "NULL"; variables["default_value"] = "NULL";
...@@ -145,11 +144,11 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -145,11 +144,11 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
variables["flags"] = "0"; variables["flags"] = "0";
if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED if (descriptor_->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED
&& is_packable_type (descriptor_->type()) && is_packable_type (descriptor_->type())
&& descriptor_->options().packed()) { && descriptor_->options().packed()) {
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED"; variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED";
} else if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED } else if (descriptor_->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED
&& is_packable_type (descriptor_->type()) && is_packable_type (descriptor_->type())
&& FieldSyntax(descriptor_) == 3 && FieldSyntax(descriptor_) == 3
&& !descriptor_->options().has_packed()) { && !descriptor_->options().has_packed()) {
...@@ -170,7 +169,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -170,7 +169,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
printer->Print("{\n"); printer->Print("{\n");
if (descriptor_->file()->options().has_optimize_for() && if (descriptor_->file()->options().has_optimize_for() &&
descriptor_->file()->options().optimize_for() == descriptor_->file()->options().optimize_for() ==
FileOptions_OptimizeMode_CODE_SIZE) { google::protobuf::FileOptions_OptimizeMode_CODE_SIZE) {
printer->Print(" NULL, /* CODE_SIZE */\n"); printer->Print(" NULL, /* CODE_SIZE */\n");
} else { } else {
printer->Print(variables, " \"$proto_name$\",\n"); printer->Print(variables, " \"$proto_name$\",\n");
...@@ -180,10 +179,10 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -180,10 +179,10 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
" PROTOBUF_C_LABEL_$LABEL$,\n" " PROTOBUF_C_LABEL_$LABEL$,\n"
" PROTOBUF_C_TYPE_$TYPE$,\n"); " PROTOBUF_C_TYPE_$TYPE$,\n");
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables, " 0, /* quantifier_offset */\n"); printer->Print(variables, " 0, /* quantifier_offset */\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (oneof != NULL) { if (oneof != NULL) {
printer->Print(variables, " offsetof($classname$, $oneofname$_case),\n"); printer->Print(variables, " offsetof($classname$, $oneofname$_case),\n");
} else if (optional_uses_has) { } else if (optional_uses_has) {
...@@ -192,7 +191,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -192,7 +191,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
printer->Print(variables, " 0, /* quantifier_offset */\n"); printer->Print(variables, " 0, /* quantifier_offset */\n");
} }
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(variables, " offsetof($classname$, n_$name$),\n"); printer->Print(variables, " offsetof($classname$, n_$name$),\n");
break; break;
} }
...@@ -204,7 +203,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -204,7 +203,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
printer->Print("},\n"); printer->Print("},\n");
} }
FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) FieldGeneratorMap::FieldGeneratorMap(const google::protobuf::Descriptor* descriptor)
: descriptor_(descriptor), : descriptor_(descriptor),
field_generators_( field_generators_(
new std::unique_ptr<FieldGenerator>[descriptor->field_count()]) { new std::unique_ptr<FieldGenerator>[descriptor->field_count()]) {
...@@ -214,21 +213,21 @@ FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) ...@@ -214,21 +213,21 @@ FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor)
} }
} }
FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field) { FieldGenerator* FieldGeneratorMap::MakeGenerator(const google::protobuf::FieldDescriptor* field) {
const ProtobufCFieldOptions opt = field->options().GetExtension(pb_c_field); const ProtobufCFieldOptions opt = field->options().GetExtension(pb_c_field);
switch (field->type()) { switch (field->type()) {
case FieldDescriptor::TYPE_MESSAGE: case google::protobuf::FieldDescriptor::TYPE_MESSAGE:
return new MessageFieldGenerator(field); return new MessageFieldGenerator(field);
case FieldDescriptor::TYPE_STRING: case google::protobuf::FieldDescriptor::TYPE_STRING:
if (opt.string_as_bytes()) if (opt.string_as_bytes())
return new BytesFieldGenerator(field); return new BytesFieldGenerator(field);
else else
return new StringFieldGenerator(field); return new StringFieldGenerator(field);
case FieldDescriptor::TYPE_BYTES: case google::protobuf::FieldDescriptor::TYPE_BYTES:
return new BytesFieldGenerator(field); return new BytesFieldGenerator(field);
case FieldDescriptor::TYPE_ENUM: case google::protobuf::FieldDescriptor::TYPE_ENUM:
return new EnumFieldGenerator(field); return new EnumFieldGenerator(field);
case FieldDescriptor::TYPE_GROUP: case google::protobuf::FieldDescriptor::TYPE_GROUP:
return 0; // XXX return 0; // XXX
default: default:
return new PrimitiveFieldGenerator(field); return new PrimitiveFieldGenerator(field);
...@@ -238,12 +237,9 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field) { ...@@ -238,12 +237,9 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field) {
FieldGeneratorMap::~FieldGeneratorMap() {} FieldGeneratorMap::~FieldGeneratorMap() {}
const FieldGenerator& FieldGeneratorMap::get( const FieldGenerator& FieldGeneratorMap::get(
const FieldDescriptor* field) const { const google::protobuf::FieldDescriptor* field) const {
GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); GOOGLE_CHECK_EQ(field->containing_type(), descriptor_);
return *field_generators_[field->index()]; return *field_generators_[field->index()];
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_FIELD_H__
#include <memory> #include <memory>
...@@ -70,56 +70,50 @@ ...@@ -70,56 +70,50 @@
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class FieldGenerator { class FieldGenerator {
public: public:
explicit FieldGenerator(const FieldDescriptor *descriptor) : descriptor_(descriptor) {} explicit FieldGenerator(const google::protobuf::FieldDescriptor *descriptor) : descriptor_(descriptor) {}
virtual ~FieldGenerator(); virtual ~FieldGenerator();
// Generate definitions to be included in the structure. // Generate definitions to be included in the structure.
virtual void GenerateStructMembers(io::Printer* printer) const = 0; virtual void GenerateStructMembers(google::protobuf::io::Printer* printer) const = 0;
// Generate a static initializer for this field. // Generate a static initializer for this field.
virtual void GenerateDescriptorInitializer(io::Printer* printer) const = 0; virtual void GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const = 0;
virtual void GenerateDefaultValueDeclarations(io::Printer* printer) const { } virtual void GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const { }
virtual void GenerateDefaultValueImplementations(io::Printer* printer) const { } virtual void GenerateDefaultValueImplementations(google::protobuf::io::Printer* printer) const { }
virtual std::string GetDefaultValue() const = 0; virtual std::string GetDefaultValue() const = 0;
// Generate members to initialize this field from a static initializer // Generate members to initialize this field from a static initializer
virtual void GenerateStaticInit(io::Printer* printer) const = 0; virtual void GenerateStaticInit(google::protobuf::io::Printer* printer) const = 0;
protected: protected:
void GenerateDescriptorInitializerGeneric(io::Printer* printer, void GenerateDescriptorInitializerGeneric(google::protobuf::io::Printer* printer,
bool optional_uses_has, bool optional_uses_has,
const std::string &type_macro, const std::string &type_macro,
const std::string &descriptor_addr) const; const std::string &descriptor_addr) const;
const FieldDescriptor *descriptor_; const google::protobuf::FieldDescriptor *descriptor_;
}; };
// Convenience class which constructs FieldGenerators for a Descriptor. // Convenience class which constructs FieldGenerators for a Descriptor.
class FieldGeneratorMap { class FieldGeneratorMap {
public: public:
explicit FieldGeneratorMap(const Descriptor* descriptor); explicit FieldGeneratorMap(const google::protobuf::Descriptor* descriptor);
~FieldGeneratorMap(); ~FieldGeneratorMap();
const FieldGenerator& get(const FieldDescriptor* field) const; const FieldGenerator& get(const google::protobuf::FieldDescriptor* field) const;
private: private:
const Descriptor* descriptor_; const google::protobuf::Descriptor* descriptor_;
std::unique_ptr<std::unique_ptr<FieldGenerator>[]> field_generators_; std::unique_ptr<std::unique_ptr<FieldGenerator>[]> field_generators_;
static FieldGenerator* MakeGenerator(const FieldDescriptor* field); static FieldGenerator* MakeGenerator(const google::protobuf::FieldDescriptor* field);
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_FIELD_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <protobuf-c/protobuf-c.pb.h> #include <protobuf-c/protobuf-c.pb.h>
...@@ -73,14 +74,11 @@ ...@@ -73,14 +74,11 @@
#include "c_message.h" #include "c_message.h"
#include "c_service.h" #include "c_service.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
// =================================================================== // ===================================================================
FileGenerator::FileGenerator(const FileDescriptor* file, FileGenerator::FileGenerator(const google::protobuf::FileDescriptor* file,
const std::string& dllexport_decl) const std::string& dllexport_decl)
: file_(file), : file_(file),
message_generators_( message_generators_(
...@@ -115,7 +113,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, ...@@ -115,7 +113,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file,
FileGenerator::~FileGenerator() {} FileGenerator::~FileGenerator() {}
void FileGenerator::GenerateHeader(io::Printer* printer) { void FileGenerator::GenerateHeader(google::protobuf::io::Printer* printer) {
std::string filename_identifier = FilenameIdentifier(file_->name()); std::string filename_identifier = FilenameIdentifier(file_->name());
const int min_header_version = 1003000; const int min_header_version = 1003000;
...@@ -228,7 +226,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { ...@@ -228,7 +226,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"filename_identifier", filename_identifier); "filename_identifier", filename_identifier);
} }
void FileGenerator::GenerateSource(io::Printer* printer) { void FileGenerator::GenerateSource(google::protobuf::io::Printer* printer) {
printer->Print( printer->Print(
"/* Generated by the protocol buffer compiler. DO NOT EDIT! */\n" "/* Generated by the protocol buffer compiler. DO NOT EDIT! */\n"
"/* Generated from: $filename$ */\n" "/* Generated from: $filename$ */\n"
...@@ -264,7 +262,4 @@ void FileGenerator::GenerateSource(io::Printer* printer) { ...@@ -264,7 +262,4 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_FILE_H__
#define GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_FILE_H__
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -72,30 +72,26 @@ ...@@ -72,30 +72,26 @@
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
#include "c_enum.h"
#include "c_extension.h"
#include "c_field.h" #include "c_field.h"
#include "c_message.h"
#include "c_service.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class EnumGenerator; // enum.h
class MessageGenerator; // message.h
class ServiceGenerator; // service.h
class ExtensionGenerator; // extension.h
class FileGenerator { class FileGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl. // See generator.cc for the meaning of dllexport_decl.
explicit FileGenerator(const FileDescriptor* file, explicit FileGenerator(const google::protobuf::FileDescriptor* file,
const std::string& dllexport_decl); const std::string& dllexport_decl);
~FileGenerator(); ~FileGenerator();
void GenerateHeader(io::Printer* printer); void GenerateHeader(google::protobuf::io::Printer* printer);
void GenerateSource(io::Printer* printer); void GenerateSource(google::protobuf::io::Printer* printer);
private: private:
const FileDescriptor* file_; const google::protobuf::FileDescriptor* file_;
std::unique_ptr<std::unique_ptr<MessageGenerator>[]> message_generators_; std::unique_ptr<std::unique_ptr<MessageGenerator>[]> message_generators_;
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_; std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;
...@@ -103,9 +99,6 @@ class FileGenerator { ...@@ -103,9 +99,6 @@ class FileGenerator {
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_; std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_FILE_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_FILE_H__
...@@ -73,10 +73,7 @@ ...@@ -73,10 +73,7 @@
#include "c_generator.h" #include "c_generator.h"
#include "c_helpers.h" #include "c_helpers.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
// Parses a set of comma-delimited name/value pairs, e.g.: // Parses a set of comma-delimited name/value pairs, e.g.:
// "foo=bar,baz,qux=corge" // "foo=bar,baz,qux=corge"
...@@ -103,9 +100,9 @@ void ParseOptions(const std::string& text, std::vector<std::pair<std::string, st ...@@ -103,9 +100,9 @@ void ParseOptions(const std::string& text, std::vector<std::pair<std::string, st
CGenerator::CGenerator() {} CGenerator::CGenerator() {}
CGenerator::~CGenerator() {} CGenerator::~CGenerator() {}
bool CGenerator::Generate(const FileDescriptor* file, bool CGenerator::Generate(const google::protobuf::FileDescriptor* file,
const std::string& parameter, const std::string& parameter,
OutputDirectory* output_directory, google::protobuf::compiler::OutputDirectory* output_directory,
std::string* error) const { std::string* error) const {
if (file->options().GetExtension(pb_c_file).no_generate()) if (file->options().GetExtension(pb_c_file).no_generate())
return true; return true;
...@@ -154,24 +151,21 @@ bool CGenerator::Generate(const FileDescriptor* file, ...@@ -154,24 +151,21 @@ bool CGenerator::Generate(const FileDescriptor* file,
// Generate header. // Generate header.
{ {
std::unique_ptr<io::ZeroCopyOutputStream> output( std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
output_directory->Open(basename + ".h")); output_directory->Open(basename + ".h"));
io::Printer printer(output.get(), '$'); google::protobuf::io::Printer printer(output.get(), '$');
file_generator.GenerateHeader(&printer); file_generator.GenerateHeader(&printer);
} }
// Generate cc file. // Generate cc file.
{ {
std::unique_ptr<io::ZeroCopyOutputStream> output( std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
output_directory->Open(basename + ".c")); output_directory->Open(basename + ".c"));
io::Printer printer(output.get(), '$'); google::protobuf::io::Printer printer(output.get(), '$');
file_generator.GenerateSource(&printer); file_generator.GenerateSource(&printer);
} }
return true; return true;
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -63,49 +63,43 @@ ...@@ -63,49 +63,43 @@
// Generates C code for a given .proto file. // Generates C code for a given .proto file.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_GENERATOR_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_C_GENERATOR_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_GENERATOR_H__
#include <string> #include <string>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB) #if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
# define PROTOC_C_EXPORT __declspec(dllexport) # define PROTOBUF_C_EXPORT __declspec(dllexport)
#else #else
# define PROTOC_C_EXPORT # define PROTOBUF_C_EXPORT
#endif #endif
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
// CodeGenerator implementation which generates a C++ source file and // CodeGenerator implementation which generates a C++ source file and
// header. If you create your own protocol compiler binary and you want // header. If you create your own protocol compiler binary and you want
// it to support C++ output, you can do so by registering an instance of this // it to support C++ output, you can do so by registering an instance of this
// CodeGenerator with the CommandLineInterface in your main() function. // CodeGenerator with the CommandLineInterface in your main() function.
class PROTOC_C_EXPORT CGenerator : public CodeGenerator { class PROTOBUF_C_EXPORT CGenerator : public google::protobuf::compiler::CodeGenerator {
public: public:
CGenerator(); CGenerator();
~CGenerator(); ~CGenerator();
// implements CodeGenerator ---------------------------------------- // implements CodeGenerator ----------------------------------------
bool Generate(const FileDescriptor* file, bool Generate(const google::protobuf::FileDescriptor* file,
const std::string& parameter, const std::string& parameter,
OutputDirectory* output_directory, google::protobuf::compiler::OutputDirectory* output_directory,
std::string* error) const; std::string* error) const;
#if GOOGLE_PROTOBUF_VERSION >= 5026000 #if GOOGLE_PROTOBUF_VERSION >= 5026000
uint64_t GetSupportedFeatures() const { return 0; } uint64_t GetSupportedFeatures() const { return 0; }
Edition GetMinimumEdition() const { return Edition::EDITION_PROTO2; } google::protobuf::Edition GetMinimumEdition() const { return google::protobuf::Edition::EDITION_PROTO2; }
Edition GetMaximumEdition() const { return Edition::EDITION_PROTO3; } google::protobuf::Edition GetMaximumEdition() const { return google::protobuf::Edition::EDITION_PROTO3; }
#endif #endif
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_GENERATOR_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_GENERATOR_H__
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <cstdint>
#include <memory> #include <memory>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -68,14 +69,12 @@ ...@@ -68,14 +69,12 @@
#include <float.h> #include <float.h>
#include <stdio.h> // for snprintf #include <stdio.h> // for snprintf
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
#include "c_helpers.h" #include "c_helpers.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
#if defined(_MSC_VER) #if defined(_MSC_VER)
// FIXME: In the case where the generated string is longer than the buffer, // FIXME: In the case where the generated string is longer than the buffer,
...@@ -180,8 +179,7 @@ std::string ToCamel(const std::string &name) { ...@@ -180,8 +179,7 @@ std::string ToCamel(const std::string &name) {
return rv; return rv;
} }
std::string OverrideFullName(const std::string &full_name, std::string OverrideFullName(const std::string &full_name, const google::protobuf::FileDescriptor* file) {
const FileDescriptor *file) {
const ProtobufCFileOptions opt = file->options().GetExtension(pb_c_file); const ProtobufCFileOptions opt = file->options().GetExtension(pb_c_file);
if (!opt.has_c_package()) if (!opt.has_c_package())
return full_name; return full_name;
...@@ -193,8 +191,7 @@ std::string OverrideFullName(const std::string &full_name, ...@@ -193,8 +191,7 @@ std::string OverrideFullName(const std::string &full_name,
return new_name + full_name.substr(file->package().length()); return new_name + full_name.substr(file->package().length());
} }
std::string FullNameToLower(const std::string &full_name, std::string FullNameToLower(const std::string &full_name, const google::protobuf::FileDescriptor* file) {
const FileDescriptor *file) {
std::vector<std::string> pieces; std::vector<std::string> pieces;
SplitStringUsing(OverrideFullName(full_name, file), ".", &pieces); SplitStringUsing(OverrideFullName(full_name, file), ".", &pieces);
std::string rv = ""; std::string rv = "";
...@@ -205,8 +202,7 @@ std::string FullNameToLower(const std::string &full_name, ...@@ -205,8 +202,7 @@ std::string FullNameToLower(const std::string &full_name,
} }
return rv; return rv;
} }
std::string FullNameToUpper(const std::string &full_name, std::string FullNameToUpper(const std::string &full_name, const google::protobuf::FileDescriptor* file) {
const FileDescriptor *file) {
std::vector<std::string> pieces; std::vector<std::string> pieces;
SplitStringUsing(OverrideFullName(full_name, file), ".", &pieces); SplitStringUsing(OverrideFullName(full_name, file), ".", &pieces);
std::string rv = ""; std::string rv = "";
...@@ -217,8 +213,7 @@ std::string FullNameToUpper(const std::string &full_name, ...@@ -217,8 +213,7 @@ std::string FullNameToUpper(const std::string &full_name,
} }
return rv; return rv;
} }
std::string FullNameToC(const std::string &full_name, std::string FullNameToC(const std::string &full_name, const google::protobuf::FileDescriptor* file) {
const FileDescriptor *file) {
std::vector<std::string> pieces; std::vector<std::string> pieces;
SplitStringUsing(OverrideFullName(full_name, file), ".", &pieces); SplitStringUsing(OverrideFullName(full_name, file), ".", &pieces);
std::string rv = ""; std::string rv = "";
...@@ -230,7 +225,7 @@ std::string FullNameToC(const std::string &full_name, ...@@ -230,7 +225,7 @@ std::string FullNameToC(const std::string &full_name,
return rv; return rv;
} }
void PrintComment (io::Printer* printer, std::string comment) void PrintComment(google::protobuf::io::Printer* printer, std::string comment)
{ {
if (!comment.empty()) if (!comment.empty())
{ {
...@@ -297,7 +292,7 @@ std::set<std::string> MakeKeywordsMap() { ...@@ -297,7 +292,7 @@ std::set<std::string> MakeKeywordsMap() {
std::set<std::string> kKeywords = MakeKeywordsMap(); std::set<std::string> kKeywords = MakeKeywordsMap();
std::string FieldName(const FieldDescriptor* field) { std::string FieldName(const google::protobuf::FieldDescriptor* field) {
std::string result = ToLower(field->name()); std::string result = ToLower(field->name());
if (kKeywords.count(result) > 0) { if (kKeywords.count(result) > 0) {
result.append("_"); result.append("_");
...@@ -305,7 +300,7 @@ std::string FieldName(const FieldDescriptor* field) { ...@@ -305,7 +300,7 @@ std::string FieldName(const FieldDescriptor* field) {
return result; return result;
} }
std::string FieldDeprecated(const FieldDescriptor* field) { std::string FieldDeprecated(const google::protobuf::FieldDescriptor* field) {
if (field->options().deprecated()) { if (field->options().deprecated()) {
return " PROTOBUF_C__DEPRECATED"; return " PROTOBUF_C__DEPRECATED";
} }
...@@ -331,7 +326,7 @@ std::string FilenameIdentifier(const std::string& filename) { ...@@ -331,7 +326,7 @@ std::string FilenameIdentifier(const std::string& filename) {
// use the hex code for the character. // use the hex code for the character.
result.push_back('_'); result.push_back('_');
char buffer[32]; char buffer[32];
result.append(FastHexToBuffer(static_cast<uint8>(filename[i]), buffer)); result.append(FastHexToBuffer(static_cast<std::uint8_t>(filename[i]), buffer));
} }
} }
return result; return result;
...@@ -342,17 +337,17 @@ std::string GlobalBuildDescriptorsName(const std::string& filename) { ...@@ -342,17 +337,17 @@ std::string GlobalBuildDescriptorsName(const std::string& filename) {
return "proto_BuildDescriptors_" + FilenameIdentifier(filename); return "proto_BuildDescriptors_" + FilenameIdentifier(filename);
} }
std::string GetLabelName(FieldDescriptor::Label label) { std::string GetLabelName(google::protobuf::FieldDescriptor::Label label) {
switch (label) { switch (label) {
case FieldDescriptor::LABEL_OPTIONAL: return "optional"; case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: return "optional";
case FieldDescriptor::LABEL_REQUIRED: return "required"; case google::protobuf::FieldDescriptor::LABEL_REQUIRED: return "required";
case FieldDescriptor::LABEL_REPEATED: return "repeated"; case google::protobuf::FieldDescriptor::LABEL_REPEATED: return "repeated";
} }
return "bad-label"; return "bad-label";
} }
unsigned unsigned
WriteIntRanges(io::Printer* printer, int n_values, const int *values, const std::string &name) WriteIntRanges(google::protobuf::io::Printer* printer, int n_values, const int *values, const std::string &name)
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = name; vars["name"] = name;
...@@ -530,7 +525,7 @@ static int CEscapeInternal(const char* src, int src_len, char* dest, ...@@ -530,7 +525,7 @@ static int CEscapeInternal(const char* src, int src_len, char* dest,
if (dest_len - used < 4) // need space for 4 letter escape if (dest_len - used < 4) // need space for 4 letter escape
return -1; return -1;
snprintf(dest + used, dest_len - used, (use_hex ? "\\x%02x" : "\\%03o"), snprintf(dest + used, dest_len - used, (use_hex ? "\\x%02x" : "\\%03o"),
static_cast<uint8>(*src)); static_cast<std::uint8_t>(*src));
is_hex_escape = use_hex; is_hex_escape = use_hex;
used += 4; used += 4;
} else { } else {
...@@ -555,7 +550,4 @@ std::string CEscape(const std::string& src) { ...@@ -555,7 +550,4 @@ std::string CEscape(const std::string& src) {
return std::string(dest.get(), len); return std::string(dest.get(), len);
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_HELPERS_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_HELPERS_H__
#define GOOGLE_PROTOBUF_COMPILER_C_HELPERS_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_HELPERS_H__
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -73,10 +73,7 @@ ...@@ -73,10 +73,7 @@
#include <protobuf-c/protobuf-c.pb.h> #include <protobuf-c/protobuf-c.pb.h>
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
// --- Borrowed from stubs. --- // --- Borrowed from stubs. ---
template <typename T> std::string SimpleItoa(T n) { template <typename T> std::string SimpleItoa(T n) {
...@@ -99,14 +96,14 @@ char* FastHexToBuffer(int i, char* buffer); ...@@ -99,14 +96,14 @@ char* FastHexToBuffer(int i, char* buffer);
// The name is coerced to lower-case to emulate proto1 behavior. People // The name is coerced to lower-case to emulate proto1 behavior. People
// should be using lowercase-with-underscores style for proto field names // should be using lowercase-with-underscores style for proto field names
// anyway, so normally this just returns field->name(). // anyway, so normally this just returns field->name().
std::string FieldName(const FieldDescriptor* field); std::string FieldName(const google::protobuf::FieldDescriptor* field);
// Get macro string for deprecated field // Get macro string for deprecated field
std::string FieldDeprecated(const FieldDescriptor* field); std::string FieldDeprecated(const google::protobuf::FieldDescriptor* field);
// Returns the scope where the field was defined (for extensions, this is // Returns the scope where the field was defined (for extensions, this is
// different from the message type to which the field applies). // different from the message type to which the field applies).
inline const Descriptor* FieldScope(const FieldDescriptor* field) { inline const google::protobuf::Descriptor* FieldScope(const google::protobuf::FieldDescriptor* field) {
return field->is_extension() ? return field->is_extension() ?
field->extension_scope() : field->containing_type(); field->extension_scope() : field->containing_type();
} }
...@@ -124,14 +121,14 @@ std::string ToLower(const std::string &class_name); ...@@ -124,14 +121,14 @@ std::string ToLower(const std::string &class_name);
std::string ToUpper(const std::string &class_name); std::string ToUpper(const std::string &class_name);
// full_name() to lowercase with underscores // full_name() to lowercase with underscores
std::string FullNameToLower(const std::string &full_name, const FileDescriptor *file); std::string FullNameToLower(const std::string &full_name, const google::protobuf::FileDescriptor *file);
std::string FullNameToUpper(const std::string &full_name, const FileDescriptor *file); std::string FullNameToUpper(const std::string &full_name, const google::protobuf::FileDescriptor *file);
// full_name() to c-typename (with underscores for packages, otherwise camel case) // full_name() to c-typename (with underscores for packages, otherwise camel case)
std::string FullNameToC(const std::string &class_name, const FileDescriptor *file); std::string FullNameToC(const std::string &class_name, const google::protobuf::FileDescriptor *file);
// Splits, indents, formats, and prints comment lines // Splits, indents, formats, and prints comment lines
void PrintComment (io::Printer* printer, std::string comment); void PrintComment(google::protobuf::io::Printer* printer, std::string comment);
// make a string of spaces as long as input // make a string of spaces as long as input
std::string ConvertToSpaces(const std::string &input); std::string ConvertToSpaces(const std::string &input);
...@@ -144,11 +141,11 @@ std::string StripProto(const std::string& filename); ...@@ -144,11 +141,11 @@ std::string StripProto(const std::string& filename);
// with a ::. If you are using the type as a template parameter, you will // with a ::. If you are using the type as a template parameter, you will
// need to insure there is a space between the < and the ::, because the // need to insure there is a space between the < and the ::, because the
// ridiculous C++ standard defines "<:" to be a synonym for "[". // ridiculous C++ standard defines "<:" to be a synonym for "[".
const char* PrimitiveTypeName(FieldDescriptor::CppType type); const char* PrimitiveTypeName(google::protobuf::FieldDescriptor::CppType type);
// Get the declared type name in CamelCase format, as is used e.g. for the // Get the declared type name in CamelCase format, as is used e.g. for the
// methods of WireFormat. For example, TYPE_INT32 becomes "Int32". // methods of WireFormat. For example, TYPE_INT32 becomes "Int32".
const char* DeclaredTypeMethodName(FieldDescriptor::Type type); const char* DeclaredTypeMethodName(google::protobuf::FieldDescriptor::Type type);
// Convert a file name into a valid identifier. // Convert a file name into a valid identifier.
std::string FilenameIdentifier(const std::string& filename); std::string FilenameIdentifier(const std::string& filename);
...@@ -157,12 +154,12 @@ std::string FilenameIdentifier(const std::string& filename); ...@@ -157,12 +154,12 @@ std::string FilenameIdentifier(const std::string& filename);
std::string GlobalBuildDescriptorsName(const std::string& filename); std::string GlobalBuildDescriptorsName(const std::string& filename);
// return 'required', 'optional', or 'repeated' // return 'required', 'optional', or 'repeated'
std::string GetLabelName(FieldDescriptor::Label label); std::string GetLabelName(google::protobuf::FieldDescriptor::Label label);
// write IntRanges entries for a bunch of sorted values. // write IntRanges entries for a bunch of sorted values.
// returns the number of ranges there are to bsearch. // returns the number of ranges there are to bsearch.
unsigned WriteIntRanges(io::Printer* printer, int n_values, const int *values, const std::string &name); unsigned WriteIntRanges(google::protobuf::io::Printer* printer, int n_values, const int *values, const std::string &name);
struct NameIndex struct NameIndex
{ {
...@@ -172,8 +169,8 @@ struct NameIndex ...@@ -172,8 +169,8 @@ struct NameIndex
int compare_name_indices_by_name(const void*, const void*); int compare_name_indices_by_name(const void*, const void*);
// Return the syntax version of the file containing the field. // Return the syntax version of the file containing the field.
inline int FieldSyntax(const FieldDescriptor* field) { inline int FieldSyntax(const google::protobuf::FieldDescriptor* field) {
auto proto = FileDescriptorProto(); auto proto = google::protobuf::FileDescriptorProto();
field->file()->CopyTo(&proto); field->file()->CopyTo(&proto);
if (proto.has_syntax()) { if (proto.has_syntax()) {
...@@ -199,9 +196,6 @@ inline int FieldSyntax(const FieldDescriptor* field) { ...@@ -199,9 +196,6 @@ inline int FieldSyntax(const FieldDescriptor* field) {
# define GOOGLE_LOG ABSL_LOG # define GOOGLE_LOG ABSL_LOG
#endif #endif
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_HELPERS_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_HELPERS_H__
This diff is collapsed.
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_MESSAGE_H__
#define GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_MESSAGE_H__
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -74,41 +74,38 @@ ...@@ -74,41 +74,38 @@
#include "c_extension.h" #include "c_extension.h"
#include "c_field.h" #include "c_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class MessageGenerator { class MessageGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl. // See generator.cc for the meaning of dllexport_decl.
explicit MessageGenerator(const Descriptor* descriptor, explicit MessageGenerator(const google::protobuf::Descriptor* descriptor,
const std::string& dllexport_decl); const std::string& dllexport_decl);
~MessageGenerator(); ~MessageGenerator();
// Header stuff. // Header stuff.
// Generate typedef. // Generate typedef.
void GenerateStructTypedef(io::Printer* printer); void GenerateStructTypedef(google::protobuf::io::Printer* printer);
// Generate descriptor prototype // Generate descriptor prototype
void GenerateDescriptorDeclarations(io::Printer* printer); void GenerateDescriptorDeclarations(google::protobuf::io::Printer* printer);
// Generate descriptor prototype // Generate descriptor prototype
void GenerateClosureTypedef(io::Printer* printer); void GenerateClosureTypedef(google::protobuf::io::Printer* printer);
// Generate definitions of all nested enums (must come before class // Generate definitions of all nested enums (must come before class
// definitions because those classes use the enums definitions). // definitions because those classes use the enums definitions).
void GenerateEnumDefinitions(io::Printer* printer); void GenerateEnumDefinitions(google::protobuf::io::Printer* printer);
// Generate definitions for this class and all its nested types. // Generate definitions for this class and all its nested types.
void GenerateStructDefinition(io::Printer* printer); void GenerateStructDefinition(google::protobuf::io::Printer* printer);
// Generate __INIT macro for populating this structure // Generate __INIT macro for populating this structure
void GenerateStructStaticInitMacro(io::Printer* printer); void GenerateStructStaticInitMacro(google::protobuf::io::Printer* printer);
// Generate standard helper functions declarations for this message. // Generate standard helper functions declarations for this message.
void GenerateHelperFunctionDeclarations(io::Printer* printer, void GenerateHelperFunctionDeclarations(google::protobuf::io::Printer* printer,
bool is_pack_deep, bool is_pack_deep,
bool gen_pack, bool gen_pack,
bool gen_init); bool gen_init);
...@@ -117,17 +114,17 @@ class MessageGenerator { ...@@ -117,17 +114,17 @@ class MessageGenerator {
// Generate code that initializes the global variable storing the message's // Generate code that initializes the global variable storing the message's
// descriptor. // descriptor.
void GenerateMessageDescriptor(io::Printer* printer, bool gen_init); void GenerateMessageDescriptor(google::protobuf::io::Printer* printer, bool gen_init);
void GenerateHelperFunctionDefinitions(io::Printer* printer, void GenerateHelperFunctionDefinitions(google::protobuf::io::Printer* printer,
bool is_pack_deep, bool is_pack_deep,
bool gen_pack, bool gen_pack,
bool gen_init); bool gen_init);
private: private:
int GetOneofUnionOrder(const FieldDescriptor *fd); int GetOneofUnionOrder(const google::protobuf::FieldDescriptor *fd);
const Descriptor* descriptor_; const google::protobuf::Descriptor* descriptor_;
std::string dllexport_decl_; std::string dllexport_decl_;
FieldGeneratorMap field_generators_; FieldGeneratorMap field_generators_;
std::unique_ptr<std::unique_ptr<MessageGenerator>[]> nested_generators_; std::unique_ptr<std::unique_ptr<MessageGenerator>[]> nested_generators_;
...@@ -135,9 +132,6 @@ class MessageGenerator { ...@@ -135,9 +132,6 @@ class MessageGenerator {
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_; std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_MESSAGE_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__
...@@ -61,40 +61,34 @@ ...@@ -61,40 +61,34 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format.h>
#include "c_helpers.h" #include "c_helpers.h"
#include "c_message_field.h" #include "c_message_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
using internal::WireFormat;
// ===================================================================
MessageFieldGenerator:: MessageFieldGenerator::
MessageFieldGenerator(const FieldDescriptor* descriptor) MessageFieldGenerator(const google::protobuf::FieldDescriptor* descriptor)
: FieldGenerator(descriptor) { : FieldGenerator(descriptor) {
} }
MessageFieldGenerator::~MessageFieldGenerator() {} MessageFieldGenerator::~MessageFieldGenerator() {}
void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const void MessageFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = FieldName(descriptor_); vars["name"] = FieldName(descriptor_);
vars["type"] = FullNameToC(descriptor_->message_type()->full_name(), descriptor_->message_type()->file()); vars["type"] = FullNameToC(descriptor_->message_type()->full_name(), descriptor_->message_type()->file());
vars["deprecated"] = FieldDeprecated(descriptor_); vars["deprecated"] = FieldDeprecated(descriptor_);
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
printer->Print(vars, "$type$ *$name$$deprecated$;\n"); printer->Print(vars, "$type$ *$name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(vars, "size_t n_$name$$deprecated$;\n"); printer->Print(vars, "size_t n_$name$$deprecated$;\n");
printer->Print(vars, "$type$ **$name$$deprecated$;\n"); printer->Print(vars, "$type$ **$name$$deprecated$;\n");
break; break;
...@@ -107,25 +101,22 @@ std::string MessageFieldGenerator::GetDefaultValue(void) const ...@@ -107,25 +101,22 @@ std::string MessageFieldGenerator::GetDefaultValue(void) const
*/ */
return "NULL"; return "NULL";
} }
void MessageFieldGenerator::GenerateStaticInit(io::Printer* printer) const void MessageFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
printer->Print("NULL"); printer->Print("NULL");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print("0,NULL"); printer->Print("0,NULL");
break; break;
} }
} }
void MessageFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void MessageFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const
{ {
std::string addr = "&" + FullNameToLower(descriptor_->message_type()->full_name(), descriptor_->message_type()->file()) + "__descriptor"; std::string addr = "&" + FullNameToLower(descriptor_->message_type()->full_name(), descriptor_->message_type()->file()) + "__descriptor";
GenerateDescriptorInitializerGeneric(printer, false, "MESSAGE", addr); GenerateDescriptorInitializerGeneric(printer, false, "MESSAGE", addr);
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,35 +61,28 @@ ...@@ -61,35 +61,28 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_FIELD_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_MESSAGE_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_FIELD_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_MESSAGE_FIELD_H__
#include <map> #include <map>
#include <string> #include <string>
#include "c_field.h" #include "c_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class MessageFieldGenerator : public FieldGenerator { class MessageFieldGenerator : public FieldGenerator {
public: public:
explicit MessageFieldGenerator(const FieldDescriptor* descriptor); explicit MessageFieldGenerator(const google::protobuf::FieldDescriptor* descriptor);
~MessageFieldGenerator(); ~MessageFieldGenerator();
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(google::protobuf::io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const;
std::string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(google::protobuf::io::Printer* printer) const;
}; };
} // namespace protobuf_c
} // namespace c #endif // PROTOBUF_C_PROTOC_GEN_C_C_MESSAGE_FIELD_H__
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_FIELD_H__
...@@ -61,47 +61,45 @@ ...@@ -61,47 +61,45 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format.h>
#include "c_helpers.h" #include "c_helpers.h"
#include "c_primitive_field.h" #include "c_primitive_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
PrimitiveFieldGenerator:: PrimitiveFieldGenerator::
PrimitiveFieldGenerator(const FieldDescriptor* descriptor) PrimitiveFieldGenerator(const google::protobuf::FieldDescriptor* descriptor)
: FieldGenerator(descriptor) { : FieldGenerator(descriptor) {
} }
PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {} PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {}
void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const void PrimitiveFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const
{ {
std::string c_type; std::string c_type;
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
switch (descriptor_->type()) { switch (descriptor_->type()) {
case FieldDescriptor::TYPE_SINT32 : case google::protobuf::FieldDescriptor::TYPE_SINT32 :
case FieldDescriptor::TYPE_SFIXED32: case google::protobuf::FieldDescriptor::TYPE_SFIXED32:
case FieldDescriptor::TYPE_INT32 : c_type = "int32_t"; break; case google::protobuf::FieldDescriptor::TYPE_INT32 : c_type = "int32_t"; break;
case FieldDescriptor::TYPE_SINT64 : case google::protobuf::FieldDescriptor::TYPE_SINT64 :
case FieldDescriptor::TYPE_SFIXED64: case google::protobuf::FieldDescriptor::TYPE_SFIXED64:
case FieldDescriptor::TYPE_INT64 : c_type = "int64_t"; break; case google::protobuf::FieldDescriptor::TYPE_INT64 : c_type = "int64_t"; break;
case FieldDescriptor::TYPE_UINT32 : case google::protobuf::FieldDescriptor::TYPE_UINT32 :
case FieldDescriptor::TYPE_FIXED32 : c_type = "uint32_t"; break; case google::protobuf::FieldDescriptor::TYPE_FIXED32 : c_type = "uint32_t"; break;
case FieldDescriptor::TYPE_UINT64 : case google::protobuf::FieldDescriptor::TYPE_UINT64 :
case FieldDescriptor::TYPE_FIXED64 : c_type = "uint64_t"; break; case google::protobuf::FieldDescriptor::TYPE_FIXED64 : c_type = "uint64_t"; break;
case FieldDescriptor::TYPE_FLOAT : c_type = "float"; break; case google::protobuf::FieldDescriptor::TYPE_FLOAT : c_type = "float"; break;
case FieldDescriptor::TYPE_DOUBLE : c_type = "double"; break; case google::protobuf::FieldDescriptor::TYPE_DOUBLE : c_type = "double"; break;
case FieldDescriptor::TYPE_BOOL : c_type = "protobuf_c_boolean"; break; case google::protobuf::FieldDescriptor::TYPE_BOOL : c_type = "protobuf_c_boolean"; break;
case FieldDescriptor::TYPE_ENUM : case google::protobuf::FieldDescriptor::TYPE_ENUM :
case FieldDescriptor::TYPE_STRING : case google::protobuf::FieldDescriptor::TYPE_STRING :
case FieldDescriptor::TYPE_BYTES : case google::protobuf::FieldDescriptor::TYPE_BYTES :
case FieldDescriptor::TYPE_GROUP : case google::protobuf::FieldDescriptor::TYPE_GROUP :
case FieldDescriptor::TYPE_MESSAGE : GOOGLE_LOG(FATAL) << "not a primitive type"; break; case google::protobuf::FieldDescriptor::TYPE_MESSAGE : GOOGLE_LOG(FATAL) << "not a primitive type"; break;
// No default because we want the compiler to complain if any new // No default because we want the compiler to complain if any new
// types are added. // types are added.
...@@ -111,15 +109,15 @@ void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -111,15 +109,15 @@ void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const
vars["deprecated"] = FieldDeprecated(descriptor_); vars["deprecated"] = FieldDeprecated(descriptor_);
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(vars, "$c_type$ $name$$deprecated$;\n"); printer->Print(vars, "$c_type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2)
printer->Print(vars, "protobuf_c_boolean has_$name$$deprecated$;\n"); printer->Print(vars, "protobuf_c_boolean has_$name$$deprecated$;\n");
printer->Print(vars, "$c_type$ $name$$deprecated$;\n"); printer->Print(vars, "$c_type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(vars, "size_t n_$name$$deprecated$;\n"); printer->Print(vars, "size_t n_$name$$deprecated$;\n");
printer->Print(vars, "$c_type$ *$name$$deprecated$;\n"); printer->Print(vars, "$c_type$ *$name$$deprecated$;\n");
break; break;
...@@ -130,26 +128,26 @@ std::string PrimitiveFieldGenerator::GetDefaultValue() const ...@@ -130,26 +128,26 @@ std::string PrimitiveFieldGenerator::GetDefaultValue() const
/* XXX: SimpleItoa seems woefully inadequate for anything but int32, /* XXX: SimpleItoa seems woefully inadequate for anything but int32,
* but that's what protobuf uses. */ * but that's what protobuf uses. */
switch (descriptor_->cpp_type()) { switch (descriptor_->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
return SimpleItoa(descriptor_->default_value_int32()); return SimpleItoa(descriptor_->default_value_int32());
case FieldDescriptor::CPPTYPE_INT64: case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
return SimpleItoa(descriptor_->default_value_int64()) + "ll"; return SimpleItoa(descriptor_->default_value_int64()) + "ll";
case FieldDescriptor::CPPTYPE_UINT32: case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
return SimpleItoa(descriptor_->default_value_uint32()) + "u"; return SimpleItoa(descriptor_->default_value_uint32()) + "u";
case FieldDescriptor::CPPTYPE_UINT64: case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
return SimpleItoa(descriptor_->default_value_uint64()) + "ull"; return SimpleItoa(descriptor_->default_value_uint64()) + "ull";
case FieldDescriptor::CPPTYPE_FLOAT: case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
return SimpleFtoa(descriptor_->default_value_float()); return SimpleFtoa(descriptor_->default_value_float());
case FieldDescriptor::CPPTYPE_DOUBLE: case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
return SimpleDtoa(descriptor_->default_value_double()); return SimpleDtoa(descriptor_->default_value_double());
case FieldDescriptor::CPPTYPE_BOOL: case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
return descriptor_->default_value_bool() ? "1" : "0"; return descriptor_->default_value_bool() ? "1" : "0";
default: default:
GOOGLE_LOG(FATAL) << "unexpected CPPTYPE in c_primitive_field"; GOOGLE_LOG(FATAL) << "unexpected CPPTYPE in c_primitive_field";
return "UNEXPECTED_CPPTYPE"; return "UNEXPECTED_CPPTYPE";
} }
} }
void PrimitiveFieldGenerator::GenerateStaticInit(io::Printer* printer) const void PrimitiveFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
if (descriptor_->has_default_value()) { if (descriptor_->has_default_value()) {
...@@ -158,25 +156,25 @@ void PrimitiveFieldGenerator::GenerateStaticInit(io::Printer* printer) const ...@@ -158,25 +156,25 @@ void PrimitiveFieldGenerator::GenerateStaticInit(io::Printer* printer) const
vars["default_value"] = "0"; vars["default_value"] = "0";
} }
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
printer->Print(vars, "$default_value$"); printer->Print(vars, "$default_value$");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (FieldSyntax(descriptor_) == 2) if (FieldSyntax(descriptor_) == 2)
printer->Print(vars, "0, "); printer->Print(vars, "0, ");
printer->Print(vars, "$default_value$"); printer->Print(vars, "$default_value$");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print("0,NULL"); printer->Print("0,NULL");
break; break;
} }
} }
void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void PrimitiveFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const
{ {
std::string c_type_macro; std::string c_type_macro;
switch (descriptor_->type()) { switch (descriptor_->type()) {
#define WRITE_CASE(shortname) case FieldDescriptor::TYPE_##shortname: c_type_macro = #shortname; break; #define WRITE_CASE(shortname) case google::protobuf::FieldDescriptor::TYPE_##shortname: c_type_macro = #shortname; break;
WRITE_CASE(INT32) WRITE_CASE(INT32)
WRITE_CASE(SINT32) WRITE_CASE(SINT32)
WRITE_CASE(UINT32) WRITE_CASE(UINT32)
...@@ -195,11 +193,11 @@ void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer ...@@ -195,11 +193,11 @@ void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer
WRITE_CASE(BOOL) WRITE_CASE(BOOL)
#undef WRITE_CASE #undef WRITE_CASE
case FieldDescriptor::TYPE_ENUM : case google::protobuf::FieldDescriptor::TYPE_ENUM :
case FieldDescriptor::TYPE_STRING : case google::protobuf::FieldDescriptor::TYPE_STRING :
case FieldDescriptor::TYPE_BYTES : case google::protobuf::FieldDescriptor::TYPE_BYTES :
case FieldDescriptor::TYPE_GROUP : case google::protobuf::FieldDescriptor::TYPE_GROUP :
case FieldDescriptor::TYPE_MESSAGE : GOOGLE_LOG(FATAL) << "not a primitive type"; break; case google::protobuf::FieldDescriptor::TYPE_MESSAGE : GOOGLE_LOG(FATAL) << "not a primitive type"; break;
// No default because we want the compiler to complain if any new // No default because we want the compiler to complain if any new
// types are added. // types are added.
...@@ -207,7 +205,4 @@ void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer ...@@ -207,7 +205,4 @@ void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer
GenerateDescriptorInitializerGeneric(printer, true, c_type_macro, "NULL"); GenerateDescriptorInitializerGeneric(printer, true, c_type_macro, "NULL");
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,34 +61,28 @@ ...@@ -61,34 +61,28 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_PRIMITIVE_FIELD_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_PRIMITIVE_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_C_PRIMITIVE_FIELD_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_PRIMITIVE_FIELD_H__
#include <map> #include <map>
#include <string> #include <string>
#include "c_field.h" #include "c_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class PrimitiveFieldGenerator : public FieldGenerator { class PrimitiveFieldGenerator : public FieldGenerator {
public: public:
explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor); explicit PrimitiveFieldGenerator(const google::protobuf::FieldDescriptor* descriptor);
~PrimitiveFieldGenerator(); ~PrimitiveFieldGenerator();
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(google::protobuf::io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const;
std::string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(google::protobuf::io::Printer* printer) const;
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_PRIMITIVE_FIELD_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_PRIMITIVE_FIELD_H__
...@@ -61,17 +61,15 @@ ...@@ -61,17 +61,15 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include "c_helpers.h" #include "c_helpers.h"
#include "c_service.h" #include "c_service.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor, ServiceGenerator::ServiceGenerator(const google::protobuf::ServiceDescriptor* descriptor,
const std::string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor) { : descriptor_(descriptor) {
vars_["name"] = descriptor_->name(); vars_["name"] = descriptor_->name();
...@@ -91,13 +89,13 @@ ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor, ...@@ -91,13 +89,13 @@ ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor,
ServiceGenerator::~ServiceGenerator() {} ServiceGenerator::~ServiceGenerator() {}
// Header stuff. // Header stuff.
void ServiceGenerator::GenerateMainHFile(io::Printer* printer) void ServiceGenerator::GenerateMainHFile(google::protobuf::io::Printer* printer)
{ {
GenerateVfuncs(printer); GenerateVfuncs(printer);
GenerateInitMacros(printer); GenerateInitMacros(printer);
GenerateCallersDeclarations(printer); GenerateCallersDeclarations(printer);
} }
void ServiceGenerator::GenerateVfuncs(io::Printer* printer) void ServiceGenerator::GenerateVfuncs(google::protobuf::io::Printer* printer)
{ {
printer->Print(vars_, printer->Print(vars_,
"typedef struct $cname$_Service $cname$_Service;\n" "typedef struct $cname$_Service $cname$_Service;\n"
...@@ -105,7 +103,7 @@ void ServiceGenerator::GenerateVfuncs(io::Printer* printer) ...@@ -105,7 +103,7 @@ void ServiceGenerator::GenerateVfuncs(io::Printer* printer)
"{\n" "{\n"
" ProtobufCService base;\n"); " ProtobufCService base;\n");
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor *method = descriptor_->method(i); const google::protobuf::MethodDescriptor* method = descriptor_->method(i);
std::string lcname = CamelToLower(method->name()); std::string lcname = CamelToLower(method->name());
vars_["method"] = lcname; vars_["method"] = lcname;
vars_["metpad"] = ConvertToSpaces(lcname); vars_["metpad"] = ConvertToSpaces(lcname);
...@@ -124,7 +122,7 @@ void ServiceGenerator::GenerateVfuncs(io::Printer* printer) ...@@ -124,7 +122,7 @@ void ServiceGenerator::GenerateVfuncs(io::Printer* printer)
"void $lcfullname$__init ($cname$_Service *service,\n" "void $lcfullname$__init ($cname$_Service *service,\n"
" $lcfullpadd$ $cname$_ServiceDestroy destroy);\n"); " $lcfullpadd$ $cname$_ServiceDestroy destroy);\n");
} }
void ServiceGenerator::GenerateInitMacros(io::Printer* printer) void ServiceGenerator::GenerateInitMacros(google::protobuf::io::Printer* printer)
{ {
printer->Print(vars_, printer->Print(vars_,
"#define $ucfullname$__BASE_INIT \\\n" "#define $ucfullname$__BASE_INIT \\\n"
...@@ -132,7 +130,7 @@ void ServiceGenerator::GenerateInitMacros(io::Printer* printer) ...@@ -132,7 +130,7 @@ void ServiceGenerator::GenerateInitMacros(io::Printer* printer)
"#define $ucfullname$__INIT(function_prefix__) \\\n" "#define $ucfullname$__INIT(function_prefix__) \\\n"
" { $ucfullname$__BASE_INIT"); " { $ucfullname$__BASE_INIT");
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor *method = descriptor_->method(i); const google::protobuf::MethodDescriptor* method = descriptor_->method(i);
std::string lcname = CamelToLower(method->name()); std::string lcname = CamelToLower(method->name());
vars_["method"] = lcname; vars_["method"] = lcname;
vars_["metpad"] = ConvertToSpaces(lcname); vars_["metpad"] = ConvertToSpaces(lcname);
...@@ -142,10 +140,10 @@ void ServiceGenerator::GenerateInitMacros(io::Printer* printer) ...@@ -142,10 +140,10 @@ void ServiceGenerator::GenerateInitMacros(io::Printer* printer)
printer->Print(vars_, printer->Print(vars_,
" }\n"); " }\n");
} }
void ServiceGenerator::GenerateCallersDeclarations(io::Printer* printer) void ServiceGenerator::GenerateCallersDeclarations(google::protobuf::io::Printer* printer)
{ {
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor *method = descriptor_->method(i); const google::protobuf::MethodDescriptor* method = descriptor_->method(i);
std::string lcname = CamelToLower(method->name()); std::string lcname = CamelToLower(method->name());
std::string lcfullname = FullNameToLower(descriptor_->full_name(), descriptor_->file()); std::string lcfullname = FullNameToLower(descriptor_->full_name(), descriptor_->file());
vars_["method"] = lcname; vars_["method"] = lcname;
...@@ -161,20 +159,20 @@ void ServiceGenerator::GenerateCallersDeclarations(io::Printer* printer) ...@@ -161,20 +159,20 @@ void ServiceGenerator::GenerateCallersDeclarations(io::Printer* printer)
} }
} }
void ServiceGenerator::GenerateDescriptorDeclarations(io::Printer* printer) void ServiceGenerator::GenerateDescriptorDeclarations(google::protobuf::io::Printer* printer)
{ {
printer->Print(vars_, "extern const ProtobufCServiceDescriptor $lcfullname$__descriptor;\n"); printer->Print(vars_, "extern const ProtobufCServiceDescriptor $lcfullname$__descriptor;\n");
} }
// Source file stuff. // Source file stuff.
void ServiceGenerator::GenerateCFile(io::Printer* printer) void ServiceGenerator::GenerateCFile(google::protobuf::io::Printer* printer)
{ {
GenerateServiceDescriptor(printer); GenerateServiceDescriptor(printer);
GenerateCallersImplementations(printer); GenerateCallersImplementations(printer);
GenerateInit(printer); GenerateInit(printer);
} }
void ServiceGenerator::GenerateInit(io::Printer* printer) void ServiceGenerator::GenerateInit(google::protobuf::io::Printer* printer)
{ {
printer->Print(vars_, printer->Print(vars_,
"void $lcfullname$__init ($cname$_Service *service,\n" "void $lcfullname$__init ($cname$_Service *service,\n"
...@@ -195,20 +193,20 @@ compare_method_index_and_name_by_name (const void *a, const void *b) ...@@ -195,20 +193,20 @@ compare_method_index_and_name_by_name (const void *a, const void *b)
return strcmp (ma->name, mb->name); return strcmp (ma->name, mb->name);
} }
void ServiceGenerator::GenerateServiceDescriptor(io::Printer* printer) void ServiceGenerator::GenerateServiceDescriptor(google::protobuf::io::Printer* printer)
{ {
int n_methods = descriptor_->method_count(); int n_methods = descriptor_->method_count();
MethodIndexAndName *mi_array = new MethodIndexAndName[n_methods]; MethodIndexAndName *mi_array = new MethodIndexAndName[n_methods];
bool optimize_code_size = descriptor_->file()->options().has_optimize_for() && bool optimize_code_size = descriptor_->file()->options().has_optimize_for() &&
descriptor_->file()->options().optimize_for() == descriptor_->file()->options().optimize_for() ==
FileOptions_OptimizeMode_CODE_SIZE; google::protobuf::FileOptions_OptimizeMode_CODE_SIZE;
vars_["n_methods"] = SimpleItoa(n_methods); vars_["n_methods"] = SimpleItoa(n_methods);
printer->Print(vars_, "static const ProtobufCMethodDescriptor $lcfullname$__method_descriptors[$n_methods$] =\n" printer->Print(vars_, "static const ProtobufCMethodDescriptor $lcfullname$__method_descriptors[$n_methods$] =\n"
"{\n"); "{\n");
for (int i = 0; i < n_methods; i++) { for (int i = 0; i < n_methods; i++) {
const MethodDescriptor *method = descriptor_->method(i); const google::protobuf::MethodDescriptor* method = descriptor_->method(i);
vars_["method"] = method->name(); vars_["method"] = method->name();
vars_["input_descriptor"] = "&" + FullNameToLower(method->input_type()->full_name(), method->input_type()->file()) + "__descriptor"; vars_["input_descriptor"] = "&" + FullNameToLower(method->input_type()->full_name(), method->input_type()->file()) + "__descriptor";
vars_["output_descriptor"] = "&" + FullNameToLower(method->output_type()->full_name(), method->output_type()->file()) + "__descriptor"; vars_["output_descriptor"] = "&" + FullNameToLower(method->output_type()->full_name(), method->output_type()->file()) + "__descriptor";
...@@ -264,10 +262,10 @@ void ServiceGenerator::GenerateServiceDescriptor(io::Printer* printer) ...@@ -264,10 +262,10 @@ void ServiceGenerator::GenerateServiceDescriptor(io::Printer* printer)
delete[] mi_array; delete[] mi_array;
} }
void ServiceGenerator::GenerateCallersImplementations(io::Printer* printer) void ServiceGenerator::GenerateCallersImplementations(google::protobuf::io::Printer* printer)
{ {
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor *method = descriptor_->method(i); const google::protobuf::MethodDescriptor* method = descriptor_->method(i);
std::string lcname = CamelToLower(method->name()); std::string lcname = CamelToLower(method->name());
std::string lcfullname = FullNameToLower(descriptor_->full_name(), descriptor_->file()); std::string lcfullname = FullNameToLower(descriptor_->full_name(), descriptor_->file());
vars_["method"] = lcname; vars_["method"] = lcname;
...@@ -289,8 +287,4 @@ void ServiceGenerator::GenerateCallersImplementations(io::Printer* printer) ...@@ -289,8 +287,4 @@ void ServiceGenerator::GenerateCallersImplementations(io::Printer* printer)
} }
} }
} // namespace protobuf_c
} // namespace c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_SERVICE_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_SERVICE_H__
#define GOOGLE_PROTOBUF_COMPILER_C_SERVICE_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_SERVICE_H__
#include <map> #include <map>
#include <string> #include <string>
...@@ -70,38 +70,32 @@ ...@@ -70,38 +70,32 @@
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class ServiceGenerator { class ServiceGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl. // See generator.cc for the meaning of dllexport_decl.
explicit ServiceGenerator(const ServiceDescriptor* descriptor, explicit ServiceGenerator(const google::protobuf::ServiceDescriptor* descriptor,
const std::string& dllexport_decl); const std::string& dllexport_decl);
~ServiceGenerator(); ~ServiceGenerator();
// Header stuff. // Header stuff.
void GenerateMainHFile(io::Printer* printer); void GenerateMainHFile(google::protobuf::io::Printer* printer);
void GenerateVfuncs(io::Printer* printer); void GenerateVfuncs(google::protobuf::io::Printer* printer);
void GenerateInitMacros(io::Printer* printer); void GenerateInitMacros(google::protobuf::io::Printer* printer);
void GenerateDescriptorDeclarations(io::Printer* printer); void GenerateDescriptorDeclarations(google::protobuf::io::Printer* printer);
void GenerateCallersDeclarations(io::Printer* printer); void GenerateCallersDeclarations(google::protobuf::io::Printer* printer);
// Source file stuff. // Source file stuff.
void GenerateCFile(io::Printer* printer); void GenerateCFile(google::protobuf::io::Printer* printer);
void GenerateServiceDescriptor(io::Printer* printer); void GenerateServiceDescriptor(google::protobuf::io::Printer* printer);
void GenerateInit(io::Printer* printer); void GenerateInit(google::protobuf::io::Printer* printer);
void GenerateCallersImplementations(io::Printer* printer); void GenerateCallersImplementations(google::protobuf::io::Printer* printer);
const ServiceDescriptor* descriptor_; const google::protobuf::ServiceDescriptor* descriptor_;
std::map<std::string, std::string> vars_; std::map<std::string, std::string> vars_;
}; };
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google #endif // PROTOBUF_C_PROTOC_GEN_C_C_SERVICE_H__
#endif // GOOGLE_PROTOBUF_COMPILER_C_SERVICE_H__
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format.h>
...@@ -69,14 +70,9 @@ ...@@ -69,14 +70,9 @@
#include "c_helpers.h" #include "c_helpers.h"
#include "c_string_field.h" #include "c_string_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
using internal::WireFormat; void SetStringVariables(const google::protobuf::FieldDescriptor* descriptor,
void SetStringVariables(const FieldDescriptor* descriptor,
std::map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["default"] = FullNameToLower(descriptor->full_name(), descriptor->file()) (*variables)["default"] = FullNameToLower(descriptor->full_name(), descriptor->file())
...@@ -87,25 +83,25 @@ void SetStringVariables(const FieldDescriptor* descriptor, ...@@ -87,25 +83,25 @@ void SetStringVariables(const FieldDescriptor* descriptor,
// =================================================================== // ===================================================================
StringFieldGenerator:: StringFieldGenerator::
StringFieldGenerator(const FieldDescriptor* descriptor) StringFieldGenerator(const google::protobuf::FieldDescriptor* descriptor)
: FieldGenerator(descriptor) { : FieldGenerator(descriptor) {
SetStringVariables(descriptor, &variables_); SetStringVariables(descriptor, &variables_);
} }
StringFieldGenerator::~StringFieldGenerator() {} StringFieldGenerator::~StringFieldGenerator() {}
void StringFieldGenerator::GenerateStructMembers(io::Printer* printer) const void StringFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const
{ {
const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file); const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file);
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
if (opt.const_strings()) if (opt.const_strings())
printer->Print(variables_, "const "); printer->Print(variables_, "const ");
printer->Print(variables_, "char *$name$$deprecated$;\n"); printer->Print(variables_, "char *$name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); printer->Print(variables_, "size_t n_$name$$deprecated$;\n");
if (opt.const_strings()) if (opt.const_strings())
printer->Print(variables_, "const "); printer->Print(variables_, "const ");
...@@ -113,11 +109,11 @@ void StringFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -113,11 +109,11 @@ void StringFieldGenerator::GenerateStructMembers(io::Printer* printer) const
break; break;
} }
} }
void StringFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer) const void StringFieldGenerator::GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const
{ {
printer->Print(variables_, "extern char $default$[];\n"); printer->Print(variables_, "extern char $default$[];\n");
} }
void StringFieldGenerator::GenerateDefaultValueImplementations(io::Printer* printer) const void StringFieldGenerator::GenerateDefaultValueImplementations(google::protobuf::io::Printer* printer) const
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["default"] = variables_.find("default")->second; vars["default"] = variables_.find("default")->second;
...@@ -129,7 +125,7 @@ std::string StringFieldGenerator::GetDefaultValue(void) const ...@@ -129,7 +125,7 @@ std::string StringFieldGenerator::GetDefaultValue(void) const
{ {
return variables_.find("default")->second; return variables_.find("default")->second;
} }
void StringFieldGenerator::GenerateStaticInit(io::Printer* printer) const void StringFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const
{ {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file); const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file);
...@@ -143,21 +139,18 @@ void StringFieldGenerator::GenerateStaticInit(io::Printer* printer) const ...@@ -143,21 +139,18 @@ void StringFieldGenerator::GenerateStaticInit(io::Printer* printer) const
vars["default"] = "(char *)protobuf_c_empty_string"; vars["default"] = "(char *)protobuf_c_empty_string";
} }
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case google::protobuf::FieldDescriptor::LABEL_REQUIRED:
case FieldDescriptor::LABEL_OPTIONAL: case google::protobuf::FieldDescriptor::LABEL_OPTIONAL:
printer->Print(vars, "$default$"); printer->Print(vars, "$default$");
break; break;
case FieldDescriptor::LABEL_REPEATED: case google::protobuf::FieldDescriptor::LABEL_REPEATED:
printer->Print(vars, "0,NULL"); printer->Print(vars, "0,NULL");
break; break;
} }
} }
void StringFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void StringFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const
{ {
GenerateDescriptorInitializerGeneric(printer, false, "STRING", "NULL"); GenerateDescriptorInitializerGeneric(printer, false, "STRING", "NULL");
} }
} // namespace c } // namespace protobuf_c
} // namespace compiler
} // namespace protobuf
} // namespace google
...@@ -61,40 +61,33 @@ ...@@ -61,40 +61,33 @@
// Modified to implement C code by Dave Benson. // Modified to implement C code by Dave Benson.
#ifndef GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__ #ifndef PROTOBUF_C_PROTOC_GEN_C_C_STRING_FIELD_H__
#define GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__ #define PROTOBUF_C_PROTOC_GEN_C_C_STRING_FIELD_H__
#include <map> #include <map>
#include <string> #include <string>
#include "c_field.h" #include "c_field.h"
namespace google { namespace protobuf_c {
namespace protobuf {
namespace compiler {
namespace c {
class StringFieldGenerator : public FieldGenerator { class StringFieldGenerator : public FieldGenerator {
public: public:
explicit StringFieldGenerator(const FieldDescriptor* descriptor); explicit StringFieldGenerator(const google::protobuf::FieldDescriptor* descriptor);
~StringFieldGenerator(); ~StringFieldGenerator();
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(google::protobuf::io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const;
void GenerateDefaultValueDeclarations(io::Printer* printer) const; void GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const;
void GenerateDefaultValueImplementations(io::Printer* printer) const; void GenerateDefaultValueImplementations(google::protobuf::io::Printer* printer) const;
std::string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(google::protobuf::io::Printer* printer) const;
private: private:
std::map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
} // namespace protobuf_c
} // namespace c #endif // PROTOBUF_C_PROTOC_GEN_C_C_STRING_FIELD_H__
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_C_STRING_FIELD_H__
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "c_generator.h" #include "c_generator.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
google::protobuf::compiler::c::CGenerator c_generator; protobuf_c::CGenerator c_generator;
std::string invocation_name = argv[0]; std::string invocation_name = argv[0];
std::string invocation_basename = invocation_name.substr(invocation_name.find_last_of("/") + 1); std::string invocation_basename = invocation_name.substr(invocation_name.find_last_of("/") + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment