aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2008-08-14 20:33:35 +0100
committerJon Skeet <skeet@pobox.com>2008-08-14 20:33:35 +0100
commit800f65e20915d3cda9b6b681013dc0a5dd5ddee2 (patch)
tree55685a947b575345a6ba225408ed223ab5bf0aa5
parent007f859664d2d83b908c3931764d1eb2f0ab889b (diff)
downloadprotobuf-800f65e20915d3cda9b6b681013dc0a5dd5ddee2.tar.gz
protobuf-800f65e20915d3cda9b6b681013dc0a5dd5ddee2.tar.bz2
protobuf-800f65e20915d3cda9b6b681013dc0a5dd5ddee2.zip
Patch from Miguel de Icaza - tweaks to generated C#
-rwxr-xr-xautogen.sh4
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_enum_field.cc35
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_extension.cc4
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_message.cc8
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_message_field.cc86
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_primitive_field.cc5
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_service.cc2
7 files changed, 73 insertions, 71 deletions
diff --git a/autogen.sh b/autogen.sh
index 34a4d2e3..ca7488bc 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -17,10 +17,10 @@ set -ex
rm -rf autom4te.cache
-aclocal-1.9 --force -I m4
+aclocal-1.10 --force -I m4
libtoolize -c -f
autoheader -f -W all
-automake-1.9 --foreign -a -c -f -W all
+automake-1.10 --foreign -a -c -f -W all
autoconf -f -W all,no-obsolete
rm -rf autom4te.cache config.h.in~
diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
index 7895d948..f5414961 100644
--- a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
@@ -70,25 +70,25 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"private boolean has$capitalized_name$;\r\n"
"private $type$ $name$_ = $default$;\r\n"
- "public boolean has$capitalized_name$() { return has$capitalized_name$; }\r\n"
- "public $type$ get$capitalized_name$() { return $name$_; }\r\n");
+ "public boolean Has$capitalized_name$() { return has$capitalized_name$; }\r\n"
+ "public $type$ Get$capitalized_name$() { return $name$_; }\r\n");
}
void EnumFieldGenerator::
GenerateBuilderMembers(io::Printer* printer) const {
printer->Print(variables_,
- "public boolean has$capitalized_name$() {\r\n"
- " return result.has$capitalized_name$();\r\n"
+ "public boolean Has$capitalized_name$() {\r\n"
+ " return result.Has$capitalized_name$();\r\n"
"}\r\n"
- "public $type$ get$capitalized_name$() {\r\n"
- " return result.get$capitalized_name$();\r\n"
+ "public $type$ Get$capitalized_name$() {\r\n"
+ " return result.Get$capitalized_name$();\r\n"
"}\r\n"
- "public Builder set$capitalized_name$($type$ value) {\r\n"
+ "public Builder Set$capitalized_name$($type$ value) {\r\n"
" result.has$capitalized_name$ = true;\r\n"
" result.$name$_ = value;\r\n"
" return this;\r\n"
"}\r\n"
- "public Builder clear$capitalized_name$() {\r\n"
+ "public Builder Clear$capitalized_name$() {\r\n"
" result.has$capitalized_name$ = false;\r\n"
" result.$name$_ = $default$;\r\n"
" return this;\r\n"
@@ -154,15 +154,18 @@ RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {}
void RepeatedEnumFieldGenerator::
GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
- "private java.util.List<$type$> $name$_ =\r\n"
- " java.util.Collections.emptyList();\r\n"
- "public java.util.List<$type$> get$capitalized_name$List() {\r\n"
- " return $name$_;\r\n" // note: unmodifiable list
+ "private System.Collections.Generic.List<$type$> $name$_ =\r\n"
+ " new System.Collections.Generic.List<$type$> ();\r\n"
+ "public System.Collections.Generic.List<$type$> $capitalized_name$List() {\r\n"
+ " return $name$_.AsReadOnly ();\r\n" // note: unmodifiable list
"}\r\n"
- "public int get$capitalized_name$Count() { return $name$_.size(); }\r\n"
- "public $type$ get$capitalized_name$(int index) {\r\n"
- " return $name$_.get(index);\r\n"
- "}\r\n");
+
+ // Redundant API calls?
+ //"public int $capitalized_name$Count() { get { return $name$_.Count; } }\r\n"
+ //"public $type$ get$capitalized_name$(int index) {\r\n"
+ //" return $name$_.get(index);\r\n"
+ //"}\r\n"
+ );
}
void RepeatedEnumFieldGenerator::
diff --git a/src/google/protobuf/compiler/csharp/csharp_extension.cc b/src/google/protobuf/compiler/csharp/csharp_extension.cc
index fee5c31e..9b760873 100644
--- a/src/google/protobuf/compiler/csharp/csharp_extension.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_extension.cc
@@ -63,7 +63,7 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
" pb::GeneratedMessage\r\n"
" .newRepeatedGeneratedExtension(\r\n"
" getDescriptor().getExtensions().get($index$),\r\n"
- " $type$.class);\r\n");
+ " typeof ($type$));\r\n");
} else {
printer->Print(vars,
"public static final\r\n"
@@ -72,7 +72,7 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
" $type$> $name$ =\r\n"
" pb::GeneratedMessage.newGeneratedExtension(\r\n"
" getDescriptor().getExtensions().get($index$),\r\n"
- " $type$.class);\r\n");
+ " typeof ($type$));\r\n");
}
}
diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc
index 520cb982..5630f783 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message.cc
@@ -165,12 +165,12 @@ void MessageGenerator::GenerateStaticVariables(io::Printer* printer) {
// The descriptor for this type.
if (descriptor_->containing_type() == NULL) {
printer->Print(vars,
- "$private$static readonly pb::Descriptors.Descriptor {\r\n"
+ "$private$static readonly pb::Descriptors.Descriptor \r\n"
" internal_$identifier$_descriptor =\r\n"
" getDescriptor().getMessageTypes().get($index$);\r\n");
} else {
printer->Print(vars,
- "$private$static readonly pb::Descriptors.Descriptor {\r\n"
+ "$private$static readonly pb::Descriptors.Descriptor \r\n"
" internal_$identifier$_descriptor =\r\n"
" internal_$parent$_descriptor.getNestedTypes().get($index$);\r\n");
}
@@ -190,8 +190,8 @@ void MessageGenerator::GenerateStaticVariables(io::Printer* printer) {
UnderscoresToCapitalizedCamelCase(descriptor_->field(i)));
}
printer->Print("},\r\n"
- " $classname$.class,\r\n"
- " $classname$.Builder.class);\r\n",
+ " typeof ($classname$),\r\n"
+ " typeof ($classname$.Builder));\r\n",
"classname", ClassName(descriptor_));
// Generate static members for all nested types.
diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_message_field.cc
index 56a8b0a7..95b3e969 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message_field.cc
@@ -175,14 +175,15 @@ RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {}
void RepeatedMessageFieldGenerator::
GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
- "private java.util.List<$type$> $name$_ =\r\n"
- " java.util.Collections.emptyList();\r\n"
- "public java.util.List<$type$> get$capitalized_name$List() {\r\n"
- " return $name$_;\r\n" // note: unmodifiable list
+ "internal System.Collections.Generic.IList<$type$> Empty$capitalized_name$ =\r\n"
+ " new System.Collections.ReadOnlyCollection<$type$> ();\r\n"
+ "internal System.Collections.Generic.IList<$type$> $name$_ = Empty$capitalized_name$;\r\n"
+ "public System.Collections.Generic.IList<$type$> $capitalized_name$List {\r\n"
+ " get { return $name$_; } \r\n" // note: unmodifiable list
"}\r\n"
- "public int get$capitalized_name$Count() { return $name$_.size(); }\r\n"
- "public $type$ get$capitalized_name$(int index) {\r\n"
- " return $name$_.get(index);\r\n"
+ "public int $capitalized_name$Count { get { return $name$_.Count; } }\r\n"
+ "public $type$ $capitalized_name$(int index) {\r\n"
+ " return $name$_ [index];\r\n"
"}\r\n");
}
@@ -193,48 +194,47 @@ GenerateBuilderMembers(io::Printer* printer) const {
// could hold on to the returned list and modify it after the message
// has been built, thus mutating the message which is supposed to be
// immutable.
- "public java.util.List<$type$> get$capitalized_name$List() {\r\n"
- " return java.util.Collections.unmodifiableList(result.$name$_);\r\n"
+ "public System.Collections.Generic.IList<$type$> Get$capitalized_name$List() {\r\n"
+ " if (result.$name$_ == $type$.Empty$capitalized_name$)\r\n"
+ " return result.$name$;\r\n"
+ " return result.$name$_.AsReadOnly ();\r\n"
"}\r\n"
- "public int get$capitalized_name$Count() {\r\n"
- " return result.get$capitalized_name$Count();\r\n"
+ "public int Get$capitalized_name$Count() {\r\n"
+ " return result.Get$capitalized_name$Count();\r\n"
"}\r\n"
- "public $type$ get$capitalized_name$(int index) {\r\n"
- " return result.get$capitalized_name$(index);\r\n"
+ "public $type$ Get$capitalized_name$(int index) {\r\n"
+ " return result.Get$capitalized_name$(index);\r\n"
"}\r\n"
- "public Builder set$capitalized_name$(int index, $type$ value) {\r\n"
- " result.$name$_.set(index, value);\r\n"
+ "public Builder Set$capitalized_name$(int index, $type$ value) {\r\n"
+ " result.$name$_ [index] = value;\r\n"
" return this;\r\n"
"}\r\n"
- "public Builder set$capitalized_name$(int index, "
+ "public Builder Set$capitalized_name$(int index, "
"$type$.Builder builderForValue) {\r\n"
- " result.$name$_.set(index, builderForValue.build());\r\n"
+ " result.$name$_ [index] = builderForValue.build();\r\n"
" return this;\r\n"
"}\r\n"
- "public Builder add$capitalized_name$($type$ value) {\r\n"
- " if (result.$name$_.isEmpty()) {\r\n"
- " result.$name$_ = new java.util.ArrayList<$type$>();\r\n"
- " }\r\n"
- " result.$name$_.add(value);\r\n"
+ "public Builder Add$capitalized_name$($type$ value) {\r\n"
+ " if (result.$name$ == $type$.Empty$capitalized_name$)\r\n"
+ " result.$name$ = new System.Collections.Generic.List<$type$>();\r\n"
+ " result.$name$_.Add(value);\r\n"
" return this;\r\n"
"}\r\n"
- "public Builder add$capitalized_name$($type$.Builder builderForValue) {\r\n"
- " if (result.$name$_.isEmpty()) {\r\n"
- " result.$name$_ = new java.util.ArrayList<$type$>();\r\n"
- " }\r\n"
- " result.$name$_.add(builderForValue.build());\r\n"
+ "public Builder Add$capitalized_name$($type$.Builder builderForValue) {\r\n"
+ " if (result.$name$ == $type$.Empty$capitalized_name$)\r\n"
+ " result.$name$ = new System.Collections.Generic.List<$type$>();\r\n"
+ " result.$name$_.Add(builderForValue.build());\r\n"
" return this;\r\n"
"}\r\n"
- "public Builder addAll$capitalized_name$<T>(\r\n"
+ "public Builder AddAll$capitalized_name$<T>(\r\n"
" global::System.Collections.Generic.IEnumerable<T> values) where T : $type$ {\r\n"
- " if (result.$name$_.isEmpty()) {\r\n"
- " result.$name$_ = new java.util.ArrayList<$type$>();\r\n"
- " }\r\n"
- " super.addAll(values, result.$name$_);\r\n"
+ " if (result.$name$ == $type$.Empty$capitalized_name$)\r\n"
+ " result.$name$ = new System.Collections.Generic.List<$type$>();\r\n"
+ " result.$name$_.AddEnumerable (values);\r\n"
" return this;\r\n"
"}\r\n"
- "public Builder clear$capitalized_name$() {\r\n"
- " result.$name$_ = java.util.Collections.emptyList();\r\n"
+ "public Builder Clear$capitalized_name$() {\r\n"
+ " result.$name$_ = $type$.Empty$capitalized_name$;\r\n"
" return this;\r\n"
"}\r\n");
}
@@ -242,20 +242,20 @@ GenerateBuilderMembers(io::Printer* printer) const {
void RepeatedMessageFieldGenerator::
GenerateMergingCode(io::Printer* printer) const {
printer->Print(variables_,
- "if (!other.$name$_.isEmpty()) {\r\n"
- " if (result.$name$_.isEmpty()) {\r\n"
- " result.$name$_ = new java.util.ArrayList<$type$>();\r\n"
+ "if (!other.$name$_ != $type$.Empty$capitalized_name$) {\r\n"
+ " if (result.$name$_ == $type$.Empty$capitalized_name$) {\r\n"
+ " result.$name$_ = new System.Collections.Generic.List<$type$>();\r\n"
" }\r\n"
- " result.$name$_.addAll(other.$name$_);\r\n"
+ " result.$name$_.AddCollection(other.$name$_);\r\n"
"}\r\n");
}
void RepeatedMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const {
printer->Print(variables_,
- "if (result.$name$_ != java.util.Collections.EMPTY_LIST) {\r\n"
+ "if (result.$name$_ != $type$.Empty$capitalized_name$) {\r\n"
" result.$name$_ =\r\n"
- " java.util.Collections.unmodifiableList(result.$name$_);\r\n"
+ " result.$name$_.AsReadOnly ();\r\n"
"}\r\n");
}
@@ -273,13 +273,13 @@ GenerateParsingCode(io::Printer* printer) const {
}
printer->Print(variables_,
- "add$capitalized_name$(subBuilder.buildPartial());\r\n");
+ "Add$capitalized_name$(subBuilder.buildPartial());\r\n");
}
void RepeatedMessageFieldGenerator::
GenerateSerializationCode(io::Printer* printer) const {
printer->Print(variables_,
- "for ($type$ element : get$capitalized_name$List()) {\r\n"
+ "foreach ($type$ element in Get$capitalized_name$List()) {\r\n"
" output.write$group_or_message$($number$, element);\r\n"
"}\r\n");
}
@@ -287,7 +287,7 @@ GenerateSerializationCode(io::Printer* printer) const {
void RepeatedMessageFieldGenerator::
GenerateSerializedSizeCode(io::Printer* printer) const {
printer->Print(variables_,
- "for ($type$ element : get$capitalized_name$List()) {\r\n"
+ "foreach ($type$ element in Get$capitalized_name$List()) {\r\n"
" size += pb::CodedOutputStream\r\n"
" .compute$group_or_message$Size($number$, element);\r\n"
"}\r\n");
diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
index c504fd5b..d86219e9 100644
--- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
@@ -102,12 +102,11 @@ string DefaultValue(const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_INT32:
return SimpleItoa(field->default_value_int32());
case FieldDescriptor::CPPTYPE_UINT32:
- // Need to print as a signed int since Java has no unsigned.
- return SimpleItoa(static_cast<int32>(field->default_value_uint32()));
+ return SimpleItoa(field->default_value_uint32());
case FieldDescriptor::CPPTYPE_INT64:
return SimpleItoa(field->default_value_int64()) + "L";
case FieldDescriptor::CPPTYPE_UINT64:
- return SimpleItoa(static_cast<int64>(field->default_value_uint64())) +
+ return SimpleItoa(field->default_value_uint64()) +
"L";
case FieldDescriptor::CPPTYPE_DOUBLE:
return SimpleDtoa(field->default_value_double()) + "D";
diff --git a/src/google/protobuf/compiler/csharp/csharp_service.cc b/src/google/protobuf/compiler/csharp/csharp_service.cc
index 52d92b2b..8b235135 100644
--- a/src/google/protobuf/compiler/csharp/csharp_service.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_service.cc
@@ -211,7 +211,7 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) {
" $output$.getDefaultInstance(),\r\n"
" pb::RpcUtil.generalizeCallback(\r\n"
" done,\r\n"
- " $output$.class,\r\n"
+ " typeof ($output$),\r\n"
" $output$.getDefaultInstance()));\r\n"
"}\r\n");
}