Skip to main content

Module common

Module common 

Source
Expand description

Shared codegen primitives that every language generator can reuse.

Until 0.4.0, every generator hand-rolled its own copy of the module tree walker, the doc-comment emitter, and the “is this type a C pointer at the ABI boundary?” predicate. Pulling them in here gives the generators one source of truth and shrinks each crate by a few dozen lines of near-identical helper code.

Specialised flavours that exist in only one generator (Go’s godoc-style first-line symbol prefix, .NET’s <summary> XML tags, Python’s triple-quoted docstring) stay generator-local because their behaviour is non-uniform; this module deliberately covers only the common 80%.

Enums§

DocCommentStyle
Doc-comment flavour used by emit_doc.

Functions§

emit_doc
Emit a doc comment for doc at the given indent, using the given style. No-op when doc is None or trims to empty.
is_c_pointer_type
Predicate: returns true when the IR type is represented as a pointer at the C ABI boundary.
pascal_case
Convert a snake_case identifier to PascalCase by uppercasing the first character of each _-separated segment and preserving the rest.
walk_modules
Iterate over every module in roots and its descendants in depth-first pre-order: each module is yielded before its children, and children are yielded left-to-right.
walk_modules_with_path
Like walk_modules, but each module is paired with its underscore-joined path (e.g. parent_child_grandchild). The path matches the canonical C symbol prefix segment that the C generator builds when emitting {c_prefix}_{module_path}_{name}.