fn from_parsed(annotation: ParsedAnnotation, decl: CDecl) -> ComposerResult<Self> {

        debug!("parsed annotation: {:?}, decl: {}", annotation, decl);

        if annotation.parameters.len() != decl.arguments.len() {
            return composer_err!("Number of annotation types must equal number of args in declaration.");
        }

        if annotation.return_type.is_none() && decl.return_type != "void" {
            return composer_err!("Annotation over function with non-void return type must have return type in annotation.");
        }

        if annotation.return_type.is_some() && decl.return_type == "void" {
            return composer_err!("Annotation over function with void return type cannot have return type in annotation.");
        }

        // Extract the parameter names.
        let mut annotation_param_names: Vec<_> = annotation.parameters.iter()
            .map(|param| param.name.as_str())
            .collect();

        // Make sure the parameter names are unique.
        let length = annotation_param_names.len();
        annotation_param_names.dedup();

        if length != annotation_param_names.len() {
            return composer_err!("Parameter names in annotation must be unique.");
        }

        // The final result is reversed (so the arguments for the first split type appear last in
        // the list), so we can pop off elements in O(1) time in the following step.
        let mut arguments: Vec<_> = annotation.parameters.iter()
            .map(|param| args_to_positions(&annotation_param_names, &param.ty))
            .rev()
            .collect::<Result<_>>()?;

        let return_param = if let Some(ref return_type) = annotation.return_type {
            Some(SplitTypeParameter {
                arguments: args_to_positions(&annotation_param_names, return_type)?.unwrap_or(vec![]),
                ty: return_type.clone().into()
            })
        } else {
            None
        };

        // Construct the split type parameter.
        //
        // We first construct each split type, and then add it to a parameter.  We use the argument
        // indices constructed in the previous step.
        let parameters: Vec<_> = annotation.parameters.into_iter()
            .map(|param| param.ty)
            .map(|ty| ty.into())
            .map(|ty| SplitTypeParameter {
                ty: ty,
                arguments: arguments.pop().unwrap().unwrap_or(vec![]),
            })
            .collect();


        let annotation = Annotation {
            function: decl,
            return_param: return_param,
            params: parameters,
            defaults: HashMap::new(),
        };
        debug!("annotation: {:?}", annotation);
        Ok(annotation)
    }
/// Converts a single parsed annotation and single C declaration into `Self`.
Converts a single parsed annotation and single C declaration into `Self`.
Converts a single parsed annotation and single C declaration into ` Self ` .
fn from_parsed(annotation: ParsedAnnotation, decl: CDecl) -> ComposerResult<Self> {
        debug!("parsed annotation: {:?}, decl: {}", annotation, decl);
        if annotation.parameters.len() != decl.arguments.len() {
            return composer_err!("Number of annotation types must equal number of args in declaration.");
        }
        if annotation.return_type.is_none() && decl.return_type != "void" {
            return composer_err!("Annotation over function with non-void return type must have return type in annotation.");
        }
        if annotation.return_type.is_some() && decl.return_type == "void" {
            return composer_err!("Annotation over function with void return type cannot have return type in annotation.");
        }
        // Extract the parameter names.
        let mut annotation_param_names: Vec<_> = annotation.parameters.iter()
            .map(|param| param.name.as_str())
            .collect();
        // Make sure the parameter names are unique.
        let length = annotation_param_names.len();
        annotation_param_names.dedup();
        if length != annotation_param_names.len() {
            return composer_err!("Parameter names in annotation must be unique.");
        }
        // The final result is reversed (so the arguments for the first split type appear last in
        // the list), so we can pop off elements in O(1) time in the following step.
        let mut arguments: Vec<_> = annotation.parameters.iter()
            .map(|param| args_to_positions(&annotation_param_names, &param.ty))
            .rev()
            .collect::<Result<_>>()?;
        let return_param = if let Some(ref return_type) = annotation.return_type {
            Some(SplitTypeParameter {
                arguments: args_to_positions(&annotation_param_names, return_type)?.unwrap_or(vec![]),
                ty: return_type.clone().into()
            })
        } else {
            None
        };
        // Construct the split type parameter.
        //
        // We first construct each split type, and then add it to a parameter.  We use the argument
        // indices constructed in the previous step.
        let parameters: Vec<_> = annotation.parameters.into_iter()
            .map(|param| param.ty)
            .map(|ty| ty.into())
            .map(|ty| SplitTypeParameter {
                ty: ty,
                arguments: arguments.pop().unwrap().unwrap_or(vec![]),
            })
            .collect();
        let annotation = Annotation {
            function: decl,
            return_param: return_param,
            params: parameters,
            defaults: HashMap::new(),
        };
        debug!("annotation: {:?}", annotation);
        Ok(annotation)
    }
fn from_parsed ( annotation : ParsedAnnotation , decl : CDecl ) -> ComposerResult < Self > { debug ! ( " " annotation decl ) ; if annotation . parameters . len ( ) != decl . arguments . len ( ) { return composer_err ! ( " " ) ; } if annotation . return_type . is_none ( ) && decl . return_type != " " { return composer_err ! ( " " ) ; } if annotation . return_type . is_some ( ) && decl . return_type == " " { return composer_err ! ( " " ) ; } // Extract the parameter names. let mut annotation_param_names : Vec < _ > = annotation . parameters . iter ( ) . map ( | param | param . name . as_str ( ) ) . collect ( ) ; // Make sure the parameter names are unique. let length = annotation_param_names . len ( ) ; annotation_param_names . dedup ( ) ; if length != annotation_param_names . len ( ) { return composer_err ! ( " " ) ; } // The final result is reversed (so the arguments for the first split type appear last in // the list), so we can pop off elements in O(1) time in the following step. let mut arguments : Vec < _ > = annotation . parameters . iter ( ) . map ( | param | args_to_positions ( & annotation_param_names , & param . ty ) ) . rev ( ) . collect :: < Result < _ > > ( ) ? ; let return_param = if let Some ( ref return_type ) = annotation . return_type { Some ( SplitTypeParameter { arguments : args_to_positions ( & annotation_param_names , return_type ) ? . unwrap_or ( vec ! [ ] ) , ty : return_type . clone ( ) . into ( ) } ) } else { None } ; // Construct the split type parameter. // // We first construct each split type, and then add it to a parameter.  We use the argument // indices constructed in the previous step. let parameters : Vec < _ > = annotation . parameters . into_iter ( ) . map ( | param | param . ty ) . map ( | ty | ty . into ( ) ) . map ( | ty | SplitTypeParameter { ty : ty , arguments : arguments . pop ( ) . unwrap ( ) . unwrap_or ( vec ! [ ] ) , } ) . collect ( ) ; let annotation = Annotation { function : decl , return_param : return_param , params : parameters , defaults : HashMap :: new ( ) , } ; debug ! ( " " annotation ) ; Ok ( annotation ) }
Converts a single parsed annotation and single C declaration into `Self`.
Converts a single parsed annotation and single C declaration into ` Self ` .
annotation
ParsedAnnotation
decl
CDecl