Skip to content

Commit b427553

Browse files
committed
Updated support for C function pointers so raylib header works again
1 parent 5459b97 commit b427553

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Diff for: src/asg/datatype/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ impl Type {
4545
TypeKind::AnonymousUnion() => todo!("strip_constraints for anonymous union"),
4646
TypeKind::AnonymousEnum(_) => (),
4747
TypeKind::FixedArray(fixed_array) => fixed_array.inner.strip_constraints(),
48-
TypeKind::FuncPtr(_) => todo!("strip_constraints for function pointer"),
48+
TypeKind::FuncPtr(func) => {
49+
for param in func.params.required.iter_mut() {
50+
param.ty.strip_constraints();
51+
}
52+
func.return_type.strip_constraints();
53+
}
4954
TypeKind::Enum(_, _) => (),
5055
TypeKind::Structure(_, _, parameters) => {
5156
for parameter in parameters {

Diff for: src/resolve/polymorph/resolver.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,32 @@ impl<'a> PolyRecipeResolver<'a> {
6969
}))
7070
.at(ty.source)
7171
}
72-
asg::TypeKind::FuncPtr(_) => todo!(),
72+
asg::TypeKind::FuncPtr(func) => {
73+
let required = func
74+
.params
75+
.required
76+
.iter()
77+
.map(|param| {
78+
self.resolve_type(&param.ty).and_then(|ty| {
79+
Ok(asg::Param {
80+
name: param.name.clone(),
81+
ty,
82+
})
83+
})
84+
})
85+
.collect::<Result<Vec<_>, _>>()?;
86+
87+
let return_type = self.resolve_type(&func.return_type)?;
88+
89+
asg::TypeKind::FuncPtr(asg::FuncPtr {
90+
params: asg::Params {
91+
required,
92+
is_cstyle_vararg: func.params.is_cstyle_vararg,
93+
},
94+
return_type: Box::new(return_type),
95+
})
96+
.at(ty.source)
97+
}
7398
asg::TypeKind::Enum(_, _) => ty.clone(),
7499
asg::TypeKind::Structure(human_name, struct_ref, poly_args) => {
75100
let args = poly_args

0 commit comments

Comments
 (0)