pub fn gen_operand_parse_methods(grammar: &[structs::OperandKind]) -> TokenStream {
    // Operand kinds whose enumerants have parameters. For these kinds, we need
    // to decode more than just the enumerants themselves.
    let (further_parse_kinds, further_parse_methods): (Vec<_>, Vec<_>) =
        gen_operand_param_parse_methods(grammar).into_iter().unzip();
    let further_parse_cases = further_parse_kinds.iter().map(|kind| {
        let function_name = as_ident(&format!("parse_{}_arguments", kind.to_snake_case()));
        let decode = get_decode_method(kind);
        let kind = as_ident(kind);
        quote! {
            GOpKind::#kind => {
                let val = self.decoder.#decode()?;
                let mut ops = vec![dr::Operand::#kind(val)];
                ops.append(&mut self.#function_name(val)?);
                ops
            }
        }
    });

    // Logic operands that expand to concrete operand pairs,
    // that is, those operand kinds with 'Pair' name prefix.
    // We only have two cases. So hard code it.
    let pair_kinds = vec![("IdRef", "LiteralInteger"), ("IdRef", "IdRef")];
    let pair_cases = pair_kinds.iter().map(|&(k0, k1)| {
        let kind = as_ident(&format!("Pair{}{}", k0, k1));
        let kind0 = get_dr_operand_kind(k0);
        let kind1 = get_dr_operand_kind(k1);
        let method0 = get_decode_method(k0);
        let method1 = get_decode_method(k1);
        quote! {
            GOpKind::#kind => vec![
                dr::Operand::#kind0(self.decoder.#method0()?),
                dr::Operand::#kind1(self.decoder.#method1()?),
            ]
        }
    });

    // These kinds are manually handled.
    let manual_kinds = vec![
        "IdResultType",
        "IdResult",
        "LiteralContextDependentNumber",
        "LiteralSpecConstantOpInteger",
        "PairLiteralIntegerIdRef",
    ];

    // For the rest operand kinds, which takes exactly one word.
    let normal_cases = grammar
        .iter()
        .filter_map(|element| {
            if further_parse_kinds.contains(&element.kind.as_str())
                || manual_kinds.contains(&element.kind.as_str())
                || element.kind.starts_with("Pair")
            {
                None
            } else {
                Some(element.kind.as_str())
            }
        })
        .map(|kind| {
            let gkind = as_ident(kind);
            let dkind = get_dr_operand_kind(kind);
            let decode = get_decode_method(kind);
            quote! {
                GOpKind::#gkind => vec![dr::Operand::#dkind(self.decoder.#decode()?)]
            }
        });

    let manual_cases = manual_kinds.iter().map(|kind| {
        let kind = as_ident(kind);
        quote! {
            GOpKind::#kind => panic!() // not handled here
        }
    });

    quote! {
        impl<'c, 'd> Parser<'c, 'd> {
            fn parse_operand(&mut self, kind: GOpKind) -> Result<Vec<dr::Operand>> {
                Ok(match kind {
                    #(#normal_cases),*,
                    #(#pair_cases),*,
                    #(#further_parse_cases),*,
                    #(#manual_cases),*,
                })
            }
            #(#further_parse_methods)*
        }
    }
}
/// Returns the generated operand parsing methods for binary::Parser by
/// walking the given SPIR-V operand kinds `grammar`.
Returns the generated operand parsing methods for binary::Parser by
walking the given SPIR-V operand kinds `grammar`.
Returns the generated operand parsing methods for binary :: Parser by walking the given SPIR - V operand kinds ` grammar ` .
pub fn gen_operand_parse_methods(grammar: &[structs::OperandKind]) -> TokenStream {
    // Operand kinds whose enumerants have parameters. For these kinds, we need
    // to decode more than just the enumerants themselves.
    let (further_parse_kinds, further_parse_methods): (Vec<_>, Vec<_>) =
        gen_operand_param_parse_methods(grammar).into_iter().unzip();
    let further_parse_cases = further_parse_kinds.iter().map(|kind| {
        let function_name = as_ident(&format!("parse_{}_arguments", kind.to_snake_case()));
        let decode = get_decode_method(kind);
        let kind = as_ident(kind);
        quote! {
            GOpKind::#kind => {
                let val = self.decoder.#decode()?;
                let mut ops = vec![dr::Operand::#kind(val)];
                ops.append(&mut self.#function_name(val)?);
                ops
            }
        }
    });
    // Logic operands that expand to concrete operand pairs,
    // that is, those operand kinds with 'Pair' name prefix.
    // We only have two cases. So hard code it.
    let pair_kinds = vec![("IdRef", "LiteralInteger"), ("IdRef", "IdRef")];
    let pair_cases = pair_kinds.iter().map(|&(k0, k1)| {
        let kind = as_ident(&format!("Pair{}{}", k0, k1));
        let kind0 = get_dr_operand_kind(k0);
        let kind1 = get_dr_operand_kind(k1);
        let method0 = get_decode_method(k0);
        let method1 = get_decode_method(k1);
        quote! {
            GOpKind::#kind => vec![
                dr::Operand::#kind0(self.decoder.#method0()?),
                dr::Operand::#kind1(self.decoder.#method1()?),
            ]
        }
    });
    // These kinds are manually handled.
    let manual_kinds = vec![
        "IdResultType",
        "IdResult",
        "LiteralContextDependentNumber",
        "LiteralSpecConstantOpInteger",
        "PairLiteralIntegerIdRef",
    ];
    // For the rest operand kinds, which takes exactly one word.
    let normal_cases = grammar
        .iter()
        .filter_map(|element| {
            if further_parse_kinds.contains(&element.kind.as_str())
                || manual_kinds.contains(&element.kind.as_str())
                || element.kind.starts_with("Pair")
            {
                None
            } else {
                Some(element.kind.as_str())
            }
        })
        .map(|kind| {
            let gkind = as_ident(kind);
            let dkind = get_dr_operand_kind(kind);
            let decode = get_decode_method(kind);
            quote! {
                GOpKind::#gkind => vec![dr::Operand::#dkind(self.decoder.#decode()?)]
            }
        });
    let manual_cases = manual_kinds.iter().map(|kind| {
        let kind = as_ident(kind);
        quote! {
            GOpKind::#kind => panic!() // not handled here
        }
    });
    quote! {
        impl<'c, 'd> Parser<'c, 'd> {
            fn parse_operand(&mut self, kind: GOpKind) -> Result<Vec<dr::Operand>> {
                Ok(match kind {
                    #(#normal_cases),*,
                    #(#pair_cases),*,
                    #(#further_parse_cases),*,
                    #(#manual_cases),*,
                })
            }
            #(#further_parse_methods)*
        }
    }
}
pub fn gen_operand_parse_methods ( grammar : & [ structs :: OperandKind ] ) -> TokenStream { // Operand kinds whose enumerants have parameters. For these kinds, we need // to decode more than just the enumerants themselves. let ( further_parse_kinds , further_parse_methods ) : ( Vec < _ > , Vec < _ > ) = gen_operand_param_parse_methods ( grammar ) . into_iter ( ) . unzip ( ) ; let further_parse_cases = further_parse_kinds . iter ( ) . map ( | kind | { let function_name = as_ident ( & format ! ( " " kind to_snake_case ( ) ) ) ; let decode = get_decode_method ( kind ) ; let kind = as_ident ( kind ) ; quote ! { GOpKind kind { let val self decoder decode ( ) let mut ops vec [ dr Operand kind ( val ) ] ops append ( mut self function_name ( val ) ) ops } } } ) ; // Logic operands that expand to concrete operand pairs, // that is, those operand kinds with 'Pair' name prefix. // We only have two cases. So hard code it. let pair_kinds = vec ! [ ( " " " " ) ( " " " " ) ] ; let pair_cases = pair_kinds . iter ( ) . map ( | & ( k0 , k1 ) | { let kind = as_ident ( & format ! ( " " k0 k1 ) ) ; let kind0 = get_dr_operand_kind ( k0 ) ; let kind1 = get_dr_operand_kind ( k1 ) ; let method0 = get_decode_method ( k0 ) ; let method1 = get_decode_method ( k1 ) ; quote ! { GOpKind kind vec [ dr Operand kind0 ( self decoder method0 ( ) ) dr Operand kind1 ( self decoder method1 ( ) ) ] } } ) ; // These kinds are manually handled. let manual_kinds = vec ! [ " " " " " " " " " " ] ; // For the rest operand kinds, which takes exactly one word. let normal_cases = grammar . iter ( ) . filter_map ( | element | { if further_parse_kinds . contains ( & element . kind . as_str ( ) ) || manual_kinds . contains ( & element . kind . as_str ( ) ) || element . kind . starts_with ( " " ) { None } else { Some ( element . kind . as_str ( ) ) } } ) . map ( | kind | { let gkind = as_ident ( kind ) ; let dkind = get_dr_operand_kind ( kind ) ; let decode = get_decode_method ( kind ) ; quote ! { GOpKind gkind vec [ dr Operand dkind ( self decoder decode ( ) ) ] } } ) ; let manual_cases = manual_kinds . iter ( ) . map ( | kind | { let kind = as_ident ( kind ) ; quote ! { GOpKind kind panic ( ) // not handled here } } ) ; quote ! { impl ' c ' d Parser ' c ' d { fn parse_operand ( mut self kind GOpKind ) Result Vec dr Operand { Ok ( match kind { ( normal_cases ) ( pair_cases ) ( further_parse_cases ) ( manual_cases ) } ) } ( further_parse_methods ) } } }
Returns the generated operand parsing methods for binary::Parser by
walking the given SPIR-V operand kinds `grammar`.
Returns the generated operand parsing methods for binary :: Parser by walking the given SPIR - V operand kinds ` grammar ` .
grammar
&[structs::OperandKind]
grammar
&[structs::OperandKind]