Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
protobuf-c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
protobuf-c
Commits
35ec2e2f
Commit
35ec2e2f
authored
Dec 16, 2014
by
Ilya Lipnitskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protoc-c: Print comments for generated enum, message, and field definitions
parent
8eec9c90
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
0 deletions
+48
-0
protoc-c/c_enum.cc
protoc-c/c_enum.cc
+9
-0
protoc-c/c_helpers.cc
protoc-c/c_helpers.cc
+22
-0
protoc-c/c_helpers.h
protoc-c/c_helpers.h
+3
-0
protoc-c/c_message.cc
protoc-c/c_message.cc
+14
-0
No files found.
protoc-c/c_enum.cc
View file @
35ec2e2f
...
...
@@ -86,6 +86,10 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
vars
[
"shortname"
]
=
descriptor_
->
name
();
vars
[
"uc_name"
]
=
FullNameToUpper
(
descriptor_
->
full_name
());
SourceLocation
sourceLoc
;
descriptor_
->
GetSourceLocation
(
&
sourceLoc
);
PrintComment
(
printer
,
sourceLoc
.
leading_comments
);
printer
->
Print
(
vars
,
"typedef enum _$classname$ {
\n
"
);
printer
->
Indent
();
...
...
@@ -101,6 +105,11 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
if
(
i
+
1
==
descriptor_
->
value_count
())
vars
[
"opt_comma"
]
=
""
;
SourceLocation
valSourceLoc
;
descriptor_
->
value
(
i
)
->
GetSourceLocation
(
&
valSourceLoc
);
PrintComment
(
printer
,
valSourceLoc
.
leading_comments
);
PrintComment
(
printer
,
valSourceLoc
.
trailing_comments
);
printer
->
Print
(
vars
,
"$prefix$$name$ = $number$$opt_comma$
\n
"
);
if
(
descriptor_
->
value
(
i
)
->
number
()
<
min_value
->
number
())
{
...
...
protoc-c/c_helpers.cc
View file @
35ec2e2f
...
...
@@ -210,6 +210,28 @@ string FullNameToC(const string &full_name) {
return
rv
;
}
void
PrintComment
(
io
::
Printer
*
printer
,
string
comment
)
{
if
(
!
comment
.
empty
())
{
vector
<
string
>
comment_lines
;
SplitStringUsing
(
comment
,
"
\r\n
"
,
&
comment_lines
);
printer
->
Print
(
"/*
\n
"
);
for
(
int
i
=
0
;
i
<
comment_lines
.
size
();
i
++
)
{
if
(
!
comment_lines
[
i
].
empty
())
{
/* Make sure we don't inadvertently close the comment block */
if
(
comment_lines
[
i
][
0
]
==
'/'
)
comment_lines
[
i
]
=
' '
+
comment_lines
[
i
];
printer
->
Print
(
" *$line$
\n
"
,
"line"
,
comment_lines
[
i
]);
}
}
printer
->
Print
(
" */
\n
"
);
}
}
string
ConvertToSpaces
(
const
string
&
input
)
{
return
string
(
input
.
size
(),
' '
);
}
...
...
protoc-c/c_helpers.h
View file @
35ec2e2f
...
...
@@ -138,6 +138,9 @@ string FullNameToUpper(const string &full_name);
// full_name() to c-typename (with underscores for packages, otherwise camel case)
string
FullNameToC
(
const
string
&
class_name
);
// Splits, indents, formats, and prints comment lines
void
PrintComment
(
io
::
Printer
*
printer
,
string
comment
);
// make a string of spaces as long as input
string
ConvertToSpaces
(
const
string
&
input
);
...
...
protoc-c/c_message.cc
View file @
35ec2e2f
...
...
@@ -166,6 +166,10 @@ GenerateStructDefinition(io::Printer* printer) {
printer
->
Print
(
vars
,
"} $foneofname$Case;
\n\n
"
);
}
SourceLocation
msgSourceLoc
;
descriptor_
->
GetSourceLocation
(
&
msgSourceLoc
);
PrintComment
(
printer
,
msgSourceLoc
.
leading_comments
);
printer
->
Print
(
vars
,
"struct $dllexport$ _$classname$
\n
"
"{
\n
"
...
...
@@ -176,6 +180,11 @@ GenerateStructDefinition(io::Printer* printer) {
for
(
int
i
=
0
;
i
<
descriptor_
->
field_count
();
i
++
)
{
const
FieldDescriptor
*
field
=
descriptor_
->
field
(
i
);
if
(
field
->
containing_oneof
()
==
NULL
)
{
SourceLocation
fieldSourceLoc
;
field
->
GetSourceLocation
(
&
fieldSourceLoc
);
PrintComment
(
printer
,
fieldSourceLoc
.
leading_comments
);
PrintComment
(
printer
,
fieldSourceLoc
.
trailing_comments
);
field_generators_
.
get
(
field
).
GenerateStructMembers
(
printer
);
}
}
...
...
@@ -192,6 +201,11 @@ GenerateStructDefinition(io::Printer* printer) {
printer
->
Indent
();
for
(
int
j
=
0
;
j
<
oneof
->
field_count
();
j
++
)
{
const
FieldDescriptor
*
field
=
oneof
->
field
(
j
);
SourceLocation
fieldSourceLoc
;
field
->
GetSourceLocation
(
&
fieldSourceLoc
);
PrintComment
(
printer
,
fieldSourceLoc
.
leading_comments
);
PrintComment
(
printer
,
fieldSourceLoc
.
trailing_comments
);
field_generators_
.
get
(
field
).
GenerateStructMembers
(
printer
);
}
printer
->
Outdent
();
...
...
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