Skip to main content

desugared_string_method

Function desugared_string_method 

Source
pub fn desugared_string_method<'a>(
    call_node: &'a AIRNode,
    callee: &'a AIRNode,
    args: &'a [AirArg],
) -> Option<(&'a AIRNode, &'a str, &'a [AirArg])>
Expand description

Recognise a desugared String built-in method call.

Building on desugared_self_call, this additionally requires that (a) the call_node carries the checker’s recv_kind = "Primitive:String" annotation and (b) the method is one of STRING_METHODS. Returns the receiver node, the method name, and the remaining (non-self) arguments — everything a backend needs to lower the call to the target’s native string op (s.toUpperCase() / s.upper() / s.to_uppercase() / strings.ToUpper(s), [...s].length / len(s) / s.chars().count() / utf8.RuneCountInString(s), …). Each backend wires this into its Call arm before desugared_list_method so a String receiver’s len/contains no longer hits the List path (the Go []interface{} scan).

call_node is the full Call AIR node (it holds the annotation); callee and args are its callee/args fields, passed separately so a backend can call this from inside its NodeKind::Call { callee, args, .. } arm.