Skip to content

Preserve trailing struct comments in generated C (closes #336) - #399

Closed
khushi-infinity wants to merge 3 commits into
dvidelabs:masterfrom
khushi-infinity:fix-comment-placement-bug
Closed

khushi-infinity wants to merge 3 commits into
dvidelabs:masterfrom
khushi-infinity:fix-comment-placement-bug

Conversation

@khushi-infinity

Copy link
Copy Markdown

Summary

Trailing /// comments after the last field of a schema struct were emitted before a later generated type instead of inside the generated C struct. This change keeps those comments with their schema
struct and places them before the generated closing brace.

Changes

  • Store trailing documentation comments on the schema struct and clear parser comment state before advancing past }.
  • Emit the saved comments inside the generated C struct.
  • Add a regression test for multiple trailing comment lines and for a separate comment after the closing brace.

Testing

  • cmake -S . -B /private/tmp/flatcc-issue336-build -G "Unix Makefiles" -DFLATCC_CXX_TEST=OFF -DCMAKE_BUILD_TYPE=Debug — passed.
  • cmake --build /private/tmp/flatcc-issue336-build --target cgen_test test_generated — passed; generated C compiled.
  • ctest --test-dir /private/tmp/flatcc-issue336-build -R cgen_test --output-on-failure — passed, 2/2 tests.
  • git diff --check — passed.
  • ASan/UBSan build did not complete: Apple Clang treated an existing sprintf deprecation in src/compiler/semantics.c:1536 as an error, so the sanitizer test did not run.
  • cppcheck and clang-format were unavailable.

Issue

Fixes #336.

AI assistance

ByteAsk assisted with investigation, implementation, regression-test development, verification, and drafting this description. This text is AI-generated and has not been represented as human-written.

@mikkelfj

Copy link
Copy Markdown
Contributor

Insufficient AI capability.

@mikkelfj mikkelfj closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment lines placed after the last 'struct' field (in schema file) appear outside generated C language 'struct' definition

2 participants