aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/ruby/ruby_generator.cc
diff options
context:
space:
mode:
authorGravatar Josh Haberman <jhaberman@gmail.com>2015-07-15 11:05:10 -0700
committerGravatar Josh Haberman <jhaberman@gmail.com>2015-07-16 12:25:55 -0700
commit181c7f26360429b236ab833c746d10d97811931f (patch)
tree3abdbaf4abb0115c17892bcf2a1629c9475f147c /src/google/protobuf/compiler/ruby/ruby_generator.cc
parentfde6e89f99eda04a4f1b8677bcea07e6c2040405 (diff)
Added Ruby to conformance tests.
This involved fixing a few important bugs in the Ruby implementation -- mostly cases of mixing upb field types and descriptor types (upb field types do not distinguish between int/sint/fixed/sfixed like descriptor types do). Also added protobuf-specific exceptions so parse errors can be caught specifically. Change-Id: Ib49d3db976900b2c6f3455c8b88af52cfb86e036
Diffstat (limited to 'src/google/protobuf/compiler/ruby/ruby_generator.cc')
-rw-r--r--src/google/protobuf/compiler/ruby/ruby_generator.cc34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc
index a9b6837e..9692f1bf 100644
--- a/src/google/protobuf/compiler/ruby/ruby_generator.cc
+++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc
@@ -47,7 +47,7 @@ namespace compiler {
namespace ruby {
// Forward decls.
-std::string IntToString(uint32 value);
+std::string IntToString(int32 value);
std::string StripDotProto(const std::string& proto_file);
std::string LabelForField(google::protobuf::FieldDescriptor* field);
std::string TypeName(google::protobuf::FieldDescriptor* field);
@@ -64,7 +64,7 @@ void GenerateEnumAssignment(
const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer);
-std::string IntToString(uint32 value) {
+std::string IntToString(int32 value) {
std::ostringstream os;
os << value;
return os.str();
@@ -85,17 +85,25 @@ std::string LabelForField(const google::protobuf::FieldDescriptor* field) {
}
std::string TypeName(const google::protobuf::FieldDescriptor* field) {
- switch (field->cpp_type()) {
- case FieldDescriptor::CPPTYPE_INT32: return "int32";
- case FieldDescriptor::CPPTYPE_INT64: return "int64";
- case FieldDescriptor::CPPTYPE_UINT32: return "uint32";
- case FieldDescriptor::CPPTYPE_UINT64: return "uint64";
- case FieldDescriptor::CPPTYPE_DOUBLE: return "double";
- case FieldDescriptor::CPPTYPE_FLOAT: return "float";
- case FieldDescriptor::CPPTYPE_BOOL: return "bool";
- case FieldDescriptor::CPPTYPE_ENUM: return "enum";
- case FieldDescriptor::CPPTYPE_STRING: return "string";
- case FieldDescriptor::CPPTYPE_MESSAGE: return "message";
+ switch (field->type()) {
+ case FieldDescriptor::TYPE_INT32: return "int32";
+ case FieldDescriptor::TYPE_INT64: return "int64";
+ case FieldDescriptor::TYPE_UINT32: return "uint32";
+ case FieldDescriptor::TYPE_UINT64: return "uint64";
+ case FieldDescriptor::TYPE_SINT32: return "sint32";
+ case FieldDescriptor::TYPE_SINT64: return "sint64";
+ case FieldDescriptor::TYPE_FIXED32: return "fixed32";
+ case FieldDescriptor::TYPE_FIXED64: return "fixed64";
+ case FieldDescriptor::TYPE_SFIXED32: return "sfixed32";
+ case FieldDescriptor::TYPE_SFIXED64: return "sfixed64";
+ case FieldDescriptor::TYPE_DOUBLE: return "double";
+ case FieldDescriptor::TYPE_FLOAT: return "float";
+ case FieldDescriptor::TYPE_BOOL: return "bool";
+ case FieldDescriptor::TYPE_ENUM: return "enum";
+ case FieldDescriptor::TYPE_STRING: return "string";
+ case FieldDescriptor::TYPE_BYTES: return "bytes";
+ case FieldDescriptor::TYPE_MESSAGE: return "message";
+ case FieldDescriptor::TYPE_GROUP: return "group";
default: assert(false); return "";
}
}