Expand description
IDL → C99 codegen mode (vendor spec zerodds-xcdr2-c-1.0).
For each IDL specification, this module emits:
- C99
typedef structdefinitions perstruct(with a module prefix in the type name, because C99 has no namespaces). - Static
zerodds_typesupport_ttables with XCDR2 encoder/ decoder/key-hash/free function pointers. - Inline body implementations of the encoders/decoders that produce the XCDR2 wire format (XTypes 1.3 §7.4) byte-exactly.
§Scope
Supported:
- Structs with
@final/@appendable/@mutableextensibility. - Primitive types (boolean, octet, short/long/long long + unsigned, float, double).
string(unbounded).sequence<T>(unbounded; nested sequences allowed).- Nested modules → type-name prefix with
::(cross-language convention) and identifier prefix with_(C99-conformant). @keymembers → key-hash routine viaPlainCdr2BeKeyHolder.@id(N)for @mutable.- Enums →
int32_talias + prefixed enumerator constants (Bug C). - Typedefs → resolved to the aliased type at every reference (Bug C).
- Nested struct members → inline-embedded by value (Bug C).
- Fixed arrays (
T x[N][M]…) → C array, no length prefix (Bug C). @optionalmembers →<name>_presentcompanion flag + a wire presence boolean (Bug C2; no longer flattened to mandatory).- Array bound by named constant (
long v[N]) → the bound is resolved through the const symbol table (#43, const-array-bound). sequence<T>for primitive, string, enum, nested struct and nestedsequence<…>element types (#43, sequence widening).map<K,V>→ parallelkeys[]/vals[]arrays + DHEADER/count codec (#43, map).wstring→ NUL-terminateduint16_t*, UTF-16-LE on the wire (XTypes §7.4.4.6) (#43, wstring).- Discriminated
union→ C tagged unionstruct { D _d; union {…} _u; }with a switch-on-discriminator encode/decode (#43, union). A top-level union additionally gets aTypeSupportso it can be a topic type. typedef-to-aggregate (alias of a struct / sequence / map) → resolved to the aliased aggregate at every reference (#43, typedef-to-aggregate).- typedef ALIAS CHAIN + typedef-to-array (
typedef A B; typedef long M[3][3];) → resolved through the chain to the root type; an array-alias contributes its dims at the use site (#43, typedefs). bitmask→ smallest holder uint typedef (default@bit_bound(32)→uint32_t) +<LABEL>flag-bit constants;bitset→ packed holder uint typedef + per-field SHIFT/MASK accessor macros. Both serialize as their holder integer (XTypes §7.3.1.2) (#43, bitset/bitmask).- Self-/mutually-recursive types (self-referential through a sequence,
or mutual
@external) → a heap-indirected C type (pointer-to-tag element) plus a runtime_write_body/_read_bodyhelper that splices the recursion at RUNTIME (XTypes §7.4.5) (#43, recursion / forward-decl). - Forward-declared struct/union (then defined) → aggregate typedefs are emitted in by-value dependency order so a later definition is reachable.
Out of scope (errors at the codegen level, honest partial):
fixed<M,N>decimal,any,long double— these legitimately stay out of the C profile (no native C fixed-decimal / variant type).- A genuinely infinite-size type (a by-value self/mutual cycle, e.g.
struct Node { Node n; };) is rejected cleanly — the only legal self-reference is heap-indirected (through a sequence). @optionalinside a nested struct, nested@appendable/@mutablestruct splice (only the inline@finalform is wired), nested-aggregate union arms inside a@mutablemember, and freeing of heap-owning members reached only through a fixed array.
§Invocation
use zerodds_idl::config::ParserConfig;
use zerodds_idl_cpp::{generate_c_header, CGenOptions};
let ast = zerodds_idl::parse("@final struct Point { long x; long y; };",
&ParserConfig::default()).unwrap();
let header = generate_c_header(&ast, &CGenOptions::default()).unwrap();
assert!(header.contains("typedef struct Point_s"));
assert!(header.contains("Point_typesupport"));Structs§
- CGen
Options - Codegen options (parallel to
CppGenOptions).
Functions§
- generate_
c_ header - Produces a complete C99 header from an IDL specification.