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
44664bb7
Commit
44664bb7
authored
9 years ago
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated C# codegen to use restricted set of csharp options from descriptor.proto
parent
b52cf04b
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
27 additions
and
52 deletions
+27
-52
csharp_extension.cc
src/google/protobuf/compiler/csharp/csharp_extension.cc
+1
-1
csharp_field_base.cc
src/google/protobuf/compiler/csharp/csharp_field_base.cc
+1
-1
csharp_generator.cc
src/google/protobuf/compiler/csharp/csharp_generator.cc
+4
-2
csharp_helpers.cc
src/google/protobuf/compiler/csharp/csharp_helpers.cc
+4
-15
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+2
-13
csharp_source_generator_base.cc
.../protobuf/compiler/csharp/csharp_source_generator_base.cc
+5
-0
csharp_source_generator_base.h
...e/protobuf/compiler/csharp/csharp_source_generator_base.h
+1
-0
csharp_umbrella_class.cc
src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
+9
-20
No files found.
src/google/protobuf/compiler/csharp/csharp_extension.cc
View file @
44664bb7
...
...
@@ -63,7 +63,7 @@ ExtensionGenerator::~ExtensionGenerator() {
}
void
ExtensionGenerator
::
Generate
(
Writer
*
writer
)
{
if
(
descriptor_
->
file
()
->
options
().
csharp_
cls_compliance
()
if
(
cls_compliance
()
&&
(
GetFieldConstantName
(
descriptor_
).
substr
(
0
,
1
)
==
"_"
))
{
writer
->
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_field_base.cc
View file @
44664bb7
...
...
@@ -84,7 +84,7 @@ void FieldGeneratorBase::AddPublicMemberAttributes(Writer* writer) {
}
void
FieldGeneratorBase
::
AddClsComplianceCheck
(
Writer
*
writer
)
{
if
(
!
is_cls_compliant
()
&&
descriptor_
->
file
()
->
options
().
csharp_cls_compliance
())
{
if
(
cls_compliance
()
&&
!
is_cls_compliant
())
{
writer
->
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_generator.cc
View file @
44664bb7
...
...
@@ -61,9 +61,11 @@ bool Generator::Generate(
GeneratorContext
*
generator_context
,
string
*
error
)
const
{
// TODO: parse generator parameters...
// TODO(jtattermusch): parse generator parameters:
// cls_compliance
// file_extension
// TODO
: file
output file naming logic
// TODO
(jtattermusch): rework
output file naming logic
std
::
string
filename
=
StripDotProto
(
file
->
name
())
+
".cs"
;
scoped_ptr
<
io
::
ZeroCopyOutputStream
>
output
(
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_helpers.cc
View file @
44664bb7
...
...
@@ -122,16 +122,12 @@ std::string GetUmbrellaClassNameInternal(const std::string& proto_file) {
}
std
::
string
GetFileUmbrellaClassname
(
const
FileDescriptor
*
descriptor
)
{
if
(
descriptor
->
options
().
has_csharp_umbrella_classname
())
{
return
descriptor
->
options
().
csharp_umbrella_namespace
();
}
else
{
return
GetUmbrellaClassNameInternal
(
descriptor
->
name
());
}
// umbrella_classname can no longer be set using message option.
return
GetUmbrellaClassNameInternal
(
descriptor
->
name
());
}
std
::
string
GetFileUmbrellaNamespace
(
const
FileDescriptor
*
descriptor
)
{
if
(
!
descriptor
->
options
().
csharp_nest_classes
()
&&
!
descriptor
->
options
().
has_csharp_umbrella_namespace
())
{
if
(
!
descriptor
->
options
().
has_csharp_umbrella_namespace
())
{
bool
collision
=
false
;
// TODO(jtattermusch): detect collisions!
// foreach (IDescriptor d in MessageTypes)
...
...
@@ -196,12 +192,6 @@ std::string UnderscoresToPascalCase(const std::string& input) {
std
::
string
ToCSharpName
(
const
std
::
string
&
name
,
const
FileDescriptor
*
file
)
{
std
::
string
result
=
GetFileNamespace
(
file
);
if
(
file
->
options
().
csharp_nest_classes
())
{
if
(
result
!=
""
)
{
result
+=
"."
;
}
result
+=
GetFileUmbrellaClassname
(
file
);
}
if
(
result
!=
""
)
{
result
+=
'.'
;
}
...
...
@@ -233,8 +223,7 @@ std::string GetQualifiedUmbrellaClassName(const FileDescriptor* descriptor) {
std
::
string
umbrellaClassname
=
GetFileUmbrellaClassname
(
descriptor
);
std
::
string
fullName
=
umbrellaClassname
;
if
(
!
descriptor
->
options
().
csharp_nest_classes
()
&&
!
umbrellaNamespace
.
empty
())
{
if
(
!
umbrellaNamespace
.
empty
())
{
fullName
=
umbrellaNamespace
+
"."
+
umbrellaClassname
;
}
return
fullName
;
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
44664bb7
...
...
@@ -118,9 +118,7 @@ void MessageGenerator::GenerateStaticVariables(Writer* writer) {
if
(
!
use_lite_runtime
())
{
// The descriptor for this type.
std
::
string
access
=
descriptor_
->
file
()
->
options
().
csharp_nest_classes
()
?
"private"
:
"internal"
;
std
::
string
access
=
"internal"
;
writer
->
WriteLine
(
"$0$ static pbd::MessageDescriptor internal__$1$__Descriptor;"
,
access
,
identifier
);
...
...
@@ -175,9 +173,6 @@ void MessageGenerator::GenerateStaticVariableInitializers(Writer* writer) {
}
void
MessageGenerator
::
Generate
(
Writer
*
writer
)
{
if
(
descriptor_
->
file
()
->
options
().
csharp_add_serializable
())
{
writer
->
WriteLine
(
"[global::System.SerializableAttribute()]"
);
}
writer
->
WriteLine
(
"[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"
);
WriteGeneratedCodeAttributes
(
writer
);
...
...
@@ -187,9 +182,6 @@ void MessageGenerator::Generate(Writer* writer) {
descriptor_
->
extension_range_count
()
>
0
?
"Extendable"
:
"Generated"
,
runtime_suffix
());
writer
->
Indent
();
if
(
descriptor_
->
file
()
->
options
().
csharp_generate_private_ctor
())
{
writer
->
WriteLine
(
"private $0$() { }"
,
class_name
());
}
// Must call MakeReadOnly() to make sure all lists are made read-only
writer
->
WriteLine
(
"private static readonly $0$ defaultInstance = new $0$().MakeReadOnly();"
,
...
...
@@ -271,7 +263,7 @@ void MessageGenerator::Generate(Writer* writer) {
for
(
int
i
=
0
;
i
<
descriptor_
->
field_count
();
i
++
)
{
const
FieldDescriptor
*
fieldDescriptor
=
descriptor_
->
field
(
i
);
// TODO(jtattermusch): same code for cls compliance is in csharp_extension
if
(
descriptor_
->
file
()
->
options
().
csharp_
cls_compliance
()
if
(
cls_compliance
()
&&
GetFieldConstantName
(
fieldDescriptor
)[
0
]
==
'_'
)
{
writer
->
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
...
...
@@ -557,9 +549,6 @@ void MessageGenerator::GenerateBuilder(Writer* writer) {
writer
->
WriteLine
(
" return new Builder(prototype);"
);
writer
->
WriteLine
(
"}"
);
writer
->
WriteLine
();
if
(
descriptor_
->
file
()
->
options
().
csharp_add_serializable
())
{
writer
->
WriteLine
(
"[global::System.SerializableAttribute()]"
);
}
writer
->
WriteLine
(
"[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"
);
WriteGeneratedCodeAttributes
(
writer
);
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
View file @
44664bb7
...
...
@@ -76,6 +76,11 @@ std::string SourceGeneratorBase::class_access_level() {
return
"public"
;
}
bool
SourceGeneratorBase
::
cls_compliance
()
{
// TODO(jtattermusch): implement this based on "cls_compliance" cmdline param.
return
true
;
}
}
// namespace csharp
}
// namespace compiler
}
// namespace protobuf
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
View file @
44664bb7
...
...
@@ -48,6 +48,7 @@ class SourceGeneratorBase {
virtual
~
SourceGeneratorBase
();
std
::
string
class_access_level
();
bool
cls_compliance
();
bool
optimize_size
()
{
return
optimizeSize_
;
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc
View file @
44664bb7
...
...
@@ -86,17 +86,14 @@ void UmbrellaClassGenerator::Generate(Writer* writer) {
}
else
{
WriteLiteExtensions
(
writer
);
}
// The class declaration either gets closed before or after the children are written.
if
(
!
file_
->
options
().
csharp_nest_classes
())
{
// Close the class declaration.
writer
->
Outdent
();
writer
->
WriteLine
(
"}"
);
// Close the namespace around the umbrella class if defined
if
(
!
umbrellaNamespace_
.
empty
())
{
writer
->
Outdent
();
writer
->
WriteLine
(
"}"
);
// Close the namespace around the umbrella class if defined
if
(
!
file_
->
options
().
csharp_nest_classes
()
&&
!
umbrellaNamespace_
.
empty
())
{
writer
->
Outdent
();
writer
->
WriteLine
(
"}"
);
}
}
// write children: Enums
...
...
@@ -121,12 +118,8 @@ void UmbrellaClassGenerator::Generate(Writer* writer) {
writer
->
WriteLine
();
}
// TODO(jtattermusch): add support for generating services.
//WriteChildren(writer, "Services", Descriptor.Services);
if
(
file_
->
options
().
csharp_nest_classes
())
{
writer
->
Outdent
();
writer
->
WriteLine
(
"}"
);
}
// TODO(jtattermusch): add insertion point for services.
if
(
!
namespace_
.
empty
())
{
writer
->
Outdent
();
writer
->
WriteLine
(
"}"
);
...
...
@@ -155,16 +148,12 @@ void UmbrellaClassGenerator::WriteIntroduction(Writer* writer) {
}
// Add the namespace around the umbrella class if defined
if
(
!
file_
->
options
().
csharp_nest_classes
()
&&
!
umbrellaNamespace_
.
empty
())
{
if
(
!
umbrellaNamespace_
.
empty
())
{
writer
->
WriteLine
(
"namespace $0$ {"
,
umbrellaNamespace_
);
writer
->
Indent
();
writer
->
WriteLine
();
}
if
(
file_
->
options
().
csharp_code_contracts
())
{
writer
->
WriteLine
(
"[global::System.Diagnostics.Contracts.ContractVerificationAttribute(false)]"
);
}
writer
->
WriteLine
(
"[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"
);
WriteGeneratedCodeAttributes
(
writer
);
...
...
This diff is collapsed.
Click to expand it.
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