in src/bindgen/cdecl.rs [109:193]
fn build_type(&mut self, t: &Type, is_const: bool, config: &Config) {
match t {
Type::Path(ref generic) => {
if is_const {
assert!(
self.type_qualifers.is_empty(),
"error generating cdecl for {:?}",
t
);
"const".clone_into(&mut self.type_qualifers);
}
assert!(
self.type_name.is_empty(),
"error generating cdecl for {:?}",
t
);
generic.export_name().clone_into(&mut self.type_name);
assert!(
self.type_generic_args.is_empty(),
"error generating cdecl for {:?}",
t
);
generic.generics().clone_into(&mut self.type_generic_args);
self.type_ctype = generic.ctype().cloned();
}
Type::Primitive(ref p) => {
if is_const {
assert!(
self.type_qualifers.is_empty(),
"error generating cdecl for {:?}",
t
);
"const".clone_into(&mut self.type_qualifers);
}
assert!(
self.type_name.is_empty(),
"error generating cdecl for {:?}",
t
);
self.type_name = p.to_repr_c(config).to_string();
}
Type::Ptr {
ref ty,
is_nullable,
is_const: ptr_is_const,
is_ref,
} => {
self.declarators.push(CDeclarator::Ptr {
is_const,
is_nullable: *is_nullable,
is_ref: *is_ref,
});
self.build_type(ty, *ptr_is_const, config);
}
Type::Array(ref t, ref constant) => {
let len = constant.as_str().to_owned();
self.declarators.push(CDeclarator::Array(len));
self.build_type(t, is_const, config);
}
Type::FuncPtr {
ref ret,
ref args,
is_nullable: _,
never_return,
} => {
let args = args
.iter()
.map(|(ref name, ref ty)| (name.clone(), CDecl::from_type(ty, config)))
.collect();
self.declarators.push(CDeclarator::Ptr {
is_const: false,
is_nullable: true,
is_ref: false,
});
self.declarators.push(CDeclarator::Func {
args,
layout: config.function.args,
never_return: *never_return,
});
self.build_type(ret, false, config);
}
}
}