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
cef46e11
Commit
cef46e11
authored
Apr 07, 2016
by
Jon Skeet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1390 from jskeet/tidy-up
Tidy up for C# codegen
parents
28c5c253
2a18bb5a
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
111 additions
and
49 deletions
+111
-49
csharp_enum_field.cc
src/google/protobuf/compiler/csharp/csharp_enum_field.cc
+2
-2
csharp_enum_field.h
src/google/protobuf/compiler/csharp/csharp_enum_field.h
+6
-2
csharp_field_base.cc
src/google/protobuf/compiler/csharp/csharp_field_base.cc
+6
-4
csharp_field_base.h
src/google/protobuf/compiler/csharp/csharp_field_base.h
+3
-1
csharp_generator.cc
src/google/protobuf/compiler/csharp/csharp_generator.cc
+2
-2
csharp_helpers.cc
src/google/protobuf/compiler/csharp/csharp_helpers.cc
+4
-2
csharp_helpers.h
src/google/protobuf/compiler/csharp/csharp_helpers.h
+11
-7
csharp_map_field.cc
src/google/protobuf/compiler/csharp/csharp_map_field.cc
+4
-2
csharp_map_field.h
src/google/protobuf/compiler/csharp/csharp_map_field.h
+3
-1
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+10
-5
csharp_message_field.cc
src/google/protobuf/compiler/csharp/csharp_message_field.cc
+6
-3
csharp_message_field.h
src/google/protobuf/compiler/csharp/csharp_message_field.h
+6
-2
csharp_options.h
src/google/protobuf/compiler/csharp/csharp_options.h
+19
-4
csharp_primitive_field.h
src/google/protobuf/compiler/csharp/csharp_primitive_field.h
+6
-2
csharp_reflection_class.h
...google/protobuf/compiler/csharp/csharp_reflection_class.h
+3
-1
csharp_repeated_enum_field.h
...gle/protobuf/compiler/csharp/csharp_repeated_enum_field.h
+3
-1
csharp_repeated_message_field.cc
...protobuf/compiler/csharp/csharp_repeated_message_field.cc
+4
-2
csharp_repeated_message_field.h
.../protobuf/compiler/csharp/csharp_repeated_message_field.h
+3
-1
csharp_source_generator_base.cc
.../protobuf/compiler/csharp/csharp_source_generator_base.cc
+2
-1
csharp_wrapper_field.cc
src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
+2
-2
csharp_wrapper_field.h
src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
+6
-2
No files found.
src/google/protobuf/compiler/csharp/csharp_enum_field.cc
View file @
cef46e11
...
@@ -81,8 +81,8 @@ void EnumFieldGenerator::GenerateCodecCode(io::Printer* printer) {
...
@@ -81,8 +81,8 @@ void EnumFieldGenerator::GenerateCodecCode(io::Printer* printer) {
"pb::FieldCodec.ForEnum($tag$, x => (int) x, x => ($type_name$) x)"
);
"pb::FieldCodec.ForEnum($tag$, x => (int) x, x => ($type_name$) x)"
);
}
}
EnumOneofFieldGenerator
::
EnumOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
EnumOneofFieldGenerator
::
EnumOneofFieldGenerator
(
int
fieldOrdinal
,
const
Options
*
options
)
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
)
:
PrimitiveOneofFieldGenerator
(
descriptor
,
fieldOrdinal
,
options
)
{
:
PrimitiveOneofFieldGenerator
(
descriptor
,
fieldOrdinal
,
options
)
{
}
}
...
...
src/google/protobuf/compiler/csharp/csharp_enum_field.h
View file @
cef46e11
...
@@ -43,7 +43,9 @@ namespace csharp {
...
@@ -43,7 +43,9 @@ namespace csharp {
class
EnumFieldGenerator
:
public
PrimitiveFieldGenerator
{
class
EnumFieldGenerator
:
public
PrimitiveFieldGenerator
{
public
:
public
:
EnumFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
EnumFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
EnumFieldGenerator
();
~
EnumFieldGenerator
();
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
...
@@ -57,7 +59,9 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator {
...
@@ -57,7 +59,9 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator {
class
EnumOneofFieldGenerator
:
public
PrimitiveOneofFieldGenerator
{
class
EnumOneofFieldGenerator
:
public
PrimitiveOneofFieldGenerator
{
public
:
public
:
EnumOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
EnumOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
EnumOneofFieldGenerator
();
~
EnumOneofFieldGenerator
();
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateParsingCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_field_base.cc
View file @
cef46e11
...
@@ -94,7 +94,8 @@ void FieldGeneratorBase::SetCommonFieldVariables(
...
@@ -94,7 +94,8 @@ void FieldGeneratorBase::SetCommonFieldVariables(
void
FieldGeneratorBase
::
SetCommonOneofFieldVariables
(
void
FieldGeneratorBase
::
SetCommonOneofFieldVariables
(
map
<
string
,
string
>*
variables
)
{
map
<
string
,
string
>*
variables
)
{
(
*
variables
)[
"oneof_name"
]
=
oneof_name
();
(
*
variables
)[
"oneof_name"
]
=
oneof_name
();
(
*
variables
)[
"has_property_check"
]
=
oneof_name
()
+
"Case_ == "
+
oneof_property_name
()
+
(
*
variables
)[
"has_property_check"
]
=
oneof_name
()
+
"Case_ == "
+
oneof_property_name
()
+
"OneofCase."
+
property_name
();
"OneofCase."
+
property_name
();
(
*
variables
)[
"oneof_property_name"
]
=
oneof_property_name
();
(
*
variables
)[
"oneof_property_name"
]
=
oneof_property_name
();
}
}
...
@@ -158,10 +159,11 @@ std::string FieldGeneratorBase::type_name(const FieldDescriptor* descriptor) {
...
@@ -158,10 +159,11 @@ std::string FieldGeneratorBase::type_name(const FieldDescriptor* descriptor) {
case
FieldDescriptor
:
:
TYPE_MESSAGE
:
case
FieldDescriptor
:
:
TYPE_MESSAGE
:
case
FieldDescriptor
:
:
TYPE_GROUP
:
case
FieldDescriptor
:
:
TYPE_GROUP
:
if
(
IsWrapperType
(
descriptor
))
{
if
(
IsWrapperType
(
descriptor
))
{
const
FieldDescriptor
*
wrapped_field
=
descriptor
->
message_type
()
->
field
(
0
);
const
FieldDescriptor
*
wrapped_field
=
descriptor
->
message_type
()
->
field
(
0
);
string
wrapped_field_type_name
=
type_name
(
wrapped_field
);
string
wrapped_field_type_name
=
type_name
(
wrapped_field
);
// String and ByteString go to the same type; other wrapped types
go to the
// String and ByteString go to the same type; other wrapped types
// nullable equivalent.
//
go to the
nullable equivalent.
if
(
wrapped_field
->
type
()
==
FieldDescriptor
::
TYPE_STRING
||
if
(
wrapped_field
->
type
()
==
FieldDescriptor
::
TYPE_STRING
||
wrapped_field
->
type
()
==
FieldDescriptor
::
TYPE_BYTES
)
{
wrapped_field
->
type
()
==
FieldDescriptor
::
TYPE_BYTES
)
{
return
wrapped_field_type_name
;
return
wrapped_field_type_name
;
...
...
src/google/protobuf/compiler/csharp/csharp_field_base.h
View file @
cef46e11
...
@@ -44,7 +44,9 @@ namespace csharp {
...
@@ -44,7 +44,9 @@ namespace csharp {
class
FieldGeneratorBase
:
public
SourceGeneratorBase
{
class
FieldGeneratorBase
:
public
SourceGeneratorBase
{
public
:
public
:
FieldGeneratorBase
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
FieldGeneratorBase
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
FieldGeneratorBase
();
~
FieldGeneratorBase
();
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
)
=
0
;
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
)
=
0
;
...
...
src/google/protobuf/compiler/csharp/csharp_generator.cc
View file @
cef46e11
...
@@ -80,7 +80,7 @@ bool Generator::Generate(
...
@@ -80,7 +80,7 @@ bool Generator::Generate(
cli_options
.
file_extension
=
options
[
i
].
second
;
cli_options
.
file_extension
=
options
[
i
].
second
;
}
else
if
(
options
[
i
].
first
==
"base_namespace"
)
{
}
else
if
(
options
[
i
].
first
==
"base_namespace"
)
{
cli_options
.
base_namespace
=
options
[
i
].
second
;
cli_options
.
base_namespace
=
options
[
i
].
second
;
cli_options
.
generate_directories
=
true
;
cli_options
.
base_namespace_specified
=
true
;
}
else
{
}
else
{
*
error
=
"Unknown generator option: "
+
options
[
i
].
first
;
*
error
=
"Unknown generator option: "
+
options
[
i
].
first
;
return
false
;
return
false
;
...
@@ -90,7 +90,7 @@ bool Generator::Generate(
...
@@ -90,7 +90,7 @@ bool Generator::Generate(
string
filename_error
=
""
;
string
filename_error
=
""
;
std
::
string
filename
=
GetOutputFile
(
file
,
std
::
string
filename
=
GetOutputFile
(
file
,
cli_options
.
file_extension
,
cli_options
.
file_extension
,
cli_options
.
generate_directories
,
cli_options
.
base_namespace_specified
,
cli_options
.
base_namespace
,
cli_options
.
base_namespace
,
&
filename_error
);
&
filename_error
);
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.cc
View file @
cef46e11
...
@@ -128,7 +128,8 @@ std::string GetFileNameBase(const FileDescriptor* descriptor) {
...
@@ -128,7 +128,8 @@ std::string GetFileNameBase(const FileDescriptor* descriptor) {
}
}
std
::
string
GetReflectionClassUnqualifiedName
(
const
FileDescriptor
*
descriptor
)
{
std
::
string
GetReflectionClassUnqualifiedName
(
const
FileDescriptor
*
descriptor
)
{
// TODO: Detect collisions with existing messages, and append an underscore if necessary.
// TODO: Detect collisions with existing messages,
// and append an underscore if necessary.
return
GetFileNameBase
(
descriptor
)
+
"Reflection"
;
return
GetFileNameBase
(
descriptor
)
+
"Reflection"
;
}
}
...
@@ -352,7 +353,8 @@ std::string FileDescriptorToBase64(const FileDescriptor* descriptor) {
...
@@ -352,7 +353,8 @@ std::string FileDescriptorToBase64(const FileDescriptor* descriptor) {
}
}
FieldGeneratorBase
*
CreateFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
FieldGeneratorBase
*
CreateFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
)
{
int
fieldOrdinal
,
const
Options
*
options
)
{
switch
(
descriptor
->
type
())
{
switch
(
descriptor
->
type
())
{
case
FieldDescriptor
:
:
TYPE_GROUP
:
case
FieldDescriptor
:
:
TYPE_GROUP
:
case
FieldDescriptor
:
:
TYPE_MESSAGE
:
case
FieldDescriptor
:
:
TYPE_MESSAGE
:
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.h
View file @
cef46e11
...
@@ -83,7 +83,9 @@ std::string GetPropertyName(const FieldDescriptor* descriptor);
...
@@ -83,7 +83,9 @@ std::string GetPropertyName(const FieldDescriptor* descriptor);
int
GetFixedSize
(
FieldDescriptor
::
Type
type
);
int
GetFixedSize
(
FieldDescriptor
::
Type
type
);
std
::
string
UnderscoresToCamelCase
(
const
std
::
string
&
input
,
bool
cap_next_letter
,
bool
preserve_period
);
std
::
string
UnderscoresToCamelCase
(
const
std
::
string
&
input
,
bool
cap_next_letter
,
bool
preserve_period
);
inline
std
::
string
UnderscoresToCamelCase
(
const
std
::
string
&
input
,
bool
cap_next_letter
)
{
inline
std
::
string
UnderscoresToCamelCase
(
const
std
::
string
&
input
,
bool
cap_next_letter
)
{
return
UnderscoresToCamelCase
(
input
,
cap_next_letter
,
false
);
return
UnderscoresToCamelCase
(
input
,
cap_next_letter
,
false
);
...
@@ -96,17 +98,19 @@ std::string StringToBase64(const std::string& input);
...
@@ -96,17 +98,19 @@ std::string StringToBase64(const std::string& input);
std
::
string
FileDescriptorToBase64
(
const
FileDescriptor
*
descriptor
);
std
::
string
FileDescriptorToBase64
(
const
FileDescriptor
*
descriptor
);
FieldGeneratorBase
*
CreateFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
FieldGeneratorBase
*
CreateFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
// Determines whether the given message is a map entry message,
i.e. one implicitly created
// Determines whether the given message is a map entry message,
// by protoc due to a map<key, value> field.
//
i.e. one implicitly created
by protoc due to a map<key, value> field.
inline
bool
IsMapEntryMessage
(
const
Descriptor
*
descriptor
)
{
inline
bool
IsMapEntryMessage
(
const
Descriptor
*
descriptor
)
{
return
descriptor
->
options
().
map_entry
();
return
descriptor
->
options
().
map_entry
();
}
}
// Determines whether we're generating code for the proto representation of
descriptors etc,
// Determines whether we're generating code for the proto representation of
//
for use in the runtime. This is the only type which is allowed to use proto2 syntax,
//
descriptors etc, for use in the runtime. This is the only type which is
// and it generates internal classes.
// a
llowed to use proto2 syntax, a
nd it generates internal classes.
inline
bool
IsDescriptorProto
(
const
FileDescriptor
*
descriptor
)
{
inline
bool
IsDescriptorProto
(
const
FileDescriptor
*
descriptor
)
{
return
descriptor
->
name
()
==
"google/protobuf/descriptor.proto"
;
return
descriptor
->
name
()
==
"google/protobuf/descriptor.proto"
;
}
}
...
...
src/google/protobuf/compiler/csharp/csharp_map_field.cc
View file @
cef46e11
...
@@ -63,8 +63,10 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) {
...
@@ -63,8 +63,10 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) {
descriptor_
->
message_type
()
->
FindFieldByName
(
"value"
);
descriptor_
->
message_type
()
->
FindFieldByName
(
"value"
);
variables_
[
"key_type_name"
]
=
type_name
(
key_descriptor
);
variables_
[
"key_type_name"
]
=
type_name
(
key_descriptor
);
variables_
[
"value_type_name"
]
=
type_name
(
value_descriptor
);
variables_
[
"value_type_name"
]
=
type_name
(
value_descriptor
);
scoped_ptr
<
FieldGeneratorBase
>
key_generator
(
CreateFieldGenerator
(
key_descriptor
,
1
,
this
->
options
()));
scoped_ptr
<
FieldGeneratorBase
>
key_generator
(
scoped_ptr
<
FieldGeneratorBase
>
value_generator
(
CreateFieldGenerator
(
value_descriptor
,
2
,
this
->
options
()));
CreateFieldGenerator
(
key_descriptor
,
1
,
this
->
options
()));
scoped_ptr
<
FieldGeneratorBase
>
value_generator
(
CreateFieldGenerator
(
value_descriptor
,
2
,
this
->
options
()));
printer
->
Print
(
printer
->
Print
(
variables_
,
variables_
,
...
...
src/google/protobuf/compiler/csharp/csharp_map_field.h
View file @
cef46e11
...
@@ -43,7 +43,9 @@ namespace csharp {
...
@@ -43,7 +43,9 @@ namespace csharp {
class
MapFieldGenerator
:
public
FieldGeneratorBase
{
class
MapFieldGenerator
:
public
FieldGeneratorBase
{
public
:
public
:
MapFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
MapFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
MapFieldGenerator
();
~
MapFieldGenerator
();
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
cef46e11
...
@@ -60,7 +60,8 @@ bool CompareFieldNumbers(const FieldDescriptor* d1, const FieldDescriptor* d2) {
...
@@ -60,7 +60,8 @@ bool CompareFieldNumbers(const FieldDescriptor* d1, const FieldDescriptor* d2) {
return
d1
->
number
()
<
d2
->
number
();
return
d1
->
number
()
<
d2
->
number
();
}
}
MessageGenerator
::
MessageGenerator
(
const
Descriptor
*
descriptor
,
const
Options
*
options
)
MessageGenerator
::
MessageGenerator
(
const
Descriptor
*
descriptor
,
const
Options
*
options
)
:
SourceGeneratorBase
(
descriptor
->
file
(),
options
),
:
SourceGeneratorBase
(
descriptor
->
file
(),
options
),
descriptor_
(
descriptor
)
{
descriptor_
(
descriptor
)
{
...
@@ -185,7 +186,8 @@ void MessageGenerator::Generate(io::Printer* printer) {
...
@@ -185,7 +186,8 @@ void MessageGenerator::Generate(io::Printer* printer) {
}
}
printer
->
Outdent
();
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
printer
->
Print
(
"}
\n
"
);
// TODO: Should we put the oneof .proto comments here? It's unclear exactly where they should go.
// TODO: Should we put the oneof .proto comments here?
// It's unclear exactly where they should go.
printer
->
Print
(
printer
->
Print
(
vars
,
vars
,
"private $property_name$OneofCase $name$Case_ = $property_name$OneofCase.None;
\n
"
"private $property_name$OneofCase $name$Case_ = $property_name$OneofCase.None;
\n
"
...
@@ -220,7 +222,8 @@ void MessageGenerator::Generate(io::Printer* printer) {
...
@@ -220,7 +222,8 @@ void MessageGenerator::Generate(io::Printer* printer) {
for
(
int
i
=
0
;
i
<
descriptor_
->
nested_type_count
();
i
++
)
{
for
(
int
i
=
0
;
i
<
descriptor_
->
nested_type_count
();
i
++
)
{
// Don't generate nested types for maps...
// Don't generate nested types for maps...
if
(
!
IsMapEntryMessage
(
descriptor_
->
nested_type
(
i
)))
{
if
(
!
IsMapEntryMessage
(
descriptor_
->
nested_type
(
i
)))
{
MessageGenerator
messageGenerator
(
descriptor_
->
nested_type
(
i
),
this
->
options
());
MessageGenerator
messageGenerator
(
descriptor_
->
nested_type
(
i
),
this
->
options
());
messageGenerator
.
Generate
(
printer
);
messageGenerator
.
Generate
(
printer
);
}
}
}
}
...
@@ -268,7 +271,8 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) {
...
@@ -268,7 +271,8 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) {
// Clone just the right field for each oneof
// Clone just the right field for each oneof
for
(
int
i
=
0
;
i
<
descriptor_
->
oneof_decl_count
();
++
i
)
{
for
(
int
i
=
0
;
i
<
descriptor_
->
oneof_decl_count
();
++
i
)
{
vars
[
"name"
]
=
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
)
->
name
(),
false
);
vars
[
"name"
]
=
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
)
->
name
(),
false
);
vars
[
"property_name"
]
=
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
)
->
name
(),
true
);
vars
[
"property_name"
]
=
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
)
->
name
(),
true
);
printer
->
Print
(
vars
,
"switch (other.$property_name$Case) {
\n
"
);
printer
->
Print
(
vars
,
"switch (other.$property_name$Case) {
\n
"
);
printer
->
Indent
();
printer
->
Indent
();
for
(
int
j
=
0
;
j
<
descriptor_
->
oneof_decl
(
i
)
->
field_count
();
j
++
)
{
for
(
int
j
=
0
;
j
<
descriptor_
->
oneof_decl
(
i
)
->
field_count
();
j
++
)
{
...
@@ -449,7 +453,8 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
...
@@ -449,7 +453,8 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
uint32
tag
=
internal
::
WireFormatLite
::
MakeTag
(
field
->
number
(),
wt
);
uint32
tag
=
internal
::
WireFormatLite
::
MakeTag
(
field
->
number
(),
wt
);
// Handle both packed and unpacked repeated fields with the same Read*Array call;
// Handle both packed and unpacked repeated fields with the same Read*Array call;
// the two generated cases are the packed and unpacked tags.
// the two generated cases are the packed and unpacked tags.
// TODO(jonskeet): Check that is_packable is equivalent to is_repeated && wt in { VARINT, FIXED32, FIXED64 }.
// TODO(jonskeet): Check that is_packable is equivalent to
// is_repeated && wt in { VARINT, FIXED32, FIXED64 }.
// It looks like it is...
// It looks like it is...
if
(
field
->
is_packable
())
{
if
(
field
->
is_packable
())
{
printer
->
Print
(
printer
->
Print
(
...
...
src/google/protobuf/compiler/csharp/csharp_message_field.cc
View file @
cef46e11
...
@@ -49,7 +49,8 @@ namespace compiler {
...
@@ -49,7 +49,8 @@ namespace compiler {
namespace
csharp
{
namespace
csharp
{
MessageFieldGenerator
::
MessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
MessageFieldGenerator
::
MessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
)
int
fieldOrdinal
,
const
Options
*
options
)
:
FieldGeneratorBase
(
descriptor
,
fieldOrdinal
,
options
)
{
:
FieldGeneratorBase
(
descriptor
,
fieldOrdinal
,
options
)
{
variables_
[
"has_property_check"
]
=
name
()
+
"_ != null"
;
variables_
[
"has_property_check"
]
=
name
()
+
"_ != null"
;
variables_
[
"has_not_property_check"
]
=
name
()
+
"_ == null"
;
variables_
[
"has_not_property_check"
]
=
name
()
+
"_ == null"
;
...
@@ -144,8 +145,10 @@ void MessageFieldGenerator::GenerateCodecCode(io::Printer* printer) {
...
@@ -144,8 +145,10 @@ void MessageFieldGenerator::GenerateCodecCode(io::Printer* printer) {
"pb::FieldCodec.ForMessage($tag$, $type_name$.Parser)"
);
"pb::FieldCodec.ForMessage($tag$, $type_name$.Parser)"
);
}
}
MessageOneofFieldGenerator
::
MessageOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
MessageOneofFieldGenerator
::
MessageOneofFieldGenerator
(
int
fieldOrdinal
,
const
Options
*
options
)
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
)
:
MessageFieldGenerator
(
descriptor
,
fieldOrdinal
,
options
)
{
:
MessageFieldGenerator
(
descriptor
,
fieldOrdinal
,
options
)
{
SetCommonOneofFieldVariables
(
&
variables_
);
SetCommonOneofFieldVariables
(
&
variables_
);
}
}
...
...
src/google/protobuf/compiler/csharp/csharp_message_field.h
View file @
cef46e11
...
@@ -43,7 +43,9 @@ namespace csharp {
...
@@ -43,7 +43,9 @@ namespace csharp {
class
MessageFieldGenerator
:
public
FieldGeneratorBase
{
class
MessageFieldGenerator
:
public
FieldGeneratorBase
{
public
:
public
:
MessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
MessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
MessageFieldGenerator
();
~
MessageFieldGenerator
();
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
...
@@ -65,7 +67,9 @@ class MessageFieldGenerator : public FieldGeneratorBase {
...
@@ -65,7 +67,9 @@ class MessageFieldGenerator : public FieldGeneratorBase {
class
MessageOneofFieldGenerator
:
public
MessageFieldGenerator
{
class
MessageOneofFieldGenerator
:
public
MessageFieldGenerator
{
public
:
public
:
MessageOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
MessageOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
MessageOneofFieldGenerator
();
~
MessageOneofFieldGenerator
();
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_options.h
View file @
cef46e11
...
@@ -41,14 +41,29 @@ namespace csharp {
...
@@ -41,14 +41,29 @@ namespace csharp {
// Generator options (used by csharp_generator.cc):
// Generator options (used by csharp_generator.cc):
struct
Options
{
struct
Options
{
Options
()
:
file_extension
(
".cs"
),
base_namespace
(
""
),
generate_directories
(
false
)
{
Options
()
:
file_extension
(
".cs"
),
base_namespace
(
""
),
base_namespace_specified
(
false
)
{
}
}
// Extension of the generated file. Defaults to ".cs"
// Extension of the generated file. Defaults to ".cs"
string
file_extension
;
string
file_extension
;
// Base namespace to use to create directory hierarchy. Defaults to ""
// Base namespace to use to create directory hierarchy. Defaults to "".
// This option allows the simple creation of a conventional C# file layout,
// where directories are created relative to a project-specific base
// namespace. For example, in a project with a base namespace of PetShop, a
// proto of user.proto with a C# namespace of PetShop.Model.Shared would
// generate Model/Shared/User.cs underneath the specified --csharp_out
// directory.
//
// If no base namespace is specified, all files are generated in the
// --csharp_out directory, with no subdirectories created automatically.
string
base_namespace
;
string
base_namespace
;
// Whether or not to generate directory hierarchy. Defaults to false
// Whether the base namespace has been explicitly specified by the user.
bool
generate_directories
;
// This is required as the base namespace can be explicitly set to the empty
// string, meaning "create a full directory hierarchy, starting from the first
// segment of the namespace."
bool
base_namespace_specified
;
};
};
}
// namespace csharp
}
// namespace csharp
...
...
src/google/protobuf/compiler/csharp/csharp_primitive_field.h
View file @
cef46e11
...
@@ -45,7 +45,9 @@ struct Options;
...
@@ -45,7 +45,9 @@ struct Options;
class
PrimitiveFieldGenerator
:
public
FieldGeneratorBase
{
class
PrimitiveFieldGenerator
:
public
FieldGeneratorBase
{
public
:
public
:
PrimitiveFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
PrimitiveFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
PrimitiveFieldGenerator
();
~
PrimitiveFieldGenerator
();
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
...
@@ -69,7 +71,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
...
@@ -69,7 +71,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
class
PrimitiveOneofFieldGenerator
:
public
PrimitiveFieldGenerator
{
class
PrimitiveOneofFieldGenerator
:
public
PrimitiveFieldGenerator
{
public
:
public
:
PrimitiveOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
PrimitiveOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
PrimitiveOneofFieldGenerator
();
~
PrimitiveOneofFieldGenerator
();
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_reflection_class.h
View file @
cef46e11
...
@@ -56,7 +56,9 @@ class ReflectionClassGenerator : public SourceGeneratorBase {
...
@@ -56,7 +56,9 @@ class ReflectionClassGenerator : public SourceGeneratorBase {
void
WriteIntroduction
(
io
::
Printer
*
printer
);
void
WriteIntroduction
(
io
::
Printer
*
printer
);
void
WriteDescriptor
(
io
::
Printer
*
printer
);
void
WriteDescriptor
(
io
::
Printer
*
printer
);
void
WriteGeneratedCodeInfo
(
const
Descriptor
*
descriptor
,
io
::
Printer
*
printer
,
bool
last
);
void
WriteGeneratedCodeInfo
(
const
Descriptor
*
descriptor
,
io
::
Printer
*
printer
,
bool
last
);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
ReflectionClassGenerator
);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
ReflectionClassGenerator
);
};
};
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
View file @
cef46e11
...
@@ -45,7 +45,9 @@ namespace csharp {
...
@@ -45,7 +45,9 @@ namespace csharp {
// should probably have a RepeatedFieldGeneratorBase.
// should probably have a RepeatedFieldGeneratorBase.
class
RepeatedEnumFieldGenerator
:
public
FieldGeneratorBase
{
class
RepeatedEnumFieldGenerator
:
public
FieldGeneratorBase
{
public
:
public
:
RepeatedEnumFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
RepeatedEnumFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
RepeatedEnumFieldGenerator
();
~
RepeatedEnumFieldGenerator
();
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
View file @
cef46e11
...
@@ -66,10 +66,12 @@ void RepeatedMessageFieldGenerator::GenerateMembers(io::Printer* printer) {
...
@@ -66,10 +66,12 @@ void RepeatedMessageFieldGenerator::GenerateMembers(io::Printer* printer) {
// "create single field generator for this repeated field"
// "create single field generator for this repeated field"
// function, but it doesn't seem worth it for just this.
// function, but it doesn't seem worth it for just this.
if
(
IsWrapperType
(
descriptor_
))
{
if
(
IsWrapperType
(
descriptor_
))
{
scoped_ptr
<
FieldGeneratorBase
>
single_generator
(
new
WrapperFieldGenerator
(
descriptor_
,
fieldOrdinal_
,
this
->
options
()));
scoped_ptr
<
FieldGeneratorBase
>
single_generator
(
new
WrapperFieldGenerator
(
descriptor_
,
fieldOrdinal_
,
this
->
options
()));
single_generator
->
GenerateCodecCode
(
printer
);
single_generator
->
GenerateCodecCode
(
printer
);
}
else
{
}
else
{
scoped_ptr
<
FieldGeneratorBase
>
single_generator
(
new
MessageFieldGenerator
(
descriptor_
,
fieldOrdinal_
,
this
->
options
()));
scoped_ptr
<
FieldGeneratorBase
>
single_generator
(
new
MessageFieldGenerator
(
descriptor_
,
fieldOrdinal_
,
this
->
options
()));
single_generator
->
GenerateCodecCode
(
printer
);
single_generator
->
GenerateCodecCode
(
printer
);
}
}
printer
->
Print
(
";
\n
"
);
printer
->
Print
(
";
\n
"
);
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
View file @
cef46e11
...
@@ -45,7 +45,9 @@ struct Options;
...
@@ -45,7 +45,9 @@ struct Options;
class
RepeatedMessageFieldGenerator
:
public
FieldGeneratorBase
{
class
RepeatedMessageFieldGenerator
:
public
FieldGeneratorBase
{
public
:
public
:
RepeatedMessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
RepeatedMessageFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
RepeatedMessageFieldGenerator
();
~
RepeatedMessageFieldGenerator
();
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCloningCode
(
io
::
Printer
*
printer
);
...
...
src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
View file @
cef46e11
...
@@ -47,7 +47,8 @@ namespace protobuf {
...
@@ -47,7 +47,8 @@ namespace protobuf {
namespace
compiler
{
namespace
compiler
{
namespace
csharp
{
namespace
csharp
{
SourceGeneratorBase
::
SourceGeneratorBase
(
const
FileDescriptor
*
descriptor
,
const
Options
*
options
)
SourceGeneratorBase
::
SourceGeneratorBase
(
const
FileDescriptor
*
descriptor
,
const
Options
*
options
)
:
descriptor_
(
descriptor
),
options_
(
options
)
{
:
descriptor_
(
descriptor
),
options_
(
options
)
{
}
}
...
...
src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
View file @
cef46e11
...
@@ -152,8 +152,8 @@ void WrapperFieldGenerator::GenerateCodecCode(io::Printer* printer) {
...
@@ -152,8 +152,8 @@ void WrapperFieldGenerator::GenerateCodecCode(io::Printer* printer) {
}
}
}
}
WrapperOneofFieldGenerator
::
WrapperOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
WrapperOneofFieldGenerator
::
WrapperOneofFieldGenerator
(
int
fieldOrdinal
,
const
Options
*
options
)
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
)
:
WrapperFieldGenerator
(
descriptor
,
fieldOrdinal
,
options
)
{
:
WrapperFieldGenerator
(
descriptor
,
fieldOrdinal
,
options
)
{
SetCommonOneofFieldVariables
(
&
variables_
);
SetCommonOneofFieldVariables
(
&
variables_
);
}
}
...
...
src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
View file @
cef46e11
...
@@ -45,7 +45,9 @@ struct Options;
...
@@ -45,7 +45,9 @@ struct Options;
class
WrapperFieldGenerator
:
public
FieldGeneratorBase
{
class
WrapperFieldGenerator
:
public
FieldGeneratorBase
{
public
:
public
:
WrapperFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
WrapperFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
WrapperFieldGenerator
();
~
WrapperFieldGenerator
();
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
virtual
void
GenerateCodecCode
(
io
::
Printer
*
printer
);
...
@@ -67,7 +69,9 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
...
@@ -67,7 +69,9 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
class
WrapperOneofFieldGenerator
:
public
WrapperFieldGenerator
{
class
WrapperOneofFieldGenerator
:
public
WrapperFieldGenerator
{
public
:
public
:
WrapperOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
WrapperOneofFieldGenerator
(
const
FieldDescriptor
*
descriptor
,
int
fieldOrdinal
,
const
Options
*
options
);
~
WrapperOneofFieldGenerator
();
~
WrapperOneofFieldGenerator
();
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
virtual
void
GenerateMembers
(
io
::
Printer
*
printer
);
...
...
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