Skip to content

v.gen.c.naming

Constants #

const operator_method_c_prefix = '${internal_symbol_c_prefix}op_'

operator_method_c_prefix starts the C name of an operator overload method (Vec.+). sanitize spells an operator as a word (Vec__plus), and an ordinary method of the same receiver can have that word as its name (Vec.plus). No source name can sanitize to a name in the internal namespace, so the two cannot meet in C.

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 fn_signature_key #

fn fn_signature_key(variant string) string

fn global_rename #

fn global_rename(cname string) string

global_rename returns collision-free storage for a global sharing a callable name. The internal namespace is disjoint from source names and renamed locals.

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_operator_method_name #

@[direct_array_access]
fn is_operator_method_name(name string) bool

is_operator_method_name reports whether name is the V name of an operator overload method: a receiver, . and the operator (Vec.+, Box[T].[]=).

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 plain_name_may_be_reserved #

@[direct_array_access; inline]
fn plain_name_may_be_reserved(name string) bool

plain_name_may_be_reserved is false only for a name that is neither a reserved word nor a libc collision; a clear filter bit proves that with one scan of the name instead of three table probes.

fn sanitize #

@[direct_array_access]
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 sum_field_name #

fn sum_field_name(variant string) string

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*.

fn word_name_needs_internal_namespace #

@[inline]
fn word_name_needs_internal_namespace(name string) bool

word_name_needs_internal_namespace is c_name_needs_internal_namespace for a name of letters, digits, _ and . only: such a name contains no static method marker and does not end in an operator, which leaves the internal prefix.