use sigmd::model::Parameter;
use super::{BuildContext, Error, clang, sal, ty::build_type};
pub fn build_parameter(
cursor: clang::Entity<'_>,
ctx: &BuildContext,
) -> Result<BuildParameter, Error> {
let name = cursor.get_name();
let ty = build_type(cursor.get_type().expect("entity has type"), ctx);
let mut annotations = Vec::new();
for child in cursor.get_children() {
if child.get_kind() == clang::EntityKind::AnnotateAttr
&& let Some(child_name) = child.get_name()
{
annotations.push(child_name);
}
}
let flags = sal::flags(&sal::decode(&annotations));
let parameter = Parameter::builder()
.maybe_name(name)
.flags(flags)
.ty(ty)
.build();
Ok(BuildParameter {
parameter,
annotations,
is_invalid: cursor.is_invalid_declaration(),
})
}
pub struct BuildParameter {
pub parameter: Parameter,
pub annotations: Vec<String>,
pub is_invalid: bool,
}