MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / gen_iterator

Function gen_iterator

cranelift/codegen/meta/src/gen_settings.rs:54–72  ·  view source on GitHub ↗

Generates the `iter` function.

(group: &SettingGroup, fmt: &mut Formatter)

Source from the content-addressed store, hash-verified

52
53/// Generates the `iter` function.
54fn gen_iterator(group: &SettingGroup, fmt: &mut Formatter) {
55 fmt.add_block("impl Flags",|fmt| {
56 fmt.doc_comment("Iterates the setting values.");
57 fmt.add_block("pub fn iter(&self) -> impl Iterator<Item = Value> + use<>",|fmt| {
58 fmtln!(fmt, "let mut bytes = [0; {}];", group.settings_size);
59 fmtln!(fmt, "bytes.copy_from_slice(&self.bytes[0..{}]);", group.settings_size);
60 fmt.add_block("DESCRIPTORS.iter().filter_map(move |d|", |fmt| {
61 fmt.add_block("let values = match &d.detail", |fmt| {
62 fmtln!(fmt, "detail::Detail::Preset => return None,");
63 fmtln!(fmt, "detail::Detail::Enum {{ last, enumerators }} => Some(TEMPLATE.enums(*last, *enumerators)),");
64 fmtln!(fmt, "_ => None");
65 });
66 fmtln!(fmt, ";");
67 fmtln!(fmt, "Some(Value {{ name: d.name, detail: d.detail, values, value: bytes[d.offset as usize] }})");
68 });
69 fmtln!(fmt, ")");
70 });
71 });
72}
73
74/// Generates a `all()` function with all options for this enum
75fn gen_enum_all(name: &str, values: &[&'static str], fmt: &mut Formatter) {

Callers 1

gen_groupFunction · 0.85

Calls 2

doc_commentMethod · 0.80
add_blockMethod · 0.45

Tested by

no test coverage detected