1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use super::{fields, ns};
use crate::options;
use lib_ruby_parser_nodes::NodeWithField;

/// Returns name of the node field getter for the given `node`/`field` pair
pub fn name(node: &NodeWithField) -> String {
    format!(
        "{ns}__{lower}__get_{field_name}",
        ns = ns(),
        lower = node.node.lower_name(),
        field_name = node.field.snakecase_name,
    )
}

/// Returns C signature of the node field getter for the given `node`/`field` pair
pub fn sig(node: &NodeWithField) -> String {
    format!(
        "{return_type} *{fn_attributes} {getter_name}({node_variant_blob} *self_blob)",
        return_type = fields::field_type(&node.field),
        fn_attributes = options().fn_attributes,
        getter_name = name(node),
        node_variant_blob = options().node_variant_blob_name(&node.node)
    )
}