/// Returns the generated operand decoding methods for binary::Decoder by
/// walking the given SPIR-V operand kinds `grammar.
Returns the generated operand decoding methods for binary::Decoder by
walking the given SPIR-V operand kinds `grammar.
Returns the generated operand decoding methods for binary :: Decoder by walking the given SPIR - V operand kinds ` grammar .
pub fn gen_operand_decode_methods(grammar: &[structs::OperandKind]) -> TokenStream {
    let methods = grammar.iter().filter(|element| {
        // For kinds whose values may occupy more than one word, we need to
        // implement manually.
        !(element.kind.starts_with("Pair") ||
          element.kind.starts_with("Id") ||
          element.kind.starts_with("Literal"))
    }).map(|element| {
        // Method definition for decoding values of a particular operand
        // kind. If the operand kind belongs to BitEnum, we use from_bits(),
        // otherwise, from_u32().
        let kind = as_ident(&element.kind);
        let comment = format!("Decodes and returns the next SPIR-V word as\na SPIR-V {} value.", kind);
        let function_name = as_ident(&element.kind.to_snake_case());
        let convert = as_ident(&format!("from_{}", if element.category == structs::Category::BitEnum { "bits" } else { "u32" }));
        let error_name = as_ident(&format!("{}Unknown", kind));
        quote! {
            #[doc = #comment]
            pub fn #function_name(&mut self) -> Result<spirv::#kind> {
                if let Ok(word) = self.word() {
                    spirv::#kind::#convert(word).ok_or(Error::#error_name(self.offset - WORD_NUM_BYTES, word))
                } else {
                    Err(Error::StreamExpected(self.offset))
                }
            }
        }
    });
    quote! {
        impl<'a> Decoder<'a> {
            #(#methods)*
        }
    }
}
pub fn gen_operand_decode_methods ( grammar : & [ structs :: OperandKind ] ) -> TokenStream { let methods = grammar . iter ( ) . filter ( | element | { // For kinds whose values may occupy more than one word, we need to // implement manually. ! ( element . kind . starts_with ( " " ) || element . kind . starts_with ( " " ) || element . kind . starts_with ( " " ) ) } ) . map ( | element | { // Method definition for decoding values of a particular operand // kind. If the operand kind belongs to BitEnum, we use from_bits(), // otherwise, from_u32(). let kind = as_ident ( & element . kind ) ; let comment = format ! ( " \n " kind ) ; let function_name = as_ident ( & element . kind . to_snake_case ( ) ) ; let convert = as_ident ( & format ! ( " " if element category structs Category BitEnum { " " } else { " " } ) ) ; let error_name = as_ident ( & format ! ( " " kind ) ) ; quote ! { [ doc comment ] pub fn function_name ( mut self ) Result spirv kind { if let Ok ( word ) self word ( ) { spirv kind convert ( word ) ok_or ( Error error_name ( self offset WORD_NUM_BYTES word ) ) } else { Err ( Error StreamExpected ( self offset ) ) } } } } ) ; quote ! { impl ' a Decoder ' a { ( methods ) } } }
Returns the generated operand decoding methods for binary::Decoder by
walking the given SPIR-V operand kinds `grammar.
Returns the generated operand decoding methods for binary :: Decoder by walking the given SPIR - V operand kinds ` grammar .
grammar
&[structs::OperandKind]