Merge pull request #443 from acozzette/std-string

Updated the generator to fully qualify std::string
This commit is contained in:
Robert Edmonds 2020-10-16 20:03:05 -04:00 committed by GitHub
commit 94532c7a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 174 additions and 174 deletions

View File

@ -74,7 +74,7 @@ namespace c {
using internal::WireFormat; using internal::WireFormat;
void SetBytesVariables(const FieldDescriptor* descriptor, void SetBytesVariables(const FieldDescriptor* descriptor,
std::map<string, string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["default"] = (*variables)["default"] =
"\"" + CEscape(descriptor->default_value_string()) + "\""; "\"" + CEscape(descriptor->default_value_string()) + "\"";
@ -89,7 +89,7 @@ BytesFieldGenerator(const FieldDescriptor* descriptor)
SetBytesVariables(descriptor, &variables_); SetBytesVariables(descriptor, &variables_);
variables_["default_value"] = descriptor->has_default_value() variables_["default_value"] = descriptor->has_default_value()
? GetDefaultValue() ? GetDefaultValue()
: string("{0,NULL}"); : std::string("{0,NULL}");
} }
BytesFieldGenerator::~BytesFieldGenerator() {} BytesFieldGenerator::~BytesFieldGenerator() {}
@ -113,7 +113,7 @@ void BytesFieldGenerator::GenerateStructMembers(io::Printer* printer) const
} }
void BytesFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer) const void BytesFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer) const
{ {
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["default_value_data"] = FullNameToLower(descriptor_->full_name()) vars["default_value_data"] = FullNameToLower(descriptor_->full_name())
+ "__default_value_data"; + "__default_value_data";
printer->Print(vars, "extern uint8_t $default_value_data$[];\n"); printer->Print(vars, "extern uint8_t $default_value_data$[];\n");
@ -121,13 +121,13 @@ void BytesFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer)
void BytesFieldGenerator::GenerateDefaultValueImplementations(io::Printer* printer) const void BytesFieldGenerator::GenerateDefaultValueImplementations(io::Printer* printer) const
{ {
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["default_value_data"] = FullNameToLower(descriptor_->full_name()) vars["default_value_data"] = FullNameToLower(descriptor_->full_name())
+ "__default_value_data"; + "__default_value_data";
vars["escaped"] = CEscape(descriptor_->default_value_string()); vars["escaped"] = CEscape(descriptor_->default_value_string());
printer->Print(vars, "uint8_t $default_value_data$[] = \"$escaped$\";\n"); printer->Print(vars, "uint8_t $default_value_data$[] = \"$escaped$\";\n");
} }
string BytesFieldGenerator::GetDefaultValue(void) const std::string BytesFieldGenerator::GetDefaultValue(void) const
{ {
return "{ " return "{ "
+ SimpleItoa(descriptor_->default_value_string().size()) + SimpleItoa(descriptor_->default_value_string().size())

View File

@ -82,11 +82,11 @@ class BytesFieldGenerator : public FieldGenerator {
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(io::Printer* printer) const;
void GenerateDefaultValueDeclarations(io::Printer* printer) const; void GenerateDefaultValueDeclarations(io::Printer* printer) const;
void GenerateDefaultValueImplementations(io::Printer* printer) const; void GenerateDefaultValueImplementations(io::Printer* printer) const;
string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(io::Printer* printer) const;
private: private:
std::map<string, string> variables_; std::map<std::string, std::string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(BytesFieldGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(BytesFieldGenerator);
}; };

View File

@ -73,7 +73,7 @@ namespace compiler {
namespace c { namespace c {
EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,
const string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor), : descriptor_(descriptor),
dllexport_decl_(dllexport_decl) { dllexport_decl_(dllexport_decl) {
} }
@ -81,7 +81,7 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,
EnumGenerator::~EnumGenerator() {} EnumGenerator::~EnumGenerator() {}
void EnumGenerator::GenerateDefinition(io::Printer* printer) { void EnumGenerator::GenerateDefinition(io::Printer* printer) {
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["classname"] = FullNameToC(descriptor_->full_name()); vars["classname"] = FullNameToC(descriptor_->full_name());
vars["shortname"] = descriptor_->name(); vars["shortname"] = descriptor_->name();
vars["uc_name"] = FullNameToUpper(descriptor_->full_name()); vars["uc_name"] = FullNameToUpper(descriptor_->full_name());
@ -126,7 +126,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
} }
void EnumGenerator::GenerateDescriptorDeclarations(io::Printer* printer) { void EnumGenerator::GenerateDescriptorDeclarations(io::Printer* printer) {
std::map<string, string> vars; std::map<std::string, std::string> vars;
if (dllexport_decl_.empty()) { if (dllexport_decl_.empty()) {
vars["dllexport"] = ""; vars["dllexport"] = "";
} else { } else {
@ -149,7 +149,7 @@ struct ValueIndex
void EnumGenerator::GenerateValueInitializer(io::Printer *printer, int index) void EnumGenerator::GenerateValueInitializer(io::Printer *printer, int index)
{ {
const EnumValueDescriptor *vd = descriptor_->value(index); const EnumValueDescriptor *vd = descriptor_->value(index);
std::map<string, 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; FileOptions_OptimizeMode_CODE_SIZE;
@ -182,7 +182,7 @@ static int compare_value_indices_by_name(const void *a, const void *b)
} }
void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) { void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) {
std::map<string, 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()); vars["lcclassname"] = FullNameToLower(descriptor_->full_name());
vars["cname"] = FullNameToC(descriptor_->full_name()); vars["cname"] = FullNameToC(descriptor_->full_name());

View File

@ -81,7 +81,7 @@ 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 EnumDescriptor* descriptor,
const string& dllexport_decl); const std::string& dllexport_decl);
~EnumGenerator(); ~EnumGenerator();
// Header stuff. // Header stuff.
@ -105,7 +105,7 @@ class EnumGenerator {
private: private:
const EnumDescriptor* descriptor_; const EnumDescriptor* descriptor_;
string dllexport_decl_; std::string dllexport_decl_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
}; };

View File

@ -75,7 +75,7 @@ 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 FieldDescriptor* descriptor,
std::map<string, 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()); (*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name());
@ -114,7 +114,7 @@ void EnumFieldGenerator::GenerateStructMembers(io::Printer* printer) const
} }
} }
string EnumFieldGenerator::GetDefaultValue(void) const std::string EnumFieldGenerator::GetDefaultValue(void) const
{ {
return variables_.find("default")->second; return variables_.find("default")->second;
} }
@ -138,7 +138,7 @@ void EnumFieldGenerator::GenerateStaticInit(io::Printer* printer) const
void EnumFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void EnumFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const
{ {
string addr = "&" + FullNameToLower(descriptor_->enum_type()->full_name()) + "__descriptor"; std::string addr = "&" + FullNameToLower(descriptor_->enum_type()->full_name()) + "__descriptor";
GenerateDescriptorInitializerGeneric(printer, true, "ENUM", addr); GenerateDescriptorInitializerGeneric(printer, true, "ENUM", addr);
} }

View File

@ -80,11 +80,11 @@ class EnumFieldGenerator : public FieldGenerator {
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(io::Printer* printer) const;
string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(io::Printer* printer) const;
private: private:
std::map<string, string> variables_; std::map<std::string, std::string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
}; };

View File

@ -70,7 +70,7 @@ namespace compiler {
namespace c { namespace c {
ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
const string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor), : descriptor_(descriptor),
dllexport_decl_(dllexport_decl) { dllexport_decl_(dllexport_decl) {
} }

View File

@ -85,7 +85,7 @@ 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 FieldDescriptor* descriptor,
const string& dllexport_decl); const std::string& dllexport_decl);
~ExtensionGenerator(); ~ExtensionGenerator();
// Header stuff. // Header stuff.
@ -96,8 +96,8 @@ class ExtensionGenerator {
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
string type_traits_; std::string type_traits_;
string dllexport_decl_; std::string dllexport_decl_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
}; };

View File

@ -103,10 +103,10 @@ static bool is_packable_type(FieldDescriptor::Type type)
void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
bool optional_uses_has, bool optional_uses_has,
const string &type_macro, const std::string &type_macro,
const string &descriptor_addr) const const std::string &descriptor_addr) const
{ {
std::map<string, string> variables; std::map<std::string, std::string> variables;
variables["TYPE"] = type_macro; variables["TYPE"] = type_macro;
variables["classname"] = FullNameToC(FieldScope(descriptor_)->full_name()); variables["classname"] = FullNameToC(FieldScope(descriptor_)->full_name());
variables["name"] = FieldName(descriptor_); variables["name"] = FieldName(descriptor_);
@ -126,7 +126,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
} }
if (descriptor_->has_default_value()) { if (descriptor_->has_default_value()) {
variables["default_value"] = string("&") variables["default_value"] = std::string("&")
+ FullNameToLower(descriptor_->full_name()) + FullNameToLower(descriptor_->full_name())
+ "__default_value"; + "__default_value";
} else if (FieldSyntax(descriptor_) == 3 && } else if (FieldSyntax(descriptor_) == 3 &&

View File

@ -91,7 +91,7 @@ class FieldGenerator {
virtual void GenerateDefaultValueDeclarations(io::Printer* printer) const { } virtual void GenerateDefaultValueDeclarations(io::Printer* printer) const { }
virtual void GenerateDefaultValueImplementations(io::Printer* printer) const { } virtual void GenerateDefaultValueImplementations(io::Printer* printer) const { }
virtual 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(io::Printer* printer) const = 0;
@ -100,8 +100,8 @@ class FieldGenerator {
protected: protected:
void GenerateDescriptorInitializerGeneric(io::Printer* printer, void GenerateDescriptorInitializerGeneric(io::Printer* printer,
bool optional_uses_has, bool optional_uses_has,
const string &type_macro, const std::string &type_macro,
const string &descriptor_addr) const; const std::string &descriptor_addr) const;
const FieldDescriptor *descriptor_; const FieldDescriptor *descriptor_;
private: private:

View File

@ -80,7 +80,7 @@ namespace c {
// =================================================================== // ===================================================================
FileGenerator::FileGenerator(const FileDescriptor* file, FileGenerator::FileGenerator(const FileDescriptor* file,
const string& dllexport_decl) const std::string& dllexport_decl)
: file_(file), : file_(file),
message_generators_( message_generators_(
new std::unique_ptr<MessageGenerator>[file->message_type_count()]), new std::unique_ptr<MessageGenerator>[file->message_type_count()]),
@ -117,7 +117,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file,
FileGenerator::~FileGenerator() {} FileGenerator::~FileGenerator() {}
void FileGenerator::GenerateHeader(io::Printer* printer) { void FileGenerator::GenerateHeader(io::Printer* printer) {
string filename_identifier = FilenameIdentifier(file_->name()); std::string filename_identifier = FilenameIdentifier(file_->name());
int min_header_version = 1000000; int min_header_version = 1000000;
#if defined(HAVE_PROTO3) #if defined(HAVE_PROTO3)

View File

@ -90,7 +90,7 @@ 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 FileDescriptor* file,
const string& dllexport_decl); const std::string& dllexport_decl);
~FileGenerator(); ~FileGenerator();
void GenerateHeader(io::Printer* printer); void GenerateHeader(io::Printer* printer);
@ -105,7 +105,7 @@ class FileGenerator {
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_; std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
// E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
std::vector<string> package_parts_; std::vector<std::string> package_parts_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
}; };

View File

@ -81,14 +81,14 @@ namespace c {
// "foo=bar,baz,qux=corge" // "foo=bar,baz,qux=corge"
// parses to the pairs: // parses to the pairs:
// ("foo", "bar"), ("baz", ""), ("qux", "corge") // ("foo", "bar"), ("baz", ""), ("qux", "corge")
void ParseOptions(const string& text, std::vector<std::pair<string, string> >* output) { void ParseOptions(const std::string& text, std::vector<std::pair<std::string, std::string> >* output) {
std::vector<string> parts; std::vector<std::string> parts;
SplitStringUsing(text, ",", &parts); SplitStringUsing(text, ",", &parts);
for (unsigned i = 0; i < parts.size(); i++) { for (unsigned i = 0; i < parts.size(); i++) {
string::size_type equals_pos = parts[i].find_first_of('='); std::string::size_type equals_pos = parts[i].find_first_of('=');
std::pair<string, string> value; std::pair<std::string, std::string> value;
if (equals_pos == string::npos) { if (equals_pos == std::string::npos) {
value.first = parts[i]; value.first = parts[i];
value.second = ""; value.second = "";
} else { } else {
@ -103,10 +103,10 @@ CGenerator::CGenerator() {}
CGenerator::~CGenerator() {} CGenerator::~CGenerator() {}
bool CGenerator::Generate(const FileDescriptor* file, bool CGenerator::Generate(const FileDescriptor* file,
const string& parameter, const std::string& parameter,
OutputDirectory* output_directory, OutputDirectory* output_directory,
string* error) const { std::string* error) const {
std::vector<std::pair<string, string> > options; std::vector<std::pair<std::string, std::string> > options;
ParseOptions(parameter, &options); ParseOptions(parameter, &options);
// ----------------------------------------------------------------- // -----------------------------------------------------------------
@ -129,7 +129,7 @@ bool CGenerator::Generate(const FileDescriptor* file,
// } // }
// FOO_EXPORT is a macro which should expand to __declspec(dllexport) or // FOO_EXPORT is a macro which should expand to __declspec(dllexport) or
// __declspec(dllimport) depending on what is being compiled. // __declspec(dllimport) depending on what is being compiled.
string dllexport_decl; std::string dllexport_decl;
for (unsigned i = 0; i < options.size(); i++) { for (unsigned i = 0; i < options.size(); i++) {
if (options[i].first == "dllexport_decl") { if (options[i].first == "dllexport_decl") {
@ -143,7 +143,7 @@ bool CGenerator::Generate(const FileDescriptor* file,
// ----------------------------------------------------------------- // -----------------------------------------------------------------
string basename = StripProto(file->name()); std::string basename = StripProto(file->name());
basename.append(".pb-c"); basename.append(".pb-c");
FileGenerator file_generator(file, dllexport_decl); FileGenerator file_generator(file, dllexport_decl);

View File

@ -84,9 +84,9 @@ class LIBPROTOC_EXPORT CGenerator : public CodeGenerator {
// implements CodeGenerator ---------------------------------------- // implements CodeGenerator ----------------------------------------
bool Generate(const FileDescriptor* file, bool Generate(const FileDescriptor* file,
const string& parameter, const std::string& parameter,
OutputDirectory* output_directory, OutputDirectory* output_directory,
string* error) const; std::string* error) const;
private: private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CGenerator);

View File

@ -87,30 +87,30 @@ namespace c {
#pragma warning(disable:4996) #pragma warning(disable:4996)
#endif #endif
string DotsToUnderscores(const string& name) { std::string DotsToUnderscores(const std::string& name) {
return StringReplace(name, ".", "_", true); return StringReplace(name, ".", "_", true);
} }
string DotsToColons(const string& name) { std::string DotsToColons(const std::string& name) {
return StringReplace(name, ".", "::", true); return StringReplace(name, ".", "::", true);
} }
string SimpleFtoa(float f) { std::string SimpleFtoa(float f) {
char buf[100]; char buf[100];
snprintf(buf,sizeof(buf),"%.*g", FLT_DIG, f); snprintf(buf,sizeof(buf),"%.*g", FLT_DIG, f);
buf[sizeof(buf)-1] = 0; /* should NOT be necessary */ buf[sizeof(buf)-1] = 0; /* should NOT be necessary */
return buf; return buf;
} }
string SimpleDtoa(double d) { std::string SimpleDtoa(double d) {
char buf[100]; char buf[100];
snprintf(buf,sizeof(buf),"%.*g", DBL_DIG, d); snprintf(buf,sizeof(buf),"%.*g", DBL_DIG, d);
buf[sizeof(buf)-1] = 0; /* should NOT be necessary */ buf[sizeof(buf)-1] = 0; /* should NOT be necessary */
return buf; return buf;
} }
string CamelToUpper(const string &name) { std::string CamelToUpper(const std::string &name) {
bool was_upper = true; // suppress initial _ bool was_upper = true; // suppress initial _
string rv = ""; std::string rv = "";
int len = name.length(); int len = name.length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
bool is_upper = isupper(name[i]); bool is_upper = isupper(name[i]);
@ -125,9 +125,9 @@ string CamelToUpper(const string &name) {
} }
return rv; return rv;
} }
string CamelToLower(const string &name) { std::string CamelToLower(const std::string &name) {
bool was_upper = true; // suppress initial _ bool was_upper = true; // suppress initial _
string rv = ""; std::string rv = "";
int len = name.length(); int len = name.length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
bool is_upper = isupper(name[i]); bool is_upper = isupper(name[i]);
@ -144,24 +144,24 @@ string CamelToLower(const string &name) {
} }
string ToUpper(const string &name) { std::string ToUpper(const std::string &name) {
string rv = ""; std::string rv = "";
int len = name.length(); int len = name.length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
rv += toupper(name[i]); rv += toupper(name[i]);
} }
return rv; return rv;
} }
string ToLower(const string &name) { std::string ToLower(const std::string &name) {
string rv = ""; std::string rv = "";
int len = name.length(); int len = name.length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
rv += tolower(name[i]); rv += tolower(name[i]);
} }
return rv; return rv;
} }
string ToCamel(const string &name) { std::string ToCamel(const std::string &name) {
string rv = ""; std::string rv = "";
int len = name.length(); int len = name.length();
bool next_is_upper = true; bool next_is_upper = true;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
@ -177,10 +177,10 @@ string ToCamel(const string &name) {
return rv; return rv;
} }
string FullNameToLower(const string &full_name) { std::string FullNameToLower(const std::string &full_name) {
std::vector<string> pieces; std::vector<std::string> pieces;
SplitStringUsing(full_name, ".", &pieces); SplitStringUsing(full_name, ".", &pieces);
string rv = ""; std::string rv = "";
for (unsigned i = 0; i < pieces.size(); i++) { for (unsigned i = 0; i < pieces.size(); i++) {
if (pieces[i] == "") continue; if (pieces[i] == "") continue;
if (rv != "") rv += "__"; if (rv != "") rv += "__";
@ -188,10 +188,10 @@ string FullNameToLower(const string &full_name) {
} }
return rv; return rv;
} }
string FullNameToUpper(const string &full_name) { std::string FullNameToUpper(const std::string &full_name) {
std::vector<string> pieces; std::vector<std::string> pieces;
SplitStringUsing(full_name, ".", &pieces); SplitStringUsing(full_name, ".", &pieces);
string rv = ""; std::string rv = "";
for (unsigned i = 0; i < pieces.size(); i++) { for (unsigned i = 0; i < pieces.size(); i++) {
if (pieces[i] == "") continue; if (pieces[i] == "") continue;
if (rv != "") rv += "__"; if (rv != "") rv += "__";
@ -199,10 +199,10 @@ string FullNameToUpper(const string &full_name) {
} }
return rv; return rv;
} }
string FullNameToC(const string &full_name) { std::string FullNameToC(const std::string &full_name) {
std::vector<string> pieces; std::vector<std::string> pieces;
SplitStringUsing(full_name, ".", &pieces); SplitStringUsing(full_name, ".", &pieces);
string rv = ""; std::string rv = "";
for (unsigned i = 0; i < pieces.size(); i++) { for (unsigned i = 0; i < pieces.size(); i++) {
if (pieces[i] == "") continue; if (pieces[i] == "") continue;
if (rv != "") rv += "__"; if (rv != "") rv += "__";
@ -211,11 +211,11 @@ string FullNameToC(const string &full_name) {
return rv; return rv;
} }
void PrintComment (io::Printer* printer, string comment) void PrintComment (io::Printer* printer, std::string comment)
{ {
if (!comment.empty()) if (!comment.empty())
{ {
std::vector<string> comment_lines; std::vector<std::string> comment_lines;
SplitStringUsing (comment, "\r\n", &comment_lines); SplitStringUsing (comment, "\r\n", &comment_lines);
printer->Print ("/*\n"); printer->Print ("/*\n");
for (int i = 0; i < comment_lines.size(); i++) for (int i = 0; i < comment_lines.size(); i++)
@ -228,10 +228,10 @@ void PrintComment (io::Printer* printer, string comment)
/* Or cause other compiler issues. */ /* Or cause other compiler issues. */
size_t delim_i; size_t delim_i;
while ((delim_i = comment_lines[i].find("/*")) != string::npos) while ((delim_i = comment_lines[i].find("/*")) != std::string::npos)
comment_lines[i][delim_i] = ' '; comment_lines[i][delim_i] = ' ';
while ((delim_i = comment_lines[i].find("*/")) != string::npos) while ((delim_i = comment_lines[i].find("*/")) != std::string::npos)
comment_lines[i][delim_i + 1] = ' '; comment_lines[i][delim_i + 1] = ' ';
printer->Print (" *$line$\n", "line", comment_lines[i]); printer->Print (" *$line$\n", "line", comment_lines[i]);
@ -241,8 +241,8 @@ void PrintComment (io::Printer* printer, string comment)
} }
} }
string ConvertToSpaces(const string &input) { std::string ConvertToSpaces(const std::string &input) {
return string(input.size(), ' '); return std::string(input.size(), ' ');
} }
int compare_name_indices_by_name(const void *a, const void *b) int compare_name_indices_by_name(const void *a, const void *b)
@ -253,7 +253,7 @@ int compare_name_indices_by_name(const void *a, const void *b)
} }
string CEscape(const string& src); std::string CEscape(const std::string& src);
const char* const kKeywordList[] = { const char* const kKeywordList[] = {
"and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case",
@ -268,24 +268,24 @@ const char* const kKeywordList[] = {
"void", "volatile", "wchar_t", "while", "xor", "xor_eq" "void", "volatile", "wchar_t", "while", "xor", "xor_eq"
}; };
std::set<string> MakeKeywordsMap() { std::set<std::string> MakeKeywordsMap() {
std::set<string> result; std::set<std::string> result;
for (int i = 0; i < GOOGLE_ARRAYSIZE(kKeywordList); i++) { for (int i = 0; i < GOOGLE_ARRAYSIZE(kKeywordList); i++) {
result.insert(kKeywordList[i]); result.insert(kKeywordList[i]);
} }
return result; return result;
} }
std::set<string> kKeywords = MakeKeywordsMap(); std::set<std::string> kKeywords = MakeKeywordsMap();
string ClassName(const Descriptor* descriptor, bool qualified) { std::string ClassName(const Descriptor* descriptor, bool qualified) {
// Find "outer", the descriptor of the top-level message in which // Find "outer", the descriptor of the top-level message in which
// "descriptor" is embedded. // "descriptor" is embedded.
const Descriptor* outer = descriptor; const Descriptor* outer = descriptor;
while (outer->containing_type() != NULL) outer = outer->containing_type(); while (outer->containing_type() != NULL) outer = outer->containing_type();
const string& outer_name = outer->full_name(); const std::string& outer_name = outer->full_name();
string inner_name = descriptor->full_name().substr(outer_name.size()); std::string inner_name = descriptor->full_name().substr(outer_name.size());
if (qualified) { if (qualified) {
return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name); return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);
@ -294,7 +294,7 @@ string ClassName(const Descriptor* descriptor, bool qualified) {
} }
} }
string ClassName(const EnumDescriptor* enum_descriptor, bool qualified) { std::string ClassName(const EnumDescriptor* enum_descriptor, bool qualified) {
if (enum_descriptor->containing_type() == NULL) { if (enum_descriptor->containing_type() == NULL) {
if (qualified) { if (qualified) {
return DotsToColons(enum_descriptor->full_name()); return DotsToColons(enum_descriptor->full_name());
@ -302,29 +302,29 @@ string ClassName(const EnumDescriptor* enum_descriptor, bool qualified) {
return enum_descriptor->name(); return enum_descriptor->name();
} }
} else { } else {
string result = ClassName(enum_descriptor->containing_type(), qualified); std::string result = ClassName(enum_descriptor->containing_type(), qualified);
result += '_'; result += '_';
result += enum_descriptor->name(); result += enum_descriptor->name();
return result; return result;
} }
} }
string FieldName(const FieldDescriptor* field) { std::string FieldName(const FieldDescriptor* field) {
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("_");
} }
return result; return result;
} }
string FieldDeprecated(const FieldDescriptor* field) { std::string FieldDeprecated(const FieldDescriptor* field) {
if (field->options().deprecated()) { if (field->options().deprecated()) {
return " PROTOBUF_C__DEPRECATED"; return " PROTOBUF_C__DEPRECATED";
} }
return ""; return "";
} }
string StripProto(const string& filename) { std::string StripProto(const std::string& filename) {
if (HasSuffixString(filename, ".protodevel")) { if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel"); return StripSuffixString(filename, ".protodevel");
} else { } else {
@ -333,8 +333,8 @@ string StripProto(const string& filename) {
} }
// Convert a file name into a valid identifier. // Convert a file name into a valid identifier.
string FilenameIdentifier(const string& filename) { std::string FilenameIdentifier(const std::string& filename) {
string result; std::string result;
for (unsigned i = 0; i < filename.size(); i++) { for (unsigned i = 0; i < filename.size(); i++) {
if (isalnum(filename[i])) { if (isalnum(filename[i])) {
result.push_back(filename[i]); result.push_back(filename[i]);
@ -350,11 +350,11 @@ string FilenameIdentifier(const string& filename) {
} }
// Return the name of the BuildDescriptors() function for a given file. // Return the name of the BuildDescriptors() function for a given file.
string GlobalBuildDescriptorsName(const string& filename) { std::string GlobalBuildDescriptorsName(const std::string& filename) {
return "proto_BuildDescriptors_" + FilenameIdentifier(filename); return "proto_BuildDescriptors_" + FilenameIdentifier(filename);
} }
string GetLabelName(FieldDescriptor::Label label) { std::string GetLabelName(FieldDescriptor::Label label) {
switch (label) { switch (label) {
case FieldDescriptor::LABEL_OPTIONAL: return "optional"; case FieldDescriptor::LABEL_OPTIONAL: return "optional";
case FieldDescriptor::LABEL_REQUIRED: return "required"; case FieldDescriptor::LABEL_REQUIRED: return "required";
@ -364,9 +364,9 @@ string GetLabelName(FieldDescriptor::Label label) {
} }
unsigned unsigned
WriteIntRanges(io::Printer* printer, int n_values, const int *values, const string &name) WriteIntRanges(io::Printer* printer, int n_values, const int *values, const std::string &name)
{ {
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["name"] = name; vars["name"] = name;
if (n_values > 0) { if (n_values > 0) {
int n_ranges = 1; int n_ranges = 1;
@ -420,19 +420,19 @@ WriteIntRanges(io::Printer* printer, int n_values, const int *values, const stri
// it only replaces the first instance of "old." // it only replaces the first instance of "old."
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
void StringReplace(const string& s, const string& oldsub, void StringReplace(const std::string& s, const std::string& oldsub,
const string& newsub, bool replace_all, const std::string& newsub, bool replace_all,
string* res) { std::string* res) {
if (oldsub.empty()) { if (oldsub.empty()) {
res->append(s); // if empty, append the given string. res->append(s); // if empty, append the given string.
return; return;
} }
string::size_type start_pos = 0; std::string::size_type start_pos = 0;
string::size_type pos; std::string::size_type pos;
do { do {
pos = s.find(oldsub, start_pos); pos = s.find(oldsub, start_pos);
if (pos == string::npos) { if (pos == std::string::npos) {
break; break;
} }
res->append(s, start_pos, pos - start_pos); res->append(s, start_pos, pos - start_pos);
@ -452,9 +452,9 @@ void StringReplace(const string& s, const string& oldsub,
// happened or not. // happened or not.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
string StringReplace(const string& s, const string& oldsub, std::string StringReplace(const std::string& s, const std::string& oldsub,
const string& newsub, bool replace_all) { const std::string& newsub, bool replace_all) {
string ret; std::string ret;
StringReplace(s, oldsub, newsub, replace_all, &ret); StringReplace(s, oldsub, newsub, replace_all, &ret);
return ret; return ret;
} }
@ -469,7 +469,7 @@ string StringReplace(const string& s, const string& oldsub,
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
template <typename ITR> template <typename ITR>
static inline static inline
void SplitStringToIteratorUsing(const string& full, void SplitStringToIteratorUsing(const std::string& full,
const char* delim, const char* delim,
ITR& result) { ITR& result) {
// Optimize the common case where delim is a single character. // Optimize the common case where delim is a single character.
@ -483,17 +483,17 @@ void SplitStringToIteratorUsing(const string& full,
} else { } else {
const char* start = p; const char* start = p;
while (++p != end && *p != c); while (++p != end && *p != c);
*result++ = string(start, p - start); *result++ = std::string(start, p - start);
} }
} }
return; return;
} }
string::size_type begin_index, end_index; std::string::size_type begin_index, end_index;
begin_index = full.find_first_not_of(delim); begin_index = full.find_first_not_of(delim);
while (begin_index != string::npos) { while (begin_index != std::string::npos) {
end_index = full.find_first_of(delim, begin_index); end_index = full.find_first_of(delim, begin_index);
if (end_index == string::npos) { if (end_index == std::string::npos) {
*result++ = full.substr(begin_index); *result++ = full.substr(begin_index);
return; return;
} }
@ -502,10 +502,10 @@ void SplitStringToIteratorUsing(const string& full,
} }
} }
void SplitStringUsing(const string& full, void SplitStringUsing(const std::string& full,
const char* delim, const char* delim,
std::vector<string>* result) { std::vector<std::string>* result) {
std::back_insert_iterator< std::vector<string> > it(*result); std::back_insert_iterator< std::vector<std::string> > it(*result);
SplitStringToIteratorUsing(full, delim, it); SplitStringToIteratorUsing(full, delim, it);
} }
@ -558,13 +558,13 @@ static int CEscapeInternal(const char* src, int src_len, char* dest,
dest[used] = '\0'; // doesn't count towards return value though dest[used] = '\0'; // doesn't count towards return value though
return used; return used;
} }
string CEscape(const string& src) { std::string CEscape(const std::string& src) {
const int dest_length = src.size() * 4 + 1; // Maximum possible expansion const int dest_length = src.size() * 4 + 1; // Maximum possible expansion
std::unique_ptr<char[]> dest(new char[dest_length]); std::unique_ptr<char[]> dest(new char[dest_length]);
const int len = CEscapeInternal(src.data(), src.size(), const int len = CEscapeInternal(src.data(), src.size(),
dest.get(), dest_length, false); dest.get(), dest_length, false);
GOOGLE_DCHECK_GE(len, 0); GOOGLE_DCHECK_GE(len, 0);
return string(dest.get(), len); return std::string(dest.get(), len);
} }
} // namespace c } // namespace c

View File

@ -83,23 +83,23 @@ namespace c {
// Foo__Bar__Baz_Qux // Foo__Bar__Baz_Qux
// While the non-qualified version would be: // While the non-qualified version would be:
// Baz_Qux // Baz_Qux
string ClassName(const Descriptor* descriptor, bool qualified); std::string ClassName(const Descriptor* descriptor, bool qualified);
string ClassName(const EnumDescriptor* enum_descriptor, bool qualified); std::string ClassName(const EnumDescriptor* enum_descriptor, bool qualified);
// --- Borrowed from stubs. --- // --- Borrowed from stubs. ---
template <typename T> string SimpleItoa(T n) { template <typename T> std::string SimpleItoa(T n) {
std::stringstream stream; std::stringstream stream;
stream << n; stream << n;
return stream.str(); return stream.str();
} }
string SimpleFtoa(float f); std::string SimpleFtoa(float f);
string SimpleDtoa(double f); std::string SimpleDtoa(double f);
void SplitStringUsing(const string &str, const char *delim, std::vector<string> *out); void SplitStringUsing(const std::string &str, const char *delim, std::vector<std::string> *out);
string CEscape(const string& src); std::string CEscape(const std::string& src);
string StringReplace(const string& s, const string& oldsub, const string& newsub, bool replace_all); std::string StringReplace(const std::string& s, const std::string& oldsub, const std::string& newsub, bool replace_all);
inline bool HasSuffixString(const string& str, const string& suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } inline bool HasSuffixString(const std::string& str, const std::string& suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; }
inline string StripSuffixString(const string& str, const string& suffix) { if (HasSuffixString(str, suffix)) { return str.substr(0, str.size() - suffix.size()); } else { return str; } } inline std::string StripSuffixString(const std::string& str, const std::string& suffix) { if (HasSuffixString(str, suffix)) { return str.substr(0, str.size() - suffix.size()); } else { return str; } }
char* FastHexToBuffer(int i, char* buffer); char* FastHexToBuffer(int i, char* buffer);
@ -107,10 +107,10 @@ 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().
string FieldName(const FieldDescriptor* field); std::string FieldName(const FieldDescriptor* field);
// Get macro string for deprecated field // Get macro string for deprecated field
string FieldDeprecated(const FieldDescriptor* field); std::string FieldDeprecated(const 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).
@ -121,31 +121,31 @@ inline const Descriptor* FieldScope(const FieldDescriptor* field) {
// convert a CamelCase class name into an all uppercase affair // convert a CamelCase class name into an all uppercase affair
// with underscores separating words, e.g. MyClass becomes MY_CLASS. // with underscores separating words, e.g. MyClass becomes MY_CLASS.
string CamelToUpper(const string &class_name); std::string CamelToUpper(const std::string &class_name);
string CamelToLower(const string &class_name); std::string CamelToLower(const std::string &class_name);
// lowercased, underscored name to camel case // lowercased, underscored name to camel case
string ToCamel(const string &name); std::string ToCamel(const std::string &name);
// lowercase the string // lowercase the string
string ToLower(const string &class_name); std::string ToLower(const std::string &class_name);
string ToUpper(const string &class_name); std::string ToUpper(const std::string &class_name);
// full_name() to lowercase with underscores // full_name() to lowercase with underscores
string FullNameToLower(const string &full_name); std::string FullNameToLower(const std::string &full_name);
string FullNameToUpper(const string &full_name); std::string FullNameToUpper(const std::string &full_name);
// full_name() to c-typename (with underscores for packages, otherwise camel case) // full_name() to c-typename (with underscores for packages, otherwise camel case)
string FullNameToC(const string &class_name); std::string FullNameToC(const std::string &class_name);
// Splits, indents, formats, and prints comment lines // Splits, indents, formats, and prints comment lines
void PrintComment (io::Printer* printer, string comment); void PrintComment (io::Printer* printer, std::string comment);
// make a string of spaces as long as input // make a string of spaces as long as input
string ConvertToSpaces(const string &input); std::string ConvertToSpaces(const std::string &input);
// Strips ".proto" or ".protodevel" from the end of a filename. // Strips ".proto" or ".protodevel" from the end of a filename.
string StripProto(const string& filename); std::string StripProto(const std::string& filename);
// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.). // Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.).
// Note: non-built-in type names will be qualified, meaning they will start // Note: non-built-in type names will be qualified, meaning they will start
@ -159,18 +159,18 @@ const char* PrimitiveTypeName(FieldDescriptor::CppType type);
const char* DeclaredTypeMethodName(FieldDescriptor::Type type); const char* DeclaredTypeMethodName(FieldDescriptor::Type type);
// Convert a file name into a valid identifier. // Convert a file name into a valid identifier.
string FilenameIdentifier(const string& filename); std::string FilenameIdentifier(const std::string& filename);
// Return the name of the BuildDescriptors() function for a given file. // Return the name of the BuildDescriptors() function for a given file.
string GlobalBuildDescriptorsName(const string& filename); std::string GlobalBuildDescriptorsName(const std::string& filename);
// return 'required', 'optional', or 'repeated' // return 'required', 'optional', or 'repeated'
string GetLabelName(FieldDescriptor::Label label); std::string GetLabelName(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 string &name); unsigned WriteIntRanges(io::Printer* printer, int n_values, const int *values, const std::string &name);
struct NameIndex struct NameIndex
{ {

View File

@ -80,7 +80,7 @@ namespace c {
// =================================================================== // ===================================================================
MessageGenerator::MessageGenerator(const Descriptor* descriptor, MessageGenerator::MessageGenerator(const Descriptor* descriptor,
const string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor), : descriptor_(descriptor),
dllexport_decl_(dllexport_decl), dllexport_decl_(dllexport_decl),
field_generators_(descriptor), field_generators_(descriptor),
@ -137,7 +137,7 @@ GenerateStructDefinition(io::Printer* printer) {
nested_generators_[i]->GenerateStructDefinition(printer); nested_generators_[i]->GenerateStructDefinition(printer);
} }
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["classname"] = FullNameToC(descriptor_->full_name()); vars["classname"] = FullNameToC(descriptor_->full_name());
vars["lcclassname"] = FullNameToLower(descriptor_->full_name()); vars["lcclassname"] = FullNameToLower(descriptor_->full_name());
vars["ucclassname"] = FullNameToUpper(descriptor_->full_name()); vars["ucclassname"] = FullNameToUpper(descriptor_->full_name());
@ -258,7 +258,7 @@ GenerateHelperFunctionDeclarations(io::Printer* printer, bool is_submessage)
nested_generators_[i]->GenerateHelperFunctionDeclarations(printer, true); nested_generators_[i]->GenerateHelperFunctionDeclarations(printer, true);
} }
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["classname"] = FullNameToC(descriptor_->full_name()); vars["classname"] = FullNameToC(descriptor_->full_name());
vars["lcclassname"] = FullNameToLower(descriptor_->full_name()); vars["lcclassname"] = FullNameToLower(descriptor_->full_name());
printer->Print(vars, printer->Print(vars,
@ -306,7 +306,7 @@ void MessageGenerator::GenerateClosureTypedef(io::Printer* printer)
for (int i = 0; i < descriptor_->nested_type_count(); i++) { for (int i = 0; i < descriptor_->nested_type_count(); i++) {
nested_generators_[i]->GenerateClosureTypedef(printer); nested_generators_[i]->GenerateClosureTypedef(printer);
} }
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["name"] = FullNameToC(descriptor_->full_name()); vars["name"] = FullNameToC(descriptor_->full_name());
printer->Print(vars, printer->Print(vars,
"typedef void (*$name$_Closure)\n" "typedef void (*$name$_Closure)\n"
@ -331,7 +331,7 @@ GenerateHelperFunctionDefinitions(io::Printer* printer, bool is_submessage)
nested_generators_[i]->GenerateHelperFunctionDefinitions(printer, true); nested_generators_[i]->GenerateHelperFunctionDefinitions(printer, true);
} }
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["classname"] = FullNameToC(descriptor_->full_name()); vars["classname"] = FullNameToC(descriptor_->full_name());
vars["lcclassname"] = FullNameToLower(descriptor_->full_name()); vars["lcclassname"] = FullNameToLower(descriptor_->full_name());
vars["ucclassname"] = FullNameToUpper(descriptor_->full_name()); vars["ucclassname"] = FullNameToUpper(descriptor_->full_name());
@ -389,7 +389,7 @@ GenerateHelperFunctionDefinitions(io::Printer* printer, bool is_submessage)
void MessageGenerator:: void MessageGenerator::
GenerateMessageDescriptor(io::Printer* printer) { GenerateMessageDescriptor(io::Printer* printer) {
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["fullname"] = descriptor_->full_name(); vars["fullname"] = descriptor_->full_name();
vars["classname"] = FullNameToC(descriptor_->full_name()); vars["classname"] = FullNameToC(descriptor_->full_name());
vars["lcclassname"] = FullNameToLower(descriptor_->full_name()); vars["lcclassname"] = FullNameToLower(descriptor_->full_name());

View File

@ -86,7 +86,7 @@ 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 Descriptor* descriptor,
const string& dllexport_decl); const std::string& dllexport_decl);
~MessageGenerator(); ~MessageGenerator();
// Header stuff. // Header stuff.
@ -122,10 +122,10 @@ class MessageGenerator {
private: private:
string GetDefaultValueC(const FieldDescriptor *fd); std::string GetDefaultValueC(const FieldDescriptor *fd);
const Descriptor* descriptor_; const Descriptor* descriptor_;
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_;
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_; std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;

View File

@ -83,7 +83,7 @@ MessageFieldGenerator::~MessageFieldGenerator() {}
void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const
{ {
std::map<string, 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()); vars["type"] = FullNameToC(descriptor_->message_type()->full_name());
vars["deprecated"] = FieldDeprecated(descriptor_); vars["deprecated"] = FieldDeprecated(descriptor_);
@ -98,7 +98,7 @@ void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const
break; break;
} }
} }
string MessageFieldGenerator::GetDefaultValue(void) const std::string MessageFieldGenerator::GetDefaultValue(void) const
{ {
/* XXX: update when protobuf gets support /* XXX: update when protobuf gets support
* for default-values of message fields. * for default-values of message fields.
@ -119,7 +119,7 @@ void MessageFieldGenerator::GenerateStaticInit(io::Printer* printer) const
} }
void MessageFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void MessageFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const
{ {
string addr = "&" + FullNameToLower(descriptor_->message_type()->full_name()) + "__descriptor"; std::string addr = "&" + FullNameToLower(descriptor_->message_type()->full_name()) + "__descriptor";
GenerateDescriptorInitializerGeneric(printer, false, "MESSAGE", addr); GenerateDescriptorInitializerGeneric(printer, false, "MESSAGE", addr);
} }

View File

@ -80,7 +80,7 @@ class MessageFieldGenerator : public FieldGenerator {
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(io::Printer* printer) const;
string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(io::Printer* printer) const;
private: private:

View File

@ -79,8 +79,8 @@ PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {}
void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const
{ {
string c_type; std::string c_type;
std::map<string, string> vars; std::map<std::string, std::string> vars;
switch (descriptor_->type()) { switch (descriptor_->type()) {
case FieldDescriptor::TYPE_SINT32 : case FieldDescriptor::TYPE_SINT32 :
case FieldDescriptor::TYPE_SFIXED32: case FieldDescriptor::TYPE_SFIXED32:
@ -123,7 +123,7 @@ void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const
break; break;
} }
} }
string PrimitiveFieldGenerator::GetDefaultValue() const 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. */
@ -149,7 +149,7 @@ string PrimitiveFieldGenerator::GetDefaultValue() const
} }
void PrimitiveFieldGenerator::GenerateStaticInit(io::Printer* printer) const void PrimitiveFieldGenerator::GenerateStaticInit(io::Printer* printer) const
{ {
std::map<string, string> vars; std::map<std::string, std::string> vars;
if (descriptor_->has_default_value()) { if (descriptor_->has_default_value()) {
vars["default_value"] = GetDefaultValue(); vars["default_value"] = GetDefaultValue();
} else { } else {
@ -172,7 +172,7 @@ void PrimitiveFieldGenerator::GenerateStaticInit(io::Printer* printer) const
void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const void PrimitiveFieldGenerator::GenerateDescriptorInitializer(io::Printer* printer) const
{ {
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 FieldDescriptor::TYPE_##shortname: c_type_macro = #shortname; break;
WRITE_CASE(INT32) WRITE_CASE(INT32)

View File

@ -80,7 +80,7 @@ class PrimitiveFieldGenerator : public FieldGenerator {
// implements FieldGenerator --------------------------------------- // implements FieldGenerator ---------------------------------------
void GenerateStructMembers(io::Printer* printer) const; void GenerateStructMembers(io::Printer* printer) const;
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(io::Printer* printer) const;
string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(io::Printer* printer) const;
private: private:

View File

@ -70,7 +70,7 @@ namespace compiler {
namespace c { namespace c {
ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor, ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor,
const string& dllexport_decl) const std::string& dllexport_decl)
: descriptor_(descriptor) { : descriptor_(descriptor) {
vars_["name"] = descriptor_->name(); vars_["name"] = descriptor_->name();
vars_["fullname"] = descriptor_->full_name(); vars_["fullname"] = descriptor_->full_name();
@ -104,7 +104,7 @@ void ServiceGenerator::GenerateVfuncs(io::Printer* printer)
" 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 MethodDescriptor *method = descriptor_->method(i);
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);
vars_["input_typename"] = FullNameToC(method->input_type()->full_name()); vars_["input_typename"] = FullNameToC(method->input_type()->full_name());
@ -131,7 +131,7 @@ void ServiceGenerator::GenerateInitMacros(io::Printer* printer)
" { $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 MethodDescriptor *method = descriptor_->method(i);
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);
printer->Print(vars_, printer->Print(vars_,
@ -144,8 +144,8 @@ void ServiceGenerator::GenerateCallersDeclarations(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 MethodDescriptor *method = descriptor_->method(i);
string lcname = CamelToLower(method->name()); std::string lcname = CamelToLower(method->name());
string lcfullname = FullNameToLower(descriptor_->full_name()); std::string lcfullname = FullNameToLower(descriptor_->full_name());
vars_["method"] = lcname; vars_["method"] = lcname;
vars_["metpad"] = ConvertToSpaces(lcname); vars_["metpad"] = ConvertToSpaces(lcname);
vars_["input_typename"] = FullNameToC(method->input_type()->full_name()); vars_["input_typename"] = FullNameToC(method->input_type()->full_name());
@ -266,8 +266,8 @@ void ServiceGenerator::GenerateCallersImplementations(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 MethodDescriptor *method = descriptor_->method(i);
string lcname = CamelToLower(method->name()); std::string lcname = CamelToLower(method->name());
string lcfullname = FullNameToLower(descriptor_->full_name()); std::string lcfullname = FullNameToLower(descriptor_->full_name());
vars_["method"] = lcname; vars_["method"] = lcname;
vars_["metpad"] = ConvertToSpaces(lcname); vars_["metpad"] = ConvertToSpaces(lcname);
vars_["input_typename"] = FullNameToC(method->input_type()->full_name()); vars_["input_typename"] = FullNameToC(method->input_type()->full_name());

View File

@ -82,7 +82,7 @@ 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 ServiceDescriptor* descriptor,
const string& dllexport_decl); const std::string& dllexport_decl);
~ServiceGenerator(); ~ServiceGenerator();
// Header stuff. // Header stuff.
@ -99,7 +99,7 @@ class ServiceGenerator {
void GenerateCallersImplementations(io::Printer* printer); void GenerateCallersImplementations(io::Printer* printer);
const ServiceDescriptor* descriptor_; const ServiceDescriptor* descriptor_;
std::map<string, string> vars_; std::map<std::string, std::string> vars_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
}; };

View File

@ -74,7 +74,7 @@ namespace c {
using internal::WireFormat; using internal::WireFormat;
void SetStringVariables(const FieldDescriptor* descriptor, void SetStringVariables(const FieldDescriptor* descriptor,
std::map<string, string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["default"] = FullNameToLower(descriptor->full_name()) (*variables)["default"] = FullNameToLower(descriptor->full_name())
+ "__default_value"; + "__default_value";
@ -110,19 +110,19 @@ void StringFieldGenerator::GenerateDefaultValueDeclarations(io::Printer* printer
} }
void StringFieldGenerator::GenerateDefaultValueImplementations(io::Printer* printer) const void StringFieldGenerator::GenerateDefaultValueImplementations(io::Printer* printer) const
{ {
std::map<string, string> vars; std::map<std::string, std::string> vars;
vars["default"] = variables_.find("default")->second; vars["default"] = variables_.find("default")->second;
vars["escaped"] = CEscape(descriptor_->default_value_string()); vars["escaped"] = CEscape(descriptor_->default_value_string());
printer->Print(vars, "char $default$[] = \"$escaped$\";\n"); printer->Print(vars, "char $default$[] = \"$escaped$\";\n");
} }
string StringFieldGenerator::GetDefaultValue(void) const 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(io::Printer* printer) const
{ {
std::map<string, string> vars; std::map<std::string, std::string> vars;
if (descriptor_->has_default_value()) { if (descriptor_->has_default_value()) {
vars["default"] = GetDefaultValue(); vars["default"] = GetDefaultValue();
} else if (FieldSyntax(descriptor_) == 2) { } else if (FieldSyntax(descriptor_) == 2) {

View File

@ -82,11 +82,11 @@ class StringFieldGenerator : public FieldGenerator {
void GenerateDescriptorInitializer(io::Printer* printer) const; void GenerateDescriptorInitializer(io::Printer* printer) const;
void GenerateDefaultValueDeclarations(io::Printer* printer) const; void GenerateDefaultValueDeclarations(io::Printer* printer) const;
void GenerateDefaultValueImplementations(io::Printer* printer) const; void GenerateDefaultValueImplementations(io::Printer* printer) const;
string GetDefaultValue(void) const; std::string GetDefaultValue(void) const;
void GenerateStaticInit(io::Printer* printer) const; void GenerateStaticInit(io::Printer* printer) const;
private: private:
std::map<string, string> variables_; std::map<std::string, std::string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator);
}; };