v.gen.c.naming #
Keep this marker synchronized with v.flat's static type-method name codec.
fn c_name #
fn c_name(name string) string
c_name returns the C identifier used for a V symbol or type name.
fn c_name_needs_internal_namespace #
fn c_name_needs_internal_namespace(name string) bool
c_name_needs_internal_namespace reports names that cannot use cgen's direct identifier fast paths because c_name applies the internal-symbol partition.
fn fn_ptr_encoded #
fn fn_ptr_encoded(ret string, params []string) string
fn_ptr_encoded returns the internal fn_ptr:ret|params key of a function-pointer signature from the C spellings of its return type and parameter types. A part that is itself a fn_ptr: key is wrapped in parentheses (see fn_ptr_encoded_part), so its own | and , separators cannot merge into the enclosing signature.
fn fn_ptr_encoded_params #
fn fn_ptr_encoded_params(params string) []string
fn_ptr_encoded_params splits the raw parameter list of a fn_ptr:ret|params key into its parameter C types, keeping each parenthesized nested fn_ptr: key in one piece and unwrapping it. A void (or empty) list yields no parameters.
fn fn_ptr_encoded_part #
fn fn_ptr_encoded_part(ct string) string
fn_ptr_encoded_part spells a return or parameter C type the way it is embedded in an enclosing fn_ptr:ret|params key. A nested fn_ptr: key is parenthesized: spliced in as is, fn (int, fn (int, int) int) and fn (int, fn (int) int, int) would both read fn_ptr:void|i64, fn_ptr:i64|i64, i64.
fn fn_ptr_encoded_split #
fn fn_ptr_encoded_split(encoded string) (string, string)
fn_ptr_encoded_split splits a fn_ptr:ret|params key into its return type (with a nested fn_ptr: key unwrapped) and its raw parameter list (see fn_ptr_encoded_params). A key without a parameter list yields void parameters.
fn fn_ptr_encoded_unwrap #
fn fn_ptr_encoded_unwrap(part string) string
fn_ptr_encoded_unwrap undoes fn_ptr_encoded_part for one return or parameter part.
fn fn_ptr_type_name #
fn fn_ptr_type_name(encoded string) string
fn_ptr_type_name returns the stable C typedef name for an encoded function-pointer signature.
fn is_libc_collision #
fn is_libc_collision(name string) bool
is_libc_collision reports whether name needs a prefix to avoid a libc symbol.
fn is_plain_identifier #
fn is_plain_identifier(name string) bool
is_plain_identifier reports whether name already contains only C identifier characters.
fn is_reserved_word #
fn is_reserved_word(name string) bool
is_reserved_word reports whether name needs a prefix to avoid a C reserved word.
fn local_rename #
fn local_rename(cname string) string
local_rename returns the name a local is emitted under when it cannot keep its own. A suffix would not be enough: a function may have both array and array__local of its own, and a suffix would bring the two together under one name. Nothing a source name sanitizes to begins with this prefix -- c_name pushes anything that tries into its source_ namespace -- so nothing can arrive here by accident.
fn sanitize #
fn sanitize(name string) string
sanitize converts a V symbol or type spelling into a C identifier spelling without applying reserved-word or libc collision prefixes.
fn type_name_part #
fn type_name_part(s string) string
type_name_part turns a C type or length expression into a fragment that is safe to embed inside a C identifier: * becomes ptr (so pointer payloads stay distinguishable), and every other character that is not a letter, digit, or _ becomes _. This keeps const-expression fixed-array lengths (e.g. segs + 1) and pointer return types (Foo*) from producing invalid identifiers such as Array_fixed_f32_segs_+_1 or __v_thread_arr_wait_Foo*.