mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Output multiline doc comments over multiple lines
Tested: on Linux Bug: 15779934 Change-Id: I6f822f1705e443d8721ea208dcb021aad3c8715c
This commit is contained in:
@@ -38,11 +38,13 @@ std::string MakeCamel(const std::string &in, bool first) {
|
||||
}
|
||||
|
||||
// Generate a documentation comment, if available.
|
||||
void GenComment(const std::string &dc, std::string *code_ptr,
|
||||
void GenComment(const std::vector<std::string> &dc, std::string *code_ptr,
|
||||
const char *prefix) {
|
||||
std::string &code = *code_ptr;
|
||||
if (dc.length()) {
|
||||
code += std::string(prefix) + "///" + dc + "\n";
|
||||
for (auto it = dc.begin();
|
||||
it != dc.end();
|
||||
++it) {
|
||||
code += std::string(prefix) + "///" + *it + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,16 +44,6 @@ static std::string GenTypeGet(const Type &type);
|
||||
static std::string TypeName(const FieldDef &field);
|
||||
|
||||
|
||||
// Write a comment.
|
||||
static void Comment(const std::string &dc,
|
||||
std::string *code_ptr,
|
||||
const char *prefix = "") {
|
||||
std::string &code = *code_ptr;
|
||||
if (dc.length()) {
|
||||
code += std::string(prefix) + "///" + dc + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Most field accessors need to retrieve and test the field offset first,
|
||||
// this is the prefix code for that.
|
||||
std::string OffsetPrefix(const FieldDef &field) {
|
||||
@@ -453,7 +443,7 @@ static void GenReceiver(const StructDef &struct_def, std::string *code_ptr) {
|
||||
static void GenStructAccessor(const StructDef &struct_def,
|
||||
const FieldDef &field,
|
||||
std::string *code_ptr) {
|
||||
Comment(field.doc_comment, code_ptr, "");
|
||||
GenComment(field.doc_comment, code_ptr, "");
|
||||
if (IsScalar(field.value.type.base_type)) {
|
||||
if (struct_def.fixed) {
|
||||
GetScalarFieldOfStruct(struct_def, field, code_ptr);
|
||||
@@ -520,7 +510,7 @@ static void GenStruct(const StructDef &struct_def,
|
||||
StructDef *root_struct_def) {
|
||||
if (struct_def.generated) return;
|
||||
|
||||
Comment(struct_def.doc_comment, code_ptr);
|
||||
GenComment(struct_def.doc_comment, code_ptr);
|
||||
BeginClass(struct_def, code_ptr);
|
||||
if (&struct_def == root_struct_def) {
|
||||
// Generate a special accessor for the table that has been declared as
|
||||
@@ -552,13 +542,13 @@ static void GenStruct(const StructDef &struct_def,
|
||||
static void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
|
||||
if (enum_def.generated) return;
|
||||
|
||||
Comment(enum_def.doc_comment, code_ptr);
|
||||
GenComment(enum_def.doc_comment, code_ptr);
|
||||
BeginEnum(code_ptr);
|
||||
for (auto it = enum_def.vals.vec.begin();
|
||||
it != enum_def.vals.vec.end();
|
||||
++it) {
|
||||
auto &ev = **it;
|
||||
Comment(ev.doc_comment, code_ptr, " ");
|
||||
GenComment(ev.doc_comment, code_ptr, "\t");
|
||||
EnumMember(enum_def, ev, code_ptr);
|
||||
}
|
||||
EndEnum(code_ptr);
|
||||
|
||||
@@ -186,8 +186,7 @@ void Parser::Next() {
|
||||
if (*start == '/') { // documentation comment
|
||||
if (!seen_newline)
|
||||
Error("a documentation comment should be on a line on its own");
|
||||
// todo: do we want to support multiline comments instead?
|
||||
doc_comment_ += std::string(start + 1, cursor_);
|
||||
doc_comment_.push_back(std::string(start + 1, cursor_));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -345,7 +344,7 @@ FieldDef &Parser::AddField(StructDef &struct_def,
|
||||
|
||||
void Parser::ParseField(StructDef &struct_def) {
|
||||
std::string name = attribute_;
|
||||
std::string dc = doc_comment_;
|
||||
std::vector<std::string> dc = doc_comment_;
|
||||
Expect(kTokenIdentifier);
|
||||
Expect(':');
|
||||
Type type;
|
||||
@@ -704,7 +703,7 @@ StructDef *Parser::LookupCreateStruct(const std::string &name) {
|
||||
}
|
||||
|
||||
void Parser::ParseEnum(bool is_union) {
|
||||
std::string dc = doc_comment_;
|
||||
std::vector<std::string> dc = doc_comment_;
|
||||
Next();
|
||||
std::string name = attribute_;
|
||||
Expect(kTokenIdentifier);
|
||||
@@ -734,7 +733,7 @@ void Parser::ParseEnum(bool is_union) {
|
||||
if (is_union) enum_def.vals.Add("NONE", new EnumVal("NONE", 0));
|
||||
do {
|
||||
std::string name = attribute_;
|
||||
std::string dc = doc_comment_;
|
||||
std::vector<std::string> dc = doc_comment_;
|
||||
Expect(kTokenIdentifier);
|
||||
auto prevsize = enum_def.vals.vec.size();
|
||||
auto value = enum_def.vals.vec.size()
|
||||
@@ -767,7 +766,7 @@ void Parser::ParseEnum(bool is_union) {
|
||||
}
|
||||
|
||||
void Parser::ParseDecl() {
|
||||
std::string dc = doc_comment_;
|
||||
std::vector<std::string> dc = doc_comment_;
|
||||
bool fixed = IsNext(kTokenStruct);
|
||||
if (!fixed) Expect(kTokenTable);
|
||||
std::string name = attribute_;
|
||||
|
||||
Reference in New Issue
Block a user