Definition() : generated(false), defined_namespace(nullptr) {}
std::string name;
- std::string doc_comment;
+ std::vector<std::string> doc_comment;
SymbolTable<Value> attributes;
bool generated; // did we already output code for this definition?
Namespace *defined_namespace; // Where it was defined.
: name(_name), value(_val), struct_def(nullptr) {}
std::string name;
- std::string doc_comment;
+ std::vector<std::string> doc_comment;
int64_t value;
StructDef *struct_def; // only set if this is a union
};
const char *source_, *cursor_;
int line_; // the current line being parsed
int token_;
- std::string attribute_, doc_comment_;
+ std::string attribute_;
+ std::vector<std::string> doc_comment_;
std::vector<std::pair<Value, FieldDef *>> field_stack_;
std::vector<uint8_t> struct_stack_;
// Utility functions for multiple generators:
extern std::string MakeCamel(const std::string &in, bool first = true);
-extern void GenComment(const std::string &dc, std::string *code_ptr,
+extern void GenComment(const std::vector<std::string> &dc,
+ std::string *code_ptr,
const char *prefix = "");
// Container of options that may apply to any of the source/text generators.
}
// 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";
}
}
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) {
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);
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
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);
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;
}
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;
}
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);
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()
}
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_;
public int Test4Length() { int o = __offset(22); return o != 0 ? __vector_len(o) : 0; }
public string Testarrayofstring(int j) { int o = __offset(24); return o != 0 ? __string(__vector(o) + j * 4) : null; }
public int TestarrayofstringLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; }
- /// an example documentation comment: this will end up in the generated code multiline too
+ /// an example documentation comment: this will end up in the generated code
+ /// multiline too
public Monster Testarrayoftables(int j) { return Testarrayoftables(new Monster(), j); }
public Monster Testarrayoftables(Monster obj, int j) { int o = __offset(26); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; }
public int TestarrayoftablesLength() { int o = __offset(26); return o != 0 ? __vector_len(o) : 0; }
return 0
}
-/// an example documentation comment: this will end up in the generated code multiline too
+/// an example documentation comment: this will end up in the generated code
+/// multiline too
func (rcv *Monster) Testarrayoftables(obj *Monster, j int) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(26))
if o != 0 {
public String testarrayofstring(int j) { int o = __offset(24); return o != 0 ? __string(__vector(o) + j * 4) : null; }
public int testarrayofstringLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; }
public ByteBuffer testarrayofstringAsByteBuffer() { return __vector_as_bytebuffer(24, 4); }
- /// an example documentation comment: this will end up in the generated code multiline too
+ /// an example documentation comment: this will end up in the generated code
+ /// multiline too
public Monster testarrayoftables(int j) { return testarrayoftables(new Monster(), j); }
public Monster testarrayoftables(Monster obj, int j) { int o = __offset(26); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; }
public int testarrayoftablesLength() { int o = __offset(26); return o != 0 ? __vector_len(o) : 0; }
const void *test() const { return GetPointer<const void *>(20); }
const flatbuffers::Vector<const Test *> *test4() const { return GetPointer<const flatbuffers::Vector<const Test *> *>(22); }
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *testarrayofstring() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(24); }
- /// an example documentation comment: this will end up in the generated code multiline too
+ /// an example documentation comment: this will end up in the generated code
+ /// multiline too
const flatbuffers::Vector<flatbuffers::Offset<Monster>> *testarrayoftables() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Monster>> *>(26); }
const Monster *enemy() const { return GetPointer<const Monster *>(28); }
const flatbuffers::Vector<uint8_t> *testnestedflatbuffer() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(30); }