aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler/generator_helpers.h
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2016-04-15 10:46:41 -0700
committerGravatar yang-g <yangg@google.com>2016-04-15 10:46:41 -0700
commit2e08941a37450b42dd21e8755e07091ea444f545 (patch)
treeac983fa62738be1f70788719f30254d097fa9dd2 /src/compiler/generator_helpers.h
parent8282b755a217031a60329fb4ed2f54cd46966628 (diff)
Use the comments before syntax line as file comments.
Diffstat (limited to 'src/compiler/generator_helpers.h')
-rw-r--r--src/compiler/generator_helpers.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h
index 16f0ca32df..9ba7356857 100644
--- a/src/compiler/generator_helpers.h
+++ b/src/compiler/generator_helpers.h
@@ -207,6 +207,33 @@ inline void GetComment(const DescriptorType *desc, CommentType type,
}
}
+// For file level leading and detached leading comments, we return comments
+// above syntax line. Return nothing for trailing comments.
+template <>
+inline void GetComment(const grpc::protobuf::FileDescriptor *desc,
+ CommentType type, std::vector<grpc::string> *out) {
+ if (type == COMMENTTYPE_TRAILING) {
+ return;
+ }
+ grpc::protobuf::SourceLocation location;
+ std::vector<int> path;
+ path.push_back(grpc::protobuf::FileDescriptorProto::kSyntaxFieldNumber);
+ if (!desc->GetSourceLocation(path, &location)) {
+ return;
+ }
+ if (type == COMMENTTYPE_LEADING) {
+ Split(location.leading_comments, '\n', out);
+ } else if (type == COMMENTTYPE_LEADING_DETACHED) {
+ for (unsigned int i = 0; i < location.leading_detached_comments.size();
+ i++) {
+ Split(location.leading_detached_comments[i], '\n', out);
+ out->push_back("");
+ }
+ } else {
+ abort();
+ }
+}
+
} // namespace grpc_generator
#endif // GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H