Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
f5242682
Commit
f5242682
authored
Jun 05, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First stab at new proto3-only code generator
parent
8fe039a6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
112 additions
and
1192 deletions
+112
-1192
Makefile.am
src/Makefile.am
+1
-5
csharp_enum.cc
src/google/protobuf/compiler/csharp/csharp_enum.cc
+1
-1
csharp_enum_field.cc
src/google/protobuf/compiler/csharp/csharp_enum_field.cc
+13
-36
csharp_extension.cc
src/google/protobuf/compiler/csharp/csharp_extension.cc
+0
-184
csharp_extension.h
src/google/protobuf/compiler/csharp/csharp_extension.h
+0
-78
csharp_field_base.cc
src/google/protobuf/compiler/csharp/csharp_field_base.cc
+4
-33
csharp_field_base.h
src/google/protobuf/compiler/csharp/csharp_field_base.h
+0
-5
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+0
-0
csharp_message.h
src/google/protobuf/compiler/csharp/csharp_message.h
+1
-13
csharp_message_field.cc
src/google/protobuf/compiler/csharp/csharp_message_field.cc
+0
-0
csharp_message_field.h
src/google/protobuf/compiler/csharp/csharp_message_field.h
+0
-6
csharp_primitive_field.cc
...google/protobuf/compiler/csharp/csharp_primitive_field.cc
+40
-137
csharp_primitive_field.h
src/google/protobuf/compiler/csharp/csharp_primitive_field.h
+3
-6
csharp_repeated_enum_field.cc
...le/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
+15
-116
csharp_repeated_enum_field.h
...gle/protobuf/compiler/csharp/csharp_repeated_enum_field.h
+2
-4
csharp_repeated_message_field.cc
...protobuf/compiler/csharp/csharp_repeated_message_field.cc
+14
-106
csharp_repeated_message_field.h
.../protobuf/compiler/csharp/csharp_repeated_message_field.h
+0
-4
csharp_repeated_primitive_field.cc
...otobuf/compiler/csharp/csharp_repeated_primitive_field.cc
+14
-105
csharp_repeated_primitive_field.h
...rotobuf/compiler/csharp/csharp_repeated_primitive_field.h
+0
-4
csharp_source_generator_base.cc
.../protobuf/compiler/csharp/csharp_source_generator_base.cc
+0
-8
csharp_source_generator_base.h
...e/protobuf/compiler/csharp/csharp_source_generator_base.h
+0
-17
csharp_umbrella_class.cc
src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
+4
-84
csharp_umbrella_class.h
src/google/protobuf/compiler/csharp/csharp_umbrella_class.h
+0
-7
csharp_writer.cc
src/google/protobuf/compiler/csharp/csharp_writer.cc
+0
-136
csharp_writer.h
src/google/protobuf/compiler/csharp/csharp_writer.h
+0
-93
libprotoc.vcproj
vsprojects/libprotoc.vcproj
+0
-4
No files found.
src/Makefile.am
View file @
f5242682
...
...
@@ -369,8 +369,6 @@ libprotoc_la_SOURCES = \
google/protobuf/compiler/csharp/csharp_enum.h
\
google/protobuf/compiler/csharp/csharp_enum_field.cc
\
google/protobuf/compiler/csharp/csharp_enum_field.h
\
google/protobuf/compiler/csharp/csharp_extension.cc
\
google/protobuf/compiler/csharp/csharp_extension.h
\
google/protobuf/compiler/csharp/csharp_field_base.cc
\
google/protobuf/compiler/csharp/csharp_field_base.h
\
google/protobuf/compiler/csharp/csharp_generator.cc
\
...
...
@@ -391,9 +389,7 @@ libprotoc_la_SOURCES = \
google/protobuf/compiler/csharp/csharp_source_generator_base.cc
\
google/protobuf/compiler/csharp/csharp_source_generator_base.h
\
google/protobuf/compiler/csharp/csharp_umbrella_class.cc
\
google/protobuf/compiler/csharp/csharp_umbrella_class.h
\
google/protobuf/compiler/csharp/csharp_writer.cc
\
google/protobuf/compiler/csharp/csharp_writer.h
google/protobuf/compiler/csharp/csharp_umbrella_class.h
bin_PROGRAMS
=
protoc
protoc_LDADD
=
$(PTHREAD_LIBS)
libprotobuf.la libprotoc.la
...
...
src/google/protobuf/compiler/csharp/csharp_enum.cc
View file @
f5242682
...
...
@@ -58,7 +58,7 @@ EnumGenerator::~EnumGenerator() {
void
EnumGenerator
::
Generate
(
io
::
Printer
*
printer
)
{
WriteGeneratedCodeAttributes
(
printer
);
printer
->
Print
(
"$access_level$ enum $name$ {
\n
"
,
printer
->
Print
(
"$access_level$ enum $name$
: long
{
\n
"
,
"access_level"
,
class_access_level
(),
"name"
,
descriptor_
->
name
());
printer
->
Indent
();
...
...
src/google/protobuf/compiler/csharp/csharp_enum_field.cc
View file @
f5242682
...
...
@@ -55,36 +55,22 @@ EnumFieldGenerator::~EnumFieldGenerator() {
void
EnumFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"object unknown;
\n
"
"if(input.ReadEnum(ref result.$name$_, out unknown)) {
\n
"
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
" result.has$property_name$ = true;
\n
"
);
}
printer
->
Print
(
"} else if(unknown is int) {
\n
"
);
if
(
!
use_lite_runtime
())
{
printer
->
Print
(
variables_
,
" if (unknownFields == null) {
\n
"
// First unknown field - create builder now
" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
\n
"
" }
\n
"
" unknownFields.MergeVarintField($number$, (ulong)(int)unknown);
\n
"
);
}
printer
->
Print
(
"}
\n
"
);
"input.ReadEnum(ref $name$_);
\n
"
);
}
void
EnumFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if ($has_property_check$) {
\n
"
" output.WriteEnum($number$, field_names[$field_ordinal$], (int
) $property_name$, $property_name$);
\n
"
"}
\n
"
);
"if ($has_property_check$) {
\n
"
" output.WriteEnum($number$, fieldNames[$field_ordinal$], (long
) $property_name$, $property_name$);
\n
"
"}
\n
"
);
}
void
EnumFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if ($has_property_check$) {
\n
"
" size += pb::CodedOutputStream.ComputeEnumSize($number$, (int
) $property_name$);
\n
"
"}
\n
"
);
variables_
,
"if ($has_property_check$) {
\n
"
" size += pb::CodedOutputStream.ComputeEnumSize($number$, (long
) $property_name$);
\n
"
"}
\n
"
);
}
EnumOneofFieldGenerator
::
EnumOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
...
...
@@ -96,30 +82,21 @@ EnumOneofFieldGenerator::~EnumOneofFieldGenerator() {
}
void
EnumOneofFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): What about if we read the default value?
printer
->
Print
(
variables_
,
"object unknown;
\n
"
"$type_name$ enumValue = $default_value$;
\n
"
"if(input.ReadEnum(ref enumValue
, out unknown
)) {
\n
"
"if(input.ReadEnum(ref enumValue)) {
\n
"
" result.$oneof_name$_ = enumValue;
\n
"
" result.$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
"} else if(unknown is int) {
\n
"
);
if
(
!
use_lite_runtime
())
{
printer
->
Print
(
variables_
,
" if (unknownFields == null) {
\n
"
// First unknown field - create builder now
" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
\n
"
" }
\n
"
" unknownFields.MergeVarintField($number$, (ulong)(int)unknown);
\n
"
);
}
printer
->
Print
(
"}
\n
"
);
"}
\n
"
);
}
void
EnumOneofFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if ($has_property_check$) {
\n
"
" output.WriteEnum($number$, field
_names[$field_ordinal$], (int
) $property_name$, $property_name$);
\n
"
" output.WriteEnum($number$, field
Names[$field_ordinal$], (long
) $property_name$, $property_name$);
\n
"
"}
\n
"
);
}
...
...
@@ -127,7 +104,7 @@ void EnumOneofFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {
printer
->
Print
(
variables_
,
"if ($has_property_check$) {
\n
"
" size += pb::CodedOutputStream.ComputeEnumSize($number$, (
int
) $property_name$);
\n
"
" size += pb::CodedOutputStream.ComputeEnumSize($number$, (
long
) $property_name$);
\n
"
"}
\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_extension.cc
deleted
100644 → 0
View file @
8fe039a6
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/compiler/csharp/csharp_extension.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
using
google
::
protobuf
::
internal
::
scoped_ptr
;
namespace
google
{
namespace
protobuf
{
namespace
compiler
{
namespace
csharp
{
ExtensionGenerator
::
ExtensionGenerator
(
const
FieldDescriptor
*
descriptor
)
:
FieldGeneratorBase
(
descriptor
,
0
)
{
if
(
descriptor_
->
extension_scope
())
{
variables_
[
"scope"
]
=
GetClassName
(
descriptor_
->
extension_scope
());
}
else
{
variables_
[
"scope"
]
=
GetFullUmbrellaClassName
(
descriptor_
->
file
());
}
variables_
[
"extends"
]
=
GetClassName
(
descriptor_
->
containing_type
());
variables_
[
"capitalized_type_name"
]
=
capitalized_type_name
();
variables_
[
"full_name"
]
=
descriptor_
->
full_name
();
variables_
[
"access_level"
]
=
class_access_level
();
variables_
[
"index"
]
=
SimpleItoa
(
descriptor_
->
index
());
variables_
[
"property_name"
]
=
property_name
();
variables_
[
"type_name"
]
=
type_name
();
if
(
use_lite_runtime
())
{
variables_
[
"generated_extension"
]
=
descriptor_
->
is_repeated
()
?
"GeneratedRepeatExtensionLite"
:
"GeneratedExtensionLite"
;
}
else
{
variables_
[
"generated_extension"
]
=
descriptor_
->
is_repeated
()
?
"GeneratedRepeatExtension"
:
"GeneratedExtension"
;
}
}
ExtensionGenerator
::~
ExtensionGenerator
()
{
}
void
ExtensionGenerator
::
Generate
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"public const int $constant_name$ = $number$;
\n
"
,
"constant_name"
,
GetFieldConstantName
(
descriptor_
),
"number"
,
SimpleItoa
(
descriptor_
->
number
()));
if
(
use_lite_runtime
())
{
// TODO(jtattermusch): include the following check
//if (Descriptor.MappedType == MappedType.Message && Descriptor.MessageType.Options.MessageSetWireFormat)
//{
// throw new ArgumentException(
// "option message_set_wire_format = true; is not supported in Lite runtime extensions.");
//}
printer
->
Print
(
variables_
,
"$access_level$ static pb::$generated_extension$<$extends$, $type_name$> $property_name$;
\n
"
);
}
else
if
(
descriptor_
->
is_repeated
())
{
printer
->
Print
(
variables_
,
"$access_level$ static pb::GeneratedExtensionBase<scg::IList<$type_name$>> $property_name$;
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"$access_level$ static pb::GeneratedExtensionBase<$type_name$> $property_name$;
\n
"
);
}
}
void
ExtensionGenerator
::
GenerateStaticVariableInitializers
(
io
::
Printer
*
printer
)
{
if
(
use_lite_runtime
())
{
printer
->
Print
(
variables_
,
"$scope$.$property_name$ =
\n
"
);
printer
->
Indent
();
printer
->
Print
(
variables_
,
"new pb::$generated_extension$<$extends$, $type_name$>(
\n
"
);
printer
->
Indent
();
printer
->
Print
(
variables_
,
"
\"
$full_name$
\"
,
\n
"
"$extends$.DefaultInstance,
\n
"
);
if
(
!
descriptor_
->
is_repeated
())
{
std
::
string
default_val
;
if
(
descriptor_
->
has_default_value
())
{
default_val
=
default_value
();
}
else
{
default_val
=
is_nullable_type
()
?
"null"
:
(
"default("
+
type_name
()
+
")"
);
}
printer
->
Print
(
"$default_val$,
\n
"
,
"default_val"
,
default_val
);
}
printer
->
Print
(
"$message_val$,
\n
"
,
"message_val"
,
(
GetCSharpType
(
descriptor_
->
type
())
==
CSHARPTYPE_MESSAGE
)
?
type_name
()
+
".DefaultInstance"
:
"null"
);
printer
->
Print
(
"$enum_val$,
\n
"
,
"enum_val"
,
(
GetCSharpType
(
descriptor_
->
type
())
==
CSHARPTYPE_ENUM
)
?
"new EnumLiteMap<"
+
type_name
()
+
">()"
:
"null"
);
printer
->
Print
(
variables_
,
"$scope$.$property_name$FieldNumber,
\n
"
"pbd::FieldType.$capitalized_type_name$"
);
if
(
descriptor_
->
is_repeated
())
{
printer
->
Print
(
",
\n
"
"$is_packed$"
,
"is_packed"
,
descriptor_
->
is_packed
()
?
"true"
:
"false"
);
}
printer
->
Outdent
();
printer
->
Print
(
");
\n
"
);
printer
->
Outdent
();
}
else
if
(
descriptor_
->
is_repeated
())
{
printer
->
Print
(
variables_
,
"$scope$.$property_name$ = pb::GeneratedRepeatExtension<$type_name$>.CreateInstance($scope$.Descriptor.Extensions[$index$]);
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"$scope$.$property_name$ = pb::GeneratedSingleExtension<$type_name$>.CreateInstance($scope$.Descriptor.Extensions[$index$]);
\n
"
);
}
}
void
ExtensionGenerator
::
GenerateExtensionRegistrationCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"registry.Add($scope$.$property_name$);
\n
"
);
}
void
ExtensionGenerator
::
WriteHash
(
io
::
Printer
*
printer
)
{
}
void
ExtensionGenerator
::
WriteEquals
(
io
::
Printer
*
printer
)
{
}
void
ExtensionGenerator
::
WriteToString
(
io
::
Printer
*
printer
)
{
}
}
// namespace csharp
}
// namespace compiler
}
// namespace protobuf
}
// namespace google
src/google/protobuf/compiler/csharp/csharp_extension.h
deleted
100644 → 0
View file @
8fe039a6
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_EXTENSION_H__
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_EXTENSION_H__
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
namespace
google
{
namespace
protobuf
{
namespace
compiler
{
namespace
csharp
{
class
ExtensionGenerator
:
public
FieldGeneratorBase
{
public
:
ExtensionGenerator
(
const
FieldDescriptor
*
descriptor
);
~
ExtensionGenerator
();
void
GenerateStaticVariableInitializers
(
io
::
Printer
*
printer
);
void
GenerateExtensionRegistrationCode
(
io
::
Printer
*
printer
);
void
Generate
(
io
::
Printer
*
printer
);
virtual
void
WriteHash
(
io
::
Printer
*
printer
);
virtual
void
WriteEquals
(
io
::
Printer
*
printer
);
virtual
void
WriteToString
(
io
::
Printer
*
printer
);
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
)
{};
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
{};
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
)
{};
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
)
{};
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
)
{};
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{};
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{};
private
:
std
::
string
scope_
;
std
::
string
extends_
;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
ExtensionGenerator
);
};
}
// namespace csharp
}
// namespace compiler
}
// namespace protobuf
}
// namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_EXTENSION_H__
src/google/protobuf/compiler/csharp/csharp_field_base.cc
View file @
f5242682
...
...
@@ -263,37 +263,13 @@ bool AllPrintableAscii(const std::string& text) {
}
std
::
string
FieldGeneratorBase
::
GetStringDefaultValueInternal
()
{
if
(
!
descriptor_
->
has_default_value
())
{
return
"
\"\"
"
;
}
if
(
AllPrintableAscii
(
descriptor_
->
default_value_string
()))
{
// All chars are ASCII and printable. In this case we only
// need to escape quotes and backslashes.
std
::
string
temp
=
descriptor_
->
default_value_string
();
temp
=
StringReplace
(
temp
,
"
\\
"
,
"
\\\\
"
,
true
);
temp
=
StringReplace
(
temp
,
"'"
,
"
\\
'"
,
true
);
temp
=
StringReplace
(
temp
,
"
\"
"
,
"
\\\"
"
,
true
);
return
"
\"
"
+
temp
+
"
\"
"
;
}
if
(
use_lite_runtime
())
{
return
"pb::ByteString.FromBase64(
\"
"
+
StringToBase64
(
descriptor_
->
default_value_string
())
+
"
\"
).ToStringUtf8()"
;
}
return
"(string) "
+
GetClassName
(
descriptor_
->
containing_type
())
+
".Descriptor.Fields["
+
SimpleItoa
(
descriptor_
->
index
())
+
"].DefaultValue"
;
// No other default values needed for proto3...
return
"
\"\"
"
;
}
std
::
string
FieldGeneratorBase
::
GetBytesDefaultValueInternal
()
{
if
(
!
descriptor_
->
has_default_value
())
{
return
"pb::ByteString.Empty"
;
}
if
(
use_lite_runtime
())
{
return
"pb::ByteString.FromBase64(
\"
"
+
StringToBase64
(
descriptor_
->
default_value_string
())
+
"
\"
)"
;
}
return
"(pb::ByteString) "
+
GetClassName
(
descriptor_
->
containing_type
())
+
".Descriptor.Fields["
+
SimpleItoa
(
descriptor_
->
index
())
+
"].DefaultValue"
;
// No other default values needed for proto3...
return
"pb::ByteString.Empty"
;
}
std
::
string
FieldGeneratorBase
::
default_value
()
{
...
...
@@ -365,11 +341,6 @@ std::string FieldGeneratorBase::number() {
return
SimpleItoa
(
descriptor_
->
number
());
}
std
::
string
FieldGeneratorBase
::
message_or_group
()
{
return
(
descriptor_
->
type
()
==
FieldDescriptor
::
TYPE_GROUP
)
?
"Group"
:
"Message"
;
}
std
::
string
FieldGeneratorBase
::
capitalized_type_name
()
{
switch
(
descriptor_
->
type
())
{
case
FieldDescriptor
:
:
TYPE_ENUM
:
...
...
src/google/protobuf/compiler/csharp/csharp_field_base.h
View file @
f5242682
...
...
@@ -42,17 +42,13 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
FieldGeneratorBase
:
public
SourceGeneratorBase
{
public
:
FieldGeneratorBase
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
);
~
FieldGeneratorBase
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
=
0
;
...
...
@@ -82,7 +78,6 @@ class FieldGeneratorBase : public SourceGeneratorBase {
bool
is_nullable_type
();
std
::
string
default_value
();
std
::
string
number
();
std
::
string
message_or_group
();
std
::
string
capitalized_type_name
();
std
::
string
field_ordinal
();
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
f5242682
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_message.h
View file @
f5242682
...
...
@@ -43,7 +43,6 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
FieldGeneratorBase
;
class
MessageGenerator
:
public
SourceGeneratorBase
{
...
...
@@ -53,7 +52,6 @@ class MessageGenerator : public SourceGeneratorBase {
void
GenerateStaticVariables
(
io
::
Printer
*
printer
);
void
GenerateStaticVariableInitializers
(
io
::
Printer
*
printer
);
void
GenerateExtensionRegistrationCode
(
io
::
Printer
*
printer
);
void
Generate
(
io
::
Printer
*
printer
);
private
:
...
...
@@ -61,17 +59,8 @@ class MessageGenerator : public SourceGeneratorBase {
std
::
vector
<
std
::
string
>
field_names_
;
std
::
vector
<
const
FieldDescriptor
*>
fields_by_number_
;
void
GenerateLiteRuntimeMethods
(
io
::
Printer
*
printer
);
void
GenerateMessageSerializationMethods
(
io
::
Printer
*
printer
);
void
GenerateSerializeOneField
(
io
::
Printer
*
printer
,
const
FieldDescriptor
*
fieldDescriptor
);
void
GenerateSerializeOneExtensionRange
(
io
::
Printer
*
printer
,
const
Descriptor
::
ExtensionRange
*
extendsionRange
);
void
GenerateParseFromMethods
(
io
::
Printer
*
printer
);
void
GenerateBuilder
(
io
::
Printer
*
printer
);
void
GenerateCommonBuilderMethods
(
io
::
Printer
*
printer
);
void
GenerateBuilderParsingMethods
(
io
::
Printer
*
printer
);
void
GenerateIsInitialized
(
io
::
Printer
*
printer
);
void
GenerateMergingMethods
(
io
::
Printer
*
printer
);
int
GetFieldOrdinal
(
const
FieldDescriptor
*
descriptor
);
FieldGeneratorBase
*
CreateFieldGeneratorInternal
(
...
...
@@ -95,4 +84,3 @@ class MessageGenerator : public SourceGeneratorBase {
}
// namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_H__
src/google/protobuf/compiler/csharp/csharp_message_field.cc
View file @
f5242682
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_message_field.h
View file @
f5242682
...
...
@@ -41,17 +41,13 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
MessageFieldGenerator
:
public
FieldGeneratorBase
{
public
:
MessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
);
~
MessageFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
);
...
...
@@ -70,8 +66,6 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
~
MessageOneofFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
WriteEquals
(
io
::
Printer
*
printer
);
virtual
void
WriteToString
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
View file @
f5242682
...
...
@@ -49,82 +49,37 @@ namespace csharp {
PrimitiveFieldGenerator
::
PrimitiveFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
)
:
FieldGeneratorBase
(
descriptor
,
fieldOrdinal
)
{
// TODO(jonskeet): Make this cleaner...
is_value_type
=
descriptor
->
type
()
!=
FieldDescriptor
::
TYPE_STRING
&&
descriptor
->
type
()
!=
FieldDescriptor
::
TYPE_BYTES
;
}
PrimitiveFieldGenerator
::~
PrimitiveFieldGenerator
()
{
}
void
PrimitiveFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
{
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
"private bool has$property_name$;
\n
"
);
}
// TODO(jonskeet): Work out whether we want to prevent the fields from ever being
// null, or whether we just handle it, in the cases of bytes and string.
// (Basically, should null-handling code be in the getter or the setter?)
printer
->
Print
(
variables_
,
"private $type_name$ $name_def_message$;
\n
"
);
AddDeprecatedFlag
(
printer
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
"public bool Has$property_name$ {
\n
"
" get { return has$property_name$; }
\n
"
"}
\n
"
);
}
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ $property_name$ {
\n
"
" get { return $name$_; }
\n
"
"}
\n
"
);
}
void
PrimitiveFieldGenerator
::
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
{
AddDeprecatedFlag
(
printer
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
"public bool Has$property_name$ {
\n
"
" get { return result.has$property_name$; }
\n
"
"}
\n
"
);
}
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ $property_name$ {
\n
"
" get { return result.$property_name$; }
\n
"
" set { Set$property_name$(value); }
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Set$property_name$($type_name$ value) {
\n
"
);
AddNullCheck
(
printer
);
printer
->
Print
(
" PrepareBuilder();
\n
"
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
" get { return $name$_; }
\n
"
);
if
(
is_value_type
)
{
printer
->
Print
(
variables_
,
" result.has$property_name$ = true;
\n
"
);
}
printer
->
Print
(
variables_
,
" result.$name$_ = value;
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Clear$property_name$() {
\n
"
" PrepareBuilder();
\n
"
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
" set { $name$_ = value; }
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"
result.has$property_name$ = false;
\n
"
);
"
set { $name$_ = value ?? $default_value$; }
\n
"
);
}
printer
->
Print
(
variables_
,
" result.$name$_ = $default_value$;
\n
"
" return this;
\n
"
"}
\n
"
);
printer
->
Print
(
"}
\n\n
"
);
}
void
PrimitiveFieldGenerator
::
GenerateMergingCode
(
io
::
Printer
*
printer
)
{
...
...
@@ -135,27 +90,17 @@ void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) {
"}
\n
"
);
}
void
PrimitiveFieldGenerator
::
GenerateBuildingCode
(
io
::
Printer
*
printer
)
{
// Nothing to do here for primitive types
}
void
PrimitiveFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
"result.has$property_name$ = input.Read$capitalized_type_name$(ref result.$name$_);
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"input.Read$capitalized_type_name$(ref result.$name$_);
\n
"
);
}
printer
->
Print
(
variables_
,
"input.Read$capitalized_type_name$(ref result.$name$_);
\n
"
);
}
void
PrimitiveFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if ($has_property_check$) {
\n
"
" output.Write$capitalized_type_name$($number$, field
_n
ames[$field_ordinal$], $property_name$);
\n
"
" output.Write$capitalized_type_name$($number$, field
N
ames[$field_ordinal$], $property_name$);
\n
"
"}
\n
"
);
}
...
...
@@ -171,24 +116,18 @@ void PrimitiveFieldGenerator::WriteHash(io::Printer* printer) {
printer
->
Print
(
variables_
,
"if ($has_property_check$) {
\n
"
" hash ^= $
name$_
.GetHashCode();
\n
"
" hash ^= $
property_name$
.GetHashCode();
\n
"
"}
\n
"
);
}
void
PrimitiveFieldGenerator
::
WriteEquals
(
io
::
Printer
*
printer
)
{
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
"if (has$property_name$ != other.has$property_name$ || (has$property_name$ && !$name$_.Equals(other.$name$_))) return false;
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"if (!$name$_.Equals(other.$name$_)) return false;
\n
"
);
}
printer
->
Print
(
variables_
,
"if ($property_name$ != other.$property_name$) return false;
\n
"
);
}
void
PrimitiveFieldGenerator
::
WriteToString
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"PrintField(
\"
$descriptor_name$
\"
, $has_property_check$, $
name$_
, writer);
\n
"
);
"PrintField(
\"
$descriptor_name$
\"
, $has_property_check$, $
property_name$
, writer);
\n
"
);
}
PrimitiveOneofFieldGenerator
::
PrimitiveOneofFieldGenerator
(
...
...
@@ -201,79 +140,43 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {
}
void
PrimitiveOneofFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): What should foo.OneofIntField = 0; do? Clear the oneof?
// Currently foo.OneOfStringField = null will clear the oneof, but foo.OneOfStringField = "" won't. Ick.
AddDeprecatedFlag
(
printer
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
printer
->
Print
(
variables_
,
"public bool Has$property_name$ {
\n
"
" get { return $has_property_check$; }
\n
"
"}
\n
"
);
}
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ $property_name$ {
\n
"
" get { return $has_property_check$ ? ($type_name$) $oneof_name$_ : $default_value$; }
\n
"
"}
\n
"
);
}
void
PrimitiveOneofFieldGenerator
::
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
{
AddDeprecatedFlag
(
printer
);
if
(
SupportFieldPresence
(
descriptor_
->
file
()))
{
" set {"
);
if
(
is_value_type
)
{
printer
->
Print
(
variables_
,
" $oneof_name$_ = value;
\n
"
" $oneof_name$Case_ = $oneof_property_name$Case.$property_name$;
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
" $oneof_name$_ = value ?? $default_value$;
\n
"
" $oneof_name$Case_ = value == null ? $oneof_property_name$Case.None : $oneof_property_name$Case.$property_name$;
\n
"
);
}
printer
->
Print
(
variables_
,
"public bool Has$property_name$ {
\n
"
" get { return result.$has_property_check$; }
\n
"
" }
\n
"
"}
\n
"
);
}
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ $property_name$ {
\n
"
" get { return result.$has_property_check$ ? ($type_name$) result.$oneof_name$_ : $default_value$; }
\n
"
" set { Set$property_name$(value); }
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Set$property_name$($type_name$ value) {
\n
"
);
AddNullCheck
(
printer
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$oneof_name$_ = value;
\n
"
" result.$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Clear$property_name$() {
\n
"
" PrepareBuilder();
\n
"
" if (result.$has_property_check$) {
\n
"
" result.$oneof_name$Case_ = $oneof_property_name$OneofCase.None;
\n
"
" }
\n
"
" return this;
\n
"
"}
\n
"
);
}
void
PrimitiveOneofFieldGenerator
::
WriteEquals
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if (!$property_name$.Equals(other.$property_name$)) return false;
\n
"
);
}
void
PrimitiveOneofFieldGenerator
::
WriteToString
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"PrintField(
\"
$descriptor_name$
\"
, $has_property_check$, $oneof_name$_, writer);
\n
"
);
}
void
PrimitiveOneofFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): What if the value we read is the default value for the type?
printer
->
Print
(
variables_
,
"$type_name$ value = $default_value$;
\n
"
"if (input.Read$capitalized_type_name$(ref value)) {
\n
"
"
result.
$oneof_name$_ = value;
\n
"
"
result.
$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
" $oneof_name$_ = value;
\n
"
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
"}
\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_primitive_field.h
View file @
f5242682
...
...
@@ -41,17 +41,13 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
PrimitiveFieldGenerator
:
public
FieldGeneratorBase
{
public
:
PrimitiveFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
);
~
PrimitiveFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
);
...
...
@@ -60,6 +56,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
virtual
void
WriteEquals
(
io
::
Printer
*
printer
);
virtual
void
WriteToString
(
io
::
Printer
*
printer
);
protected
:
bool
is_value_type
;
private
:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
PrimitiveFieldGenerator
);
};
...
...
@@ -70,8 +69,6 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
~
PrimitiveOneofFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
WriteEquals
(
io
::
Printer
*
printer
);
virtual
void
WriteToString
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
View file @
f5242682
...
...
@@ -56,141 +56,46 @@ RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {
}
void
RepeatedEnumFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
{
if
(
descriptor_
->
is_packed
()
&&
optimize_speed
())
{
printer
->
Print
(
variables_
,
"private int $name$MemoizedSerializedSize;
\n
"
);
}
printer
->
Print
(
variables_
,
"private pbc::PopsicleList<$type_name$> $name$_ = new pbc::PopsicleList<$type_name$>();
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public scg::IList<$type_name$> $property_name$List {
\n
"
" get { return pbc::Lists.AsReadOnly($name$_); }
\n
"
"}
\n
"
);
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public int $property_name$Count {
\n
"
" get { return $name$_.Count; }
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ Get$property_name$(int index) {
\n
"
" return $name$_[index];
\n
"
"}
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
{
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public pbc::IPopsicleList<$type_name$> $property_name$List {
\n
"
" get { return PrepareBuilder().$name$_; }
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public int $property_name$Count {
\n
"
" get { return result.$property_name$Count; }
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ Get$property_name$(int index) {
\n
"
" return result.Get$property_name$(index);
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Set$property_name$(int index, $type_name$ value) {
\n
"
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_[index] = value;
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Add$property_name$($type_name$ value) {
\n
"
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_.Add(value);
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder AddRange$property_name$(scg::IEnumerable<$type_name$> values) {
\n
"
" PrepareBuilder();
\n
"
" result.$name$_.Add(values);
\n
"
" return this;
\n
"
"}
\n
"
);
"private readonly pbc::RepeatedField<$type_name$> $name$_ = new pbc::RepeatedField<$type_name$>();
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Clear$property_name$() {
\n
"
" PrepareBuilder();
\n
"
" result.$name$_.Clear();
\n
"
" return this;
\n
"
"public pbc::RepeatedField<$type_name$> $property_name$ {
\n
"
" get { return $name$_; }
\n
"
"}
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
GenerateMergingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if (other.$name$_.Count != 0) {
\n
"
" result.$name$_.Add(other.$name$_);
\n
"
"}
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
GenerateBuildingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"$name$_.MakeReadOnly();
\n
"
);
"$name$_.Add(other.$name$_);
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"scg::ICollection<object> unknownItems;
\n
"
"input.ReadEnumArray<$type_name$>(tag, field_name, result.$name$_, out unknownItems);
\n
"
);
if
(
!
use_lite_runtime
())
{
printer
->
Print
(
variables_
,
"if (unknownItems != null) {
\n
"
" if (unknownFields == null) {
\n
"
" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
\n
"
" }
\n
"
" foreach (object rawValue in unknownItems)
\n
"
" if (rawValue is int)
\n
"
" unknownFields.MergeVarintField($number$, (ulong)(int)rawValue);
\n
"
"}
\n
"
);
}
"input.ReadEnumArray<$type_name$>(tag, fieldName, result.$name$_);
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if ($name$_.Count > 0) {
\n
"
);
printer
->
Indent
();
// TODO(jonskeet): Originally, this checked for Count > 0 first.
// The Write* call should make that cheap though - no need to generate it every time.
if
(
descriptor_
->
is_packed
())
{
printer
->
Print
(
variables_
,
"output.WritePackedEnumArray($number$, field
_names[$field_ordinal$], $name$MemoizedSerializedSize
, $name$_);
\n
"
);
"output.WritePackedEnumArray($number$, field
Names[$field_ordinal$]
, $name$_);
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"output.WriteEnumArray($number$, field
_n
ames[$field_ordinal$], $name$_);
\n
"
);
"output.WriteEnumArray($number$, field
N
ames[$field_ordinal$], $name$_);
\n
"
);
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"{
\n
"
);
printer
->
Indent
();
// TODO(jonskeet): Move all this code into CodedOutputStream? It's a lot to repeat everywhere...
printer
->
Print
(
variables_
,
"int dataSize = 0;
\n
"
...
...
@@ -199,7 +104,7 @@ void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer
printer
->
Print
(
variables_
,
"foreach ($type_name$ element in $name$_) {
\n
"
" dataSize += pb::CodedOutputStream.ComputeEnumSizeNoTag((
int
) element);
\n
"
" dataSize += pb::CodedOutputStream.ComputeEnumSizeNoTag((
long
) element);
\n
"
"}
\n
"
"size += dataSize;
\n
"
);
int
tagSize
=
internal
::
WireFormat
::
TagSize
(
descriptor_
->
number
(),
descriptor_
->
type
());
...
...
@@ -215,11 +120,6 @@ void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
// cache the data size for packed fields.
if
(
descriptor_
->
is_packed
())
{
printer
->
Print
(
variables_
,
"$name$MemoizedSerializedSize = dataSize;
\n
"
);
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
}
...
...
@@ -227,16 +127,15 @@ void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer
void
RepeatedEnumFieldGenerator
::
WriteHash
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"foreach($type_name$ i in $name$_)
\n
"
" hash ^= i.GetHashCode();
\n
"
);
"foreach($type_name$ i in $name$_) {
\n
"
" hash ^= i.GetHashCode();
\n
"
"}
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
WriteEquals
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if($name$_.Count != other.$name$_.Count) return false;
\n
"
"for(int ix=0; ix < $name$_.Count; ix++)
\n
"
" if(!$name$_[ix].Equals(other.$name$_[ix])) return false;
\n
"
);
"if(!$name$_.Equals(other.$name$)) return false;
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
WriteToString
(
io
::
Printer
*
printer
)
{
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
View file @
f5242682
...
...
@@ -41,17 +41,15 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
// TODO(jonskeet): Refactor repeated field support; all the implementations are *really* similar. We
// should probably have a RepeatedFieldGeneratorBase.
class
RepeatedEnumFieldGenerator
:
public
FieldGeneratorBase
{
public
:
RepeatedEnumFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
);
~
RepeatedEnumFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
View file @
f5242682
...
...
@@ -48,7 +48,6 @@ namespace csharp {
RepeatedMessageFieldGenerator
::
RepeatedMessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
)
:
FieldGeneratorBase
(
descriptor
,
fieldOrdinal
)
{
variables_
[
"message_or_group"
]
=
message_or_group
();
}
RepeatedMessageFieldGenerator
::~
RepeatedMessageFieldGenerator
()
{
...
...
@@ -58,11 +57,11 @@ RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {
void
RepeatedMessageFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"private
pbc::PopsicleList<$type_name$> $name$_ = new pbc::PopsicleList
<$type_name$>();
\n
"
);
"private
readonly pbc::RepeatedField<$type_name$> $name$_ = new pbc::RepeatedField
<$type_name$>();
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public
scg::IList<$type_name$> $property_name$List
{
\n
"
"public
pbc::RepeatedField<$type_name$> $property_name$
{
\n
"
" get { return $name$_; }
\n
"
"}
\n
"
);
...
...
@@ -82,137 +81,46 @@ void RepeatedMessageFieldGenerator::GenerateMembers(io::Printer* printer) {
"}
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
{
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public pbc::IPopsicleList<$type_name$> $property_name$List {
\n
"
" get { return PrepareBuilder().$name$_; }
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public int $property_name$Count {
\n
"
" get { return result.$property_name$Count; }
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ Get$property_name$(int index) {
\n
"
" return result.Get$property_name$(index);
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Set$property_name$(int index, $type_name$ value) {
\n
"
);
AddNullCheck
(
printer
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_[index] = value;
\n
"
" return this;
\n
"
"}
\n
"
);
// Extra overload for builder (just on messages)
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Set$property_name$(int index, $type_name$.Builder builderForValue) {
\n
"
);
AddNullCheck
(
printer
,
"builderForValue"
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_[index] = builderForValue.Build();
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Add$property_name$($type_name$ value) {
\n
"
);
AddNullCheck
(
printer
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_.Add(value);
\n
"
" return this;
\n
"
"}
\n
"
);
// Extra overload for builder (just on messages)
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Add$property_name$($type_name$.Builder builderForValue) {
\n
"
);
AddNullCheck
(
printer
,
"builderForValue"
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_.Add(builderForValue.Build());
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder AddRange$property_name$(scg::IEnumerable<$type_name$> values) {
\n
"
" PrepareBuilder();
\n
"
" result.$name$_.Add(values);
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Clear$property_name$() {
\n
"
" PrepareBuilder();
\n
"
" result.$name$_.Clear();
\n
"
" return this;
\n
"
"}
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
GenerateMergingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if (other.$name$_.Count != 0) {
\n
"
" result.$name$_.Add(other.$name$_);
\n
"
"}
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
GenerateBuildingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"$name$_.MakeReadOnly();
\n
"
);
"$name$_.Add(other.$name$_);
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"input.Read
$message_or_group$Array(tag, field_name, result.$name$_, $type_name$.DefaultInstance, extensionRegistry
);
\n
"
);
"input.Read
MessageArray(tag, fieldName, $name$_
);
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): Originally, this checked for Count > 0 first.
// The Write* call should make that cheap though - no need to generate it every time.
printer
->
Print
(
variables_
,
"if ($name$_.Count > 0) {
\n
"
" output.Write$message_or_group$Array($number$, field_names[$field_ordinal$], $name$_);
\n
"
"}
\n
"
);
"output.WriteMessageArray($number$, fieldNames[$field_ordinal$], $name$_);
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): Put this into CodedOutputStream.
printer
->
Print
(
variables_
,
"foreach ($type_name$ element in $property_name$
List
) {
\n
"
" size += pb::CodedOutputStream.Compute
$message_or_group$
Size($number$, element);
\n
"
"foreach ($type_name$ element in $property_name$) {
\n
"
" size += pb::CodedOutputStream.Compute
Message
Size($number$, element);
\n
"
"}
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
WriteHash
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"foreach($type_name$ i in $name$_)
\n
"
" hash ^= i.GetHashCode();
\n
"
);
"foreach($type_name$ i in $name$_) {
\n
"
" hash ^= i.GetHashCode();
\n
"
"}
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
WriteEquals
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if($name$_.Count != other.$name$_.Count) return false;
\n
"
"for(int ix=0; ix < $name$_.Count; ix++)
\n
"
" if(!$name$_[ix].Equals(other.$name$_[ix])) return false;
\n
"
);
"if(!$name$_.Equals(other.$name$)) return false;
\n
"
);
}
void
RepeatedMessageFieldGenerator
::
WriteToString
(
io
::
Printer
*
printer
)
{
variables_
[
"field_name"
]
=
GetFieldName
(
descriptor_
);
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
View file @
f5242682
...
...
@@ -41,17 +41,13 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
RepeatedMessageFieldGenerator
:
public
FieldGeneratorBase
{
public
:
RepeatedMessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
);
~
RepeatedMessageFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
View file @
f5242682
...
...
@@ -56,129 +56,43 @@ RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
{
if
(
descriptor_
->
is_packed
()
&&
optimize_speed
())
{
printer
->
Print
(
variables_
,
"private int $name$MemoizedSerializedSize;
\n
"
);
}
printer
->
Print
(
variables_
,
"private pbc::PopsicleList<$type_name$> $name$_ = new pbc::PopsicleList<$type_name$>();
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public scg::IList<$type_name$> $property_name$List {
\n
"
" get { return pbc::Lists.AsReadOnly($name$_); }
\n
"
"}
\n
"
);
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
"private readonly pbc::RepeatedField<$type_name$> $name$_ = new pbc::RepeatedField<$type_name$>();
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public int $property_name$Count {
\n
"
" get { return $name$_.Count; }
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ Get$property_name$(int index) {
\n
"
" return $name$_[index];
\n
"
"}
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
{
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public pbc::IPopsicleList<$type_name$> $property_name$List {
\n
"
" get { return PrepareBuilder().$name$_; }
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public int $property_name$Count {
\n
"
" get { return result.$property_name$Count; }
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public $type_name$ Get$property_name$(int index) {
\n
"
" return result.Get$property_name$(index);
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Set$property_name$(int index, $type_name$ value) {
\n
"
);
AddNullCheck
(
printer
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_[index] = value;
\n
"
" return this;
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Add$property_name$($type_name$ value) {
\n
"
);
AddNullCheck
(
printer
);
printer
->
Print
(
variables_
,
" PrepareBuilder();
\n
"
" result.$name$_.Add(value);
\n
"
" return this;
\n
"
"}
\n
"
);
AddPublicMemberAttributes
(
printer
);
printer
->
Print
(
variables_
,
"public Builder AddRange$property_name$(scg::IEnumerable<$type_name$> values) {
\n
"
" PrepareBuilder();
\n
"
" result.$name$_.Add(values);
\n
"
" return this;
\n
"
"}
\n
"
);
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
"public Builder Clear$property_name$() {
\n
"
" PrepareBuilder();
\n
"
" result.$name$_.Clear();
\n
"
" return this;
\n
"
"public pbc::RepeatedField<$type_name$> $property_name$ {
\n
"
" get { return $name$_; }
\n
"
"}
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateMergingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if (other.$name$_.Count != 0) {
\n
"
" result.$name$_.Add(other.$name$_);
\n
"
"}
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateBuildingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"$name$_.MakeReadOnly();
\n
"
);
"$name$_.Add(other.$name$_);
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"input.Read$capitalized_type_name$Array(tag, field
_name, result.
$name$_);
\n
"
);
"input.Read$capitalized_type_name$Array(tag, field
Name,
$name$_);
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if ($name$_.Count > 0) {
\n
"
);
printer
->
Indent
();
// TODO(jonskeet): Originally, this checked for Count > 0 first.
// The Write* call should make that cheap though - no need to generate it every time.
if
(
descriptor_
->
is_packed
())
{
printer
->
Print
(
variables_
,
"output.WritePacked$capitalized_type_name$Array($number$, field
_names[$field_ordinal$], $name$MemoizedSerializedSize
, $name$_);
\n
"
);
"output.WritePacked$capitalized_type_name$Array($number$, field
Names[$field_ordinal$]
, $name$_);
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"output.Write$capitalized_type_name$Array($number$, field
_n
ames[$field_ordinal$], $name$_);
\n
"
);
"output.Write$capitalized_type_name$Array($number$, field
N
ames[$field_ordinal$], $name$_);
\n
"
);
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): Get rid of most of this - move it into the runtime.
printer
->
Print
(
"{
\n
"
);
printer
->
Indent
();
printer
->
Print
(
"int dataSize = 0;
\n
"
);
...
...
@@ -207,10 +121,6 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializedSizeCode(
"size += $tag_size$ * $name$_.Count;
\n
"
,
"tag_size"
,
SimpleItoa
(
tagSize
),
"name"
,
name
());
}
// cache the data size for packed fields.
if
(
descriptor_
->
is_packed
())
{
printer
->
Print
(
variables_
,
"$name$MemoizedSerializedSize = dataSize;
\n
"
);
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
}
...
...
@@ -218,15 +128,14 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializedSizeCode(
void
RepeatedPrimitiveFieldGenerator
::
WriteHash
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"foreach($type_name$ i in $name$_)
\n
"
" hash ^= i.GetHashCode();
\n
"
);
"foreach($type_name$ i in $name$_)
\n
{"
" hash ^= i.GetHashCode();
\n
"
"}
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
WriteEquals
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
"if($name$_.Count != other.$name$_.Count) return false;
\n
"
"for(int ix=0; ix < $name$_.Count; ix++)
\n
"
" if(!$name$_[ix].Equals(other.$name$_[ix])) return false;
\n
"
);
"if(!$name$_.Equals(other.$name$)) return false;
\n
"
);
}
void
RepeatedPrimitiveFieldGenerator
::
WriteToString
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
variables_
,
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
View file @
f5242682
...
...
@@ -41,17 +41,13 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
RepeatedPrimitiveFieldGenerator
:
public
FieldGeneratorBase
{
public
:
RepeatedPrimitiveFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
);
~
RepeatedPrimitiveFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuilderMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateMergingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateBuildingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializationCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
View file @
f5242682
...
...
@@ -47,14 +47,6 @@ namespace csharp {
SourceGeneratorBase
::
SourceGeneratorBase
(
const
FileDescriptor
*
descriptor
)
:
descriptor_
(
descriptor
)
{
optimizeSize_
=
(
descriptor
->
options
().
optimize_for
()
==
FileOptions
::
CODE_SIZE
);
optimizeSpeed_
=
(
descriptor
->
options
().
optimize_for
()
==
FileOptions
::
SPEED
);
useLiteRuntime_
=
(
descriptor
->
options
().
optimize_for
()
==
FileOptions
::
LITE_RUNTIME
);
optimizeSpeed_
|=
useLiteRuntime_
;
runtimeSuffix_
=
useLiteRuntime_
?
"Lite"
:
""
;
}
SourceGeneratorBase
::~
SourceGeneratorBase
()
{
...
...
src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
View file @
f5242682
...
...
@@ -47,27 +47,10 @@ class SourceGeneratorBase {
std
::
string
class_access_level
();
bool
optimize_size
()
{
return
optimizeSize_
;
}
bool
optimize_speed
()
{
return
optimizeSpeed_
;
}
bool
use_lite_runtime
()
{
return
useLiteRuntime_
;
}
std
::
string
runtime_suffix
()
{
return
runtimeSuffix_
;
}
void
WriteGeneratedCodeAttributes
(
io
::
Printer
*
printer
);
private
:
const
FileDescriptor
*
descriptor_
;
bool
optimizeSize_
;
bool
optimizeSpeed_
;
bool
useLiteRuntime_
;
std
::
string
runtimeSuffix_
;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
SourceGeneratorBase
);
};
...
...
src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
View file @
f5242682
...
...
@@ -39,7 +39,6 @@
#include <google/protobuf/compiler/csharp/csharp_umbrella_class.h>
#include <google/protobuf/compiler/csharp/csharp_enum.h>
#include <google/protobuf/compiler/csharp/csharp_extension.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/compiler/csharp/csharp_message.h>
...
...
@@ -61,18 +60,6 @@ UmbrellaClassGenerator::~UmbrellaClassGenerator() {
void
UmbrellaClassGenerator
::
Generate
(
io
::
Printer
*
printer
)
{
WriteIntroduction
(
printer
);
WriteExtensionRegistration
(
printer
);
// write children: Extensions
if
(
file_
->
extension_count
()
>
0
)
{
printer
->
Print
(
"#region Extensions
\n
"
);
for
(
int
i
=
0
;
i
<
file_
->
extension_count
();
i
++
)
{
ExtensionGenerator
extensionGenerator
(
file_
->
extension
(
i
));
extensionGenerator
.
Generate
(
printer
);
}
printer
->
Print
(
"#endregion
\n
"
);
printer
->
Print
(
"
\n
"
);
}
printer
->
Print
(
"#region Static variables
\n
"
);
for
(
int
i
=
0
;
i
<
file_
->
message_type_count
();
i
++
)
{
...
...
@@ -80,11 +67,7 @@ void UmbrellaClassGenerator::Generate(io::Printer* printer) {
messageGenerator
.
GenerateStaticVariables
(
printer
);
}
printer
->
Print
(
"#endregion
\n
"
);
if
(
!
use_lite_runtime
())
{
WriteDescriptor
(
printer
);
}
else
{
WriteLiteExtensions
(
printer
);
}
WriteDescriptor
(
printer
);
// Close the class declaration.
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
...
...
@@ -134,9 +117,9 @@ void UmbrellaClassGenerator::WriteIntroduction(io::Printer* printer) {
"#pragma warning disable 1591, 0612, 3021
\n
"
"#region Designer generated code
\n
"
"
\n
"
"using pb = global::Google.Proto
colBuffers
;
\n
"
"using pbc = global::Google.Proto
colBuffers
.Collections;
\n
"
"using pbd = global::Google.Proto
colBuffers
.Descriptors;
\n
"
"using pb = global::Google.Proto
buf
;
\n
"
"using pbc = global::Google.Proto
buf
.Collections;
\n
"
"using pbd = global::Google.Proto
buf
.Descriptors;
\n
"
"using scg = global::System.Collections.Generic;
\n
"
,
"file_name"
,
file_
->
name
());
...
...
@@ -165,24 +148,6 @@ void UmbrellaClassGenerator::WriteIntroduction(io::Printer* printer) {
printer
->
Indent
();
}
void
UmbrellaClassGenerator
::
WriteExtensionRegistration
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"#region Extension registration
\n
"
"public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
\n
"
);
printer
->
Indent
();
for
(
int
i
=
0
;
i
<
file_
->
extension_count
();
i
++
)
{
ExtensionGenerator
extensionGenerator
(
file_
->
extension
(
i
));
extensionGenerator
.
GenerateExtensionRegistrationCode
(
printer
);
}
for
(
int
i
=
0
;
i
<
file_
->
message_type_count
();
i
++
)
{
MessageGenerator
messageGenerator
(
file_
->
message_type
(
i
));
messageGenerator
.
GenerateExtensionRegistrationCode
(
printer
);
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
printer
->
Print
(
"#endregion
\n
"
);
}
void
UmbrellaClassGenerator
::
WriteDescriptor
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"#region Descriptor
\n
"
...
...
@@ -219,25 +184,7 @@ void UmbrellaClassGenerator::WriteDescriptor(io::Printer* printer) {
MessageGenerator
messageGenerator
(
file_
->
message_type
(
i
));
messageGenerator
.
GenerateStaticVariableInitializers
(
printer
);
}
for
(
int
i
=
0
;
i
<
file_
->
extension_count
();
i
++
)
{
ExtensionGenerator
extensionGenerator
(
file_
->
extension
(
i
));
extensionGenerator
.
GenerateStaticVariableInitializers
(
printer
);
}
if
(
uses_extensions
())
{
// Must construct an ExtensionRegistry containing all possible extensions
// and return it.
printer
->
Print
(
"pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
\n
"
);
printer
->
Print
(
"RegisterAllExtensions(registry);
\n
"
);
for
(
int
i
=
0
;
i
<
file_
->
dependency_count
();
i
++
)
{
printer
->
Print
(
"$dependency$.RegisterAllExtensions(registry);
\n
"
,
"dependency"
,
GetFullUmbrellaClassName
(
file_
->
dependency
(
i
)));
}
printer
->
Print
(
"return registry;
\n
"
);
}
else
{
printer
->
Print
(
"return null;
\n
"
);
}
printer
->
Outdent
();
printer
->
Print
(
"};
\n
"
);
...
...
@@ -258,33 +205,6 @@ void UmbrellaClassGenerator::WriteDescriptor(io::Printer* printer) {
printer
->
Print
(
"#endregion
\n\n
"
);
}
void
UmbrellaClassGenerator
::
WriteLiteExtensions
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"#region Extensions
\n
"
"internal static readonly object Descriptor;
\n
"
"static $umbrella_class_name$() {
\n
"
,
"umbrella_class_name"
,
umbrellaClassname_
);
printer
->
Indent
();
printer
->
Print
(
"Descriptor = null;
\n
"
);
for
(
int
i
=
0
;
i
<
file_
->
message_type_count
();
i
++
)
{
MessageGenerator
messageGenerator
(
file_
->
message_type
(
i
));
messageGenerator
.
GenerateStaticVariableInitializers
(
printer
);
}
for
(
int
i
=
0
;
i
<
file_
->
extension_count
();
i
++
)
{
ExtensionGenerator
extensionGenerator
(
file_
->
extension
(
i
));
extensionGenerator
.
GenerateStaticVariableInitializers
(
printer
);
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
printer
->
Print
(
"#endregion
\n\n
"
);
}
bool
UmbrellaClassGenerator
::
uses_extensions
()
{
// TODO(jtattermusch): implement recursive descent that looks for extensions.
// For now, we conservatively assume that extensions are used.
return
true
;
}
}
// namespace csharp
}
// namespace compiler
}
// namespace protobuf
...
...
src/google/protobuf/compiler/csharp/csharp_umbrella_class.h
View file @
f5242682
...
...
@@ -41,8 +41,6 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
class
Writer
;
class
UmbrellaClassGenerator
:
public
SourceGeneratorBase
{
public
:
UmbrellaClassGenerator
(
const
FileDescriptor
*
file
);
...
...
@@ -58,11 +56,7 @@ class UmbrellaClassGenerator : public SourceGeneratorBase {
std
::
string
umbrellaNamespace_
;
void
WriteIntroduction
(
io
::
Printer
*
printer
);
void
WriteExtensionRegistration
(
io
::
Printer
*
printer
);
void
WriteDescriptor
(
io
::
Printer
*
printer
);
void
WriteLiteExtensions
(
io
::
Printer
*
printer
);
bool
uses_extensions
();
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
UmbrellaClassGenerator
);
};
...
...
@@ -73,4 +67,3 @@ class UmbrellaClassGenerator : public SourceGeneratorBase {
}
// namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_UMBRELLA_CLASS_H__
src/google/protobuf/compiler/csharp/csharp_writer.cc
deleted
100644 → 0
View file @
8fe039a6
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#include <algorithm>
#include <google/protobuf/stubs/hash.h>
#include <limits>
#include <vector>
#include <google/protobuf/compiler/csharp/csharp_writer.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
#include <google/protobuf/compiler/csharp/csharp_enum_field.h>
#include <google/protobuf/compiler/csharp/csharp_message_field.h>
#include <google/protobuf/compiler/csharp/csharp_primitive_field.h>
#include <google/protobuf/compiler/csharp/csharp_repeated_enum_field.h>
#include <google/protobuf/compiler/csharp/csharp_repeated_message_field.h>
#include <google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h>
namespace
google
{
namespace
protobuf
{
namespace
compiler
{
namespace
csharp
{
Writer
::
Writer
(
google
::
protobuf
::
io
::
Printer
*
printer
)
:
printer_
(
printer
),
newline_
(
"
\n
"
)
{
// TODO(jtattermusch): make newline customizable.
}
Writer
::~
Writer
()
{
}
void
Writer
::
Indent
()
{
printer_
->
Indent
();
}
void
Writer
::
Outdent
()
{
printer_
->
Outdent
();
}
void
Writer
::
Write
(
const
char
*
text
)
{
printer_
->
Print
(
text
);
}
void
Writer
::
Write
(
const
char
*
text
,
const
string
&
value0
)
{
printer_
->
Print
(
text
,
"0"
,
value0
);
}
void
Writer
::
Write
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
)
{
printer_
->
Print
(
text
,
"0"
,
value0
,
"1"
,
value1
);
}
void
Writer
::
Write
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
)
{
printer_
->
Print
(
text
,
"0"
,
value0
,
"1"
,
value1
,
"2"
,
value2
);
}
void
Writer
::
Write
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
,
const
string
&
value3
)
{
printer_
->
Print
(
text
,
"0"
,
value0
,
"1"
,
value1
,
"2"
,
value2
,
"3"
,
value3
);
}
void
Writer
::
WriteLine
()
{
printer_
->
Print
(
newline_
);
}
void
Writer
::
WriteLine
(
const
char
*
text
)
{
Write
(
text
);
WriteLine
();
}
void
Writer
::
WriteLine
(
const
char
*
text
,
const
string
&
value0
)
{
Write
(
text
,
value0
);
WriteLine
();
}
void
Writer
::
WriteLine
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
)
{
Write
(
text
,
value0
,
value1
);
WriteLine
();
}
void
Writer
::
WriteLine
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
)
{
Write
(
text
,
value0
,
value1
,
value2
);
WriteLine
();
}
void
Writer
::
WriteLine
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
,
const
string
&
value3
)
{
Write
(
text
,
value0
,
value1
,
value2
,
value3
);
WriteLine
();
}
}
// namespace java
}
// namespace compiler
}
// namespace protobuf
}
// namespace google
src/google/protobuf/compiler/csharp/csharp_writer.h
deleted
100644 → 0
View file @
8fe039a6
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_WRITER_H__
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_WRITER_H__
#include <string>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/io/printer.h>
namespace
google
{
namespace
protobuf
{
namespace
compiler
{
namespace
csharp
{
// Simple wrapper around Printer that supports customizable line endings
// and number-based variables (e.g. $0$).
class
Writer
{
public
:
Writer
(
io
::
Printer
*
printer
);
~
Writer
();
void
Indent
();
void
Outdent
();
void
Write
(
const
char
*
text
);
void
Write
(
const
char
*
text
,
const
string
&
value0
);
void
Write
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
);
void
Write
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
);
void
Write
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
,
const
string
&
value3
);
void
WriteLine
();
void
WriteLine
(
const
char
*
text
);
void
WriteLine
(
const
char
*
text
,
const
string
&
value0
);
void
WriteLine
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
);
void
WriteLine
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
);
void
WriteLine
(
const
char
*
text
,
const
string
&
value0
,
const
string
&
value1
,
const
string
&
value2
,
const
string
&
value3
);
private
:
io
::
Printer
*
printer_
;
const
char
*
newline_
;
};
}
// namespace csharp
}
// namespace compiler
}
// namespace protobuf
}
// namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_WRITER_H__
vsprojects/libprotoc.vcproj
View file @
f5242682
...
...
@@ -169,7 +169,6 @@
<File
RelativePath=
"..\src\google\protobuf\compiler\cpp\cpp_string_field.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_enum.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_enum_field.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_extension.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_field_base.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_generator.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_helpers.h"
></File>
...
...
@@ -181,7 +180,6 @@
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_repeated_primitive_field.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_source_generator_base.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_umbrella_class.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_writer.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\java\java_context.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\java\java_enum.h"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\java\java_enum_field.h"
></File>
...
...
@@ -269,7 +267,6 @@
<File
RelativePath=
"..\src\google\protobuf\compiler\cpp\cpp_string_field.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_enum.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_enum_field.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_extension.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_field_base.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_generator.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_helpers.cc"
></File>
...
...
@@ -281,7 +278,6 @@
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_repeated_primitive_field.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_source_generator_base.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_umbrella_class.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\csharp\csharp_writer.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\java\java_context.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\java\java_doc_comment.cc"
></File>
<File
RelativePath=
"..\src\google\protobuf\compiler\java\java_enum.cc"
></File>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment