Skip to content

Add #cpp_heap_allocated directive, deprecate #cpp_value - #145

Merged
hkalbasi merged 2 commits into
hkalbasi:mainfrom
camio:cpp-heap-allocated-directive
Aug 31, 2026
Merged

Add #cpp_heap_allocated directive, deprecate #cpp_value#145
hkalbasi merged 2 commits into
hkalbasi:mainfrom
camio:cpp-heap-allocated-directive

Conversation

@camio

@camio camio commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Non-AI synopsis

I added #cpp_heap_allocated to replace #cpp_value to address #143.

I left #cpp_value in for backward compatibility. If you use it, you get a warning.

There wasn't an effective warning mechanism in place, so I added one as well. There was some complexity because I wanted to ensure "cargo:warning=" is prefixed, so you get warnings when you use zngur through cargo. I'm not happy with the add_errors, add_error_str, and add_warning_str set of functions. It doesn't feel like a very good API, but fixing it would require deeper refactors, I fear.

What's below is AI commentary...

Summary

  • Adds #cpp_heap_allocated "CppType"; as a replacement for
    #cpp_value "field" "CppType";, dropping the field parameter that
    is parsed but never used by codegen (closes #cpp_value's first argument (field) is parsed but never used #143).
  • #cpp_value remains supported for backward compatibility: it now
    forwards to the same internal logic as #cpp_heap_allocated and
    emits a deprecation warning (rendered as an ariadne diagnostic
    pointing at the directive's location, including across imported
    .zng files).
  • Warnings are delivered via Zngur::with_warning_sink() (defaulting
    to Cargo's cargo:warning= convention when used from a build
    script) and via plain eprintln! in zngur-cli.
  • Internal representation renamed from CppValue/cpp_value to
    CppHeapAllocated/cpp_heap_allocated throughout zngur-def,
    zngur-parser, and zngur-generator, following the same
    parse-time-struct-plus-generator-produced-struct convention already
    used for ZngurField/ZngurFieldData.
  • Documentation and the two example .zng files updated to use the
    new directive.

Test plan

  • cargo test across zngur-def, zngur-parser, zngur-generator,
    zngur, zngur-cli (37 parser tests, all passing)
  • examples/tutorial_cpp (build.rs path) builds and runs correctly
    with the new directive, and with #cpp_value temporarily
    reintroduced, correctly shows the cargo:warning=-rendered
    deprecation diagnostic
  • examples/multiple_modules (CLI path via its Makefile) builds
    and runs correctly, matching expected_output.txt
  • cargo fmt --check clean on all touched crates

🤖 Generated with Claude Code

camio and others added 2 commits August 31, 2026 18:15
#cpp_value's first argument is parsed but never used by codegen (it's
overwritten before reaching generated code) — see hkalbasi#143. This adds
#cpp_heap_allocated as a replacement without that dead parameter,
deprecates #cpp_value (still functional, forwards to the same logic,
emits an ariadne-rendered deprecation warning pointing at the
directive), and updates the internal representation, docs, and
examples to match.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
cspell flagged "Allocateds" (an invented plural of CppHeapAllocated) as
an unknown word, unlike "CppRefs" nearby, whose "Refs" is a real word.
Reworded to avoid pluralizing the type name.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@hkalbasi
hkalbasi merged commit 5d304fd into hkalbasi:main Aug 31, 2026
10 checks passed
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.

#cpp_value's first argument (field) is parsed but never used

2 participants