diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc index 14351521590..74a89812ff7 100644 --- a/lang/c++/impl/avrogencpp.cc +++ b/lang/c++/impl/avrogencpp.cc @@ -113,6 +113,7 @@ class CodeGen { void generateTraits(const NodePtr &n); void generateRecordTraits(const NodePtr &n); void generateUnionTraits(const NodePtr &n); + void generateDocComment(const NodePtr &n, const char *indent = ""); void emitCopyright(); void emitGeneratedWarning(); @@ -253,6 +254,7 @@ string CodeGen::generateRecordType(const NodePtr &n) { return it->second; } + generateDocComment(n); os_ << "struct " << decoratedName << " {\n"; if (!noUnion_) { for (size_t i = 0; i < c; ++i) { @@ -271,6 +273,7 @@ string CodeGen::generateRecordType(const NodePtr &n) { // the nameAt(i) does not take c++ reserved words into account // so we need to call decorate on it std::string decoratedNameAt = decorate(n->nameAt(i)); + generateDocComment(n->leafAt(i), " "); os_ << " " << types[i]; os_ << ' ' << decoratedNameAt << ";\n"; } @@ -409,7 +412,7 @@ string CodeGen::generateUnionType(const NodePtr &n) { for (size_t i = 0; i < c; ++i) { // escape reserved literals for c++ auto branch_name = decorate(names[i]); - // avoid rare collisions, e.g. somone might name their struct int_ + // avoid rare collisions, e.g. someone might name their struct int_ if (used_branch_names.find(branch_name) != used_branch_names.end()) { size_t postfix = 2; std::string escaped_name = branch_name + "_" + std::to_string(postfix); @@ -739,6 +742,16 @@ void CodeGen::generateTraits(const NodePtr &n) { } } +void CodeGen::generateDocComment(const NodePtr &n, const char *indent) { + if (!n->getDoc().empty()) { + std::vector lines; + boost::algorithm::split(lines, n->getDoc(), boost::algorithm::is_any_of("\n")); + for (auto &line : lines) { + os_ << indent << "// " << line << "\n"; + } + } +} + void CodeGen::emitCopyright() { os_ << "/**\n" " * Licensed to the Apache Software Foundation (ASF) under one\n" @@ -954,4 +967,4 @@ bool UnionCodeTracker::unionTraitsAlreadyGenerated(const std::string &unionClass void UnionCodeTracker::setTraitsGenerated(const std::string &unionClassName) { generatedUnionTraits_.insert(unionClassName); -} \ No newline at end of file +} diff --git a/lang/c++/jsonschemas/bigrecord b/lang/c++/jsonschemas/bigrecord index af8a5ad39b8..a7db543e650 100644 --- a/lang/c++/jsonschemas/bigrecord +++ b/lang/c++/jsonschemas/bigrecord @@ -1,6 +1,6 @@ { "type": "record", - "doc": "Top level Doc.", + "doc": "Top level Doc.\nWith multiple lines", "name": "RootRecord", "fields": [ {