fn find_membertype<'a>(
    typeinfo: &'a TypeInfo,
    components: &[&str],
    component_index: usize,
    address: u64
) -> Result<(u64, &'a TypeInfo), String> {
    if component_index >= components.len() {
        Ok((address, typeinfo))
    } else {
        match typeinfo {
            TypeInfo::Class { members, .. } |
            TypeInfo::Struct { members, .. } |
            TypeInfo::Union { members, .. } => {
                if let Some((membertype, offset)) = members.get(components[component_index]) {
                    find_membertype(
                        membertype,
                        components,
                        component_index + 1,
                        address + offset
                    )
                } else {
                    Err(format!("There is no member \"{}\" in \"{}\"",
                        components[component_index],
                        components[..component_index].join(".")
                    ))
                }
            }
            TypeInfo::Array { dim, stride, arraytype, .. } => {
                let mut multi_index = 0;
                for (idx_pos, current_dim) in dim.iter().enumerate() {
                    let arraycomponent = components.get(component_index + idx_pos)
                        .unwrap_or(&"_0_"); // default to first element if no more components are specified
                    let indexval = get_index(arraycomponent)
                        .ok_or_else(|| format!("could not interpret \"{}\" as an array index", arraycomponent))?;
                    if indexval >= *current_dim as usize {
                        return Err(format!("requested array index {} in expression \"{}\", but the array only has {} elements",
                            indexval, components.join("."), current_dim));
                    }
                    multi_index = multi_index * (*current_dim) as usize + indexval;
                }

                let elementaddr = address + (multi_index as u64 * stride);
                find_membertype(
                    arraytype,
                    components,
                    component_index + dim.len(),
                    elementaddr
                )
            }
            _ => {
                if component_index >= components.len() {
                    Ok((address, typeinfo))
                } else {
                    // could not descend further to match additional symbol name components
                    Err(format!("Remaining portion \"{}\" of \"{}\" could not be matched",
                        components[component_index..].join("."),
                        components.join(".")
                    ))
                }
            }
        }
    }
}
// find the address and type of the current component of a symbol name
find the address and type of the current component of a symbol name
find the address and type of the current component of a symbol name
fn find_membertype<'a>(
    typeinfo: &'a TypeInfo,
    components: &[&str],
    component_index: usize,
    address: u64
) -> Result<(u64, &'a TypeInfo), String> {
    if component_index >= components.len() {
        Ok((address, typeinfo))
    } else {
        match typeinfo {
            TypeInfo::Class { members, .. } |
            TypeInfo::Struct { members, .. } |
            TypeInfo::Union { members, .. } => {
                if let Some((membertype, offset)) = members.get(components[component_index]) {
                    find_membertype(
                        membertype,
                        components,
                        component_index + 1,
                        address + offset
                    )
                } else {
                    Err(format!("There is no member \"{}\" in \"{}\"",
                        components[component_index],
                        components[..component_index].join(".")
                    ))
                }
            }
            TypeInfo::Array { dim, stride, arraytype, .. } => {
                let mut multi_index = 0;
                for (idx_pos, current_dim) in dim.iter().enumerate() {
                    let arraycomponent = components.get(component_index + idx_pos)
                        .unwrap_or(&"_0_"); // default to first element if no more components are specified
                    let indexval = get_index(arraycomponent)
                        .ok_or_else(|| format!("could not interpret \"{}\" as an array index", arraycomponent))?;
                    if indexval >= *current_dim as usize {
                        return Err(format!("requested array index {} in expression \"{}\", but the array only has {} elements",
                            indexval, components.join("."), current_dim));
                    }
                    multi_index = multi_index * (*current_dim) as usize + indexval;
                }
                let elementaddr = address + (multi_index as u64 * stride);
                find_membertype(
                    arraytype,
                    components,
                    component_index + dim.len(),
                    elementaddr
                )
            }
            _ => {
                if component_index >= components.len() {
                    Ok((address, typeinfo))
                } else {
                    // could not descend further to match additional symbol name components
                    Err(format!("Remaining portion \"{}\" of \"{}\" could not be matched",
                        components[component_index..].join("."),
                        components.join(".")
                    ))
                }
            }
        }
    }
}
fn find_membertype < ' a > ( typeinfo : & ' a TypeInfo , components : & [ & str ] , component_index : usize , address : u64 ) -> Result < ( u64 , & ' a TypeInfo ) , String > { if component_index >= components . len ( ) { Ok ( ( address , typeinfo ) ) } else { match typeinfo { TypeInfo :: Class { members , .. } | TypeInfo :: Struct { members , .. } | TypeInfo :: Union { members , .. } => { if let Some ( ( membertype , offset ) ) = members . get ( components [ component_index ] ) { find_membertype ( membertype , components , component_index + 1 , address + offset ) } else { Err ( format ! ( " \" \" \" \" " components [ component_index ] components [ component_index ] join ( " " ) ) ) } } TypeInfo :: Array { dim , stride , arraytype , .. } => { let mut multi_index = 0 ; for ( idx_pos , current_dim ) in dim . iter ( ) . enumerate ( ) { let arraycomponent = components . get ( component_index + idx_pos ) . unwrap_or ( & " " ) ; // default to first element if no more components are specified let indexval = get_index ( arraycomponent ) . ok_or_else ( | | format ! ( " \" \" " arraycomponent ) ) ? ; if indexval >= * current_dim as usize { return Err ( format ! ( " \" \" " indexval components join ( " " ) current_dim ) ) ; } multi_index = multi_index * ( * current_dim ) as usize + indexval ; } let elementaddr = address + ( multi_index as u64 * stride ) ; find_membertype ( arraytype , components , component_index + dim . len ( ) , elementaddr ) } _ => { if component_index >= components . len ( ) { Ok ( ( address , typeinfo ) ) } else { // could not descend further to match additional symbol name components Err ( format ! ( " \" \" \" \" " components [ component_index ] join ( " " ) components join ( " " ) ) ) } } } } }
find the address and type of the current component of a symbol name
find the address and type of the current component of a symbol name
typeinfo
&'a TypeInfo
components
&[&str]
component_index
usize
address
u64