use xur_ast::Attribute;
use xur_resolve::{DefId, RtType};
use xur_span::Symbol;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeRef {
pub name: String,
pub def: Option<DefId>,
}
impl TypeRef {
pub fn named(name: impl Into<String>) -> Self {
Self {
name: name.into(),
def: None,
}
}
pub fn record() -> Self {
Self {
name: "@".to_owned(),
def: None,
}
}
pub fn is_record(&self) -> bool {
self.name == "@" && self.def.is_none()
}
}
#[derive(Debug, Clone)]
pub struct AdtInfo {
pub name: String,
pub ctor: DefId,
pub is_variant: bool,
pub attrs: &'static [Attribute],
pub fields: Vec<FieldInfo>,
}
#[derive(Debug, Clone)]
pub struct FieldInfo {
pub name: Option<Symbol>,
pub ty: TypeRef,
pub attrs: &'static [Attribute],
}
impl AdtInfo {
pub fn field_names(&self) -> Vec<String> {
self.fields
.iter()
.enumerate()
.map(|(index, field)| match field.name {
Some(name) => name.to_string(),
None => index.to_string(),
})
.collect()
}
}
#[derive(Debug, Clone)]
pub struct FnInfo {
pub name: String,
pub param_count: usize,
pub param_names: Vec<Option<String>>,
pub param_types: Vec<Option<RtType>>,
pub return_type: Option<RtType>,
}