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
dc24b605
Commit
dc24b605
authored
Sep 23, 2011
by
csharptest
Committed by
rogerk
Sep 23, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generator changes to fix circular reference issues in static ctor
parent
8bd88ea8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
25 deletions
+32
-25
MessageFieldGenerator.cs
src/ProtoGen/MessageFieldGenerator.cs
+3
-3
MessageGenerator.cs
src/ProtoGen/MessageGenerator.cs
+26
-19
RepeatedEnumFieldGenerator.cs
src/ProtoGen/RepeatedEnumFieldGenerator.cs
+1
-1
RepeatedMessageFieldGenerator.cs
src/ProtoGen/RepeatedMessageFieldGenerator.cs
+1
-1
RepeatedPrimitiveFieldGenerator.cs
src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs
+1
-1
No files found.
src/ProtoGen/MessageFieldGenerator.cs
View file @
dc24b605
...
...
@@ -48,12 +48,12 @@ namespace Google.ProtocolBuffers.ProtoGen
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private bool has{0};"
,
PropertyName
);
writer
.
WriteLine
(
"private {0} {1}_
= {2};"
,
TypeName
,
Name
,
DefaultValu
e
);
writer
.
WriteLine
(
"private {0} {1}_
;"
,
TypeName
,
Nam
e
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return {0}_
; }}"
,
Nam
e
);
writer
.
WriteLine
(
" get {{ return {0}_
?? {1}; }}"
,
Name
,
DefaultValu
e
);
writer
.
WriteLine
(
"}"
);
}
...
...
@@ -96,7 +96,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
PropertyName
);
writer
.
WriteLine
(
" PrepareBuilder();"
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
PropertyName
);
writer
.
WriteLine
(
" result.{0}_ =
{1};"
,
Name
,
DefaultValu
e
);
writer
.
WriteLine
(
" result.{0}_ =
null;"
,
Nam
e
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
}
...
...
src/ProtoGen/MessageGenerator.cs
View file @
dc24b605
...
...
@@ -178,7 +178,7 @@ namespace Google.ProtocolBuffers.ProtoGen
RuntimeSuffix
);
writer
.
Indent
();
// Must call BuildPartial() to make sure all lists are made read-only
writer
.
WriteLine
(
"private static readonly {0} defaultInstance = new
Builder().BuildPartial
();"
,
ClassName
);
writer
.
WriteLine
(
"private static readonly {0} defaultInstance = new
{0}().MakeReadOnly
();"
,
ClassName
);
if
(
OptimizeSpeed
)
{
...
...
@@ -199,7 +199,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
();
writer
.
WriteLine
(
"public override {0} DefaultInstanceForType {{"
,
ClassName
);
writer
.
WriteLine
(
" get { return
d
efaultInstance; }"
);
writer
.
WriteLine
(
" get { return
D
efaultInstance; }"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
();
writer
.
WriteLine
(
"protected override {0} ThisMessage {{"
,
ClassName
);
...
...
@@ -547,6 +547,17 @@ namespace Google.ProtocolBuffers.ProtoGen
private
void
GenerateBuilder
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private {0} MakeReadOnly() {{"
,
ClassName
);
writer
.
Indent
();
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
CreateFieldGenerator
(
field
).
GenerateBuildingCode
(
writer
);
}
writer
.
WriteLine
(
"return this;"
);
writer
.
Outdent
();
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
();
writer
.
WriteLine
(
"public static Builder CreateBuilder() { return new Builder(); }"
);
writer
.
WriteLine
(
"public override Builder ToBuilder() { return CreateBuilder(this); }"
);
writer
.
WriteLine
(
"public override Builder CreateBuilderForType() { return new Builder(); }"
);
...
...
@@ -585,23 +596,23 @@ namespace Google.ProtocolBuffers.ProtoGen
//default constructor
writer
.
WriteLine
(
"public Builder() {"
);
//Durring static initialization of message, DefaultInstance is expected to return null.
writer
.
WriteLine
(
" result = DefaultInstance
?? new {0}();"
,
ClassName
);
writer
.
WriteLine
(
"
builderIsReadOnly = result == DefaultInstanc
e;"
);
writer
.
WriteLine
(
" result = DefaultInstance
;"
);
writer
.
WriteLine
(
"
resultIsReadOnly = tru
e;"
);
writer
.
WriteLine
(
"}"
);
//clone constructor
writer
.
WriteLine
(
"internal Builder({0} cloneFrom) {{"
,
ClassName
);
writer
.
WriteLine
(
" result = cloneFrom;"
);
writer
.
WriteLine
(
"
builder
IsReadOnly = true;"
);
writer
.
WriteLine
(
"
result
IsReadOnly = true;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
();
writer
.
WriteLine
(
"
bool builder
IsReadOnly;"
);
writer
.
WriteLine
(
"{0} result;"
,
ClassName
);
writer
.
WriteLine
(
"
private bool result
IsReadOnly;"
);
writer
.
WriteLine
(
"
private
{0} result;"
,
ClassName
);
writer
.
WriteLine
();
writer
.
WriteLine
(
"private {0} PrepareBuilder() {{"
,
ClassName
);
writer
.
WriteLine
(
" if (
builder
IsReadOnly) {"
);
writer
.
WriteLine
(
" if (
result
IsReadOnly) {"
);
writer
.
WriteLine
(
" {0} original = result;"
,
ClassName
);
writer
.
WriteLine
(
" result = new {0}();"
,
ClassName
);
writer
.
WriteLine
(
"
builder
IsReadOnly = false;"
);
writer
.
WriteLine
(
"
result
IsReadOnly = false;"
);
writer
.
WriteLine
(
" MergeFrom(original);"
);
writer
.
WriteLine
(
" }"
);
writer
.
WriteLine
(
" return result;"
);
...
...
@@ -617,13 +628,13 @@ namespace Google.ProtocolBuffers.ProtoGen
writer
.
WriteLine
();
//Not actually expecting that DefaultInstance would ever be null here; however, we will ensure it does not break
writer
.
WriteLine
(
"public override Builder Clear() {"
);
writer
.
WriteLine
(
" result = DefaultInstance
?? new {0}()
;"
,
ClassName
);
writer
.
WriteLine
(
"
builder
IsReadOnly = true;"
);
writer
.
WriteLine
(
" result = DefaultInstance;"
,
ClassName
);
writer
.
WriteLine
(
"
result
IsReadOnly = true;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
();
writer
.
WriteLine
(
"public override Builder Clone() {"
);
writer
.
WriteLine
(
" if (
builder
IsReadOnly) {"
);
writer
.
WriteLine
(
" if (
result
IsReadOnly) {"
);
writer
.
WriteLine
(
" return new Builder(result);"
);
writer
.
WriteLine
(
" } else {"
);
writer
.
WriteLine
(
" return new Builder().MergeFrom(result);"
);
...
...
@@ -644,15 +655,11 @@ namespace Google.ProtocolBuffers.ProtoGen
writer
.
WriteLine
(
"public override {0} BuildPartial() {{"
,
ClassName
);
writer
.
Indent
();
writer
.
WriteLine
(
"if (
builder
IsReadOnly) {"
);
writer
.
WriteLine
(
"if (
result
IsReadOnly) {"
);
writer
.
WriteLine
(
" return result;"
);
writer
.
WriteLine
(
"}"
);
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
CreateFieldGenerator
(
field
).
GenerateBuildingCode
(
writer
);
}
writer
.
WriteLine
(
"builderIsReadOnly = true;"
);
writer
.
WriteLine
(
"return result;"
);
writer
.
WriteLine
(
"resultIsReadOnly = true;"
);
writer
.
WriteLine
(
"return result.MakeReadOnly();"
);
writer
.
Outdent
();
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
();
...
...
src/ProtoGen/RepeatedEnumFieldGenerator.cs
View file @
dc24b605
...
...
@@ -110,7 +110,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public
void
GenerateBuildingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"
result.
{0}_.MakeReadOnly();"
,
Name
);
writer
.
WriteLine
(
"{0}_.MakeReadOnly();"
,
Name
);
}
public
void
GenerateParsingCode
(
TextGenerator
writer
)
...
...
src/ProtoGen/RepeatedMessageFieldGenerator.cs
View file @
dc24b605
...
...
@@ -122,7 +122,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public
void
GenerateBuildingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"
result.
{0}_.MakeReadOnly();"
,
Name
);
writer
.
WriteLine
(
"{0}_.MakeReadOnly();"
,
Name
);
}
public
void
GenerateParsingCode
(
TextGenerator
writer
)
...
...
src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs
View file @
dc24b605
...
...
@@ -119,7 +119,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public
void
GenerateBuildingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"
result.
{0}_.MakeReadOnly();"
,
Name
);
writer
.
WriteLine
(
"{0}_.MakeReadOnly();"
,
Name
);
}
public
void
GenerateParsingCode
(
TextGenerator
writer
)
...
...
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